gpt4 book ai didi

wildfly - java.lang.ClassNotFoundException : javax.net.ssl.SSLSocketFactory 在 WildFly8.2.0 上使用 JAVA 8 轻松休息时

转载 作者:行者123 更新时间:2023-12-02 14:12:00 28 4
gpt4 key购买 nike

我使用rest easy从第三方URL获取和发布数据,当我使用下面的代码调用获取服务时,我收到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,jsse.jar 是 JDK 1.8 lib 的一部分。然后我意识到我们不应该将这些 jar 添加到 httpclient 模块和部署 lib 文件夹中。

如果有人能解决此问题,请告诉我。

最佳答案

将“javax.api”依赖项添加到模块 org.apache.commons.httpclient 的 module.xml 后,问题得到解决。

<module ...>

<resources>
...
</resources>

<dependencies>
....
<module name="javax.api"/>
</dependencies>
</module>

关于wildfly - java.lang.ClassNotFoundException : javax.net.ssl.SSLSocketFactory 在 WildFly8.2.0 上使用 JAVA 8 轻松休息时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34024813/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com