javax.net.ssl.SSLHandshakeException:握手期间远程主机关闭连接

javax.net.ssl.SSLHandshakeException:握手期间远程主机关闭连接,java,rest,ssl,https,Java,Rest,Ssl,Https,我正在使用Java7来运行这段代码。我已经在本地javastore中添加了服务器证书,但它仍然抛出下面的异常。 我从firefox下载了服务器证书,然后用keytool导出并导入到javaStore public class TokenizeClient { public static String tokenization(String data){ byte[] credential = Base64.encodeBase64("username:password

我正在使用Java7来运行这段代码。我已经在本地javastore中添加了服务器证书,但它仍然抛出下面的异常。 我从firefox下载了服务器证书,然后用keytool导出并导入到javaStore

public class TokenizeClient {

    public static String tokenization(String data){

        byte[] credential = Base64.encodeBase64("username:password".getBytes(StandardCharsets.UTF_8));
        String encodedCrential=new String(credential);
        System.out.println("Encoded Credentials "+credential);


    /*  byte[] encoded = encodedCrential.getBytes();
        // decoding byte array into base64
        byte[] decoded = Base64.decodeBase64(encoded);
        String decodedCredential= new String(decoded, StandardCharsets.UTF_8);
        System.out.println("Decode Credentials "+decodedCredential);*/

        // Tokenize request

        URL tokenize_url;
        String token = null;
        try {

            //tokenize_url = new URL(EncryptionDecryptionConstant.VTS_TOKENIZE_URL);
            tokenize_url = new URL("https://192.168.1.74/vts/rest/v2.0/tokenize");

            System.out.println("tokenizw URL :"+tokenize_url);
            //System.setProperty("https.protocols", "TLSv1");

            HttpsURLConnection httpsConn=(HttpsURLConnection) tokenize_url.openConnection();


            String jStr ="{\"data\":\""+data+"\",\"tokengroup\":\"Enliven-Token-Test\",\"tokentemplate\":\"Enliven-Token-Temp\"}";
            //String jStr ="{\"data\":\"Anees\",\"tokengroup\":\"Enliven-Token-Test\",\"tokentemplate\":\"Enliven-Token-Temp\"}";

            System.out.println("input String :"+jStr);

            httpsConn.setRequestProperty("Content-length", String.valueOf(jStr.length()));
            httpsConn.setRequestProperty("Content-Type","application/json");
            httpsConn.setRequestProperty("Authorization","Basic "+encodedCrential);
            httpsConn.setRequestMethod("POST");
            httpsConn.setDoOutput(true);
            httpsConn.setDoInput(true);

            System.out.println("###### All header properties are set");

            DataOutputStream output = new DataOutputStream(httpsConn.getOutputStream());


            output.writeBytes(jStr);
            output.close();


            BufferedReader rd=new BufferedReader(new InputStreamReader(httpsConn.getInputStream()));

                        String line = "";
            String strResponse = "";
            while ((line = rd.readLine()) != null) {
            strResponse=strResponse+line;
            }
            rd.close();
             System.out.println("********** Response ***"+strResponse);
             token = JsonPath.read(strResponse, "$.token").toString();
            httpsConn.disconnect();

            return token;


        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return token;   
    }   

    public static void main(String[] args) {
        String result =VormetricTokenizeClient.tokenization("Anees");
        System.out.println("##############  "+result);
    }
}
例外情况:
我可以在调试控制台中看到我添加的证书

关闭ClientHello上连接的服务器可以是任何内容,如意外的协议版本或密码、缺少TLS扩展、错误的服务器设置等。它与证书验证无关。密切关注客户端的连接不会有多大帮助。相反,您需要查看服务器端,即服务器为什么关闭连接。不知道服务器的类型,但希望您有一些日志文件或其他类型的报告错误。在ClientHello上关闭连接的服务器可以是任何类型,例如意外的协议版本或密码、缺少TLS扩展、错误的服务器设置等。这与证书验证无关。密切关注客户端的连接不会有多大帮助。相反,您需要查看服务器端,即服务器为什么关闭连接。不知道服务器是什么类型的,但希望您有一些日志文件或其他类型的报告错误。
main, WRITE: TLSv1 Handshake, length = 163
main, received EOFException: error
main, handling exception: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
main, SEND TLSv1 ALERT:  fatal, description = handshake_failure
main, WRITE: TLSv1 Alert, length = 2
main, called closeSocket()
main, called close()
main, called closeInternal(true)
##############  null
javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:946)
    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.getOutputStream(HttpURLConnection.java:1091)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
    at com.ramyam.security.adapter.VormetricTokenizeClient.tokenization(VormetricTokenizeClient.java:79)
    at com.ramyam.security.adapter.VormetricTokenizeClient.main(VormetricTokenizeClient.java:210)
Caused by: java.io.EOFException: SSL peer shut down incorrectly
    at sun.security.ssl.InputRecord.read(InputRecord.java:482)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
    ... 9 more