I've got a very weird problem with HTTP connection from java.
Description: from machine A(source machine) i trying to get http response from machine B(10.13.0.69).
Important part: machine B(target) is located behind VPN tunnel. Machine B is reachable from machine A. I have no problems, if i try to access this URL from machine A OS (with curl for example):
[root@Test-LAPP01 test]# curl http://10.13.0.69:7878/testGet && echo ""
{"result":["\"AlertServer testGet ok\" "]}
Problems starts when i trying to perform same request from java program, that located at machine A: i getting SocketException: Unexpected end of file from server.
Detailed description:
[root@Test-LAPP01 test]# cat contest.java
import java.net.*;
import java.io.*;
public class contest {
public static void main(String[] args) throws Exception {
String url = "http://10.13.0.69:7878/testGet";
try {
URL alert = new URL(url);
HttpURLConnection con = (HttpURLConnection) alert.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", "chrome");
int responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " + responseCode);
}
catch (IOException e) {
e.printStackTrace();
}
}
}
[root@Test-LAPP01 test]# curl http://10.13.0.69:7878/testGet && echo ""
{"result":["\"AlertServer testGet ok\" "]}
[root@Test-LAPP01 test]# java contest
java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:851)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:848)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1587)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at contest.main(contest.java:12)
Note 1: from java app i CAN connect to external resourses, like google.com and have no issues with that.
Note 2: It works if i place target web server that i trying to reach (Machine B - 10.13.0.69) on same subnet with source machine A. So problem is somehow related to VPN.
I already tried to debug this and launched tcpdump on both machines and now i'm confused even more: i see all network requests on both sides.
So short description: i can reach destination URL from machine, but cant from java app.
UPD: updated code with @RedBoy recommendations. Now i've see this error:
апр 25, 2018 12:47:24 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://10.13.0.69:7878: The target server failed to respond
апр 25, 2018 12:47:24 PM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {}->http://10.13.0.69:7878
апр 25, 2018 12:47:55 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://10.13.0.69:7878: The target server failed to respond
апр 25, 2018 12:47:55 PM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {}->http://10.13.0.69:7878
апр 25, 2018 12:48:26 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://10.13.0.69:7878: The target server failed to respond
апр 25, 2018 12:48:26 PM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {}->http://10.13.0.69:7878
contest main org.apache.http.NoHttpResponseException: 10.13.0.69:7878 failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:143)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261)
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:165)
at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:167)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:271)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at contest.contest.main(contest.java:25)