RESTEASY004655:无法调用请求:org.apache.http.NoHttpResponseException:host_url 未能响应

发布于 2025-01-14 12:17:28 字数 2252 浏览 1 评论 0原文

有时(随机发生,有时在一个请求后,有时在 10 个请求后)我的 Batch-Job 崩溃并出现以下异常:

javax.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request: org.apache.http.NoHttpResponseException: host_url failed to respond
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:327)
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:443)
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:63)
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocationBuilder.post(ClientInvocationBuilder.java:227)

异常是由以下代码触发的:

public YpspResponse sendRequest(YpspRequest request) {
        return webTarget
                .request(MediaType.APPLICATION_XML)
                .post(Entity.xml(request))
                .readEntity(YpspResponse.class);
    }

WebTarget 使用此代码初始化:

            ResteasyClientBuilder builder = new ResteasyClientBuilder()
                    .socketTimeout(30, TimeUnit.SECONDS)
                    .connectTimeout(5, TimeUnit.SECONDS)
                    .connectionPoolSize(500)
                    .keyStore(keyStore, ynetKeystorePassword.toCharArray())
                    .trustStore(trustStore);

            if (proxyConfiguration.useProxy()){
                logger.info("{}", proxyConfiguration.getHost());
                builder.defaultProxy(proxyConfiguration.getHost(), proxyConfiguration.getPort());
            }

            return builder
                    .build()
                    .target(ynetUrl)
                    .register(messageBodyReader)
                    .register(loggingFilter)
                    .register((ClientRequestFilter) requestContext -> {
                        byte[] auth = (username + ":" + password).getBytes("UTF-8");
                        requestContext.getHeaders().putSingle(HttpHeaders.AUTHORIZATION, "BASIC " + Base64.getEncoder().encodeToString(auth));
                        requestContext.getHeaders().putSingle("version", "1.1");
                    });

我正在使用 RESTEASY:3.12.1.FINAL

看来 ResteasyClient 尝试使用已使用的连接而不是新连接。我该如何解决这个问题?

Sometimes (happens randomly, sometimes after one Requests and sometimes after 10) my Batch-Job crashes with the following Exception:

javax.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request: org.apache.http.NoHttpResponseException: host_url failed to respond
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:327)
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:443)
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:63)
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocationBuilder.post(ClientInvocationBuilder.java:227)

The exception is triggered from the following code:

public YpspResponse sendRequest(YpspRequest request) {
        return webTarget
                .request(MediaType.APPLICATION_XML)
                .post(Entity.xml(request))
                .readEntity(YpspResponse.class);
    }

WebTarget is initialized with this code:

            ResteasyClientBuilder builder = new ResteasyClientBuilder()
                    .socketTimeout(30, TimeUnit.SECONDS)
                    .connectTimeout(5, TimeUnit.SECONDS)
                    .connectionPoolSize(500)
                    .keyStore(keyStore, ynetKeystorePassword.toCharArray())
                    .trustStore(trustStore);

            if (proxyConfiguration.useProxy()){
                logger.info("{}", proxyConfiguration.getHost());
                builder.defaultProxy(proxyConfiguration.getHost(), proxyConfiguration.getPort());
            }

            return builder
                    .build()
                    .target(ynetUrl)
                    .register(messageBodyReader)
                    .register(loggingFilter)
                    .register((ClientRequestFilter) requestContext -> {
                        byte[] auth = (username + ":" + password).getBytes("UTF-8");
                        requestContext.getHeaders().putSingle(HttpHeaders.AUTHORIZATION, "BASIC " + Base64.getEncoder().encodeToString(auth));
                        requestContext.getHeaders().putSingle("version", "1.1");
                    });

I am using RESTEASY: 3.12.1.FINAL

It appears that the ResteasyClient tries to use an already used connection instead of a new one. How can I fix this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

和影子一齐双人舞 2025-01-21 12:17:28

升级到3.15.2版本问题得到解决

Upgrade to 3.15.2 version issue gets resolve

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文