无法在Weblogic 12c(12.2.1)中部署CXF3.x JAX-RS服务

时间:2017-08-03 13:40:26

标签: java web-services jax-rs cxf weblogic12c

将使用CXF3.x构建的JAX-RS服务从weblogic 12.1.3升级到12.2.1后,我面临以下奇怪的问题

<03-ago-2017, 3:22:38,789 PM CEST> <Error> <HTTP> <BEA-101216> <Servlet: "JAX-RS/Jersey#1" failed to preload on startup in Web application: "sife".
A MultiException has 1 exceptions.  They are:
1. java.lang.LinkageError: ClassCastException: attempting to castzip:C:/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain/servers/AdminServer/tmp/_WL_user/sife/845176/war/WEB-INF/lib/javax.ws.rs-api-2.0.1.jar!/javax/ws/rs/ext/RuntimeDelegate.class to jar:file:/C:/Oracle/Middleware/Oracle_Home/oracle_common/modules/javax.ws.rs.javax.ws.rs-api.jar!/javax/ws/rs/ext/RuntimeDelegate.class

        at org.jvnet.hk2.internal.Utilities.justCreate(Utilities.java:1007)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.create(ServiceLocatorImpl.java:962)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:1054)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:1046)
        at org.glassfish.jersey.model.internal.CommonConfig.configureFeatures(CommonConfig.java:696)
        Truncated. see log file for complete stacktrace

请注意,我使用的是CXF,而不是Jersey,但似乎Weblogic正在尝试使用它(12.1.3不会发生这种情况)。我按照以下建议在配置文件中禁用了它:https://jerometambo.github.io/blog/2016/12/13/How-to-use-CXF-3x-implementation-of-JAX-RS-20-REST-with-Weblogic-12c.html

  

使用默认配置,Weblogic希望使用其内部实现(JAX-RS 2.0和序列化)来部署REST Web服务(错误500):

META-INF / WebLogic的application.xml中

<weblogic-application  xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-application"
                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-application
                                           http://xmlns.oracle.com/weblogic/weblogic-application/1.8/weblogic-application.xsd">

    <prefer-application-packages>
        <package-name>javax.ws.rs.*</package-name>
        <package-name>com.fasterxml.jackson.*</package-name>
        <package-name>weblogic.jaxrs.api.client.*</package-name>
        <package-name>weblogic.jaxrs.internal.api.*</package-name>
        <package-name>weblogic.jaxrs.dispatch.*</package-name>
        <package-name>weblogic.jaxrs.monitoring.util.*</package-name>
    </prefer-application-packages>
</weblogic-application>

WEB-INF / weblogic.xml中

<weblogic-web-app 
    xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">

    <container-descriptor>
        <prefer-application-packages>
            <package-name>javax.ws.rs.*</package-name>
            <package-name>com.fasterxml.jackson.*</package-name> 
        </prefer-application-packages>
    </container-descriptor> 
</weblogic-web-app>

我不知道这是我项目的具体问题还是weblogic问题。我发现了thisthis等类似问题,我尝试使用它们。

这些是我的依赖项(IVY语法)

<dependency org="org.apache.cxf" name="cxf-rt-frontend-jaxrs" rev="3.1.10" conf="default" />
    <dependency org="org.apache.cxf" name="cxf-rt-rs-extension-providers" rev="3.1.10" conf="default" />
    <dependency org="org.apache.cxf" name="cxf-rt-transports-http" rev="3.1.10" conf="default" />
    <dependency org="com.fasterxml.jackson.jaxrs" name="jackson-jaxrs-json-provider" rev="2.6.6" conf="default" />

完整的堆栈跟踪

