Weblogic中部署Apache CXF的拦截器和Apache拦截器如何解决

How to resolve interceptors deploying Apache CXF in Weblogic and Apache interceptors

我有一个在 Tomcat 下正确部署的 Apache CXF Web 服务,但是,当我将它部署到 Weblogic 服务器时,我遇到了这个错误。

2015-01-29 14:54:02 WARN  org.apache.cxf.phase.PhaseInterceptorChain  ==> Interceptor for {http://localhost.com/esquemas/xsd/}sias has thrown exception, unwinding now
java.lang.NullPointerException
  at java.util.PropertyResourceBundle.handleGetObject(PropertyResourceBundle.java:136)
    at java.util.ResourceBundle.getObject(ResourceBundle.java:368)
    at java.util.ResourceBundle.getString(ResourceBundle.java:334)
    at org.apache.cxf.common.logging.AbstractDelegatingLogger.formatMessage(AbstractDelegatingLogger.java:363)
    at org.apache.cxf.common.logging.AbstractDelegatingLogger.internalLog(AbstractDelegatingLogger.java:352)
    at org.apache.cxf.common.logging.AbstractDelegatingLogger.doLog(AbstractDelegatingLogger.java:335)
    at org.apache.cxf.common.logging.AbstractDelegatingLogger.log(AbstractDelegatingLogger.java:78)
    at org.apache.cxf.frontend.WSDLGetUtils.getDocument(WSDLGetUtils.java:157)
    at org.apache.cxf.frontend.WSDLGetInterceptor.getDocument(WSDLGetInterceptor.java:129)
    at org.apache.cxf.frontend.WSDLGetInterceptor.handleMessage(WSDLGetInterceptor.java:77)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:251)
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:223)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:197)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:150)
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:291)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:215)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:265)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:27)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:57)
    at oracle.security.jps.ee.http.JpsAbsFilter.run(JpsAbsFilter.java:119)
    at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:315)
    at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:442)
    at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:103)
    at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:171)
    at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:57)
    at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:139)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:57)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3730)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
2015-01-29 14:54:02 DEBUG org.apache.cxf.phase.PhaseInterceptorChain  ==> Adding interceptor org.apache.cxf.interceptor.LoggingOutInterceptor@18bee97a to phase pre-stream
...

当我将 war 项目部署到本地 Tomcat 服务器时,一切正常。为了将 war 部署到 weblogic,我将其包装在一个 ear 文件中。我能够访问根上下文,但是当我要求 wsdl 时,我得到了这个响应:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Fault occurred while processing.</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>

当我查看日志文件时,我看到了之前的异常。任何帮助将不胜感激。

好吧,经过一番折腾,我终于找到了答案。问题出在我的依赖项上。我正在使用 Apache CXF 3.0.3 和许多其他依赖项混合在一起。这是我的最后一个 pom.xml,有了这个,我终于可以在我的 weblogic 服务器上看到生成的 wsdl。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <groupId>com.example.data</groupId>
    <version>1.5.20150202.6-SNAPSHOT</version>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>service</artifactId>
    <packaging>war</packaging>
    <name>service</name>    
    <properties>
           <cxf.version>2.7.2</cxf.version>
        <spring.version>3.2.2.RELEASE</spring.version>
        <spring.jpa.version>1.3.2.RELEASE</spring.jpa.version>
        <hibernate.version>4.2.1.Final</hibernate.version>
        <hibernate.jpa.version>1.0.1.Final</hibernate.jpa.version>
        <mysql.connection.version>5.1.25</mysql.connection.version>
    </properties>
    <build>
        <finalName>${project.artifactId}_${project.version}</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <version>1.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <webResources>
                        <!--<webResource>-->
                            <!--<resource>-->
                                <!--<directory>${basedir}/src/main/resources</directory>-->
                                <!--<targetPath>WEB-INF/classes</targetPath>-->
                                <!--<includes>-->
                                    <!--<include>**/*.properties</include>-->
                                <!--</includes>-->
                            <!--</resource>-->
                        <!--</webResource>-->
                        <resource>
                            <directory>${webapps.config}</directory>
                            <targetPath>WEB-INF/classes</targetPath>
                            <excludes>
                                <exclude>META-INF/**</exclude>
                            </excludes>
                        </resource>
                        <resource>
                            <directory>${webapps.config}/META-INF</directory>
                            <targetPath>META-INF</targetPath>
                            <!--<excludes>-->
                            <!--<exclude>WEB-INF/**</exclude>-->
                            <!--</excludes>-->
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
        </plugins>
        </build>
    <properties>
        <org.slf4j-version>1.6.6</org.slf4j-version>
        <apache-commons>1.4</apache-commons>
        <aspectjtools.version>1.7.1</aspectjtools.version>
    </properties>
    <dependencies>
        <!-- Spring dependencies -->
        <!-- Bean Factory and JavaBeans utilities (depends on spring-core) Define
                 this if you use Spring Bean APIs (org.springframework.beans.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- Application Context (depends on spring-core, spring-expression, spring-aop,
                        spring-beans) This is the central artifact for Spring's Dependency Injection
                        Container and is generally always defined -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- Aspect Oriented Programming (AOP) Framework (depends on core, beans)
            Define this if you use Spring AOP APIs (org.springframework.aop.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>${spring.jpa.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- Spring dependencies -->



        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${org.slf4j-version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${org.slf4j-version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.mail</groupId>
                    <artifactId>mail</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
            </exclusions>
            <scope>runtime</scope>
        </dependency>


        <!-- AspectJ -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>${aspectjtools.version}</version>
        </dependency>


        <!-- Apache CXF-->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-tools-common</artifactId>
            <version>${cxf.version}</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <!-- Apache CXF-->

        <dependency>
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <version>2.3.0</version>
        </dependency>
        </dependencies>
</project>