Content-Type is not supported in Camel DELETE method?

后端 未结 3 516
傲寒
傲寒 2021-01-26 15:59

How do i send content-type in Camel DELETE method. I have added the following way but It was not working correctly.

from(\"direct:start\")
.setHeader(Exchange.H         


        
相关标签:
3条回答
  • 2021-01-26 16:14

    As in a delete operation, no content is sent, the Exchange.CONTENT_TYPE property should not be needed.

    Please, try

    from("direct:start")
        .setHeader(Exchange.HTTP_METHOD, simple("DELETE"))
        .to("http://02.02.02.02:8080/rest/delete/student/688187");
    

    or

    from("direct:start")
        .to("restlet:http://02.02.02.02:8080/rest/delete/student/688187?restletMethod=delete");
    

    By the way, using delete in the URL is not the RESTful way and should be ommited.

    EDIT:

    Camel does not transfer the body to the request of a DELETE operation, as can be seen digging into the source code. Use a PUT operation instead. See my answer to your other SO.

    0 讨论(0)
  • 2021-01-26 16:21

    As this post mentions, camel can process body if request method is delete in HTTP method.

    Camel version 2.19.0 in http4 component with deleteWithBody option. We could just add it to the URL and use the http method as DELETE

    0 讨论(0)
  • 2021-01-26 16:35

    Content-type/body content is supported in apache camel through producer template with query param "deleteWithBody" by default it will be false.

    String endpoint = https://testuri.com/resource;
    endpoint = https://testuri.com/resource?deleteWithBody=true;
    Exchange exchange;
    exchange.getIn.setBody("test");
    exchange.getIn.setHeader("Content-Type","application/json");
    ProducerTemplate template = exchange.set(endpoint, exchange);
    
    0 讨论(0)
提交回复
热议问题