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.