<03-ago-2017, 3:32:03,645 PM CEST> <Warning> <JAXRSIntegration> <BEA-2192510> <Cannot add Jersey servlet for application class org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet$ApplicationImpl because ApplicationPath annotation is not set on it.>
<03-ago-2017, 3:32:03,737 PM CEST> <Warning> <JAXRSIntegration> <BEA-2192511> <The list of resource packages: com.fasterxml.jackson.jaxrs.base;org.apache.cxf.jaxrs.provider;com.fasterxml.jackson.jaxrs.json;org.apache.cxf.jaxrs.provider.aegis;es.aragon.sife.server.filter;org.apache.cxf.jaxrs.provider.jsrjsonp;es.aragon.sife.keystore.api;es.aragon.sife.server.account.api;org.apache.cxf.jaxrs.provider.xmlbeans;org.apache.cxf.jaxrs.validation;es.aragon.sife.server.task.api;org.apache.cxf.jaxrs.provider.json;org.apache.cxf.jaxrs.provider.atom;es.aragon.sife.server.config.api>
ago 03, 2017 3:32:16 PM es.gob.afirma.signers.xml.Utils installXmlDSigProvider
<03-ago-2017, 3:32:20,581 PM CEST> <Error> <HTTP> <BEA-101216> <Servlet: "JAX-RS/Jersey#1" failed to preload on startup in Web application: "sife".
A MultiException has 1 exceptions.  They are:
1. java.lang.LinkageError: ClassCastException: attempting to castzip:C:/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain/servers/AdminServer/tmp/_WL_user/sife/845176/war/WEB-INF/lib/javax.ws.rs-api-2.0.1.jar!/javax/ws/rs/ext/RuntimeDelegate.class to jar:file:/C:/Oracle/Middleware/Oracle_Home/oracle_common/modules/javax.ws.rs.javax.ws.rs-api.jar!/javax/ws/rs/ext/RuntimeDelegate.class

        at org.jvnet.hk2.internal.Utilities.justCreate(Utilities.java:1007)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.create(ServiceLocatorImpl.java:962)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:1054)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:1046)
        at org.glassfish.jersey.model.internal.CommonConfig.configureFeatures(CommonConfig.java:696)
        Truncated. see log file for complete stacktrace
Caused By: java.lang.LinkageError: ClassCastException: attempting to castzip:C:/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain/servers/AdminServer/tmp/_WL_user/sife/845176/war/WEB-INF/lib/javax.ws.rs-api-2.0.1.jar!/javax/ws/rs/ext/RuntimeDelegate.class to jar:file:/C:/Oracle/Middleware/Oracle_Home/oracle_common/modules/javax.ws.rs.javax.ws.rs-api.jar!/javax/ws/rs/ext/RuntimeDelegate.class
        at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:146)
        at javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:120)
        at javax.ws.rs.core.MediaType.valueOf(MediaType.java:179)
        at org.glassfish.jersey.media.sse.SseFeature.<clinit>(SseFeature.java:62)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        Truncated. see log file for complete stacktrace
>
<03-ago-2017, 3:32:20,696 PM CEST> <Error> <Deployer> <BEA-149231> <Unable to set the activation state to true for the application "sife".
weblogic.application.ModuleException: java.lang.LinkageError: ClassCastException: attempting to castzip:C:/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain/servers/AdminServer/tmp/_WL_user/sife/845176/war/WEB-INF/lib/javax.ws.rs-api-2.0.1.jar!/javax/ws/rs/ext/RuntimeDelegate.class to jar:file:/C:/Oracle/Middleware/Oracle_Home/oracle_common/modules/javax.ws.rs.javax.ws.rs-api.jar!/javax/ws/rs/ext/RuntimeDelegate.class
        at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
        at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
        at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:233)
        at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:228)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
        Truncated. see log file for complete stacktrace
Caused By: java.lang.LinkageError: ClassCastException: attempting to castzip:C:/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain/servers/AdminServer/tmp/_WL_user/sife/845176/war/WEB-INF/lib/javax.ws.rs-api-2.0.1.jar!/javax/ws/rs/ext/RuntimeDelegate.class to jar:file:/C:/Oracle/Middleware/Oracle_Home/oracle_common/modules/javax.ws.rs.javax.ws.rs-api.jar!/javax/ws/rs/ext/RuntimeDelegate.class
        at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:146)
        at javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:120)
        at javax.ws.rs.core.MediaType.valueOf(MediaType.java:179)
        at org.glassfish.jersey.media.sse.SseFeature.<clinit>(SseFeature.java:62)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        Truncated. see log file for complete stacktrace
