users@jersey.java.net

Re: [Jersey] strange Viewable path resolving problem

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 12 Nov 2009 13:10:39 +0100

Hi,

Would it be possible to send me a simple maven-based test case?

I am not sure if this is a bug in the JBoss app server or the correct
behavior. I would like to test on GF.

The inclusion of the context-root path may not be correct because the
servlet context can get the resource thus there is an inconsistency.
It basically breaks forwarding to any resource in the war regardless
of whether Jersey forwards or not. i.e. it should be reproducible with
a simple servlet that forwards to a JSP resource.


I wonder if the following will work:

1) Move your templates under the directory PMABServiceWeb

2) Add the following property to the servlet init params:

         <init-param>
             <param-
name>com.sun.jersey.config.property.JSPTemplatesBasePath</param-name>
             <param-value>PMABServiceWeb</param-value>
         </init-param>


I suspect not as the request URI of d might be:

   /PMABServiceWeb/PMABServiceWeb/com/dsths/pmab/resources/settings/
GlobalSettings/index.jsp


What happens if you do not specify the context root in the
application.xml ? or specify "/' instead?

Paul.

On Nov 11, 2009, at 11:52 PM, FSauer_at_dsthealthsolutions.com wrote:

>
> When I run jersey 1.1.2-ea in JBoss 4.2.1 - deployed from an ear -
> I am running into a weird issue:
>
> my resource class has this code:
>
> @GET
> @Produces(MediaType.TEXT_HTML)
> public Viewable getUI() {
> return new Viewable("index", this);
> }
>
> and stepping through jersey it he debugger I can see that this
> correctly resolves to a full path:
>
> TemplateFactory.resolveRelativeViewable line 133:
>
> for (TemplateProcessor t : getTemplateProcessors()) {
> String resolvedPath = t.resolve(absolutePath);
> if (resolvedPath != null) {
> 133 >>> return new ResolvedViewable(t,
> resolvedPath, v.getModel(), c);
> }
> }
>
> returns with the correct absolute path /com/dsths/pmab/resources/
> settings/GlobalSettings/index.jsp
>
> so far so good... Now we get to JSPTemplateProcessor creating a
> RequestDispatcherWrapper and in there :
>
> public void forward(ServletRequest req, ServletResponse rsp)
> throws ServletException, IOException {
> ResolvedViewable rv =
> (ResolvedViewable
> )hc
> .getProperties().get("com.sun.jersey.spi.template.ResolvedViewable");
>
> req.setAttribute("httpContext", hc);
> req.setAttribute("resolvingClass", rv.getResolvingClass());
> req.setAttribute("it", it);
> req.setAttribute("_basePath", basePath);
> req.setAttribute("_request", req);
> req.setAttribute("_response", rsp);
> >>> d.forward(req,rsp);
> }
>
> it is handed over to catalina. However, by now the requestURI in d
> (an org.apache.catalina.core.ApplicationDispatcher) is:
>
> /PMABServiceWeb/com/dsths/pmab/resources/settings/GlobalSettings/
> index.jsp
>
> the first part being the contex root set in the application.xml of
> the EAR:
>
> <module>
> <web>
> <web-uri>PMABServiceWeb.war</web-uri>
> <context-root>PMABServiceWeb</context-root>
> </web>
> </module>
>
> basePath is an empty string and so is d.servletPath
>
> and the result is a 404 without any indication of a problem like a
> stack trace..........
>
> when I insert that directory (PMABServiceWeb) the Viewable does not
> resolve correctly and I never get this far...
>
> How do I make jersey work in an ear? All of this works fine in
> another app I used to work on that deployed straight to tomcat in a
> war - no ears....
>
>
> Any suggestions?
>
> Thanks,
>
> Frank Sauer
>
>
> Please consider the environment before printing this email and any
> attachments.
>
> This e-mail and any attachments are intended only for the individual
> or company to which it is addressed and may contain information
> which is privileged, confidential and prohibited from disclosure or
> unauthorized use under applicable law. If you are not the intended
> recipient of this e-mail, you are hereby notified that any use,
> dissemination, or copying of this e-mail or the information
> contained in this e-mail is strictly prohibited by the sender. If
> you have received this transmission in error, please return the
> material received to the sender and delete all copies from your
> system.
>