【问题标题】:java.lang.ClassNotFoundException: org.apache.http.impl.conn.PoolingClientConnectionManager while using resteasy for a rest client call from an EJBjava.lang.ClassNotFoundException: org.apache.http.impl.conn.PoolingClientConnectionManager 同时使用resteasy进行来自EJB的rest客户端调用
【发布时间】:2019-01-06 13:20:08
【问题描述】:

当我使用 rest easy to call services 作为客户端时,我在 Wildfly 13 上遇到了一个问题。

我在ear 中部署了许多 EJB 项目。除了 wildfly 13 应用程序服务器(来自模块文件夹)提供的库之外,依赖项由 maven 管理。我使用最新版本的 JBoss Tools 进行部署。

我的应用程序将一些休息服务发布为服务器。当我调用这些 Web 服务(例如来自邮递员)时,一切都很好。 Wildfly 提供的其余 API org.jboss.resteasy.resteasy-jaxrs 3.5.1 可以正常工作。

但我的应用程序还需要连接到外部的 REST Web 服务,这次是作为客户端。我编写了一个无状态 EJB 来实例化一个 WebTarget,目标是提供的 URL(即外部 rest 服务的目标):

protected void setTarget(URL target) throws FmRestApiException {
    try {
        String sUrl = target.toString();
        this.target = ClientBuilder.newClient().target(sUrl);
    }
    catch(Exception e) {
        throw new FmRestApiException("Can't initialize FM Rest API to target "+target,e);
    }
}

但是当我发起调用时,Wildfly 无法构建 webtarget,resteasy 抛出以下异常:

Caused by: java.lang.NoClassDefFoundError: org/apache/http/impl/conn/PoolingClientConnectionManager
    at org.jboss.resteasy.client.jaxrs.ClientHttpEngineBuilder4.build(ClientHttpEngineBuilder4.java:110)
    at org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder.buildOld(ResteasyClientBuilder.java:381)
    at org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder.build(ResteasyClientBuilder.java:390)
    at org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder.build(ResteasyClientBuilder.java:38)
    at javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:114)
    at com.novarem.commons.fmapi.rest.AbstractFmApiRestClient.setTarget(AbstractFmApiRestClient.java:37)
    at fr.remmedia.fmadapter.FmRestApiGateway.init(FmRestApiGateway.java:50)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptor.java:96)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.weld.interceptors.Jsr299BindingsInterceptor.doLifecycleInterception(Jsr299BindingsInterceptor.java:122)
    at org.jboss.as.weld.interceptors.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:111)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:509)
    at org.jboss.weld.module.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:72)
    at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:89)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.weld.injection.WeldInjectionInterceptor.processInvocation(WeldInjectionInterceptor.java:53)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.ee.component.ManagedReferenceFieldInjectionInterceptorFactory$ManagedReferenceFieldInjectionInterceptor.processInvocation(ManagedReferenceFieldInjectionInterceptorFactory.java:112)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.ee.component.AroundConstructInterceptorFactory$1.processInvocation(AroundConstructInterceptorFactory.java:28)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.weld.injection.WeldInterceptorInjectionInterceptor.processInvocation(WeldInterceptorInjectionInterceptor.java:56)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.weld.interceptors.Jsr299BindingsCreateInterceptor.processInvocation(Jsr299BindingsCreateInterceptor.java:105)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:237)
    ... 270 more
Caused by: java.lang.ClassNotFoundException: org.apache.http.impl.conn.PoolingClientConnectionManager from [Module "org.jboss.resteasy.resteasy-jaxrs" version 3.5.1.Final from local module loader @4c40b76e (finder: local module finder @2ea6137 (roots: /Library/JBoss/wildfly-remmedia-13/modules,/Library/JBoss/wildfly-remmedia-13/modules/system/layers/base))]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:255)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)

我知道在以前版本的 Wildfly 中作为模块提供的 resteasy 和 apache httpcomponents 包之间的版本不兼容。但在 Wildfly 13 中,org.jboss.resteasy.resteasy-jaxrs 最高版本为 3.5.1,org.apache.httpcomponents 最高版本为 httpclient 4.5.2,httpcore 为 4.4.4,httpasyncclient 为 4.1.3,httpmime 为 4.5.2。

有人遇到同样的问题吗?否则,有人知道如何解决它吗?

【问题讨论】:

    标签: rest ejb wildfly resteasy


    【解决方案1】:

    我终于解决了这个问题。实际上,Wildfly 默认不加载 org.apache.httpcomponents 模块,而 resteasy 模块与它有依赖关系。所以只需强制将模块加载到standalone.xml/domain.xml 部署文件中,如下所示:

    <subsystem xmlns="urn:jboss:domain:ee:4.0">
        <global-modules>
            <module name="org.apache.httpcomponents"/>
        </global-modules>
        ...
    </subsystem>
    

    【讨论】:

      猜你喜欢
      • 2014-01-16
      • 2017-01-16
      • 2014-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-23
      • 1970-01-01
      • 2017-09-28
      相关资源
      最近更新 更多