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 ??
Related
When I create a cxf client to call a SOAP web service it returns connection refused or Unexpected end of file from server. The thing is though, it just happens on the first request, afterwards it's like the client is "warmed up" and actually starts working.
Any idea why this is happening?
...
if(port == null) {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setAddress("http://localhost:9000/helloWorld");
port = factory.create(HelloWorld.class);
...
Client client= ClientProxy.getClient(port);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setAllowChunking(false);
http.setClient(httpClientPolicy);
}
port.someMethod(); // fails on first run, but succeeds on all following runs
...
Removing the if-statement would cause the client to fail on every call not just the first. I'm really stuck and would appreciate any help.
It seems that the issue was caused through TLS 1.2. In Java8 the default TLS version changed from TLSv1 to TLSv1.2. TLS 1.2 didn't seem to work even with the latest version of CXF (3.1.7). So the Solution was to set the TLS version to be used for CXF:
...
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setAllowChunking(false);
httpClientPolicy.setAutoRedirect(true);
httpClientPolicy.setConnection(ConnectionType.KEEP_ALIVE);
String proxyUrl = "http://proxy.com";
String proxyPortString = "8080";
HTTPConduit http = (HTTPConduit)client.getConduit();
SSLContext sslContext = SSLContext.getInstance("TLSv1");
sslContext.init(null, null, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
TLSClientParameters tlsClientParameters = new TLSClientParameters();
tlsClientParameters.setUseHttpsURLConnectionDefaultSslSocketFactory(true);
http.setTlsClientParameters(tlsClientParameters);
http.setClient(httpClientPolicy);
The following code is what i have used to add Connection and Receive timeout to my CXF Web Service,Receive timeout works fine but Connection timeout does not and i think i have a clue why ,the service tries to connect at line1 but the code for setting timeout follows the code,as it always gets stuck at line1 ,how will it ever set a timeout at line2.Please share if there is any other way to set the timeout.
CalculatorService cal = new CalculatorService(); //line1
Calculator port= cal.getCalculatorPort();
Client cl = ClientProxy.getClient(port);
HTTPConduit http = (HTTPConduit)cl.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(5000); //line2
httpClientPolicy.setReceiveTimeout(4000);
http.setClient(httpClientPolicy);
port.add(1, 2);
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");
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");