3

I have a core server and a gateway server. Only gateway interacts with CORE.

one of the requests had to interact with an external partner which includes following steps.

  • CORE sends a request to GATEWAY and waits for response
  • GATEWAY sends the request to EXTERNAL and sends back response to CORE

In CORE server, I have got this IOException

java.io.IOException: Server returned HTTP response code: 504 for URL: someurl
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1626)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)

I figured that IOException is because I am using urlConnection.getInputStream() instead of urlConnection.getErrorStream().

urlConnection.connect();

OutputStreamWriter osw = new OutputStreamWriter(urlConnection.getOutputStream());
BufferedWriter buffWriter = new BufferedWriter(osw);
buffWriter.write(request.toString());
buffWriter.flush();
buffWriter.close();
osw.close();

InputStreamReader isr = new InputStreamReader(urlConnection.getInputStream());
BufferedReader buffRead = new BufferedReader(isr);

Can't figure out why I am getting error 504.

GATEWAY server got the response successfully and I see no problem there.

I have handled SocketTimeoutException,ConnectException ,FileNotFoundException exceptions for HTTPSrequestsender.

Vamsidhar
  • 822
  • 11
  • 24
  • You would have to look at the server logs. HTTP responses are carefully designed not to leak much information. You might get more information by reading the error stream if there is an error, but you mightn't. – user207421 Jun 27 '17 at 08:08
  • 1
    Found the error, LoadBalancer had default idle timeout and it sent 504 error before my code could catch some exception. @EJP Thanks. – Vamsidhar Jun 27 '17 at 11:39
  • @Vamsidhar I am getting same error, Could you please explain your solution?? – Jay Prakash Jul 19 '18 at 05:21
  • 1
    @JayPrakash In my case, Both instances were running on Amazon EC2 and Loadbalancer has less default 'Idle Connection Timeout' than the timeout which i have configured. Increasing the LoadBalancer timeout fixed the issue. – Vamsidhar Jul 20 '18 at 10:59

0 Answers0