当前位置: 首页 > 知识库问答 >
问题:

Glassfish 5.0java.lang.NosuchMethodError

颛孙凯定
2023-03-14
private int conn (String search)throws Exception {

    String key="mykey";
    URL url = new URL("https://www.googleapis.com/customsearch/v1?q="+search+"&cx=017576662512468239146%3Aomuauf_lfve&key="+key);
    doTrustToCertificates();
    HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
    connection.setDoOutput(true);
    BufferedReader reader = new BufferedReader(new InputStreamReader((connection.getInputStream())));
    String splitreader = "";
    StringBuilder ss = new StringBuilder();
    while((splitreader = reader.readLine()) != null){
        ss.append(splitreader);
}
    JSONObject json = new JSONObject(ss.toString());
    JSONObject jsonrequest = json.getJSONObject("queries").getJSONArray("request").getJSONObject(0);
    return jsonrequest.getInt("totalResults");
    }


 public void doTrustToCertificates() throws Exception {
    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    TrustManager[] trustAllCerts = new TrustManager[]{
            new X509TrustManager() {
                public X509Certificate[] getAcceptedIssuers() {
                    return null;
                }

                public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException {
                    return;
                }

                public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException {
                    return;
                }
            }
    };

    SSLContext sc = SSLContext.getInstance("SSL");
    sc.init(null, trustAllCerts, new SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    HostnameVerifier hv = new HostnameVerifier() {
        public boolean verify(String urlHostName, SSLSession session) {
            if (!urlHostName.equalsIgnoreCase(session.getPeerHost())) {
                System.out.println("Warning: URL host '" + urlHostName + "' is different to SSLSession host '" + session.getPeerHost() + "'.");
            }
            return true;
        }
    };
    HttpsURLConnection.setDefaultHostnameVerifier(hv);
}

java.lang.nosuchmethoderror:sun.security.ssl.sslsessionimpl.(lsun/security/ssl/protocolversion;lsun/security/ssl/ciphersuite;ljava/util/collection;lsun/security/ssl/sessionid;ljava/lang/string;i)V

但是代码可以在glassfish 4.1.1和wildfly上工作,我不明白为什么不能在glassfish 5.0上工作

共有1个答案

艾昊明
2023-03-14

检查您的Java版本。这是由于JDK8U161左右的JDK的变化影响了Grizzly。

总结如下:

  • 如果使用GlassFish 5.0,则需要使用JDK 8U161以下的JDK 8版本
  • 如果使用GlassFish 5.0.1或更高版本,则需要使用8u161以上的JDK 8版本
 类似资料:

相关问答

相关文章

相关阅读