users@jersey.java.net

Getting 404 response code from resource using JerseyTest

From: <Sowmya.Srinivasan_at_flagstar.com>
Date: Tue, 20 Jul 2010 17:49:34 -0400

Hello,

We are using GrizzlyWebTestContainerFactory to unit test our REST
resource.

The context.xml we use for tests is
src\test\resources\userpreferences\userpreferences-context.xml. This has a
transaction manager defined in it (as shown below). The surprising thing
is that if we remove the transaction manager from the context,xml, the
resource test works fine. With the transaction manager in there, we get a
404 response code when we run the resource test. Do you have any
suggestions on what we are missing? When we debug through it, we see that
the resource code is not getting executed at all.

I have copied the relevant pieces of code here.

userpreferences-context.xml

    <bean id="transactionManager" class=
"org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"
/>
        <property name="dataSource" ref="dataSource" />
    </bean>

    <!-- Enabling container managed transactions. -->
    <tx:annotation-driven/>

Resource Test (extends JerseyTest)

super(new WebAppDescriptor.Builder("com.fsb.lending.core.userpreferences"
).contextPath("lending-core")
            .contextParam("contextConfigLocation",
"classpath:userpreferences/userpreferences-context.xml")
            .servletClass(ServletContainer.class)
            .initParam("javax.ws.rs.Application",
                       
"com.fsb.lending.core.userpreferences.resource.util.ContextInitializer")
            .initParam("com.sun.jersey.config.property.packages",
"com.fsb.lending.core.userpreferences.resource")
            .initParam("com.sun.jersey.config.feature.Redirect", "true")
            .initParam(
"com.sun.jersey.config.property.WebPageContentRegex",
"/(images|css|jsp|js)/.*").build());
        webResource = resource();
 String responseMsg = webResource.path(
"/user/whlfund/emailpreference/option").get(String.class);
 assertNotNull(responseMsg);

Resource
    @GET
    @Path("/option")
    @Produces(value = MediaType.APPLICATION_JSON)
    public Response getUserEmailPreferenceOption(@PathParam(USER_NAME)
final String userName)
    {
        UserEmailPreferenceOption userEmailPrefs = new
UserEmailPreferenceOption();
        userEmailPrefs.setEmailOption(EmailPreferenceOptionType.parseCode(
dao.getUserEmailPreference(userName)));
        return Response.ok(userEmailPrefs, MediaType.APPLICATION_JSON
).build();
    }
Error message
   <error type="com.sun.jersey.api.client.UniformInterfaceException"
message="GET
http://localhost:9998/lending-core/user/whlfund/emailpreference/option
returned a response status of
404">com.sun.jersey.api.client.UniformInterfaceException: GET
http://localhost:9998/lending-core/user/whlfund/emailpreference/option
returned a response status of 404
        at
com.sun.jersey.api.client.WebResource.handle(WebResource.java:563)
        at com.sun.jersey.api.client.WebResource.get(WebResource.java:179)
        at
com.fsb.lending.core.userpreferences.resource.UserEmailPreferenceResourceTest.testGetUserEmailPreferences(UserEmailPreferenceResourceTest.java:74)

Thanks,

Sowmya Srinivasan
IT Projects/Component Services
5151 Corporate Drive
Troy, MI 48098-2639
Office: (248)312-5956
Sowmya.Srinivasan_at_flagstar.com
www.flagstar.com
<P>
This e-mail may contain data that is confidential, proprietary or non-public personal information, as that term is defined in the Gramm-Leach-Bliley Act (collectively, Confidential Information). The Confidential Information is disclosed conditioned upon your agreement that you will treat it confidentially and in accordance with applicable law, ensure that such data isn't used or disclosed except for the limited purpose for which it's being provided and will notify and cooperate with us regarding any requested or unauthorized disclosure or use of any Confidential Information.
By accepting and reviewing the Confidential information, you agree to indemnify us against any losses or expenses, including attorney's fees that we may incur as a result of any unauthorized use or disclosure of this data due to your acts or omissions. If a party other than the intended recipient receives this e-mail, he or she is requested to instantly notify us of the erroneous delivery and return to us all data so delivered.
</P>