异常问题解决方案(SSLProtocolException)

BUG描述:

       异常信息: javax.net.ssl.SSLProtocolException,handshake alert: unrecognized_name

    1、代码在本地开发环境正常,但上传到了服务器端后,启动tomcat就报错;

    2、使用httpclient抓取https数据,不加代理没问题,加代理之后就报错;

解决方案:

        1、在服务器端保证jdk版本是1.6及以上

       2、如果是Tomcat进程:在catalina.sh加上JAVA_OPTS="$JAVA_OPTS -Djsse.enableSNIExtension=false"

       3、如果是Java独立进程:加上代码System.setProperty("jsse.enableSNIExtension", "false");

已标记关键词 清除标记
就出现以下异常: javax.net.ssl.SSLProtocolException: handshake alert: unrecognized_name at sun.security.ssl.ClientHandshaker.handshakeAlert(ClientHandshaker.java:1292) at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1952) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1077) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323) at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1300) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254) at com.mymap.model.CaptureJavascript.getPosition(CaptureJavascript.java:60) 尝试照网上说的添加: **System.setProperty("jsse.enableSNIExtension", "false");** 但是无效。 以下是我的代码。该方法在Capture类中,servlet类中调用Capture类的方法,方法代码如下: private double[] getPosition(double lat, double lon) throws Exception { System.setProperty("jsse.enableSNIExtension", "false"); String strURL = "https://eosweb.larc.nasa.gov/cgi-bin/sse/grid.cgi?&num=230000&lat=" + lat + "&submit=Submit&veg=17&p=swv_dwn&step=2&lon=" + lon; //"https://eosweb.larc.nasa.gov/cgi-bin/sse/grid.cgi?&num=199997&lat=" + lat + "&submit=Submit&veg=17&p=swv_dwn&step=2&lon=" + lon; URL url = new URL(strURL); HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); InputStreamReader input = new InputStreamReader(httpConn.getInputStream(), "utf-8"); BufferedReader bufReader = new BufferedReader(input); StringBuilder contentBuf = new StringBuilder(); String line = ""; while((line = bufReader.readLine()) != null) { contentBuf.append(line); } String buf = contentBuf.toString(); int beginIx = buf.indexOf("year Average"); int endIx = buf.indexOf("Minimum And Maximum Difference"); String resultstr = buf.substring(beginIx, endIx); return getDoubles(resultstr); }
©️2020 CSDN 皮肤主题: 游动-白 设计师:白松林 返回首页
实付 9.90元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值