• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

org.springframework.extensions.webscripts.AbstractWebScript throws HTTP 502 exp with many calls

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code works well for a limited number of calls (sequential), say up to HTTP(s) 1,000 calls. However, when we make say over 1,000 HTTP(s) calls, and the Tomcat-Alfresco server is flooded with calls (sequential), a 502 HTTP exception is thrown.

The exception is thrown by org.springframework.extensions.webscripts.AbstractWebScriptin, which is a part of Spring-API.

I am invoking a URL, which is deployed in Alfresco-Tomcat (enterprise version 5.1.x) Windows Server 2012, R2, 64-bit operating system. The driver Java-code also runs on the same Windows machine.


I am attempting to call the Web service URL deployed in Alfresco-Windows-machine as:
https://mydomain.org/alfresco/service/getdata/xyz

The 502 exception is thrown ONLY-IF the server is flooded with hundreds of calls. It is a GET call to retrieve documents and metadata. I tried giving a time-out (pause/sleep after a certain number of calls and tried various combinations for the value of sleep and the number of calls), but it still throws 502 exception if the system is flooded with calls.


The execption stacktrace is:


java.io.IOException: Server returned HTTP response code: 502 for URL: https://mydomain.org/alfresco/service/getdata/xyz
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at MyDriver.java:63
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:58)


It is indeed true that the exception gets thrown from line number 63 of MyDriver.java, where I make the HTTP(s) call to the URL of the Java-webscript deployed in Alfresco-Windows.



The MyDriver.java code is similar to:

URL url = new URL("https://mydomain.org/alfresco/service/getdata/xyz");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod(GET_REQUEST_METHOD);
conn.setRequestProperty(ACCEPT_REQUEST_PROPERTY, APPLICATION_JSON);
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));


Line number 63 (which throws the 502 exception is thrown) is the line:

BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));



Can you suggest:

1. Any code change in the MyDriver.java code?

2. Any Java-spring related change?
 
Sheriff
Posts: 27531
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found this tutorial about what a 502 response code means: What is a 502 bad gateway and how do you fix it?.

You suspected that the error was related to the server being flooded with calls, and the tutorial confirms that server overload can result in the server sending a 502 response code.

So... the high-level solution would be to stop overloading the server. However you might also want to discuss the situation with the owner of the server and find out if the overloading is entirely your fault or if, perhaps, there are other users contributing to the overload. It's also possible that the server is deliberately reacting to your inputs by banning you from sending requests. Again, a discussion with the owner of the server might help to clarify that. Perhaps, for example, there's a different API where you can send a smaller number of requests to get the large quantity of data which you need.
reply
    Bookmark Topic Watch Topic
  • New Topic