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


I’m extending the example at http://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.

About these ads

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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 26 other followers

%d bloggers like this: