为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

HUWWW 2022-05-25 10:37:40
我有一个 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。任何指针都会有所帮助。谢谢你。如果我应该在问题中添加任何其他详细信息,请告诉我。
查看完整描述

2 回答

?
拉丁的传说

TA贡献1789条经验 获得超8个赞

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

查看完整回答
反对 回复 2022-05-25
?
慕哥6287543

TA贡献1831条经验 获得超10个赞

请尝试以下代码 -


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();

    }

}

}


查看完整回答
反对 回复 2022-05-25
  • 2 回答
  • 0 关注
  • 216 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号