You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Eduardo Perez <ed...@pyxis.com.uy> on 2015/09/24 05:30:37 UTC
Problem with Content-Length http header
Hi ,i'm trying to send a Http Request to a reverse proxy (nginx) , then the proxy responds with a HTTP error 411 ( length required).
I read CXF documentation that says that some older proxies have problems with Chunking.
I disable chunking using CXF but the header content-length is not present in my HTTP Request Header.
i tried two ways for solve this problem.
1) this way does not work
Client client = ClientProxy.getClient(port);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setAllowChunking(false);
http.setClient(httpClientPolicy);
2) write a custom Interceptor
Public CustomInterceptor extends AbstractPhaseInterceptor<Message>{
public CustomInterceptor(){
super(Phase.WRITE);
}
@override
public void handleMessage(Message message) throws Fault{
Map<String,List<String>> headers=(Map<String,List<String>>)message.getContextualProperty(Message.PROTOCOL_HEADERS);
headers.put(HttpHeaderHelper.CONTENT_LENGTH,Arryas.asList(sizeOfMyMessageInBytes));
}
}
with this code i set the Content-Length header in my HTTP Request message, but i can't determine the length of my message in bytes. how can i solve it ?
Is there another way to solve this issue(HTTP Header content-Length)?
thanks in advance .
Eduardo.
Re: Problem with Content-Length http header
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
I recall we used the 1st option to control it and it was effective.
FYI, you do need to create a new policy, this is ok too:
HTTPClientPolicy policy = ((HTTPConduit) client.getConduit()).getClient();
Try additionally setting a chunkingThreshold property to some large
value, though the 1st option should work.
What CXF and Java version do you use ?
Cheers, Sergey
On 24/09/15 04:30, Eduardo Perez wrote:
> Hi ,i'm trying to send a Http Request to a reverse proxy (nginx) , then the proxy responds with a HTTP error 411 ( length required).
>
> I read CXF documentation that says that some older proxies have problems with Chunking.
>
> I disable chunking using CXF but the header content-length is not present in my HTTP Request Header.
>
> i tried two ways for solve this problem.
>
>
> 1) this way does not work
>
>
> Client client = ClientProxy.getClient(port);
>
> HTTPConduit http = (HTTPConduit) client.getConduit();
>
> HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
>
> httpClientPolicy.setAllowChunking(false);
>
> http.setClient(httpClientPolicy);
>
>
> 2) write a custom Interceptor
>
>
> Public CustomInterceptor extends AbstractPhaseInterceptor<Message>{
>
>
> public CustomInterceptor(){
>
> super(Phase.WRITE);
>
> }
>
>
> @override
>
> public void handleMessage(Message message) throws Fault{
>
>
> Map<String,List<String>> headers=(Map<String,List<String>>)message.getContextualProperty(Message.PROTOCOL_HEADERS);
>
>
> headers.put(HttpHeaderHelper.CONTENT_LENGTH,Arryas.asList(sizeOfMyMessageInBytes));
>
>
> }
>
> }
>
>
> with this code i set the Content-Length header in my HTTP Request message, but i can't determine the length of my message in bytes. how can i solve it ?
>
>
> Is there another way to solve this issue(HTTP Header content-Length)?
>
>
> thanks in advance .
>
> Eduardo.
>
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/