REST调用抛出java.io.EOFException

时间:2018-12-18 18:42:52

标签: java linux rest weblogic firewall

我正在通过防火墙使用以下代码进行REST Web服务调用:

try {
    String url="http://testcall.us:1300/abc/testapi/json/method1"; //dummy url
    Client client = Client.create();
    WebResource webResource = client.resource(url);

    ClientResponse response = webResource.accept("application/json")
        .type(MediaType.APPLICATION_JSON)
        .header("content-type", "application/json")
        .get(ClientResponse.class);                         

    System.out.println("response.getStatus" + response.getStatus());
} catch (Exception e) {
    logger.error("Error making webservice call", e);
}

该代码在我的本地Windows环境中运行良好。但是,当我从另一个linux服务器发出相同的请求时,出现以下异常:

com.sun.jersey.api.client.ClientHandlerException: java.io.EOFException: Response had end of stream after 0 bytes
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:155)
at com.sun.jersey.api.client.Client.handle(Client.java:652)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
.......
.......

Caused By: java.io.EOFException: Response had end of stream after 0 bytes
at weblogic.net.http.MessageHeader.isHTTP(MessageHeader.java:312)
at weblogic.net.http.MessageHeader.parseHeader(MessageHeader.java:232)
at weblogic.net.http.HttpClient.parseHTTP(HttpClient.java:554)
at weblogic.net.http.HttpURLConnection.getInputStream(HttpURLConnection.java:688)
......
......

当我从相同的网址(使用不同的方法)发出另一个POST请求时,

try {
    String url="http://testcall.us:1300/abc/testapi/json/method2"; //dummy url
    Client client = Client.create();

    WebResource webResource = client
            .resource(url);                    

    String input = "{\"Id\":" + String.valueOf(id) + ",\"Status\":" + null + "}";

    ClientResponse response = webResource.type("application/json")
            .header("Environment", "dev")
            .accept("application/json")
            .post(ClientResponse.class, input);

    if (response.getStatus() != 200 && response.getStatus() != 201) {
        logger.error("REST ws call failed. HTTP error code : " + response.getStatus());
    }

    System.out.println("Output from Server .... \n");
    String output = response.getEntity(String.class);
    System.out.println(output);

} catch (Exception e) {
    logger.error("Error submitting request", e );
}

我收到以下异常:

<Error submitting request
com.sun.jersey.api.client.ClientHandlerException: java.io.IOException: Connection reset by peer
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:155)
at com.sun.jersey.api.client.Client.handle(Client.java:652)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570)
.....
.....
Caused By: java.io.IOException: Connection reset by peer
at sun.nio.ch.FileDispatcherImpl.readv0(Native Method)
at sun.nio.ch.SocketDispatcher.readv(SocketDispatcher.java:43)
at sun.nio.ch.IOUtil.read(IOUtil.java:278)

在我的本地环境中,该方法再次可以很好地工作。在另一个环境中正常工作时,相同的URL引发异常的原因可能是什么?据我所知,防火墙规则已被批准用于Linux环境。 预先感谢您提供任何见解。

更新 我刚刚发现为此URL提交的防火墙规则包含“ https”而不是“ http”。但是据我所知,防火墙并不关心它是“ http”还是“ https”。我没有访问Linux机器的权限,因此无法检查是否可以使用那里的网址获得响应:(。

更新 在腻子上使用'curl'命令,我能够在Linux服务器上得到响应。这是否意味着java / weblogic配置中缺少某些内容?

0 个答案:

没有答案