users@jersey.java.net

[Jersey] Re: Question about PackagesResourceConfig usage

From: Martin Matula <martin.matula_at_oracle.com>
Date: Thu, 10 Mar 2011 21:04:09 +0100

See here: http://java.net/jira/browse/JERSEY-672
I've also added an issue for documenting the init parameters (which are
spread across several classes and hard to find - many people are
struggling with this) - just in case you would be willing to look into
that as well - http://java.net/jira/browse/JERSEY-673
Thanks again!
Martin

On 10.3.2011 20:43, Petr Jurák wrote:
> Well and could you create it please? Then I'll assign it to myself.
> Petr
>
> 2011/3/10 Martin Matula<martin.matula_at_oracle.com>:
>> Cool, thanks! Yes, you can use Jira issue to submit the patch.
>> Martin
>>
>> On 10.3.2011 20:25, Petr Jurák wrote:
>>> Yes, I'll do that. Is JIRA improvement issue necessary? I thought
>>> about submitting patch for trunk (1.6), is it okay?
>>> Petr
>>>
>>> 2011/3/10 Martin Matula<martin.matula_at_oracle.com>:
>>>> Sure, are you volunteering for doing that?
>>>> Martin
>>>>
>>>> On 10.3.2011 16:01, Petr Jurák wrote:
>>>>> Hi Martin,
>>>>> should we extend jersey samples with this and add some more details
>>>>> about this configuration on wiki to make it more clear? What do you
>>>>> think?
>>>>> Petr
>>>>>
>>>>> 2011/3/10 Martin Matula<martin.matula_at_oracle.com>:
>>>>>> The attached project works fine for me with GF 3.0.1.
>>>>>> Martin
>>>>>>
>>>>>>
>>>>>> On 9.3.2011 22:27, NBW wrote:
>>>>>>
>>>>>> On Wed, Mar 9, 2011 at 4:14 PM, Martin Matula<martin.matula_at_oracle.com>
>>>>>> wrote:
>>>>>>> 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.
>>>>>> OK.
>>>>>>> What version of GlassFish are you using?
>>>>>> I am trying this test out in GF 3.1 fcs
>>>>>>
>>>>>>> What do you mean you tried it before with GFv3&Servlet 2.5? GFv3 is
>>>>>>> JavaEE6 - i.e. supports servlet 3.0.
>>>>>> That was a typo, should have said servlet 3.0. It was a different
>>>>>> application written with Jersey 1.0 and I took that other approach with
>>>>>> the
>>>>>> deployment descriptorless project, a class that extended Application
>>>>>> etc.
>>>>>> I
>>>>>> just mentioned it as an example of a different way I have deployed in
>>>>>> the
>>>>>> past with success, sorry for any confusion around that.
>>>>>>
>>>>>>> Can you send me your project?
>>>>>> Not easily. Is there a jersey sample that takes this approach?
>>>>>>
>>>>>>> Where exactly (in what package) is your FooTest class?
>>>>>> FooTest is in package com.myapp.api
>>>>>> TestApplication is in package com.myapp.ws.rs
>>>>>> -Noah
>>>>>>> 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>
>>>>>>> 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
>>>>>>>> To: 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;
>>>>>>>> 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