Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.ClassNotFoundException: com.sun.jersey.core.spi.factory.ResponseImpl REST-FUL Webservices

I'm trying to run a REST-FUL Java GET method using Jersey and no have any problem, but when I change any Method from GET to POST, I have error the Webserver throw

java.lang.ClassNotFoundException: com.sun.jersey.core.spi.factory.ResponseImpl

This is my code Class implementation:

@Path("/entrega")
public class EntregaWebServiceREST extends WebServiceParentREST {

    static Logger log = Logger.getLogger(EntregaWebServiceREST.class.getName());
    private EntregaService entregaService;



    public EntregaWebServiceREST() {

        entregaService = context.getBean(EntregaService.class);
    }



    @POST 
    @Produces("text/plain")
    @Consumes("text/xml")
    @Path("/sendWorkerToClient")
    public String setWorkerToClient(@RequestParam("xml")
                                            String xml) {

        try {
            return entregaService.setWorkerToClient(xml);
        } catch (Exception e) {
            log.error(e);
            e.printStackTrace();
            return "ocurrio una excepcion: " + e.getMessage();
        }
    }


}

This is my pom.xml:

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.hanhelds</groupId>
    <artifactId>OfficeDepot-REST</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <zk.version>6.5.2</zk.version>
        <spring.version>3.1.2.RELEASE</spring.version>
        <hibernate.version>4.0.0.Final</hibernate.version>
        <commons-io>1.3.1</commons-io>
        <maven.build.timestamp.format>yyyy-MM-dd</maven.build.timestamp.format>
        <packname>-${project.version}-FL-${maven.build.timestamp}</packname>

        <jersey-version>1.13</jersey-version>        
        <xstream.version>1.4.4</xstream.version>
        <!-- del proyecto jdbc -->
        <version.log4j>1.2.17</version.log4j>
        <version.slf4j>1.7.2</version.slf4j>
        <version.sql-processor>2.2.2</version.sql-processor>
        <!-- del proyecto jdbc -->    
        <m2eclipse.wtp.contextRoot>/services</m2eclipse.wtp.contextRoot>


    </properties>
    <packaging>war</packaging>
    <name>The Handhelds Project</name>
    <description>The Handhelds Project</description>
    <licenses>
        <license>
            <name>GNU LESSER GENERAL PUBLIC LICENSE, Version 3</name>
            <url>http://www.gnu.org/licenses/lgpl.html</url>
            <distribution>repo</distribution>
        </license>
    </licenses>
    <repositories>      
        <!-- para Jersey -->
        <repository>
            <id>glassfish.java.net</id>
            <name>GlassFish Maven Repository</name>
            <url>http://download.java.net/maven/glassfish</url>
            <layout>default</layout>
        </repository>
        <repository>
            <id>m2.java.net</id>
            <name>Java.net Maven 2 Repository</name>
            <url>http://download.java.net/maven/2</url>
            <layout>default</layout>
        </repository>
        <!-- para Jersey -->

    </repositories>
    <pluginRepositories>

        <!-- para Jersey -->    
        <pluginRepository>
            <id>m2.java.net</id>
            <name>Java.net Maven 2 Repository</name>
            <url>http://download.java.net/maven/2</url>
            <layout>default</layout>
        </pluginRepository>
        <!-- para Jersey -->        
    </pluginRepositories>
    <dependencies>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>${commons-io}</version>
        </dependency>

        <!-- Spring 3 dependencies -->
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- JPA(Hibernate) and HSQL dependencies -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <version>2.2.6</version>
        </dependency>


    <!-- dependencias para Jersey -->

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>${jersey-version}</version>
        </dependency> -->

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-json</artifactId>
            <version>${jersey-version}</version>
        </dependency> -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>${jersey-version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.glassfish.distributions</groupId>
            <artifactId>web-all</artifactId>
            <version>10.0-build-20080430</version>
            <scope>test</scope>
        </dependency>
         <!--
        <dependency>
            <groupId>org.glassfish.embedded</groupId>
            <artifactId>gf-embedded-api</artifactId>
            <version>1.0-alpha-4</version>
            <scope>test</scope>
        </dependency>
         -->
    <!-- dependencias para Jerysey -->


    <dependency>
        <groupId>com.thoughtworks.xstream</groupId>
        <artifactId>xstream</artifactId>
        <version>${xstream.version}</version>
    </dependency>
    <dependency>
        <groupId>xpp3</groupId>
        <artifactId>xpp3</artifactId>
        <version>1.1.4c</version>
    </dependency>
    <dependency>
        <groupId>xmlpull</groupId>
        <artifactId>xmlpull</artifactId>
        <version>1.1.3.1</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.gatein.common</groupId>
        <artifactId>common-logging</artifactId>
        <version>2.1.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>net.sf.jt400</groupId>
        <artifactId>jt400</artifactId>
        <version>6.7</version>
    </dependency>

    <!-- eliminar si agregan proyecto jdbc -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>${version.slf4j}</version>
    </dependency>

    <dependency>
        <groupId>org.sqlproc</groupId>
        <artifactId>sql-processor</artifactId>
        <version>${version.sql-processor}</version>
    </dependency>


    <!-- eliminar si agregan proyecto jdbc -->
    <!-- 
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-core</artifactId>
        <version>${jersey-version}</version>
        <scope>provided</scope>
    </dependency>  -->
    </dependencies>
    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <!-- Run withs Jetty -->
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.10</version>
                <configuration>
                    <scanIntervalSeconds>5</scanIntervalSeconds>
                    <stopKey>foo</stopKey>
                    <stopPort>9999</stopPort>
                    <contextPath>/services</contextPath>
                </configuration>
                <executions>
                    <execution>
                        <id>start-jetty</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <scanIntervalSeconds>0</scanIntervalSeconds>
                            <daemon>true</daemon>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop-jetty</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- Compile java -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
            <!-- Build war -->
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <groupId>org.apache.maven.plugins</groupId>
                <version>2.1.1</version>
            </plugin>
            <!-- Pack zips -->
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <id>webapp</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <finalName>services</finalName>
                            <appendAssemblyId>false</appendAssemblyId>
                            <descriptors>
                                <descriptor>src/main/assembly/webapp.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>


            <!-- plugins oara Jersey -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <inherited>true</inherited>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.glassfish</groupId>
                <artifactId>maven-glassfish-plugin</artifactId>
            </plugin>
            <!-- plugins oara Jersey -->            
        </plugins>

    </build>    

</project>

This is the stack trace error:

[27/08/13 18:25:37:273 CDT] 0000002a servlet       E com.ibm.ws.webcontainer.servlet.ServletWrapper service Uncaught service() exception thrown by servlet Jersey Web Application: java.lang.NoClassDefFoundError: com.sun.jersey.core.spi.factory.ResponseImpl
    at java.lang.J9VMInternals.verifyImpl(Native Method)
    at java.lang.J9VMInternals.verify(J9VMInternals.java:77)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:139)
    at com.sun.jersey.core.spi.factory.AbstractRuntimeDelegate.createResponseBuilder(AbstractRuntimeDelegate.java:99)
    at javax.ws.rs.core.Response$ResponseBuilder.newInstance(Response.java:60)
    at javax.ws.rs.core.Response.status(Response.java:263)
    at com.sun.jersey.api.Responses.status(Responses.java:127)
    at com.sun.jersey.api.Responses.methodNotAllowed(Responses.java:107)
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:221)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1480)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1411)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1360)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1350)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1147)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:722)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:449)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1020)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3639)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:950)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1659)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1648)
Caused by: java.lang.ClassNotFoundException: com.sun.jersey.core.spi.factory.ResponseImpl
    at java.net.URLClassLoader.findClass(URLClassLoader.java:434)
    at com.ibm.ws.bootstrap.ExtClassLoader.findClass(ExtClassLoader.java:198)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:646)
    at com.ibm.ws.bootstrap.ExtClassLoader.loadClass(ExtClassLoader.java:113)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:612)
    at com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java:62)
    at com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java:58)
    at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:564)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:612)
    at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:564)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:612)
    ... 45 more
like image 408
user2723428 Avatar asked Oct 04 '22 03:10

user2723428


1 Answers

The issue seems to be that classloader picks up class not compatible with application (hence J9VMInternal.verify fails). To resolve this issue, you need to specify class loader order - load classes using local class loader first (parent last).

like image 118
user3040441 Avatar answered Oct 07 '22 17:10

user3040441