0

I have written following Code to intercept the incoming request.

@Provider
public class RequestInterceptor implements  ReaderInterceptor {
    @Override
    public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
        Message message = PhaseInterceptorChain.getCurrentMessage();
        OperationResourceInfo cri = message.getExchange().get(OperationResourceInfo.class);
        return null;
    }
}

I am using Apache CXF 3.1.10 and Liberty Profile 16.

In my server.xml, following features are enabled :

<featureManager>
    <feature>webProfile-7.0</feature>
    <feature>localConnector-1.0</feature>
</featureManager>

Following is my pom.xml file:

<repositories>
        <repository>
            <id>prime-repo</id>
            <name>PrimeFaces Maven Repository</name>
            <url>http://repository.primefaces.org</url>
            <layout>default</layout>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>6.0</version>
        </dependency>
        <dependency>
            <groupId>org.primefaces.themes</groupId>
            <artifactId>all-themes</artifactId>
            <version>1.0.10</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.5</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.12</version>
        </dependency>

        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>20.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/joda-time/joda-time -->
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.9.6</version>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxrs</artifactId>
            <version>3.1.10</version>
        </dependency>


    </dependencies>

When I am running the application I am getting below error:

[INFO    ] Setting the server's publish address to be /rest/
[INFO    ] SRVE0242I: [TestApp] [/TestApp] [javax.ws.rs.core.Application]: Initialization successful.
[ERROR   ] SRVE0777E: Exception thrown by application class 'framework.rest.interceptors.RequestInterceptor.aroundReadFrom:32'
java.lang.NoClassDefFoundError: org/apache/cxf/phase/PhaseInterceptorChain
    at framework.rest.interceptors.RequestInterceptor.aroundReadFrom(RequestInterceptor.java:32)
    at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBodyReader(JAXRSUtils.java:1356)
    at [internal classes]

If I am running my application without the interceptor code then its running just fine.

Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
Prerak Tiwari
  • 3,436
  • 4
  • 34
  • 64
  • This is caused by a classloading conflict between Liberty's CXF impl and one that you have bundled in your app. Since the `webProfile-7.0` feature includes the `jaxrs-2.0` feature (and its API), can you simply not package the CXF implementation in your app? – Andy Guibert Mar 23 '17 at 22:16
  • It still giving me the errors: Do you know the Liberty's CXF impl Version number? – Prerak Tiwari Mar 23 '17 at 22:34
  • it depends on your exact liberty version, but you can check in `${wlp.install.dir}/lib/com.ibm.ws.org.apache.cxf-rt-core.X.X.jar` to see what version liberty uses – Andy Guibert Mar 23 '17 at 22:36
  • For my liberty..its com.ibm.ws.org.apache.cxf-rt-core.2.6.2_1.0.14 – Prerak Tiwari Mar 23 '17 at 22:39
  • I removed the jar CXF jar from war file but still I am getting the same error...Is there anything else I can do about it? – Prerak Tiwari Mar 23 '17 at 22:43

1 Answers1

1

Did you have just cxf-rt-frountend-jaxrs-x.x.x.jar packaged in your application? PhaseInterceptorChain.class is in cxf-core-x.x.x.jar. Perhaps try including all cxf jars in the lib directory of your .war.

bouteillebleu
  • 2,456
  • 23
  • 32