Reputation: 5
I need to make a GET invocation to a REST WS with a query string, the uri has to be like this:
http://somehost.com/someservice?parm1=value
I need to assign the value of the parameter "parm1" of the body (a normal pojo with getters and setters), so this is the camel route:
<setHeader headerName = "Exchange.HTTP_QUERY" id = "queryStringSomeService">
<simple>parm1=${body.someField}</simple>
</setHeader>
<setHeader headerName = "CamelHttpMethod" id = "httpMethodSomeService">
<constant>GET</constant>
</setHeader>
<to id="SOME_SERVICE" uri="http4:/somehost.com/someservice?bridgeEndpoint=true" />
The problem is that the query string was never added to the uri, and the http method finally used its POST, although I added the header to explicitly set GET.
I have using Spring DSL.
In the page http://camel.apache.org/http4.html of the documentation, the rules to select the HTTP method are established; in the "Calling using GET or POST" section, but apparently they are not being applied in this case.
Update:
Setting the body to null resolve the problem of changing the HTTP method to GET, although in the documentation says that you override that with the CamelHttpMethod header.
But for the query string, I have tried all the variants; with Exchange.HTTP_URI and with Exchange.HTTP_QUERY, none of then worked
This are the exchange headers before the WS invocation:
Accept: application/json
CamelHttpCharacterEncoding: ISO-8859-1
CamelHttpMethod: GET
CamelHttpQuery: ?parm1=value
CamelHttpResponseCode: 200
CamelHttpResponseText: OK
CamelHttpUri: /someservice
CamelHttpUrl: http://somehost/someservice
CamelRedelivered: false
CamelRedeliveryCounter: 0
Connection: close
Content-Type: application/json;charset=UTF-8
Date: Fri, 14 Sep 2018 16:08:19 GMT
Last-Modified: Thu, 13 Sep 2018 13:33:30 GMT
Set-Cookie: JSESSIONID=YXQkEAUAjh0yWsu4UYwSG8vE.5aa71417-9e93-3be1-99ca-7b4ec1d6f2a0; Path=/ca_tar_tarjeta
Transfer-Encoding: chunked
breadcrumbId: ID-wildfly01-1536931422750-9-23
Upvotes: 1
Views: 1792
Reputation: 7005
Take care. In a Camel route, the Camel message body becomes normally the body of an outgoing message. This could be the reason Camel is using POST anyway: your HTTP request has a body. Try setting your Camel message body to null
before you send the HTTP request.
Not sure if this is correct, I always use Java routes:
<setBody>
<simple>${bodyAs(null)}</simple>
</setBody>
However, I don't know why the query string doesn't work.
Upvotes: 1