【发布时间】:2015-01-29 07:07:40
【问题描述】:
我正在使用 jersey-apache-client 进行 ssl 连接。我在验证连接时遇到握手错误。下面是握手错误。
WRITE: TLSv1 Change Cipher Spec, length = 1
Finished
verify_data: { 165, 117, 49, 237, 116, 71, 111, 175, 161, 237, 45, 30 }
WRITE: TLSv1 Handshake, length = 48
READ: TLSv1 Alert, length = 2
RECV TLSv1 ALERT: fatal, handshake_failure
%% Invalidated: [Session-1, TLS_DHE_RSA_WITH_AES_128_CBC_SHA]
如果我使用 jersey-client-1.13 并且我没有收到握手错误,代码可以正常工作。
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(keyManagerFactory.getKeyManagers(), tmf.getTrustManagers(), null);
final ClientConfig config = new DefaultClientConfig();
config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(null, ctx));
Client create = Client.create(config);
create.resource(targetUrl).post();
由于 jersey-client.1.13 不支持代理,所以我使用了 jersey-apache-client.1.18。在下面的代码中,我使用了 DefaultApacheHttpClientConfig,添加了代理支持,使用 ApacheHttpClient 创建了客户端。
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(keyManagerFactory.getKeyManagers(), tmf.getTrustManagers(), null);
final DefaultApacheHttpClientConfig apacheConfig = new DefaultApacheHttpClientConfig();
final Map<String, Object> properties = apacheConfig.getProperties();
properties.put(DefaultApacheHttpClientConfig.PROPERTY_PROXY_URI, "http://" + proxyHost + ":" + proxyPort);
properties.put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(null,ctx));
apacheConfig.getState().setProxyCredentials(AuthScope.ANY_REALM, proxyHost, Integer.parseInt(proxyPort),proxyUser, proxyPassword);
Client create = ApacheHttpClient.create(apacheConfig);
create.resource(targetUrl).post();
我找不到解决方案。在这两种情况下,证书都很好。
注意:我也试过不带代理的jersey apache客户端,还是有错误。
有人发现出了什么问题吗?提前致谢。
【问题讨论】:
标签: java apache rest ssl jersey-client