users@jersey.java.net

Re: [Jersey] Proxy of a subresource Viewable?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 17 Dec 2009 16:26:50 +0100

Hi,

In your example, because RootResource is matched, and not
ChartResource, relative templates will be resolved from RootResource.
I think you have two choices:

1) Use an absolute template name, one that starts with "/"; or

2) Declare the resolving class as follows:

        new Viewable("chart", this, ChartResource.class);

If you like you could extend from Viewable such that you could always
derive the resolving class from the class of the model, for example:

   public class XViewable {
      public XViewable(String templateName, Object model) {
        super(templateName, model, model.getClass());
      }
   }


Paul

On Dec 17, 2009, at 3:28 PM, Casper Bang wrote:

> Hi Paul,
>
> How exactly is a Viewable template resolved and how may I influence
> this? It would be handy if one could proxy from a resource higher up
> the
> resource tree, down to a specific case. For instance, in the
> following I
> am trying to setup a simple showcase shortcut (easy to remember) to
> another complex sub-resource (hard to remember), by manually
> instantiating the resource and calling it with the ServletContext
> passed
> along:
>
> @Path("/")
> class RootResource{
> @GET
> @Path("showcase.html")
> @Produces("text/html")
> public StreamingOutput getShowCase(){
> return new
> ChartResource(servletContext).getAsPngStreamingOutput("en",
> "0125685:md5...", "...");
> }
> }
>
> @Path("/{language}/{credentials}/chart/")
> class ChartResource{
> @GET
> @Path("{query}.html")
> @Produces("text/html")
> public StreamingOutput getAsPngStreamingOutput(
> @PathParam("language") String language,
> @PathParam("credentials") String credentials,
> @PathParam("query") String query)){
> return Response.ok( new Viewable("chart",
> this) ).build();
> }
> }
>
> The above delegation works for most resources but not for Viewables
> (java.io.IOException: The template name, chart, could not be
> resolved to
> a fully qualified template name). I figure this is due to Jersey
> looking
> for the "chart" template in the RootResource folder rather than the
> ChartResource folder. Any idea how I may go about accomplishing this
> proxy behavior with Viewables (other than placing redundant templates,
> and modifying them to reflect changed path)?
>
> Only thing I can think of is using a forward/relocation response,
> but by
> my experiences not all HTTP clients (non-heavyweight browsers) cope
> well
> with this.
>
> /Casper
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>