java - 套接字异常 : Connection reset - Client Jersey 2. 0 Java 7

标签 java rest ssl jersey timeout

我收到与此 link1 类似的错误. 当我通过 REST 发布(客户端到服务器)一个小的 xml 时,一切正常。不幸的是,当我发布一些更大的 xml 时,当连接持续时间超过 10/15 分钟时,我遇到了一个错误。 (我假设这是某种超时)

我更正了我的 SSL 证书,因为它在 link1 中提到 - configureClient() 方法在我的情况下与 link1 中的解决方案相同。

我还添加了 System.setProperty("java.net.preferIPv4Stack", "true"); - 有时它解决连接重置

基本信息:

错误:javax.ws.rs.ProcessingException:java.net.SocketException:连接重置

方法:REST POST

Java 版本:7

引擎: Jersey 2.x

方:客户

系统:Windows 7

我的客户:

   System.setProperty("java.net.preferIPv4Stack" , "true");

RestMethodes restMethodes = new RestMethodes();
ClientConfig config = new ClientConfig();
config = config.property(ClientProperties.CONNECT_TIMEOUT, 0);
config = config.property(ClientProperties.READ_TIMEOUT, 0);

config.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);

Client client = configureClient(config);
client.register(HttpAuthenticationFeature.basic(USER, PASS));

WebTarget target = client.target(SERVER_URL + "/bundles/assets");
Invocation.Builder responseInvocation = target.request(MediaType.APPLICATION_JSON);

// My exception is thrown there

Response response = responseInvocation.post(Entity.xml(assetsString)); 

String entity = response.readEntity(String.class);
//entity = jsonPrettyPrinter(entity);

if (entity.isEmpty() || entity.equals("")) {
    log.info("[POST ASSETS] Failed : Response is empty");
}
Response.StatusType codeName = response.getStatusInfo();
int code = response.getStatus();

if (code != 200) {
    log.error("[POST ASSETS] Failed : HTTP error code : " + response.getStatus() + "\n" + entity);
    response.close();
} else {
    log.info("[POST ASSETS] RESPONSE CODE ID : " + code + " CODE NAME : " + codeName);
    log.info("[POST ASSETS] RESPONSE : " + entity);
    response.close();
}
client.close();

我的错误

Exception in thread "main" javax.ws.rs.ProcessingException: java.net.SocketException: Connection reset
at org.glassfish.jersey.client.internal.HttpUrlConnector.apply(HttpUrlConnector.java:287)
at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:252)
at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:684)
at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:681)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:681)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:437)
at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:343)
at com.sas.spl.saslineagebridges.test.PostTester.main(PostTester.java:61)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:209)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
at sun.security.ssl.InputRecord.read(InputRecord.java:503)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:930)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:105)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:704)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:675)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1569)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
at org.glassfish.jersey.client.internal.HttpUrlConnector._apply(HttpUrlConnector.java:399)
at org.glassfish.jersey.client.internal.HttpUrlConnector.apply(HttpUrlConnector.java:285)
... 11 more

编辑:

我忘了说我设法通过 CURL 从 bash 发出了无限超时的请求并保持 Activity 状态,所以这不应该是服务器问题。 CURL REST 帖子用了 24 分钟。我的 Java 客户端在 15 分钟后抛出连接重置。在我看来,这可能是我的错。

最佳答案

尽管您的客户端似乎配置良好,但您正面临超时问题。此超时可能由任何防火墙、代理、负载平衡器或服务器本身引起,如果它在应用程序服务器前面运行 Web 服务器(如 Apache)。请检查您的客户端和应用程序服务器之间的内容,并在各处相应地设置超时。

这并不意味着您不能对客户端本身做任何事情,但解决那里要困难得多。 在 Windows 上,您需要启用 TCP keep-alives , 第一的。 之后,根据Client Transport你正在使用,我们将尝试将 TCP keep-alives 添加到底层工厂构建的套接字中,这与我们在 Axis clients 上知道的类似。 .此解决方案对您而言更耗时。

关于java - 套接字异常 : Connection reset - Client Jersey 2. 0 Java 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48525748/

相关文章:

java - org.hibernate.PropertyAccessException : exception setting property value with CGLIB

java - Rest ,使用 Get 作为查询字符串发送参数或仅使用 Post 获取信息

java - keystore 类型 : which one to use?

android - 一种监视 android 的 TLS 流量的方法

spring - REST 排序以负 ('-' ) 符号降序,而不是 <propertyName>.dir=desc

android - 服务器证书扩展和与 Android 的接口(interface)

java - java中的数组初始化

java - 尽可能快地清除透明的 BufferedImage

java - JScrollPane 中的 JTextPane 对鼠标滚轮没有反应

asp.net - 已添加具有相同 key 的项目。 IIS WCF 休息