users@jersey.java.net

[Jersey] Re: Jersey not working while running on root context

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Tue, 13 Sep 2011 11:08:36 +0200

Hi Sigmar,

please see inline...

On 13.9.2011 7:39, Sigmar Muuga wrote:
> Sorry, on Tomcat @ localhost and jetty @ remove provider classes were
> not found :)

So you can only make it work on Jetty, but you need to deploy on Tomcat,
right?

>
> On Tue, Sep 13, 2011 at 8:38 AM, Sigmar Muuga <meediake_at_gmail.com
> <mailto:meediake_at_gmail.com>> wrote:
>
> Hey!
>
> Actually the problem is not with root context.
>
> I made tests:
> deployed it to Tomcat running on localhost - my provider classes found
> deployed it to Jetty running on localhost - provider classes were
> found
> deployed it to Jetty running on remote Linux Debian - my provider
> classes found
>
> My configuration:
>
> <servlet>
> <servlet-name>Jersey Spring Web Application</servlet-name>
> <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
> <init-param>
> <param-name>com.sun.jersey.config.property.packages</param-name>
> <param-value>com.my.api</param-value>
> <param-value>com.my.api.exception</param-value>
> <param-value>com.my.api.provider</param-value>
> <param-value>com.my.api.resource</param-value>
>

please remove the three lines above. Jersey performs recursive scan.
If you wanted to add more packages, use a single <param-value> tag with
something like: <param-value>com.my.api com.anotherone</param-value>
I am not sure how multiple <param-value> tags should work.

I.e. you should have only:

<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.my.api</param-value>
</init-param>

If the above does not work, you may want to try:

<init-param>
<param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
<param-value>com.sun.jersey.api.core.ClassNamesResourceConfig</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.classnames</param-name>
<param-value>com.my.api.ResourceClass com.my.api.ProviderClass</param-value>
</init-param>

HTH,

~Jakub

> </init-param>
> <init-param>
> <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
> <param-value>com.sun.jersey.api.core.PackagesResourceConfig</param-value>
> </init-param>
> <load-on-startup>1</load-on-startup>
> </servlet>
>
> I am really out of ideas, spent already a day for this...
>
> Also is Jersey able to scan packages recursively?
>
> On Mon, Sep 12, 2011 at 7:35 PM, Jakub Podlesak
> <jakub.podlesak_at_oracle.com <mailto:jakub.podlesak_at_oracle.com>> wrote:
>
> Hi Sigmar,
>
> I guess only you changed also some other configuration properties.
> Do you rely on the standard JAXB providers? I.e. is the
> com.my.Model
> class annotated with @javax.xml.bind.annotation.XmlRootElement
> or @javax.xml.bind.annotation.XmlType? I guess not, and you use
> a custom MessageBodyWriter, which is probably not contained in
> the updated
> configuration.
>
> ~Jakub
>
>
>
>
> On 12.9.2011 10:07, Sigmar Muuga wrote:
>
> Hello!
>
> I have the following problem:
>
> When deploying the app to the context root (/), message
> body writers stop working. I get errors like "Caused by:
> com.sun.jersey.api.MessageException: A message body writer
> for Java class com.my.Model and MIME media type
> application/xml was not found"
>
> When running the app in localhost, with maven jetty plugin
> and having the context path /myapp it all works.
>
> I googled around and read the docs but I don't have any
> idea, what may be wrong here...
>
> Sigmar
>
>
>
>