以下代码适用于某些系统,包括我的开发系统,但在其他系统上request.get()
失败(所有Win 7或Win Server 2008)。
@Provider
public static class ClientRequestFilter implements javax.ws.rs.client.ClientRequestFilter {
private Cookie cookie;
public ClientRequestFilter(Cookie cookie) {
super();
this.cookie = cookie;
}
@Override
public void filter(ClientRequestContext clientRequestContext) throws IOException {
if (this.cookie!=null) {
List<Object> cookies = new ArrayList<>();
cookies.add(this.cookie);
clientRequestContext.getHeaders().put("Cookie", cookies);
}
}
}
:
:
ResteasyClient client = new ResteasyClientBuilder()
.register(new ClientRequestFilter(authorizationToken))
.disableTrustManager()
.establishConnectionTimeout(5, TimeUnit.SECONDS)
.socketTimeout(10, TimeUnit.MINUTES)
.build();
ResteasyWebTarget target = client.target("https://xxx.yyy.net");
Builder request = target.request();
if (!OrganizationId.isEmpty())request.header("Organization-Id", OrganizationId);
Response response = request.get();
在request.get()
失败的系统上,调用是一个非常简单的调用,用于检查目标是否正在运行并应返回短文本状态。同样的调用可以在浏览器中使用。
堆栈跟踪显示我似乎没有得到目标的响应。我试图关闭防火墙和防病毒软件,以防他们干扰。
javax.ws.rs.ProcessingException: Unable to invoke request
at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:287)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:407)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocationBuilder.get(ClientInvocationBuilder.java:159)
at com.hp.pcDataCollector.DCRest.action(DCRest.java:138)
at com.hp.pcDataCollector.DCRest.get(DCRest.java:59)
at com.hp.pcDataCollector.DCaaa.checkConnection(DCaaa.java:154)
at com.hp.pcDataCollector.DCaaa.loginToGenesis(DCaaa.java:125)
at com.hp.pcDataCollector.DataCollector.run(DataCollector.java:118)
at com.hp.pcDataCollector.DataCollector.main(DataCollector.java:77)
Caused by: org.apache.http.NoHttpResponseException: xxx.yyy.net:443 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.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java
)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:251)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.j
197)
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.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:685)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:487)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:283)
... 8 more
有什么想法吗?