Jai’s Weblog – Tech, Security & Fun…

Tech, Security & Fun…

  • Jaibeer Malik

    Jaibeer Malik
  • View Jaibeer Malik's profile on LinkedIn
  • Subscribe

  • Feedburner

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 29 other followers

  • Archives

  • Categories

  • Stats

    • 379,210
  • Live Traffic

Tips&Tricks: How to set web service client request timeout value

Posted by Jai on October 9, 2013

A quick tip to set the request timeout value for the web service client. As a thumb rule always make sure to set this value at service which will be used by each request.

WebClientTestService service = new WebClientTestService() ;
int connectionTimeOutInMs = 5000;
Map<String, Object> context = ((BindingProvider)service).getRequestContext();
//Set timeout params
context.put("com.sun.xml.internal.ws.connect.timeout", connectionTimeOutInMs);
context.put("com.sun.xml.internal.ws.request.timeout", connectionTimeOutInMs);
context.put("com.sun.xml.ws.request.timeout", connectionTimeOutInMs);
context.put("com.sun.xml.ws.connect.timeout", connectionTimeOutInMs);

You don’t want to keep the client request hanging until you get the response from the server. Make sure always set timeout value while sending a request to webservice server.

One Response to “Tips&Tricks: How to set web service client request timeout value”

  1. Aldjinn said

    Thanks for this post. Setting the timeout works fine. Before, my thread was waiting indefinitely because the damn server never closed the connection.

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

 
%d bloggers like this: