users@jersey.java.net

Re: [Jersey] Getting 404 response code from resource using JerseyTest

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Fri, 30 Jul 2010 14:37:21 +0200

Hi Sowmya,

Unfortunately i have no idea why enabling the spring transaction
manager would affect Jersey. Does enabling the transaction manager
affect what beans are visible?

Can you send the log output from Jersey?

Can you enabling tracing on the server, add the init param
"com.sun.jersey.config.feature.Trace" with a value of "true"

   https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/core/ResourceConfig.html
#FEATURE_TRACE

and logging:

   https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/container/filter/LoggingFilter.html

that should give you some more clues as to the matching process.

Paul.

On Jul 20, 2010, at 11:49 PM, Sowmya.Srinivasan_at_flagstar.com wrote:

> 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>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>