Hi, I'm facing the exact issue with an HTTP GET request. However it works
fine with an HTTP POST.
Camel version: 2.13.1
RESTFul services built with RESTEasy 2.3.6
Below are the logs for HTTP GET AND POST. *Enlightenment appreciated*.
*HTTP POST ---FAILS -- Content-Type header is lost*
The server responds with 415 as it wasn't able to find the Content-Type
header, its actually *null* when the request hits the server.
*JAVA DSL:*
from("timer:foo?period=1000").process(new
MessageProcessor()).to("http4://localhost:8080/cts-rest/cts/users").bean(
CamelBeanBinding.class,"invokeMethod7");
The *MessageProcessor *in the route adds the Headers shown below:
@Override
public void process(Exchange exchange) throws Exception {
Message message = exchange.getIn();
message.setHeader(HttpHeaders.ACCEPT,RestConstants.APPLICATION_OTHER_XML);
message.setHeader(HttpHeaders.ACCEPT_CHARSET, "utf-8");
message.setHeader("content-type",RestConstants.APPLICATION_OTHER_XML);
message.setHeader(HttpHeaders.ACCEPT_LANGUAGE, "en-US");
message.setHeader(Exchange.CONTENT_ENCODING, "gzip");
message.setHeader(Exchange.CONTENT_ENCODING, "deflate");
message.setHeader(Exchange.HTTP_METHOD,"GET");
message.setHeader(Exchange.HTTP_CHARACTER_ENCODING,"UTF-8");
exchange.setOut(message);
}
*See below-- there is not outgoing Content-Type header *
[Camel (camel-1) thread #0 - timer://foo] DEBUG
org.apache.http.client.protocol.RequestAddCookies - CookieSpec selected:
best-match
[Camel (camel-1) thread #0 - timer://foo] DEBUG
org.apache.http.client.protocol.RequestAuthCache - Auth cache not set in
the context
[Camel (camel-1) thread #0 - timer://foo] DEBUG
org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection
request: [route: {}->http://localhost:8080][total kept alive: 0; route
allocated: 0 of 20; total allocated: 0 of 200]
[Camel (camel-1) thread #0 - timer://foo] DEBUG
org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection
leased: [id: 0][route: {}->http://localhost:8080][total kept alive: 0; route
allocated: 1 of 20; total allocated: 1 of 200]
[Camel (camel-1) thread #0 - timer://foo] DEBUG
org.apache.http.impl.execchain.MainClientExec - Opening connection
{}->http://localhost:8080
[Camel (camel-1) thread #0 - timer://foo] DEBUG
org.apache.http.impl.conn.HttpClientConnectionOperator - Connecting to
localhost/127.0.0.1:8080
[Camel (camel-1) thread #0 - timer://foo] DEBUG
org.apache.http.impl.conn.HttpClientConnectionOperator - Connection
established 127.0.0.1:57328<->127.0.0.1:8080
[Camel (camel-1) thread #0 - timer://foo] DEBUG
org.apache.http.impl.execchain.MainClientExec - Executing request GET
/cts-rest/cts/users HTTP/1.1
[Camel (camel-1) thread #0 - timer://foo] DEBUG
org.apache.http.impl.execchain.MainClientExec - Target auth state:
UNCHALLENGED
[Camel (camel-1) thread #0 - timer://foo] DEBUG
org.apache.http.impl.execchain.MainClientExec - Proxy auth state:
UNCHALLENGED
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.headers -
http-outgoing-0 >> GET /cts-rest/cts/users HTTP/1.1
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.headers -
http-outgoing-0 >> Accept: application/*+xml
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.headers -
http-outgoing-0 >> firedTime: Thu Jun 26 09:02:02 EDT 2014
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.headers -
http-outgoing-0 >> Accept-Language: en-US
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.headers -
http-outgoing-0 >> Content-Encoding: deflate
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.headers -
http-outgoing-0 >> breadcrumbId: ID-sporeddy-57327-1403787720885-0-1
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.headers -
http-outgoing-0 >> Accept-Charset: utf-8
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.headers -
http-outgoing-0 >> Host: localhost:8080
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.headers -
http-outgoing-0 >> Connection: Keep-Alive
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.headers -
http-outgoing-0 >> User-Agent: Apache-HttpClient/4.3.3 (java 1.5)
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.headers -
http-outgoing-0 >> Accept-Encoding: gzip,deflate
*[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.wire -
http-outgoing-0 >> "GET /cts-rest/cts/users HTTP/1.1[\r][\n]"*
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.wire -
http-outgoing-0 >> "Accept: application/*+xml[\r][\n]"
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.wire -
http-outgoing-0 >> "firedTime: Thu Jun 26 09:02:02 EDT 2014[\r][\n]"
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.wire -
http-outgoing-0 >> "Accept-Language: en-US[\r][\n]"
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.wire -
http-outgoing-0 >> "Content-Encoding: deflate[\r][\n]"
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.wire -
http-outgoing-0 >> "breadcrumbId:
ID-sporeddy-57327-1403787720885-0-1[\r][\n]"
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.wire -
http-outgoing-0 >> "Accept-Charset: utf-8[\r][\n]"
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.wire -
http-outgoing-0 >> "Host: localhost:8080[\r][\n]"
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.wire -
http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.wire -
http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.3.3 (java 1.5)[\r][\n]"
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.wire -
http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.wire -
http-outgoing-0 >> "[\r][\n]"
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.wire -
http-outgoing-0 << "HTTP/1.1 415 Unsupported Media Type[\r][\n]"
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.wire -
http-outgoing-0 << "Server: Apache-Coyote/1.1[\r][\n]"
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.wire -
http-outgoing-0 << "Content-Type: application/*+xml[\r][\n]"
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.wire -
http-outgoing-0 << "Content-Length: 162[\r][\n]"
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.wire -
http-outgoing-0 << "Date: Thu, 26 Jun 2014 13:02:08 GMT[\r][\n]"
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.wire -
http-outgoing-0 << "[\r][\n]"
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.wire -
http-outgoing-0 << "<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><ErrorResponse><ErrorCode>415</ErrorCode><ErrorText>Cannot
consume content type</ErrorText></ErrorResponse>"
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.headers -
http-outgoing-0 << HTTP/1.1 415 Unsupported Media Type
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.headers -
http-outgoing-0 << Server: Apache-Coyote/1.1
*[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.headers -
http-outgoing-0 << Content-Type: application/*+xml*
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.headers -
http-outgoing-0 << Content-Length: 162
[Camel (camel-1) thread #0 - timer://foo] DEBUG org.apache.http.headers -
http-outgoing-0 << Date: Thu, 26 Jun 2014 13:02:08 GMT
[Camel (camel-1) thread #0 - timer://foo] DEBUG
org.apache.http.impl.execchain.MainClientExec - Connection can be kept
alive indefinitely
[Camel (camel-1) thread #0 - timer://foo] DEBUG
org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection
[id: 0][route: {}->http://localhost:8080] can be kept alive indefinitely
[Camel (camel-1) thread #0 - timer://foo] DEBUG
org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection
released: [id: 0][route: {}->http://localhost:8080][total kept alive: 1;
route allocated: 1 of 20; total allocated: 1 of 200]
[Camel (camel-1) thread #0 - timer://foo] DEBUG
com.isone.oishe24.camel.jms.CamelBeanBinding - You have invoked the
method2 HTTP operation failed invoking
http://localhost:8080/cts-rest/cts/users with statusCode: 415
[main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager -
Connection manager is shutting down
[main] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection -
http-outgoing-0: Close connection
[main] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection -
http-outgoing-0: Close connection
[main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager -
Connection manager shut down
*HTTP POST ---SUCESSFUL*
*JAVA DSL ROUTE*
from("direct:suspend").process(new
MessageProcessor()).to("http4://localhost:8080/cts-rest/cts/ne/organizations").process(new
CamelRestResponseProcessor()).bean(
CamelBeanBinding.class,"invokeMethodRESTResponseMessage")
[main] DEBUG org.apache.http.client.protocol.RequestAddCookies - CookieSpec
selected: best-match
[main] DEBUG org.apache.http.client.protocol.RequestAuthCache - Auth cache
not set in the context
[main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager -
Connection request: [route: {}->http://localhost:8080][total kept alive: 0;
route allocated: 0 of 20; total allocated: 0 of 200]
[main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager -
Connection leased: [id: 0][route: {}->http://localhost:8080][total kept
alive: 0; route allocated: 1 of 20; total allocated: 1 of 200]
[main] DEBUG org.apache.http.impl.execchain.MainClientExec - Opening
connection {}->http://localhost:8080
[main] DEBUG org.apache.http.impl.conn.HttpClientConnectionOperator -
Connecting to localhost/127.0.0.1:8080
[main] DEBUG org.apache.http.impl.conn.HttpClientConnectionOperator -
Connection established 127.0.0.1:57314<->127.0.0.1:8080
[main] DEBUG org.apache.http.impl.execchain.MainClientExec - Executing
request POST /cts-rest/cts/ne/organizations HTTP/1.1
[main] DEBUG org.apache.http.impl.execchain.MainClientExec - Target auth
state: UNCHALLENGED
[main] DEBUG org.apache.http.impl.execchain.MainClientExec - Proxy auth
state: UNCHALLENGED
[main] DEBUG org.apache.http.headers - http-outgoing-0 >> POST
/cts-rest/cts/ne/organizations HTTP/1.1
[main] DEBUG org.apache.http.headers - http-outgoing-0 >> breadcrumbId:
ID-sporeddy-57313-1403787372489-0-1
[main] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Encoding:
deflate
[main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept:
application/*+xml
[main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Charset:
utf-8
[main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Language:
en-US
[main] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Length:
340
*[main] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Type:
application/*+xml*
[main] DEBUG org.apache.http.headers - http-outgoing-0 >> Host:
localhost:8080
[main] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection:
Keep-Alive
[main] DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent:
Apache-HttpClient/4.3.3 (java 1.5)
[main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Encoding:
gzip,deflate
[main] DEBUG org.apache.http.wire - http-outgoing-0 >> "POST
/cts-rest/cts/ne/organizations HTTP/1.1[\r][\n]"
[main] DEBUG org.apache.http.wire - http-outgoing-0 >> "breadcrumbId:
ID-sporeddy-57313-1403787372489-0-1[\r][\n]"
[main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Encoding:
deflate[\r][\n]"
[main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept:
application/*+xml[\r][\n]"
[main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Charset:
utf-8[\r][\n]"
[main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Language:
en-US[\r][\n]"
[main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Length:
340[\r][\n]"
*[main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Type:
application/*+xml[\r][\n]"*
[main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host:
localhost:8080[\r][\n]"
[main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection:
Keep-Alive[\r][\n]"
[main] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent:
Apache-HttpClient/4.3.3 (java 1.5)[\r][\n]"
[main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Encoding:
gzip,deflate[\r][\n]"
[main] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]"
[main] DEBUG org.apache.http.wire - http-outgoing-0 >> "<?xml version="1.0"
encoding="UTF-8"
standalone="yes"?><SuspensionTerminationRequest><Header><SubmitterID>ISONE</SubmitterID><ReceiverID>NYISO</ReceiverID></Header><messageRequestID>1403787373229</messageRequestID><NEOrganizationID>4444</NEOrganizationID><NEOrganizationStatus>Suspended</NEOrganizationStatus></SuspensionTerminationRequest>"
[main] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 201
Created[\r][\n]"
[main] DEBUG org.apache.http.wire - http-outgoing-0 << "Server:
Apache-Coyote/1.1[\r][\n]"
[main] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Length:
0[\r][\n]"
[main] DEBUG org.apache.http.wire - http-outgoing-0 << "Date: Thu, 26 Jun
2014 12:56:23 GMT[\r][\n]"
[main] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]"
[main] DEBUG org.apache.http.headers - http-outgoing-0 << HTTP/1.1 201
Created
[main] DEBUG org.apache.http.headers - http-outgoing-0 << Server:
Apache-Coyote/1.1
[main] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Length: 0
[main] DEBUG org.apache.http.headers - http-outgoing-0 << Date: Thu, 26 Jun
2014 12:56:23 GMT
[main] DEBUG org.apache.http.impl.execchain.MainClientExec - Connection can
be kept alive indefinitely
[main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager -
Connection [id: 0][route: {}->http://localhost:8080] can be kept alive
indefinitely
[main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager -
Connection released: [id: 0][route: {}->http://localhost:8080][total kept
alive: 1; route allocated: 1 of 20; total allocated: 1 of 200]
Message Received HTTP Response ee {CamelHttpMethod=POST,
CamelHttpResponseCode=201, Content-Length=0, Accept=application/*+xml,
Server=Apache-Coyote/1.1, CamelHttpCharacterEncoding=UTF-8, Date=Thu, 26 Jun
2014 12:56:23 GMT, Content-Encoding=deflate, Accept-Language=en-US,
content-type=application/*+xml, Accept-Charset=utf-8,
breadcrumbId=ID-sporeddy-57313-1403787372489-0-1}
[main] DEBUG com.isone.oishe24.camel.jms.CamelBeanBinding - You have
invoked the invokeMethodRESTResponseMessage 201
[main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager -
Connection manager is shutting down
[main] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection -
http-outgoing-0: Close connection
[main] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection -
http-outgoing-0: Close connection
[main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager -
Connection manager shut down
--
View this message in context:
http://camel.465427.n5.nabble.com/Http4-Set-Header-Content-Type-not-passing-through-to-the-HTTP-Request-tp5746414p5752856.html
Sent from the Camel - Users mailing list archive at Nabble.com.