当前位置:  开发笔记 > 运维 > 正文

java.lang.ClassNotFoundException:javax.net.ssl.SSLSocketFactory在WildFly8.2.0上使用JAVA 8时使用rest easy

如何解决《java.lang.ClassNotFoundException:javax.net.ssl.SSLSocketFactory在WildFly8.2.0上使用JAVA8时使用resteasy》经验,为你挑选了1个好方法。

我使用rest很容易从第三方URL获取和发布数据,当我使用下面的代码调用get服务时,我得到了ClassNotFoundException"javax.net.ssl.SSLSocketFactory"

final ClientRequest request = createRequest(url,acceptType,consumesType,body);
final byte[] encodedCredentials = (userName + ":" + password)
            .getBytes();
    final String encodedAuto = Base64.encodeBytes(encodedCredentials);
    request.header("Authorization", "Basic " + encodedAuto);
try {
        request.addAuthenticationHeaders(request, userName,
                password);
        response = request.get(String.class);
        if (response != null) {
            logger.info("Status of the REST Call:"
                    + response.getStatus());
        }
    } catch (final Exception e) {
        e.printStackTrace();
        logger.error("Failed the get the data from PM", e);
    }

createRequest方法如下所示

public ClientRequest createRequest(final String urlString,
        final String acceptType, final String consumesType,
        final String body) {
    final ClientRequest request = new ClientRequest(urlString);
    request.accept(acceptType);
    if (body != null) {
        request.body(consumesType, body);
    }
    request.header("Content-Type", consumesType);
    // request.header("Accept", acceptType);

    return request;
}

当它执行response = request.get(request)时; 它抛出SSLSocketFactory ClassNotFoundException,根据我的分析,这个类在rt.jar上可用,不需要添加到WildFly服务器或部署lib文件夹.

Caused by: java.lang.NoClassDefFoundError: javax/net/ssl/SSLSocketFactory
at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:82) [commons-httpclient-3.1.jar:]
at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:127) [commons-httpclient-3.1.jar:]
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707) [commons-httpclient-3.1.jar:]
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387) [commons-httpclient-3.1.jar:]
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171) [commons-httpclient-3.1.jar:]
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397) [commons-httpclient-3.1.jar:]
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323) [commons-httpclient-3.1.jar:]
at org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor.execute(ApacheHttpClientExecutor.java:81) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.core.interception.ClientExecutionContextImpl.proceed(ClientExecutionContextImpl.java:39) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.security.doseta.DigitalSigningInterceptor.execute(DigitalSigningInterceptor.java:107) [resteasy-crypto-3.0.10.Final.jar:]
at org.jboss.resteasy.core.interception.ClientExecutionContextImpl.proceed(ClientExecutionContextImpl.java:45) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.plugins.interceptors.encoding.AcceptEncodingGZIPInterceptor.execute(AcceptEncodingGZIPInterceptor.java:40) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.core.interception.ClientExecutionContextImpl.proceed(ClientExecutionContextImpl.java:45) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.client.ClientRequest.execute(ClientRequest.java:473) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.client.ClientRequest.httpMethod(ClientRequest.java:704) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.client.ClientRequest.get(ClientRequest.java:509) [resteasy-jaxrs-2.2.1.GA.jar:]
at org.jboss.resteasy.client.ClientRequest.get(ClientRequest.java:537) [resteasy-jaxrs-2.2.1.GA.jar:]
at com.example.main.framework.service.RestClientService.get(RestClientService.java:46) [main-ejb.jar:]
at com.example.main.entity.validator.EntityValidator.getPMAccountDetails(EntityValidator.java:2866) [main-ejb.jar:]
at com.example.main.entity.validator.EntityValidator.validateCompanySettingPortfolioMgr(EntityValidator.java:2633) [main-ejb.jar:]
at com.example.main.action.codegen.CompanySettingPortfolioMgrHome.persist(CompanySettingPortfolioMgrHome.java:329) [main-ejb.jar:]
... 99 more
Caused by: java.lang.ClassNotFoundException: javax.net.ssl.SSLSocketFactory from [Module "org.apache.commons.httpclient:main" from local module loader @6043cd28 (finder: local module finder @cb51256 (roots: D:\wildfly-8.2.0.Final\modules,D:\wildfly-8.2.0.Final\modules\system\layers\base))]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:213) [jboss-modules.jar:1.3.3.Final]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:459) [jboss-modules.jar:1.3.3.Final]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:408) [jboss-modules.jar:1.3.3.Final]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:389) [jboss-modules.jar:1.3.3.Final]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:134) [jboss-modules.jar:1.3.3.Final]
... 120 more

如果我们将rt.jar添加到wildfly模块,那么它会抛出与jsse.jar中的类相关的ClassNotFoundException,这是JDK 1.8 lib的一部分.然后我意识到我们不应该将这些jar既不添加到httpclient模块也不添加到部署lib文件夹.

如果有人解决这个问题,请告诉我.



1> Sreenath Red..:

在将"javax.api"依赖项添加到模块org.apache.commons.httpclient的module.xml之后,问题得到了解决.



    
        ...
    

    
        ....
         
    

推荐阅读
臭小子
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有