当我尝试连接https网址时...我正在接受ssl握手失败... 我使用的是vertx-version>> 2.1.5 请帮我解决这个问题......我被困在这里对我来说非常重要
This code is working fine, giving me proper response..
URL url = new URL("https://bugzilla.mozilla.org/rest/bug/707428/comment");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("GET");
conn.setRequestProperty("accept", "application/json");
InputStream is=conn.getInputStream();
InputStreamReader isr=new InputStreamReader(is);
BufferedReader br=new BufferedReader(isr);
String str=null;
while((str=br.readLine())!=null){
System.out.println(str);
}
conn.disconnect();
但使用vertx时。它正在给手摇晃问题
HttpClient client = MyServer.defaultVertx.createHttpClient().setSSL(true).setTrustAll(true)
.setHost("bugzilla.mozilla.org").setPort(443).setVerifyHost(false);
HttpClientRequest request= client.request("GET","/rest/bug/707428/comment",new Handler<HttpClientResponse>() {
@Override
public void handle(HttpClientResponse cRes) {
System.out.println(" HttpClientResponse Done.."+cRes);
cRes.bodyHandler(new Handler<Buffer>() {
@Override
public void handle(Buffer data) {
System.out.println("Response (" + data.length() + "): ");
System.out.println("Response >>" +data.getString(0, data.length()));
}
});
cRes.dataHandler(new Handler<Buffer>() {
@Override
public void handle(Buffer data) {
System.out.println("data Handler (" + data.length() + "): ");
System.out.println("data Handler<>> "+data.getString(0, data.length()));
}
});
cRes.exceptionHandler(new Handler<Throwable>() {
@Override
public void handle(Throwable arg0) {
arg0.printStackTrace();
}
});
}
});
request.exceptionHandler(new Handler<Throwable>() {
@Override
public void handle(Throwable arg0) {
// TODO Auto-generated method stub
arg0.printStackTrace();
}
});
request.end();
client.close();
javax.net.ssl.SSLException: Received fatal alert: handshake_failure
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1619)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1587)
at sun.security.ssl.SSLEngineImpl.recvAlert(SSLEngineImpl.java:1756)
at sun.security.ssl.SSLEngineImpl.readRecord(SSLEngineImpl.java:1060)
at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:884)
at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:758)
at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624)
at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1001)
at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:927)
at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:873)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:241)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:149)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:125)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
at java.lang.Thread.run(Thread.java:745)
答案 0 :(得分:0)
代码示例连接到端口433,而HTTPS正在侦听443。 我的猜测是你的问题是一个错字,否则你不会得到SSL握手失败。
您的代码看起来很好,它应该能够处理自签名的SSL证书。 我怀疑这是bugzilla.mozilla.org的特定SSL设置与Vert.x 2中的HTTP客户端实现相结合的问题。您可以通过访问另一个主机(https://google.com来检查这一点,例如)。
可能的原因可能是mozilla.org上的SSL设置需要SNI(服务器名称指示),并且Vert.x HTTPClient默认情况下不会发送此信息。
答案 1 :(得分:0)
很难确定此异常的确切问题。
它可能是不兼容的密码,缺少JCE策略jar,SSL版本问题等等。
我建议启用Connection相关问题的调试,看看到底出了什么问题。
<强> -Djavax.net.debug =所有强>
请参阅moreinfo
的此链接