Может повторно искать ресурс позади VPN от приложения Java: неожиданный конец файла от сервера - PullRequest
0 голосов
/ 25 апреля 2018

У меня очень странная проблема с HTTP-соединением из Java.

Описание: с компьютера A (исходный компьютер) Я пытаюсь получить http-ответ от компьютера B (10.13.0.69).

Важная часть: машина B (цель) расположена за VPN-туннелем. Машина B доступна с машины A . У меня нет проблем, если я пытаюсь получить доступ к этому URL с компьютера ОС (например, с curl):

[root@Test-LAPP01 test]# curl http://10.13.0.69:7878/testGet && echo ""
{"result":["\"AlertServer testGet ok\" "]}

Проблемы начинаются, когда я пытаюсь выполнить тот же запрос из Java-программы, которая находится на компьютере A: я получаю SocketException: неожиданный конец файла с сервера.

Подробное описание:

[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)

Примечание 1: из Java-приложения я могу подключиться к внешним ресурсам, таким как google.com, и с этим проблем не возникает.

Примечание 2: Это работает, если я помещаю целевой веб-сервер, к которому я пытаюсь связаться (Машина B - 10.13.0.69), в одну подсеть с исходным компьютером A. Так что проблема как-то связана с VPN.

Я уже пытался отладить это и запустил tcpdump на обеих машинах, и теперь я запутался еще больше: я вижу все сетевые запросы с обеих сторон.

Итак краткое описание : я могу получить целевой URL с компьютера, но не могу из Java-приложения.

UPD: обновлен код с рекомендациями @RedBoy. Теперь я вижу эту ошибку:

апр 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)
...