2
votes

My Google App Engine application use a web service, this web service is pretty slow to respond and sometimes my application crashes :

java.net.SocketTimeoutException: Timeout while fetching URL: http://...

To call this web service, I use classes generated with wsimport (Java tool to parse an existing WSDL file and generate required files).

I need to change the default deadline (5 seconds) either for this call or globally for all my app URL fetches.

App engine docs :

You can set a deadline for a request, the most amount of time the service will wait for a response. By default, the deadline for a fetch is 5 seconds. The maximum deadline is 60 seconds for HTTP requests and 10 minutes for task queue and cron job requests. When using the URLConnection interface, the service uses the connection timeout (setConnectTimeout()) plus the read timeout (setReadTimeout()) as the deadline.

Source : https://developers.google.com/appengine/docs/java/urlfetch/#Java_Making_requests

I tried to add this lines (in strong below) in my code to change the deadline but it did'nt work :

URL urlConnection = new URL(url);

URLConnection connection = urlConnection.openConnection();

connection.setConnectTimeout(180000); // 3 minutes

connection.setReadTimeout(180000); // 3 minutes

SWS webService = new SWS(urlConnection, new QName("http://...", "SWS"));

Note : SWS is the main class generated by wsimport from my WSDL

2
You are setting the timeout more than 60 secs.Keerthivasan
I have the same issue. Did you get to a solution?Pablo Chvx
I had the same problem. My solution was to test in on a .NET app, it turns out that there was an authentication problem inside the service, but the exception was not replicated to the service's response and it threw this Timeout exception. Hope this helps.Pablo Chvx

2 Answers

3
votes

Posted this here a min ago, as there was also no accepted answer: Can I globally set the timeout of HTTP connections?

For App Engine with JAX-WS you have to set the request context (tested today with SDK 1.9.15). For normal machines you cannot go higher than 60s and would have to switch to the bigger machines (Bx) for better use a task queue.

For local testing you would normally use BindingProviderProperties.CONNECT_TIMEOUT and BindingProviderProperties.REQUEST_TIMEOUT, but they are not on the App Engine JRE White List and your code inspection might constantly warn you about that. The equivalent strings can be used though:

com.sun.xml.internal.ws.connect.timeout
com.sun.xml.internal.ws.connect.timeout

For deployment to App Engine:

com.sun.xml.ws.connect.timeout
com.sun.xml.ws.request.timeout

A full example how to apply that to auto-generated code from JAX-WS 2.x, values have to be provided in milliseconds:

@WebEndpoint(name = "Your.RandomServicePort")
public YourServiceInterface getYourRandomServicePort() {
    YourRandomServiceInterface port = super.getPort(YOURRANDOMSERVICE_QNAME_PORT, YourRandomServiceInterface.class);
    Map<String, Object> requestContext = ((BindingProvider)port).getRequestContext();
    requestContext.put("com.sun.xml.ws.connect.timeout", 10000);
    requestContext.put("com.sun.xml.ws.request.timeout", 10000);
    return port;
}
0
votes

This question had gone without an upvoted answer for a long time, and although the other answer is good, I want to raise two issues which take us outside the scope of this seemingly neat-and-tidy Q&A:

  1. The issue of "changing the default timeout for web services calls on App Engine" depends what we mean by a web services call. There are many services within the Google Cloud Platform, within the wider web itself, and then there are the Java-specific notion of WSDL. All of these will have different methods, found in the relevant documentation, for changing timeout deadlines.

  2. There have been cases where setting deadlines was not working due to an issue on the platform, as reported in the Public Issue Tracker for App Engine. If anybody reading this answer is experiencing a similar issue, feel free to open a Defect Report there, and we will quickly respond and attempt to fix an issue if one exists.