You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by li...@christophercheng.com on 2018/07/26 01:00:06 UTC
How could I set HttpClientPolicy per request?
I have an user requirement to set timeout per request such that the user can
specify the timeout for the web service.
Client client = ClientProxy.getClient(port);
client.getRequestContext().put("thread.local.request.context", "true");
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setAllowChunking(false);
httpClientPolicy.setAccept("text/xml");
httpClientPolicy.setAcceptEncoding("gzip,deflate,sdch");
httpClientPolicy.setCacheControl("No-Cache");
httpClientPolicy.setContentType("text/xml");
httpClientPolicy.setConnectionTimeout(2000);
httpClientPolicy.setReceiveTimeout(receiveTimeout);
HTTPConduit http = (HTTPConduit) client.getConduit();
http.setClient(httpClientPolicy);
receiveTimeout above is a parameter. I found out that if the port is a
static variable (shared by all threads), then after the first user set
receiveTimeout, the 2nd user will be affected by this setting.
What I want to achieve is that if the user does not set the receiveTimeout,
it will be using CXF default which is 60s and it will be affected by other
threads.
RE: How could I set HttpClientPolicy per request?
Posted by Christopher Cheng <me...@christophercheng.com>.
Thanks and it is working
-----Original Message-----
From: Andrei Shakirin <as...@talend.com>
Sent: Sunday, 5 August 2018 10:04 PM
To: users@cxf.apache.org; me@christophercheng.com
Subject: RE: How could I set HttpClientPolicy per request?
Hi,
I think it should work this way:
((BindingProvider)proxy).getRequestContext().put("thread.local.request.conte
xt", "true");
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setAllowChunking(false);
httpClientPolicy.setAccept("text/xml");
httpClientPolicy.setAcceptEncoding("gzip,deflate,sdch");
httpClientPolicy.setCacheControl("No-Cache");
httpClientPolicy.setContentType("text/xml");
httpClientPolicy.setConnectionTimeout(2000);
httpClientPolicy.setReceiveTimeout(receiveTimeout);
((BindingProvider)proxy).getRequestContext().put(HTTPClientPolicy.class.getN
ame(), httpClientPolicy);
The code should works concurrently per request.
Regards,
Andrei.
> -----Original Message-----
> From: Christopher Cheng [mailto:me@christophercheng.com] On Behalf Of
> lists@christophercheng.com
> Sent: Donnerstag, 26. Juli 2018 03:00
> To: users@cxf.apache.org
> Subject: How could I set HttpClientPolicy per request?
>
> I have an user requirement to set timeout per request such that the
> user can specify the timeout for the web service.
>
>
>
>
>
>
>
> Client client = ClientProxy.getClient(port);
>
> client.getRequestContext().put("thread.local.request.context",
> "true");
>
>
>
> HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
>
> httpClientPolicy.setAllowChunking(false);
>
> httpClientPolicy.setAccept("text/xml");
>
> httpClientPolicy.setAcceptEncoding("gzip,deflate,sdch");
>
> httpClientPolicy.setCacheControl("No-Cache");
>
> httpClientPolicy.setContentType("text/xml");
>
> httpClientPolicy.setConnectionTimeout(2000);
>
> httpClientPolicy.setReceiveTimeout(receiveTimeout);
>
>
>
> HTTPConduit http = (HTTPConduit) client.getConduit();
>
> http.setClient(httpClientPolicy);
>
>
>
>
>
>
>
> receiveTimeout above is a parameter. I found out that if the port is a
> static variable (shared by all threads), then after the first user set
> receiveTimeout, the 2nd user will be affected by this setting.
>
> What I want to achieve is that if the user does not set the
> receiveTimeout, it will be using CXF default which is 60s and it will be
affected by other threads.
>
>
As a recipient of an email from Talend, your contact personal data will be
on our systems. Please see our contacts privacy notice at Talend, Inc.
<https://www.talend.com/contacts-privacy-policy/>
RE: How could I set HttpClientPolicy per request?
Posted by Andrei Shakirin <as...@talend.com>.
Hi,
I think it should work this way:
((BindingProvider)proxy).getRequestContext().put("thread.local.request.context", "true");
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setAllowChunking(false);
httpClientPolicy.setAccept("text/xml");
httpClientPolicy.setAcceptEncoding("gzip,deflate,sdch");
httpClientPolicy.setCacheControl("No-Cache");
httpClientPolicy.setContentType("text/xml");
httpClientPolicy.setConnectionTimeout(2000);
httpClientPolicy.setReceiveTimeout(receiveTimeout);
((BindingProvider)proxy).getRequestContext().put(HTTPClientPolicy.class.getName(), httpClientPolicy);
The code should works concurrently per request.
Regards,
Andrei.
> -----Original Message-----
> From: Christopher Cheng [mailto:me@christophercheng.com] On Behalf Of
> lists@christophercheng.com
> Sent: Donnerstag, 26. Juli 2018 03:00
> To: users@cxf.apache.org
> Subject: How could I set HttpClientPolicy per request?
>
> I have an user requirement to set timeout per request such that the user can
> specify the timeout for the web service.
>
>
>
>
>
>
>
> Client client = ClientProxy.getClient(port);
>
> client.getRequestContext().put("thread.local.request.context", "true");
>
>
>
> HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
>
> httpClientPolicy.setAllowChunking(false);
>
> httpClientPolicy.setAccept("text/xml");
>
> httpClientPolicy.setAcceptEncoding("gzip,deflate,sdch");
>
> httpClientPolicy.setCacheControl("No-Cache");
>
> httpClientPolicy.setContentType("text/xml");
>
> httpClientPolicy.setConnectionTimeout(2000);
>
> httpClientPolicy.setReceiveTimeout(receiveTimeout);
>
>
>
> HTTPConduit http = (HTTPConduit) client.getConduit();
>
> http.setClient(httpClientPolicy);
>
>
>
>
>
>
>
> receiveTimeout above is a parameter. I found out that if the port is a static
> variable (shared by all threads), then after the first user set receiveTimeout,
> the 2nd user will be affected by this setting.
>
> What I want to achieve is that if the user does not set the receiveTimeout, it
> will be using CXF default which is 60s and it will be affected by other threads.
>
>
As a recipient of an email from Talend, your contact personal data will be on our systems. Please see our contacts privacy notice at Talend, Inc. <https://www.talend.com/contacts-privacy-policy/>