I am trying to Develop a Consumer for Soap Service using the tutorial at
http://cxf.apache.org/docs/developing-a-consumer.html
In the section ,"Setting Connection Properties with Contexts" I am looking at the code below
// Set request context property.
java.util.Map<String, Object> requestContext =
((javax.xml.ws.BindingProvider)port).getRequestContext();
requestContext.put(ContextPropertyName, PropertyValue);
// Invoke an operation.
port.SomeOperation();
Can someone tell me if I can set the proxy server settings using the requestContext properties and how ?. My code is running behind a proxy and I need the outgoings SOAP calls to use proxy server settings.
Proxy setting are usually set by using httpconduit object
HelloService hello = new HelloService();
HelloPortType helloPort = cliente.getHelloPort();
org.apache.cxf.endpoint.Client client = ClientProxy.getClient(helloPort);
HTTPConduit http = (HTTPConduit) client.getConduit();
http.getClient().setProxyServer("proxy");
http.getClient().setProxyServerPort(8080);
http.getProxyAuthorization().setUserName("user proxy");
http.getProxyAuthorization().setPassword("password proxy");
Related
I am working on a Rest Client and I am using CXF with JAX-RS.
The problem that I have is that I cannot find any way to override the default timeout values of the client.
A simple client:
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:8080/MyApp");
target = target.path("jsp/Test.jsp");
Response response = target.request().get();
I have read that there are two timeout properties in CXF called ReceiveTimeout and ConnectionTimeout but I have not managed to find a way to set them in my client.
I have tried client.property("ReceiveTimeout", 5000); but it doesn't work.
I have seen examples of using an xml configuration file to configure the client but I prefer not to take that path if it is possible.
Any ideas?
HTTPConduit conduit = WebClient.getConfig(webClient).getHttpConduit();
conduit.getClient().setConnectionTimeout(1000 * 3);
conduit.getClient().setReceiveTimeout(1000 * 3);
You can find the correct properties in org.apache.cxf.jaxrs.client.spec.ClientImpl:
"http.connection.timeout" and "http.receive.timeout"
So just use them as property when building the client:
ClientBuilder.newClient().property("http.receive.timeout", 1000);
With JAX-RS 2.1 (supported from CXF 3.2) you can use these standard methods in ClientBuilder:
connectTimeout(long timeout, TimeUnit unit);
readTimeout(long timeout, TimeUnit unit);
See also: https://github.com/eclipse-ee4j/jaxrs-api/issues/467
You can try something like this:
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(30000);
http.setClient(httpClientPolicy);
see http://cxf.apache.org/javadoc/latest/org/apache/cxf/transports/http/configuration/HTTPClientPolicy.html
We have a CXF (2.7.X) client (see code below) in a Java 1.6.0_45 application.
The CXF client calls a Soap WS through a proxy server.
Despite all our efforts, that CXF client performs some requests directly to the WS bypassing the proxy.
The only solution for the moment is to force proxy on the JVM options.
But this solution is not acceptable.
Is there a pb in our code ?
I have not found any clue on the internet or on the CXF jira .
// work only if i define proxy on jvm
/*
System.setProperty("http.proxyHost","87.65.43.21");
System.setProperty("http.proxyPort", "808");
System.setProperty("https.proxyHost", "87.65.43.21");
System.setProperty("https.proxyPort", "808");
*/
// initialize ws
URL wsdlLocation = new URL("https://12.34.56.78:8443/mockHelloWorldSoapBinding?WSDL");
QName qName = new QName("http://my.webservice.com", "HelloWorldService");
HelloWorldService helloWorldService = new HelloWorldService(wsdlLocation, qName);
HelloWorld port = helloWorldService.getHelloWorld();
HTTPConduit httpConduit = (HTTPConduit) ClientProxy.getClient(port).getConduit();
// add proxy parameters
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setProxyServer("87.65.43.21");
policy.setProxyServerPort(808);
policy.setAllowChunking(false);
httpConduit.setClient(policy);
// call ws
String response = port.sayHello("world");
I'm trying to make a jersey client call using NTLM proxy? is that possible as i was not able to get any clear information on the same. Did anyone tried before?
Yes it is possible to configure the Jersey Client to connect through a proxy server that requires NTLM authentication.
Here is a simplified code snippet that prepares a suitable ClientConfig that should work with Jersey v2.5+:
final ClientConfig config = new ClientConfig();
config.property(ClientProperties.PROXY_URI, "http://myproxy.com:8000");
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
final AuthScope ntlmAuthScope =
new AuthScope("myproxy.com", 8000, AuthScope.ANY_REALM, "NTLM");
credentialsProvider.setCredentials(
ntlmAuthScope,
new NTCredentials("user", "password", "hostname", "domain") );
config.property(
ApacheClientProperties.CREDENTIALS_PROVIDER, credentialsProvider);
config.connectorProvider(new ApacheConnectorProvider());
Client client = ClientBuilder.newClient(config);
Please note: I am using the Apache HttpClient connector with Jersey Client - you may require slightly different code if you are using another client transport connector.
You may also need to add the following line to your code if you want your POST/PUT requests to be buffered (and therefore repeatable) in response to any 407 authentication challenges that come back from your proxy server:
config.property(ClientProperties.REQUEST_ENTITY_PROCESSING,
RequestEntityProcessing.BUFFERED);
My problem is that I call a remote web service that requires more than 60 seconds to respond and this causes a timeout exception. I do not want any timeout check: I just want the sender to wait until the web service ends. I tried to set:
HttpSession httpSession = getThreadLocalRequest().getSession();
httpSession.setMaxInactiveInterval(120000);
getThreadLocalRequest().setAttribute("session", httpSession);
to modify the web.xml session-timeout (even though I do not think that it is related with my problem) to create a custom HttpRequest. Timeout persists. Is there any way to shutdown this check?
Found the solution:
/* Connect to the service */
ClientProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();
factoryBean.setServiceClass(MyService.class);
factoryBean.setAddress("service-url");
myService = (MyService) factoryBean.create();
/* Retrive HTTP client policy and set the receive timeout */
Client client = ClientProxy.getClient(myService);
HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = httpConduit.getClient();
httpClientPolicy.setReceiveTimeout(timeoutMilliseconds);
httpSession.setMaxInactiveInterval is not what you're after.
You probably want to set connectTimeout and readTimeout on URLConnection.
How to do that, depends on what tool you use to call the remote webservice.
Can you add some more details about the service, if it's a SOAP-service, REST-service etc, and what library you use to call the service?
Hi I have a problem with change ReceiveTimeout, and setup new endpoint
I have a code:
to change the endpoint I'm using code:
Map<String, Object> prop = ((BindingProvider) port).getRequestContext();
prop.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
and change timeout :
Client client = ClientProxy.getClient(port);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = http.getClient();
httpClientPolicy.setReceiveTimeout(5000);
but this is doesn't work
the last part is setup ReceiveTimeout but for default endpoit.
I use server jboss 6.1
How to change ReceiveTimeout for new endpoint ??