Jersey deployment in jetty issues

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Jersey deployment in jetty issues

Vijay Velusamy
Hi,

I wrote a simple RESTful service with Jersey, and am able to connect to the resource endpoints either through curl "http://host:port/contextpath/resourcepath" or using a client when I use maven to run the server/servlet (using mvn jetty:run). However, When I try to deploy the war file in jetty's webapp directory and use the same client or curl, I only get 404 responses. When I curl "http://host:port/contextpath", I can see the WEB-INF and META-INF paths, but not able to access anything beyond that. I am trying to understand why this works when I do mvn jetty:run, but not when I start jetty with java -jar start.jar. Also what do I need to do to make this work on a standalone jetty server. I have provided the web.xml, and context/service.xml file used to deploy in jetty

The following is noticed when I run jetty in debug mode
 |  +-WebAppContext@66b51404@66b51404/testService/services,file:/private/var/folders/zz/zzzivhrRnAmviuee+++++++++++/-Tmp-/Jetty_0_0_0_0_8000_test.war__testService_services__.bqlltp/webapp/,/opt/xcal/jetty/install/jetty-distribution-7.0.2.v20100331/webapps/test.war started
    |  |  +-SessionHandler@3fbfbfb8 started
    |  |     +-ConstraintSecurityHandler@4125d61e started
    |  |        +-ServletHandler@45c3e9ba started
    |  |           +-null
    |  |           +-[/]=>default
    |  |           +-[*.jsp, *.jspf, *.jspx, *.xsp, *.JSP, *.JSPF, *.JSPX, *.XSP]=>jsp
    |  |           +-[/services/*]=>Test Service
    |  |        +=roles=[]
    |  |        +=/={TRACE={RoleInfo,F,C[]}}
    |  +-ContextHandler@7a8d0b0f@7a8d0b0f/javadoc,file:/opt/xcal/jetty/install/jetty-distribution-7.0.2.v20100331/javadoc/ started
    |     +-ResourceHandler@11f18cbe started
    +-DefaultHandler@37eb2c1b started
    +-RequestLogHandler@309cbd4b started
10-06-15 14:49:32.241:DBUG::REQUEST /testService/services/testpath/ on org.eclipse.jetty.server.nio.SelectChannelConnector$2@2a4bd173
2010-06-15 14:49:32.242:DBUG::sessionManager=org.eclipse.jetty.server.session.HashSessionManager@1b0c6cfc
2010-06-15 14:49:32.242:DBUG::session=null
2010-06-15 14:49:32.242:DBUG::servlet=default
2010-06-15 14:49:32.243:DBUG::servlet holder= default
2010-06-15 14:49:32.245:DBUG::chain=
2010-06-15 14:49:32.247:DBUG::Aliased resource: file:/private/var/folders/zz/zzzivhrRnAmviuee+++++++++++/-Tmp-/Jetty_0_0_0_0_8000_test.war__testService_services__.bqlltp/webapp/test~=file:/private/var/folders/zz/zzzivhrRnAmviuee+++++++++++/-Tmp-/Jetty_0_0_0_0_8000_test.war__testService_services__.bqlltp/webapp/test/
2010-06-15 14:49:32.247:DBUG::RESOURCE /test/=null
2010-06-15 14:49:32.248:DBUG::Aliased resource: file:/private/var/folders/zz/zzzivhrRnAmviuee+++++++++++/-Tmp-/Jetty_0_0_0_0_8000_test.war__testService_services__.bqlltp/webapp/test~=file:/private/var/folders/zz/zzzivhrRnAmviuee+++++++++++/-Tmp-/Jetty_0_0_0_0_8000_test.war__testService_services__.bqlltp/webapp/test/
2010-06-15 14:49:32.248:DBUG::RESOURCE /test/=null
2010-06-15 14:49:32.248:DBUG::resource=null
2010-06-15 14:49:32.255:DBUG::RESPONSE /testService/services/testpath/  404


context/service.xml:
<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
        <Set name="contextPath">/testService/services</Set>
        <Set name="war"><SystemProperty name="jetty.home" default="." />/webapps/test.war</Set>
</Configure>

web.xml
<?xml version="1.0" encoding="UTF-8"?>
        <display-name>testService</display-name>
        <servlet>
        <servlet-name>Test Service</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext.xml</param-value>
        </context-param>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.test.service</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Test Service</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
</web-app>

TIA
Reply | Threaded
Open this post in threaded view
|

Re: Jersey deployment in jetty issues

Paul Sandoz
Administrator
Hi,

I am not familiar with Jetty but there may be a mistake in your service.xml:

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
        <Set name="contextPath">/testService/services</Set>
        <Set name="war"><SystemProperty name="jetty.home" default="." />/webapps/test.war</Set>
</Configure>

Should it not be:

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
        <Set name="contextPath">/testService</Set>
        <Set name="war"><SystemProperty name="jetty.home" default="." />/webapps/test.war</Set>
</Configure>

? since the "services" path segment is defined in the web.xml

I would expect if you have the former configuration that the path to the resource would be:

  /testService/services/services/testpath/

Paul.

On Jun 15, 2010, at 9:01 PM, Vijay Velusamy wrote:

Hi,

I wrote a simple RESTful service with Jersey, and am able to connect to the resource endpoints either through curl "http://host:port/contextpath/resourcepath" or using a client when I use maven to run the server/servlet (using mvn jetty:run). However, When I try to deploy the war file in jetty's webapp directory and use the same client or curl, I only get 404 responses. When I curl "http://host:port/contextpath", I can see the WEB-INF and META-INF paths, but not able to access anything beyond that. I am trying to understand why this works when I do mvn jetty:run, but not when I start jetty with java -jar start.jar. Also what do I need to do to make this work on a standalone jetty server. I have provided the web.xml, and context/service.xml file used to deploy in jetty

The following is noticed when I run jetty in debug mode
 |  +-WebAppContext@66b51404@66b51404/testService/services,file:/private/var/folders/zz/zzzivhrRnAmviuee+++++++++++/-Tmp-/Jetty_0_0_0_0_8000_test.war__testService_services__.bqlltp/webapp/,/opt/xcal/jetty/install/jetty-distribution-7.0.2.v20100331/webapps/test.war started
    |  |  +-SessionHandler@3fbfbfb8 started
    |  |     +-ConstraintSecurityHandler@4125d61e started
    |  |        +-ServletHandler@45c3e9ba started
    |  |           +-null
    |  |           +-[/]=>default
    |  |           +-[*.jsp, *.jspf, *.jspx, *.xsp, *.JSP, *.JSPF, *.JSPX, *.XSP]=>jsp
    |  |           +-[/services/*]=>Test Service
    |  |        +=roles=[]
    |  |        +=/={TRACE={RoleInfo,F,C[]}}
    |  +-ContextHandler@7a8d0b0f@7a8d0b0f/javadoc,file:/opt/xcal/jetty/install/jetty-distribution-7.0.2.v20100331/javadoc/ started
    |     +-ResourceHandler@11f18cbe started
    +-DefaultHandler@37eb2c1b started
    +-RequestLogHandler@309cbd4b started
10-06-15 14:49:32.241:DBUG::REQUEST /testService/services/testpath/ on org.eclipse.jetty.server.nio.SelectChannelConnector$2@2a4bd173
2010-06-15 14:49:32.242:DBUG::sessionManager=org.eclipse.jetty.server.session.HashSessionManager@1b0c6cfc
2010-06-15 14:49:32.242:DBUG::session=null
2010-06-15 14:49:32.242:DBUG::servlet=default
2010-06-15 14:49:32.243:DBUG::servlet holder= default
2010-06-15 14:49:32.245:DBUG::chain=
2010-06-15 14:49:32.247:DBUG::Aliased resource: file:/private/var/folders/zz/zzzivhrRnAmviuee+++++++++++/-Tmp-/Jetty_0_0_0_0_8000_test.war__testService_services__.bqlltp/webapp/test~=file:/private/var/folders/zz/zzzivhrRnAmviuee+++++++++++/-Tmp-/Jetty_0_0_0_0_8000_test.war__testService_services__.bqlltp/webapp/test/
2010-06-15 14:49:32.247:DBUG::RESOURCE /test/=null
2010-06-15 14:49:32.248:DBUG::Aliased resource: file:/private/var/folders/zz/zzzivhrRnAmviuee+++++++++++/-Tmp-/Jetty_0_0_0_0_8000_test.war__testService_services__.bqlltp/webapp/test~=file:/private/var/folders/zz/zzzivhrRnAmviuee+++++++++++/-Tmp-/Jetty_0_0_0_0_8000_test.war__testService_services__.bqlltp/webapp/test/
2010-06-15 14:49:32.248:DBUG::RESOURCE /test/=null
2010-06-15 14:49:32.248:DBUG::resource=null
2010-06-15 14:49:32.255:DBUG::RESPONSE /testService/services/testpath/  404


context/service.xml:
<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
        <Set name="contextPath">/testService/services</Set>
        <Set name="war"><SystemProperty name="jetty.home" default="." />/webapps/test.war</Set>
</Configure>

web.xml
<?xml version="1.0" encoding="UTF-8"?>
        <display-name>testService</display-name>
        <servlet>
        <servlet-name>Test Service</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext.xml</param-value>
        </context-param>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.test.service</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Test Service</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
</web-app>

TIA