简体   繁体   English

com.sun.xml.internal.ws.client.ClientTransportException:HTTP传输错误:java.net.SocketException:连接重置

[英]com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.SocketException: Connection reset

A client developed in Java using JDK 1.6. 使用JDK 1.6在Java中开发的客户端。 I am consuming API in the java code. 我在java代码中使用API​​。 Whenever I hit this API from soapui or from JDK 1.7 it is working perfectly fine but when I tried to hit this API using JDK 1.6, it is returning the error. 每当我从soapui或JDK 1.7中获取此API时,它的工作完全正常,但是当我尝试使用JDK 1.6命中此API时,它将返回错误。 com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.SocketException: Connection reset. com.sun.xml.internal.ws.client.ClientTransportException:HTTP传输错误:java.net.SocketException:连接重置。

I have tried by developing client using WSDL and using HTTPSURLConnection, with both mechanism, I am getting the same error. 我尝试过使用WSDL开发客户端并使用HTTPSURLConnection,使用这两种机制,我得到了同样的错误。 It seems there is nothing wrong with the code. 似乎代码没有任何问题。 I am unable to find out the way for the resolution. 我无法找到解决问题的方法。

Wireshark Result: When I ran the jar from JDK 1.7, I can see the result in Wireshark, the protocol is TSLv1 but when I tried to run the jar from 1.6, the protocol has been changed to SSLv2. Wireshark结果:当我从JDK 1.7运行jar时,我可以在Wireshark中看到结果,协议是TSLv1但是当我尝试从1.6运行jar时,协议已经更改为SSLv2。 Is it possible to change protocol in the code or on the system where we are calling jar? 是否可以在代码中或我们调用jar的系统上更改协议?

Here is my code: 这是我的代码:

 public String myFun(String sender) throws IOException, 
 NoSuchAlgorithmException, KeyManagementException{


    SSLContext sslContext = SSLContext.getInstance("SSL");
    TrustManager[] trustManager = getTrustManager();
    sslContext.init(null, trustManager, new SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());

    try{
            String inquiryRequest = inquiryRequest = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:v5=\"http://xxxxxxx\">\n" 
                    +"<soapenv:Header>\n" 
                    +"</soapenv:Header>\n" 
                    +"<soapenv:Body>\n" 
                    +"<v5:single.smsReq>\n" 
                    +"<sender>"+sender+"</sender>\n" 
                    +"</v5:single.smsReq>\n" 
                    +"</soapenv:Body>\n" 
                    +"</soapenv:Envelope>";

            URL url =new URL ("https://xxxx:xx/xx");
            HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();

            conn.setRequestMethod("POST");
            conn.setRequestProperty("content-type","application/xml");
            conn.setRequestProperty("Authorization","Basic xxx");
            conn.setDoOutput(true);
            DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
                wr.writeBytes(inquiryRequest);
                wr.flush();
                wr.close();

            BufferedReader in = new BufferedReader( new InputStreamReader(conn.getInputStream()));
            String inputLine;
            StringBuilder response = new StringBuilder();
                while ((inputLine = in.readLine()) != null) {
                        response.append(inputLine);
                }
                in.close();
                conn.disconnect();

            return response.toString();

    }catch(Exception e){
        return null;
    } 

}
private TrustManager[] getTrustManager() {
    TrustManager[] certs = new TrustManager[] { new X509TrustManager() {
        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
        public void checkClientTrusted(X509Certificate[] certs, String t) {
        }
        public void checkServerTrusted(X509Certificate[] certs, String t) {
        }
    }
    };
    return certs;
}

In SSLContext you can setup your own SSlContext TSLv1 or SSLv2 then call sslContext.init with trusted certificates. 在SSLContext中,您可以设置自己的SSlContext TSLv1或SSLv2,然后使用受信任的证书调用sslContext.init。 And, add it to your HttpsURLConnection as the DefaultSSLSocketFactory. 并将其作为DefaultSSLSocketFactory添加到您的HttpsURLConnection中。

System.setProperty ("jsse.enableSNIExtension", "false");

SSLContext sslContext = SSLContext.getInstance("SSL");
TrustManager[] trustManager = getTrustManager();
sslContext.init(null, trustManager, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());

HostnameVerifier hostNameVerifier = new HostnameVerifier() {
    public boolean verify(String hostname, SSLSession session) {
        return true;
    }
};

HttpsURLConnection.setDefaultHostnameVerifier(hostNameVerifier);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JAX WS com.sun.xml.internal.ws.client.ClientTransportException:HTTP 传输错误:java.net.ConnectException:连接被拒绝 - JAX WS com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.ConnectException: Connection refused 线程“ main” com.sun.xml.internal.ws.client.ClientTransportException中的异常:服务器发送了HTTP状态代码502:代理错误 - Exception in thread “main” com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 502: Proxy Error com.sun.xml.ws.client.ClientTransportException:HTTP传输错误:java.lang.ClassCastException - com.sun.xml.ws.client.ClientTransportException: HTTP transport error: java.lang.ClassCastException 连接到 web 服务导致 com.sun.xml.internal.ws.client.ClientTransportException:服务器发送 HTTP 状态码 200 - Connecting to webservice results in com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 200: OK 导入com.sun.xml.internal.ws.client.ClientTransportException,无法读取此导入 - import com.sun.xml.internal.ws.client.ClientTransportException, can't read this import HTTP传输错误:java.net.SocketException:连接重置 - HTTP transport error: java.net.SocketException: Connection reset com.sun.jersey.api.client.ClientHandlerException:java.net.SocketException:连接重置 - com.sun.jersey.api.client.ClientHandlerException: java.net.SocketException: Connection reset Glassfish抛出com.sun.xml.ws.client.ClientTransportException:服务器发送了HTTP状态代码500:内部服务器错误 - Glassfish throws com.sun.xml.ws.client.ClientTransportException: The server sent HTTP status code 500: Internal Server Error 错误java.net.SocketException:连接重置 - ERROR java.net.SocketException: Connection reset 对等java.net.SocketException重置连接:传输端点未连接 - Connection reset by peer java.net.SocketException: Transport endpoint is not connected
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM