How to configure timeouts at client side for Apache CXF web services?


I’m extending the example at https://singztechmusings.wordpress.com/2010/12/10/java-web-services-soap-over-ssl-cxf-framework/ to show how to set connection/receive timeout duration for a CXF client.


. . .

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("client-beans.xml");
CalculationServerIfc client = (CalculationServerIfc) context.getBean("client");

ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
Client proxy = ClientProxy.getClient(client);

HTTPConduit conduit = (HTTPConduit) proxy.getConduit();

// HTTPClientPolicy - Properties used to configure a client-side HTTP port
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); // Line #1

httpClientPolicy.setConnectionTimeout(30000); // Line #2
httpClientPolicy.setReceiveTimeout(60000); // Line #3

conduit.setClient(httpClientPolicy);

System.out.println("Adding 5 and 4: " + client.add(5,4));

. .

If you’d like to wait indefinitely for connecting to server, or receiving a response, either do not add marked lines in code, or set the timeouts to zero.

One comment

  1. […] How to configure timeouts at client side for Apache CXF web services? (singztechmusings.wordpress.com) Share this:EmailPrintDiggStumbleUponFacebookTwitterRedditLinkedInLike this:LikeBe the first to like this post. […]

Leave a comment