Glassfish 5.0 java.lang.NoSuchMethodError

删除回忆录丶 提交于 2019-12-01 09:57:00

问题


When i tried connect google custom search api glassfish throw nosuchmethoderror

That's codes

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

Exception

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

But codes worked on glassfish 4.1.1 and wildfly i can't understand why not working on glassfish 5.0


回答1:


Check your Java version. This is due to changes in the JDK around JDK 8u161 which affect Grizzly.

To summarise:

  • If you use GlassFish 5.0, you need to be on a version of JDK 8 below JDK 8u161
  • If you use GlassFish 5.0.1 or higher, you need to be on a version of JDK 8 above 8u161

This bug is tracked in the GlassFish GitHub issue tracker:
https://github.com/eclipse-ee4j/glassfish/issues/22436



来源:https://stackoverflow.com/questions/49733840/glassfish-5-0-java-lang-nosuchmethoderror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!