猿问

调用我的 Web 服务时出现 SSL 协议错误

我有一个 Spring REST Web 服务,它在内部调用第三方供应商提供的 SOAP Web 服务。SOAP Web 服务客户端是使用 CXF 生成的。自从升级到我的组织提供的更新版本的 JDK 后,我看到了以下奇怪的行为

1) 如果我通过 Web 服务器调用我的 REST 服务,在第一次成功的 SOAP 调用之后,应用程序停止响应。Web 服务器开始给出 Bad Gateway 错误。

a)此时,如果我调用应用服务器,则它没有响应。Chrome 显示 SSL 协议错误,但访问日志中没有条目或 chrome 开发人员工具中没有任何响应。

2) 如果我直接在应用服务器上调用我的 REST 服务,即使调用了“n”次,该服务也会按预期工作。

根据我单位提供的变更日志,变更是从JDK版本jdk1.8.0_161_iaik5.5_ecc4.02到jdk1.8.0_161_iaik5.5_ecc4.02_1。

任何指针都会有所帮助。谢谢你。如果我应该在问题中添加任何其他详细信息,请告诉我。



HUWWW
浏览 217回答 2
2回答

拉丁的传说

请检查第三方支持的 TLS 版本。我在连接苹果云网址时遇到了 Received fatal alert: decode_error。我可以通过将协议显式设置为 TLS 1.2 来修复它。

慕哥6287543

请尝试以下代码 -public class NetClientPost {public static String getMapData(String latlong) {    String response = null;    try {        disableCertificateValidation();        URL urlForGetRequest = new URL(                "http://localhost:8080/server api url");        String readLine = null;        HttpURLConnection conection = (HttpURLConnection) urlForGetRequest.openConnection();        conection.setRequestMethod("GET");        // conection.setRequestProperty("userId", "a1bcdef"); // set userId its a sample        // here        int responseCode1 = conection.getResponseCode();        if (responseCode1 == HttpURLConnection.HTTP_OK) {            BufferedReader in1 = new BufferedReader(new InputStreamReader(conection.getInputStream()));            StringBuffer response1 = new StringBuffer();            while ((readLine = in1.readLine()) != null) {                response1.append(readLine);            }            in1.close();            // print result            response = response1.toString();            System.out.println("JSON String Result " + response1.toString());            // GetAndPost.POSTRequest(response.toString());        } else {            System.out.println("GET NOT WORKED");        }    } catch (Exception e) {        e.printStackTrace();        // TODO: handle exception    }    return response;}public static void disableCertificateValidation() {    // Create a trust manager that does not validate certificate chains    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {        public X509Certificate[] getAcceptedIssuers() {            return new X509Certificate[0];        }        public void checkClientTrusted(X509Certificate[] certs, String authType) {        }        public void checkServerTrusted(X509Certificate[] certs, String authType) {        }    } };    // Ignore differences between given hostname and certificate hostname    HostnameVerifier hv = new HostnameVerifier() {        public boolean verify(String hostname, SSLSession session) {            return true;        }    };    // Install the all-trusting trust manager    try {        SSLContext sc = SSLContext.getInstance("SSL");        sc.init(null, trustAllCerts, new SecureRandom());        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());        HttpsURLConnection.setDefaultHostnameVerifier(hv);    } catch (Exception e) {        e.printStackTrace();    }}}
随时随地看视频慕课网APP

相关分类

Java
我要回答