Reputation: 33
We have a simple camel route "from->to":
<from uri="cxf:bean:testServiceProvider?loggingFeatureEnabled=true" />
<to uri="cxf:bean:testServiceClient?loggingFeatureEnabled=true" />
This route acts like a router or proxy for a third party's web service:
Service and client in this proxy are created with cxf
beans.
The endpoint's web service seems to require Content-Length
HTTP header, but cxf
requests to endpoint does not contain this header by default. All the requests done by this proxy receive the same response:
HTTP response '411: Length required' when communicating with https://host:port/testService
We tried to add this header with an OutInterceptor, adding it to PROTOCOL_HEADERS:
Map<String, List> headers = (Map<String, List>) message.get(Message.PROTOCOL_HEADERS);
headers.put("Content-Length", Collections.singletonList(String.valueOf(messageLength)));
Two questions:
How to know the value of messageLength
?
Is there an easier way to do this?
Thanks!
Upvotes: 2
Views: 3562
Reputation: 343
You can try with http:conduit, disabling AllowChunking. This will force cxf to include Content-Length header in the request. By default cxf behaviour is to allow chunking, so it can be generating the problem you're facing, even specifying the Content-length header.
<http:conduit name="{http://namespace}WebService.http-conduit">
<http:client AllowChunking="false" CacheControl="No-Cache"
ContentType="text/xml;charset=UTF-8" ConnectionTimeout="900000"
ReceiveTimeout="900000" Connection="Keep-Alive" />
</http:conduit>
Upvotes: 2
Reputation: 466
Looking at the CXF documentation you may be able to use the relayHeaders functionality to propogate headers from the "from" endpoint to the "to" endpoint.
Alternatively you could copy the value of the content-length from the inbound message as suggested here...
"If you want to keep those headers in the old version of camel, you need to put the headers into a map and put this map into message header with the key "org.apache.cxf.message.PROTOCOL_HEADERS"."
Upvotes: 0