users@jersey.java.net

[Jersey] Re: Question about PackagesResourceConfig usage

From: Martin Matula <martin.matula_at_oracle.com>
Date: Wed, 09 Mar 2011 22:14:06 +0100

The sample in the guide does not ask you to annotate the class, because
it still registers the servlet in web.xml - we need to update that part
of the guide - it is confusing and incomplete.
What version of GlassFish are you using?
What do you mean you tried it before with GFv3&Servlet 2.5? GFv3 is
JavaEE6 - i.e. supports servlet 3.0.
Can you send me your project? Where exactly (in what package) is your
FooTest class?
Martin

On 9.3.2011 22:07, NBW wrote:
> Hi Martin,
>
> Thanks for your suggestion. I gave it a shot but no joy. I added back
> the sun-web.xml with context-root set appropriately, left out the
> web.xml and annotated my 'application' class which extends
> PackagesResourceConfig with @ApplicationPath("/") (even though this is
> not in the example in the user's guide).
>
> In a previous Jersey 1.0 application that I wrote and deployed to GFv3
> & Servlet 2.5 I had things set up like so:
>
> no web.xml
> no sun-web.xml
> a class that extended Application and was annotated with
> @ApplicationPath("/api")
>
> and things worked, my Root resource classes were 'auto discovered' in
> that case.
>
> -Noah
>
> On Wed, Mar 9, 2011 at 3:46 PM, Martin Matula
> <martin.matula_at_oracle.com <mailto:martin.matula_at_oracle.com>> wrote:
>
> Hi,
> You need to annotate your application class with
> @ApplicationPath("/") annotation. This replaces the servlet and
> servlet mapping entry in the web.xml. You still need to keep the
> sun-web.xml to specify application context path:
> <sun-web-app error-url="">
> <context-root>/contextRoot</context-root>
> </sun-web-app>
> Martin
>
>
> ----- Original Message -----
> From: emailnbw_at_gmail.com <mailto:emailnbw_at_gmail.com>
> To: users_at_jersey.java.net <mailto:users_at_jersey.java.net>
> Sent: Wednesday, March 9, 2011 8:59:30 PM GMT +01:00 Amsterdam /
> Berlin / Bern / Rome / Stockholm / Vienna
> Subject: [Jersey] Question about PackagesResourceConfig usage
>
> I was trying to try out the approach of deploying my Jersey
> service by extending PackagesResourceConfig as is done in Example
> 2.8 of the User's Guide [1]. My class looks like this:
>
> package com.myapp.ws.rs <http://com.myapp.ws.rs>;
>
> public class TestApplication extends PackagesResourceConfig {
> public TestApplication() {
> super("com.myapp.api");
> }
> }
>
> I have a Servlet 3.0 web.xml file, however, it simply contains the
> <web app .. > element. I also have a 3.0 sun-web.xml which is
> empty right now save for the DOCTYPE and an empty <sun-web-app>
> element.
>
> My Provider resource class looks like this (some content omitted):
>
> @Path("/foo")
> @Stateless
> public class FooTest {
>
> @EJB
> FooBean aFooBean;
>
> @GET
> @Produces(MediaType.APPLICATION_JSON)
> @Path("/hw")
> public Response getHW() {
> return Response.ok("hello, world").build();
> }
>
> ....
>
> I get a 404 when I try to access
> http://localhost:8080/contextRoot/foo/hw where contextRoot is the
> cr for my web app. This test code deploys and works fine when I
> take the servlet 2.5 web.xml approach of using the Jersey
> ServletContainer servlet.
>
> Any hints as to what I am missing with this other approach? Thanks,
>
> -Noah
>
> [1] -
> http://jersey.java.net/nonav/documentation/latest/user-guide.html#d4e194
>
>