>
<03-ago-2017, 3:32:20,762 PM CEST> <Notice> <Log Management> <BEA-170027> <The server has successfully established a connection with the Domain level Diagnostic Service.>
<03-ago-2017, 3:32:20,931 PM CEST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to ADMIN.>
<03-ago-2017, 3:32:21,46 PM CEST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RESUMING.>
<03-ago-2017, 3:32:21,174 PM CEST> <Notice> <WebLogicServer> <BEA-000360> <The server started in RUNNING mode.>
<03-ago-2017, 3:32:21,186 PM CEST> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to RUNNING.>
<03-ago-2017, 3:32:22,710 PM CEST> <Error> <HTTP> <BEA-101216> <Servlet: "weblogic.management.rest.Application" failed to preload on startup in Web application: "wls-management-services.war".
A MultiException has 1 exceptions.  They are:
1. java.lang.NoClassDefFoundError: Could not initialize class org.glassfish.jersey.media.sse.SseFeature

        at org.jvnet.hk2.internal.Utilities.justCreate(Utilities.java:1007)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.create(ServiceLocatorImpl.java:962)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:1054)
        at org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:1046)
        at org.glassfish.jersey.model.internal.CommonConfig.configureFeatures(CommonConfig.java:696)
        Truncated. see log file for complete stacktrace
Caused By: java.lang.NoClassDefFoundError: Could not initialize class org.glassfish.jersey.media.sse.SseFeature
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.glassfish.hk2.utilities.reflection.ReflectionHelper.makeMe(ReflectionHelper.java:1350)
        Truncated. see log file for complete stacktrace
>
<03-ago-2017, 3:32:22,747 PM CEST> <Error> <J2EE> <BEA-160001> <Error deploying Internal Application: weblogic.application.ModuleException: java.lang.NoClassDefFoundError: Could not initialize class org.glassfish.jersey.media.sse.SseFeature
weblogic.application.utils.StateChangeException: weblogic.application.ModuleException: java.lang.NoClassDefFoundError: Could not initialize class org.glassfish.jersey.media.sse.SseFeature
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:58)
        at weblogic.application.services.BackgroundDeploymentManagerService$BackgroundDeployAction.run(BackgroundDeploymentManagerService.java:396)
        at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:666)
        at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:348)
        at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:333)
        Truncated. see log file for complete stacktrace
Caused By: weblogic.application.ModuleException: java.lang.NoClassDefFoundError: Could not initialize class org.glassfish.jersey.media.sse.SseFeature
        at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
        at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
        at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:233)
        at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:228)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
        Truncated. see log file for complete stacktrace
Caused By: java.lang.NoClassDefFoundError: Could not initialize class org.glassfish.jersey.media.sse.SseFeature
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.glassfish.hk2.utilities.reflection.ReflectionHelper.makeMe(ReflectionHelper.java:1350)
        Truncated. see log file for complete stacktrace

替代方法

如果我使用默认的JAX-RS实现部署先前的其他CXF模块并删除WEB-INF/lib/javax.ws.rs-api-2.0.1.jar,则它可以正常工作。也许weblogic会进行某种内部初始化。

 myapp.ear
   init.war (JAX-RS with CXF and removing javax.ws.rs-api-2.0.1.jar)
   myapp.war (JAX-RS with CXF and weblogic configuration)

1 个答案:

答案 0 :(得分:1)

@pedrofb,这可能无法完全回答你的问题,但是,我曾经遇到过与Tomcat类似的问题。症状是相似的,问题不是真的是由于不同类别的存在在不同的罐子中,即罐子阴影。这是由于类加载器阴影。在Tomcat中,类加载实际上是倒置的,而不是通常的'问候 - 你的父级 - 类加载器 - 第一个&#39;一种模型,如果应用程序类加载器可以找到一个类(它只从WEB-INF / lib或类加载),则类加载器加载该类。现在,在您的情况下,我认为,由于JAX-RS jar存在于您的WEB-INF / lib中,因此它将从Web应用程序级别加载。但是,当将相同的对象传递给容器时,它会尝试将其强制转换为同一个类,但是在由不同的类加载器加载的容器级别。由不同类加载器加载的类被认为是不同的;这将是ClassCastException的原因。

这也可以解释为什么从WEB-INF / lib中删除JAX-RS jar时没有ClassCastException。这里的解决方法是有限的,要么就像你所做的那样从你的WEb-INF / lib中删除JAX-RS jar。 (这可能有问题,但您可以在非生产服务器中进行试验),将容器JAX-RS jar替换为您想要的容器。

正如我所说,这可能无法完全解决您的问题,但可能会指出问题来自哪里。 [正如我几年前所注意到的那样,Weblogic使用tomcat作为其web容器核心(不确定它是否仍然相同),包括更改的包名称,如com.bea.weblogic.org.apache.tomcat ...]。

希望这有帮助。