|
|
| 1 2 3 |
|
Julio Faerman
|
Hi all,
I am using implicit JSP Viewables (just like bookstore sample), but i don't know how can i reference a static resource (images, styles, scripts) from the page. I am trying a method that fowards to the requested resource, but servletContext.getRequestDispatcher().forward() is failling because the injected HttpServletRequest and Response are null. Is there a better way to do this? Thank you, Julio --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
Paul Sandoz
|
Hi Julio,
Could you send me an example? > I am using implicit JSP Viewables (just like bookstore sample), but i > don't know how can i reference a static resource (images, styles, > scripts) from the page. > Does the following describe your problem? If i have a resource: com.foo.Foo and an index.jsp in: com/foo/Foo/index.jsp and there is an image at the location: com/foo/Foo/image.png how does "index.jsp" reference "image.png". > I am trying a method that fowards to the requested resource, but > servletContext.getRequestDispatcher().forward() is failling because > the injected HttpServletRequest and Response are null. Is there a > better way to do this? > If you are using Servlet you should be able to do: @Context HttpServletRequest req; @Context HttpServletRequest res; as fields or method parameters. You should be able to reference a static page using a Viewable. Just return something like this: // Absolute reference return new Viewable("/static.png", null); // Reference relative to the resource class or a super class return new Viewable("static.png", null); Paul. --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|||||||||||||||||||
|
Julio Faerman
|
I am using a simple <img> tag. Also tried the URL directly, should be the same.
I would suggest adding an static image to the bookstore sample, like a projetct logo. Returning a new Viewable for the image was my first attempt, but it results in an exception saying it could not find the template. The exception is: java.io.IOException: The template name, line-chart.gif, could not be resolved to the path of a template The code: @Path("/") public class RootResource { @GET public Viewable getJSP(){ return new Viewable("index.jsp",""); //This works } @GET @Path("img") @Produces("image/gif") public Viewable getImage(){ return new Viewable("line-chart.gif",""); //This does not. Files are in the same directory. } } Thank you for the attention and congrats all, this project is awesome. On Mon, Sep 1, 2008 at 4:17 AM, Paul Sandoz <[hidden email]> wrote: > Hi Julio, > > Could you send me an example? > >> I am using implicit JSP Viewables (just like bookstore sample), but i >> don't know how can i reference a static resource (images, styles, >> scripts) from the page. >> > > Does the following describe your problem? > > If i have a resource: > > com.foo.Foo > > and an index.jsp in: > > com/foo/Foo/index.jsp > > and there is an image at the location: > > com/foo/Foo/image.png > > how does "index.jsp" reference "image.png". > > >> I am trying a method that fowards to the requested resource, but >> servletContext.getRequestDispatcher().forward() is failling because >> the injected HttpServletRequest and Response are null. Is there a >> better way to do this? >> > > If you are using Servlet you should be able to do: > > @Context HttpServletRequest req; > > @Context HttpServletRequest res; > > as fields or method parameters. > > You should be able to reference a static page using a Viewable. Just return > something like this: > > // Absolute reference > return new Viewable("/static.png", null); > > // Reference relative to the resource class or a super class > return new Viewable("static.png", null); > > Paul. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|||||||||||||||||||
|
Paul Sandoz
|
Hi,
I have a fix, but i am not entirely happy with it. It appears that forwarding to a non-JSP resource does not work. Even though i can create the dispatcher and call forward. Somewhere internally to the Servlet implementation a 404 is returned. If anyone is a servlet expert out there perhaps they can shed some light on this. The fix is for the JSP template processor to write out any existing resource other than a JSP file and dispatch/forward JSP files. Thus you can add images etc and implicitly they will get served as well was explicitly reference then in a Viewable, although the model makes no sense in this respect. But ideally i would like to forward to servlet and let it write out the resource with appropriate meta-data. However, i think template processing is missing the ability in general to supply HTTP meta-data and for the viewable to be processed taking into account the template meta-data (e.g. precondition checking) before the template is written out. I am going to jot down some ideas here so i don't loose them: - If an entity in the ContainerResponse implements ContainerResponseFilter then the filter method is executed before the ContainerResponse is processed to write out the HTTP meta-data and entity. - Viewable is modified to implement ContainerResponseFilter and the filter method resolves the template and handles the meta-data. Resolved state is retained on the Viewable instance for writing out. - TemplateProcessor.resolve is modified to take as a parameter request meta-data and return meta-data plus resolved template path. Such meta-data can be: - content type - content length - expires - last modified - etag hence static data can be differentiated from dynamic data. Paul. Julio Faerman wrote: > I am using a simple <img> tag. Also tried the URL directly, should be the same. > I would suggest adding an static image to the bookstore sample, like a > projetct logo. > Returning a new Viewable for the image was my first attempt, but it > results in an exception saying it could not find the template. > > The exception is: > java.io.IOException: The template name, line-chart.gif, could not be > resolved to the path of a template > > The code: > @Path("/") > public class RootResource { > @GET > public Viewable getJSP(){ > return new Viewable("index.jsp",""); //This works > } > > @GET > @Path("img") > @Produces("image/gif") > public Viewable getImage(){ > return new Viewable("line-chart.gif",""); //This does not. Files are > in the same directory. > } > } > > > Thank you for the attention and congrats all, this project is awesome. > > > > > On Mon, Sep 1, 2008 at 4:17 AM, Paul Sandoz <[hidden email]> wrote: >> Hi Julio, >> >> Could you send me an example? >> >>> I am using implicit JSP Viewables (just like bookstore sample), but i >>> don't know how can i reference a static resource (images, styles, >>> scripts) from the page. >>> >> Does the following describe your problem? >> >> If i have a resource: >> >> com.foo.Foo >> >> and an index.jsp in: >> >> com/foo/Foo/index.jsp >> >> and there is an image at the location: >> >> com/foo/Foo/image.png >> >> how does "index.jsp" reference "image.png". >> >> >>> I am trying a method that fowards to the requested resource, but >>> servletContext.getRequestDispatcher().forward() is failling because >>> the injected HttpServletRequest and Response are null. Is there a >>> better way to do this? >>> >> If you are using Servlet you should be able to do: >> >> @Context HttpServletRequest req; >> >> @Context HttpServletRequest res; >> >> as fields or method parameters. >> >> You should be able to reference a static page using a Viewable. Just return >> something like this: >> >> // Absolute reference >> return new Viewable("/static.png", null); >> >> // Reference relative to the resource class or a super class >> return new Viewable("static.png", null); >> >> Paul. >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [hidden email] >> For additional commands, e-mail: [hidden email] >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > -- | ? + ? = To question ----------------\ Paul Sandoz x38109 +33-4-76188109 --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|||||||||||||||||||
|
Julio Faerman
|
I have tried to write out the resource, but this is troublesome as the
resource is not on the classpath. I think there is a method to get web resources in servlet 2.5, but i also think that the forward should work. The viewable meta-data seems a good feature, but i think it would need to support a transparent and implicit mechanism to access resources. Perhaps using reasonable "default" meta-data. On Mon, Sep 1, 2008 at 1:03 PM, Paul Sandoz <[hidden email]> wrote: > Hi, > > I have a fix, but i am not entirely happy with it. > > It appears that forwarding to a non-JSP resource does not work. Even though > i can create the dispatcher and call forward. Somewhere internally to the > Servlet implementation a 404 is returned. If anyone is a servlet expert out > there perhaps they can shed some light on this. > > > The fix is for the JSP template processor to write out any existing resource > other than a JSP file and dispatch/forward JSP files. Thus you can add > images etc and implicitly they will get served as well was explicitly > reference then in a Viewable, although the model makes no sense in this > respect. But ideally i would like to forward to servlet and let it write out > the resource with appropriate meta-data. > > > However, i think template processing is missing the ability in general to > supply HTTP meta-data and for the viewable to be processed taking into > account the template meta-data (e.g. precondition checking) before the > template is written out. I am going to jot down some ideas here so i don't > loose them: > > - If an entity in the ContainerResponse implements > ContainerResponseFilter then the filter method is executed > before the ContainerResponse is processed to write out the HTTP > meta-data and entity. > > - Viewable is modified to implement ContainerResponseFilter and the > filter method resolves the template and handles the meta-data. > Resolved state is retained on the Viewable instance for writing > out. > > - TemplateProcessor.resolve is modified to take as a parameter > request meta-data and return meta-data plus > resolved template path. Such meta-data can be: > > - content type > - content length > - expires > - last modified > - etag > > hence static data can be differentiated from dynamic data. > > Paul. > > Julio Faerman wrote: >> >> I am using a simple <img> tag. Also tried the URL directly, should be the >> same. >> I would suggest adding an static image to the bookstore sample, like a >> projetct logo. >> Returning a new Viewable for the image was my first attempt, but it >> results in an exception saying it could not find the template. >> >> The exception is: >> java.io.IOException: The template name, line-chart.gif, could not be >> resolved to the path of a template >> >> The code: >> @Path("/") >> public class RootResource { >> @GET >> public Viewable getJSP(){ >> return new Viewable("index.jsp",""); //This works >> } >> >> @GET >> @Path("img") >> @Produces("image/gif") >> public Viewable getImage(){ >> return new Viewable("line-chart.gif",""); //This does not. >> Files are >> in the same directory. >> } >> } >> >> >> Thank you for the attention and congrats all, this project is awesome. >> >> >> >> >> On Mon, Sep 1, 2008 at 4:17 AM, Paul Sandoz <[hidden email]> wrote: >>> >>> Hi Julio, >>> >>> Could you send me an example? >>> >>>> I am using implicit JSP Viewables (just like bookstore sample), but i >>>> don't know how can i reference a static resource (images, styles, >>>> scripts) from the page. >>>> >>> Does the following describe your problem? >>> >>> If i have a resource: >>> >>> com.foo.Foo >>> >>> and an index.jsp in: >>> >>> com/foo/Foo/index.jsp >>> >>> and there is an image at the location: >>> >>> com/foo/Foo/image.png >>> >>> how does "index.jsp" reference "image.png". >>> >>> >>>> I am trying a method that fowards to the requested resource, but >>>> servletContext.getRequestDispatcher().forward() is failling because >>>> the injected HttpServletRequest and Response are null. Is there a >>>> better way to do this? >>>> >>> If you are using Servlet you should be able to do: >>> >>> @Context HttpServletRequest req; >>> >>> @Context HttpServletRequest res; >>> >>> as fields or method parameters. >>> >>> You should be able to reference a static page using a Viewable. Just >>> return >>> something like this: >>> >>> // Absolute reference >>> return new Viewable("/static.png", null); >>> >>> // Reference relative to the resource class or a super class >>> return new Viewable("static.png", null); >>> >>> Paul. >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [hidden email] >>> For additional commands, e-mail: [hidden email] >>> >>> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [hidden email] >> For additional commands, e-mail: [hidden email] >> > > -- > | ? + ? = To question > ----------------\ > Paul Sandoz > x38109 > +33-4-76188109 > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|||||||||||||||||||
|
Paul Sandoz
|
Julio Faerman wrote:
> I have tried to write out the resource, but this is troublesome as the > resource is not on the classpath. I think there is a method to get web > resources in servlet 2.5, You need to use methods on the ServletContext. > but i also think that the forward should > work. I cannot get it to :-( it works for JSPs, but not for "static" stuff like HTML and images, perhaps it is bug in the GF servlet implementation i am using? > The viewable meta-data seems a good feature, but i think it would need > to support a transparent and implicit mechanism to access resources. > Perhaps using reasonable "default" meta-data. > Yes, now if only i could get access to the information Servlet uses for static pages .e.g. it returns generated etags etc. Although it does not seem to support 304 not modified correctly. Paul. > On Mon, Sep 1, 2008 at 1:03 PM, Paul Sandoz <[hidden email]> wrote: >> Hi, >> >> I have a fix, but i am not entirely happy with it. >> >> It appears that forwarding to a non-JSP resource does not work. Even though >> i can create the dispatcher and call forward. Somewhere internally to the >> Servlet implementation a 404 is returned. If anyone is a servlet expert out >> there perhaps they can shed some light on this. >> >> >> The fix is for the JSP template processor to write out any existing resource >> other than a JSP file and dispatch/forward JSP files. Thus you can add >> images etc and implicitly they will get served as well was explicitly >> reference then in a Viewable, although the model makes no sense in this >> respect. But ideally i would like to forward to servlet and let it write out >> the resource with appropriate meta-data. >> >> >> However, i think template processing is missing the ability in general to >> supply HTTP meta-data and for the viewable to be processed taking into >> account the template meta-data (e.g. precondition checking) before the >> template is written out. I am going to jot down some ideas here so i don't >> loose them: >> >> - If an entity in the ContainerResponse implements >> ContainerResponseFilter then the filter method is executed >> before the ContainerResponse is processed to write out the HTTP >> meta-data and entity. >> >> - Viewable is modified to implement ContainerResponseFilter and the >> filter method resolves the template and handles the meta-data. >> Resolved state is retained on the Viewable instance for writing >> out. >> >> - TemplateProcessor.resolve is modified to take as a parameter >> request meta-data and return meta-data plus >> resolved template path. Such meta-data can be: >> >> - content type >> - content length >> - expires >> - last modified >> - etag >> >> hence static data can be differentiated from dynamic data. >> >> Paul. >> >> Julio Faerman wrote: >>> I am using a simple <img> tag. Also tried the URL directly, should be the >>> same. >>> I would suggest adding an static image to the bookstore sample, like a >>> projetct logo. >>> Returning a new Viewable for the image was my first attempt, but it >>> results in an exception saying it could not find the template. >>> >>> The exception is: >>> java.io.IOException: The template name, line-chart.gif, could not be >>> resolved to the path of a template >>> >>> The code: >>> @Path("/") >>> public class RootResource { >>> @GET >>> public Viewable getJSP(){ >>> return new Viewable("index.jsp",""); //This works >>> } >>> >>> @GET >>> @Path("img") >>> @Produces("image/gif") >>> public Viewable getImage(){ >>> return new Viewable("line-chart.gif",""); //This does not. >>> Files are >>> in the same directory. >>> } >>> } >>> >>> >>> Thank you for the attention and congrats all, this project is awesome. >>> >>> >>> >>> >>> On Mon, Sep 1, 2008 at 4:17 AM, Paul Sandoz <[hidden email]> wrote: >>>> Hi Julio, >>>> >>>> Could you send me an example? >>>> >>>>> I am using implicit JSP Viewables (just like bookstore sample), but i >>>>> don't know how can i reference a static resource (images, styles, >>>>> scripts) from the page. >>>>> >>>> Does the following describe your problem? >>>> >>>> If i have a resource: >>>> >>>> com.foo.Foo >>>> >>>> and an index.jsp in: >>>> >>>> com/foo/Foo/index.jsp >>>> >>>> and there is an image at the location: >>>> >>>> com/foo/Foo/image.png >>>> >>>> how does "index.jsp" reference "image.png". >>>> >>>> >>>>> I am trying a method that fowards to the requested resource, but >>>>> servletContext.getRequestDispatcher().forward() is failling because >>>>> the injected HttpServletRequest and Response are null. Is there a >>>>> better way to do this? >>>>> >>>> If you are using Servlet you should be able to do: >>>> >>>> @Context HttpServletRequest req; >>>> >>>> @Context HttpServletRequest res; >>>> >>>> as fields or method parameters. >>>> >>>> You should be able to reference a static page using a Viewable. Just >>>> return >>>> something like this: >>>> >>>> // Absolute reference >>>> return new Viewable("/static.png", null); >>>> >>>> // Reference relative to the resource class or a super class >>>> return new Viewable("static.png", null); >>>> >>>> Paul. >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: [hidden email] >>>> For additional commands, e-mail: [hidden email] >>>> >>>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [hidden email] >>> For additional commands, e-mail: [hidden email] >>> >> -- >> | ? + ? = To question >> ----------------\ >> Paul Sandoz >> x38109 >> +33-4-76188109 >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [hidden email] >> For additional commands, e-mail: [hidden email] >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > -- | ? + ? = To question ----------------\ Paul Sandoz x38109 +33-4-76188109 --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|||||||||||||||||||
|
Craig McClanahan
|
Paul Sandoz wrote:
> Julio Faerman wrote: >> I have tried to write out the resource, but this is troublesome as the >> resource is not on the classpath. I think there is a method to get web >> resources in servlet 2.5, > > You need to use methods on the ServletContext. > > >> but i also think that the forward should >> work. > > I cannot get it to :-( it works for JSPs, but not for "static" stuff > like HTML and images, perhaps it is bug in the GF servlet > implementation i am using? > > A typical servlet container will have a "default" mapping (essentially for pattern "/*") that is used to serve static resources. If you've defined your mapping to the ServletAdaptor or ServletContainer servlet to "/*", then you are overriding this default, meaning you'd need to take responsibility for serving the static resources yourself. This is technically feasible -- you could build static file service into ServletAdaptor or ServletContainer -- but a lot easier if you have the JAX-RS servlet mapped to something else. Craig >> The viewable meta-data seems a good feature, but i think it would need >> to support a transparent and implicit mechanism to access resources. >> Perhaps using reasonable "default" meta-data. >> > > Yes, now if only i could get access to the information Servlet uses > for static pages .e.g. it returns generated etags etc. Although it > does not seem to support 304 not modified correctly. > > Paul. > > >> On Mon, Sep 1, 2008 at 1:03 PM, Paul Sandoz <[hidden email]> wrote: >>> Hi, >>> >>> I have a fix, but i am not entirely happy with it. >>> >>> It appears that forwarding to a non-JSP resource does not work. Even >>> though >>> i can create the dispatcher and call forward. Somewhere internally >>> to the >>> Servlet implementation a 404 is returned. If anyone is a servlet >>> expert out >>> there perhaps they can shed some light on this. >>> >>> >>> The fix is for the JSP template processor to write out any existing >>> resource >>> other than a JSP file and dispatch/forward JSP files. Thus you can add >>> images etc and implicitly they will get served as well was explicitly >>> reference then in a Viewable, although the model makes no sense in this >>> respect. But ideally i would like to forward to servlet and let it >>> write out >>> the resource with appropriate meta-data. >>> >>> >>> However, i think template processing is missing the ability in >>> general to >>> supply HTTP meta-data and for the viewable to be processed taking into >>> account the template meta-data (e.g. precondition checking) before the >>> template is written out. I am going to jot down some ideas here so i >>> don't >>> loose them: >>> >>> - If an entity in the ContainerResponse implements >>> ContainerResponseFilter then the filter method is executed >>> before the ContainerResponse is processed to write out the HTTP >>> meta-data and entity. >>> >>> - Viewable is modified to implement ContainerResponseFilter and the >>> filter method resolves the template and handles the meta-data. >>> Resolved state is retained on the Viewable instance for writing >>> out. >>> >>> - TemplateProcessor.resolve is modified to take as a parameter >>> request meta-data and return meta-data plus >>> resolved template path. Such meta-data can be: >>> >>> - content type >>> - content length >>> - expires >>> - last modified >>> - etag >>> >>> hence static data can be differentiated from dynamic data. >>> >>> Paul. >>> >>> Julio Faerman wrote: >>>> I am using a simple <img> tag. Also tried the URL directly, should >>>> be the >>>> same. >>>> I would suggest adding an static image to the bookstore sample, like a >>>> projetct logo. >>>> Returning a new Viewable for the image was my first attempt, but it >>>> results in an exception saying it could not find the template. >>>> >>>> The exception is: >>>> java.io.IOException: The template name, line-chart.gif, could not be >>>> resolved to the path of a template >>>> >>>> The code: >>>> @Path("/") >>>> public class RootResource { >>>> @GET >>>> public Viewable getJSP(){ >>>> return new Viewable("index.jsp",""); //This works >>>> } >>>> >>>> @GET >>>> @Path("img") >>>> @Produces("image/gif") >>>> public Viewable getImage(){ >>>> return new Viewable("line-chart.gif",""); //This >>>> does not. >>>> Files are >>>> in the same directory. >>>> } >>>> } >>>> >>>> >>>> Thank you for the attention and congrats all, this project is awesome. >>>> >>>> >>>> >>>> >>>> On Mon, Sep 1, 2008 at 4:17 AM, Paul Sandoz <[hidden email]> >>>> wrote: >>>>> Hi Julio, >>>>> >>>>> Could you send me an example? >>>>> >>>>>> I am using implicit JSP Viewables (just like bookstore sample), >>>>>> but i >>>>>> don't know how can i reference a static resource (images, styles, >>>>>> scripts) from the page. >>>>>> >>>>> Does the following describe your problem? >>>>> >>>>> If i have a resource: >>>>> >>>>> com.foo.Foo >>>>> >>>>> and an index.jsp in: >>>>> >>>>> com/foo/Foo/index.jsp >>>>> >>>>> and there is an image at the location: >>>>> >>>>> com/foo/Foo/image.png >>>>> >>>>> how does "index.jsp" reference "image.png". >>>>> >>>>> >>>>>> I am trying a method that fowards to the requested resource, but >>>>>> servletContext.getRequestDispatcher().forward() is failling because >>>>>> the injected HttpServletRequest and Response are null. Is there a >>>>>> better way to do this? >>>>>> >>>>> If you are using Servlet you should be able to do: >>>>> >>>>> @Context HttpServletRequest req; >>>>> >>>>> @Context HttpServletRequest res; >>>>> >>>>> as fields or method parameters. >>>>> >>>>> You should be able to reference a static page using a Viewable. Just >>>>> return >>>>> something like this: >>>>> >>>>> // Absolute reference >>>>> return new Viewable("/static.png", null); >>>>> >>>>> // Reference relative to the resource class or a super class >>>>> return new Viewable("static.png", null); >>>>> >>>>> Paul. >>>>> >>>>> --------------------------------------------------------------------- >>>>> To unsubscribe, e-mail: [hidden email] >>>>> For additional commands, e-mail: [hidden email] >>>>> >>>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: [hidden email] >>>> For additional commands, e-mail: [hidden email] >>>> >>> -- >>> | ? + ? = To question >>> ----------------\ >>> Paul Sandoz >>> x38109 >>> +33-4-76188109 >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [hidden email] >>> For additional commands, e-mail: [hidden email] >>> >>> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [hidden email] >> For additional commands, e-mail: [hidden email] >> > --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|||||||||||||||||||
|
Paul Sandoz
|
On Sep 2, 2008, at 8:13 AM, Craig McClanahan wrote:
> Paul Sandoz wrote: >> Julio Faerman wrote: >>> I have tried to write out the resource, but this is troublesome >>> as the >>> resource is not on the classpath. I think there is a method to >>> get web >>> resources in servlet 2.5, >> >> You need to use methods on the ServletContext. >> >> >>> but i also think that the forward should >>> work. >> >> I cannot get it to :-( it works for JSPs, but not for "static" >> stuff like HTML and images, perhaps it is bug in the GF servlet >> implementation i am using? >> >> > What servlet mappings do you have defined? > "/" or "/*". I want to avoid a URL for the main application like: http://host:80/<deployment base>/<jersey base> and exposing out the other resources (static or JSP pages) explicitly. I can forward to JSPs but not to static content. For example, if i have the following in the web directory: com/foo/Foo/index.jsp com/foo/Foo/image.png And a resource class: package com.foo; @Path("/") public class Foo { ... } Then the a path of "/" slash matches Foo and Jersey can forward the servlet request to "com/foo/Foo/index.jsp" but any reference in the JSP to "image.png" does not work. > A typical servlet container will have a "default" mapping > (essentially for pattern "/*") that is used to serve static > resources. If you've defined your mapping to the ServletAdaptor or > ServletContainer servlet to "/*", then you are overriding this > default, meaning you'd need to take responsibility for serving the > static resources yourself. This is technically feasible -- you > could build static file service into ServletAdaptor or > ServletContainer -- but a lot easier if you have the JAX-RS servlet > mapped to something else. > Thanks. Yes, i want to avoid duplicating such effort. I also sent an email to [hidden email] asking more details. Paul. > Craig > >>> The viewable meta-data seems a good feature, but i think it would >>> need >>> to support a transparent and implicit mechanism to access resources. >>> Perhaps using reasonable "default" meta-data. >>> >> >> Yes, now if only i could get access to the information Servlet >> uses for static pages .e.g. it returns generated etags etc. >> Although it does not seem to support 304 not modified correctly. >> >> Paul. >> >> >>> On Mon, Sep 1, 2008 at 1:03 PM, Paul Sandoz <[hidden email]> >>> wrote: >>>> Hi, >>>> >>>> I have a fix, but i am not entirely happy with it. >>>> >>>> It appears that forwarding to a non-JSP resource does not work. >>>> Even though >>>> i can create the dispatcher and call forward. Somewhere >>>> internally to the >>>> Servlet implementation a 404 is returned. If anyone is a servlet >>>> expert out >>>> there perhaps they can shed some light on this. >>>> >>>> >>>> The fix is for the JSP template processor to write out any >>>> existing resource >>>> other than a JSP file and dispatch/forward JSP files. Thus you >>>> can add >>>> images etc and implicitly they will get served as well was >>>> explicitly >>>> reference then in a Viewable, although the model makes no sense >>>> in this >>>> respect. But ideally i would like to forward to servlet and let >>>> it write out >>>> the resource with appropriate meta-data. >>>> >>>> >>>> However, i think template processing is missing the ability in >>>> general to >>>> supply HTTP meta-data and for the viewable to be processed >>>> taking into >>>> account the template meta-data (e.g. precondition checking) >>>> before the >>>> template is written out. I am going to jot down some ideas here >>>> so i don't >>>> loose them: >>>> >>>> - If an entity in the ContainerResponse implements >>>> ContainerResponseFilter then the filter method is executed >>>> before the ContainerResponse is processed to write out the HTTP >>>> meta-data and entity. >>>> >>>> - Viewable is modified to implement ContainerResponseFilter and the >>>> filter method resolves the template and handles the meta-data. >>>> Resolved state is retained on the Viewable instance for writing >>>> out. >>>> >>>> - TemplateProcessor.resolve is modified to take as a parameter >>>> request meta-data and return meta-data plus >>>> resolved template path. Such meta-data can be: >>>> >>>> - content type >>>> - content length >>>> - expires >>>> - last modified >>>> - etag >>>> >>>> hence static data can be differentiated from dynamic data. >>>> >>>> Paul. >>>> >>>> Julio Faerman wrote: >>>>> I am using a simple <img> tag. Also tried the URL directly, >>>>> should be the >>>>> same. >>>>> I would suggest adding an static image to the bookstore sample, >>>>> like a >>>>> projetct logo. >>>>> Returning a new Viewable for the image was my first attempt, >>>>> but it >>>>> results in an exception saying it could not find the template. >>>>> >>>>> The exception is: >>>>> java.io.IOException: The template name, line-chart.gif, could >>>>> not be >>>>> resolved to the path of a template >>>>> >>>>> The code: >>>>> @Path("/") >>>>> public class RootResource { >>>>> @GET >>>>> public Viewable getJSP(){ >>>>> return new Viewable("index.jsp",""); //This works >>>>> } >>>>> >>>>> @GET >>>>> @Path("img") >>>>> @Produces("image/gif") >>>>> public Viewable getImage(){ >>>>> return new Viewable("line-chart.gif",""); //This >>>>> does not. >>>>> Files are >>>>> in the same directory. >>>>> } >>>>> } >>>>> >>>>> >>>>> Thank you for the attention and congrats all, this project is >>>>> awesome. >>>>> >>>>> >>>>> >>>>> >>>>> On Mon, Sep 1, 2008 at 4:17 AM, Paul Sandoz >>>>> <[hidden email]> wrote: >>>>>> Hi Julio, >>>>>> >>>>>> Could you send me an example? >>>>>> >>>>>>> I am using implicit JSP Viewables (just like bookstore >>>>>>> sample), but i >>>>>>> don't know how can i reference a static resource (images, >>>>>>> styles, >>>>>>> scripts) from the page. >>>>>>> >>>>>> Does the following describe your problem? >>>>>> >>>>>> If i have a resource: >>>>>> >>>>>> com.foo.Foo >>>>>> >>>>>> and an index.jsp in: >>>>>> >>>>>> com/foo/Foo/index.jsp >>>>>> >>>>>> and there is an image at the location: >>>>>> >>>>>> com/foo/Foo/image.png >>>>>> >>>>>> how does "index.jsp" reference "image.png". >>>>>> >>>>>> >>>>>>> I am trying a method that fowards to the requested resource, but >>>>>>> servletContext.getRequestDispatcher().forward() is failling >>>>>>> because >>>>>>> the injected HttpServletRequest and Response are null. Is >>>>>>> there a >>>>>>> better way to do this? >>>>>>> >>>>>> If you are using Servlet you should be able to do: >>>>>> >>>>>> @Context HttpServletRequest req; >>>>>> >>>>>> @Context HttpServletRequest res; >>>>>> >>>>>> as fields or method parameters. >>>>>> >>>>>> You should be able to reference a static page using a >>>>>> Viewable. Just >>>>>> return >>>>>> something like this: >>>>>> >>>>>> // Absolute reference >>>>>> return new Viewable("/static.png", null); >>>>>> >>>>>> // Reference relative to the resource class or a super class >>>>>> return new Viewable("static.png", null); >>>>>> >>>>>> Paul. >>>>>> >>>>>> ----------------------------------------------------------------- >>>>>> ---- >>>>>> To unsubscribe, e-mail: [hidden email] >>>>>> For additional commands, e-mail: [hidden email] >>>>>> >>>>>> >>>>> ------------------------------------------------------------------ >>>>> --- >>>>> To unsubscribe, e-mail: [hidden email] >>>>> For additional commands, e-mail: [hidden email] >>>>> >>>> -- >>>> | ? + ? = To question >>>> ----------------\ >>>> Paul Sandoz >>>> x38109 >>>> +33-4-76188109 >>>> >>>> ------------------------------------------------------------------- >>>> -- >>>> To unsubscribe, e-mail: [hidden email] >>>> For additional commands, e-mail: [hidden email] >>>> >>>> >>> >>> -------------------------------------------------------------------- >>> - >>> To unsubscribe, e-mail: [hidden email] >>> For additional commands, e-mail: [hidden email] >>> >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|||||||||||||||||||
|
Paul Sandoz
|
On Sep 2, 2008, at 8:46 AM, Paul Sandoz wrote: > On Sep 2, 2008, at 8:13 AM, Craig McClanahan wrote: > >> Paul Sandoz wrote: >>> Julio Faerman wrote: >>>> I have tried to write out the resource, but this is troublesome >>>> as the >>>> resource is not on the classpath. I think there is a method to >>>> get web >>>> resources in servlet 2.5, >>> >>> You need to use methods on the ServletContext. >>> >>> >>>> but i also think that the forward should >>>> work. >>> >>> I cannot get it to :-( it works for JSPs, but not for "static" >>> stuff like HTML and images, perhaps it is bug in the GF servlet >>> implementation i am using? >>> >>> >> What servlet mappings do you have defined? >> > > "/" or "/*". I want to avoid a URL for the main application like: > > http://host:80/<deployment base>/<jersey base> > > and exposing out the other resources (static or JSP pages) explicitly. > > I can forward to JSPs but not to static content. > After more investigation - If the URL pattern is "/" then i can forward to JSPs but not to static content. - If the URL pattern is "/*" then i cannot forward to JSPs nor static content. Paul. --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|||||||||||||||||||
|
Paul Sandoz
|
In reply to this post
by Julio Faerman
Hi Julio,
I have found a workaround that may be acceptable for you. First i have fixed a issue for dispatching/forwarding to any resource associated with a resource class. Then you need to declare the URL pattern of the Jersey servlet to be something like "/app/*" i.e. you need to ensure that the URL pattern distinguishes itself from other resources in the web pages location. This has an annoying side-effect that the JSP and static resources are accessible directly by browsing the web pages. I am not sure if this can be disabled or not. Paul. Julio Faerman wrote: > I have tried to write out the resource, but this is troublesome as the > resource is not on the classpath. I think there is a method to get web > resources in servlet 2.5, but i also think that the forward should > work. > The viewable meta-data seems a good feature, but i think it would need > to support a transparent and implicit mechanism to access resources. > Perhaps using reasonable "default" meta-data. > > On Mon, Sep 1, 2008 at 1:03 PM, Paul Sandoz <[hidden email]> wrote: >> Hi, >> >> I have a fix, but i am not entirely happy with it. >> >> It appears that forwarding to a non-JSP resource does not work. Even though >> i can create the dispatcher and call forward. Somewhere internally to the >> Servlet implementation a 404 is returned. If anyone is a servlet expert out >> there perhaps they can shed some light on this. >> >> >> The fix is for the JSP template processor to write out any existing resource >> other than a JSP file and dispatch/forward JSP files. Thus you can add >> images etc and implicitly they will get served as well was explicitly >> reference then in a Viewable, although the model makes no sense in this >> respect. But ideally i would like to forward to servlet and let it write out >> the resource with appropriate meta-data. >> >> >> However, i think template processing is missing the ability in general to >> supply HTTP meta-data and for the viewable to be processed taking into >> account the template meta-data (e.g. precondition checking) before the >> template is written out. I am going to jot down some ideas here so i don't >> loose them: >> >> - If an entity in the ContainerResponse implements >> ContainerResponseFilter then the filter method is executed >> before the ContainerResponse is processed to write out the HTTP >> meta-data and entity. >> >> - Viewable is modified to implement ContainerResponseFilter and the >> filter method resolves the template and handles the meta-data. >> Resolved state is retained on the Viewable instance for writing >> out. >> >> - TemplateProcessor.resolve is modified to take as a parameter >> request meta-data and return meta-data plus >> resolved template path. Such meta-data can be: >> >> - content type >> - content length >> - expires >> - last modified >> - etag >> >> hence static data can be differentiated from dynamic data. >> >> Paul. >> >> Julio Faerman wrote: >>> I am using a simple <img> tag. Also tried the URL directly, should be the >>> same. >>> I would suggest adding an static image to the bookstore sample, like a >>> projetct logo. >>> Returning a new Viewable for the image was my first attempt, but it >>> results in an exception saying it could not find the template. >>> >>> The exception is: >>> java.io.IOException: The template name, line-chart.gif, could not be >>> resolved to the path of a template >>> >>> The code: >>> @Path("/") >>> public class RootResource { >>> @GET >>> public Viewable getJSP(){ >>> return new Viewable("index.jsp",""); //This works >>> } >>> >>> @GET >>> @Path("img") >>> @Produces("image/gif") >>> public Viewable getImage(){ >>> return new Viewable("line-chart.gif",""); //This does not. >>> Files are >>> in the same directory. >>> } >>> } >>> >>> >>> Thank you for the attention and congrats all, this project is awesome. >>> >>> >>> >>> >>> On Mon, Sep 1, 2008 at 4:17 AM, Paul Sandoz <[hidden email]> wrote: >>>> Hi Julio, >>>> >>>> Could you send me an example? >>>> >>>>> I am using implicit JSP Viewables (just like bookstore sample), but i >>>>> don't know how can i reference a static resource (images, styles, >>>>> scripts) from the page. >>>>> >>>> Does the following describe your problem? >>>> >>>> If i have a resource: >>>> >>>> com.foo.Foo >>>> >>>> and an index.jsp in: >>>> >>>> com/foo/Foo/index.jsp >>>> >>>> and there is an image at the location: >>>> >>>> com/foo/Foo/image.png >>>> >>>> how does "index.jsp" reference "image.png". >>>> >>>> >>>>> I am trying a method that fowards to the requested resource, but >>>>> servletContext.getRequestDispatcher().forward() is failling because >>>>> the injected HttpServletRequest and Response are null. Is there a >>>>> better way to do this? >>>>> >>>> If you are using Servlet you should be able to do: >>>> >>>> @Context HttpServletRequest req; >>>> >>>> @Context HttpServletRequest res; >>>> >>>> as fields or method parameters. >>>> >>>> You should be able to reference a static page using a Viewable. Just >>>> return >>>> something like this: >>>> >>>> // Absolute reference >>>> return new Viewable("/static.png", null); >>>> >>>> // Reference relative to the resource class or a super class >>>> return new Viewable("static.png", null); >>>> >>>> Paul. >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: [hidden email] >>>> For additional commands, e-mail: [hidden email] >>>> >>>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [hidden email] >>> For additional commands, e-mail: [hidden email] >>> >> -- >> | ? + ? = To question >> ----------------\ >> Paul Sandoz >> x38109 >> +33-4-76188109 >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [hidden email] >> For additional commands, e-mail: [hidden email] >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > -- | ? + ? = To question ----------------\ Paul Sandoz x38109 +33-4-76188109 --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|||||||||||||||||||
|
Julio Faerman
|
Thank you very much, this will do.
I'll also try other containers to see if they implement the delivery of static content without passing thru servlets that may get "overriden". On Tue, Sep 2, 2008 at 7:28 AM, Paul Sandoz <[hidden email]> wrote: > Hi Julio, > > I have found a workaround that may be acceptable for you. First i have fixed > a issue for dispatching/forwarding to any resource associated with a > resource class. > > Then you need to declare the URL pattern of the Jersey servlet to be > something like "/app/*" i.e. you need to ensure that the URL pattern > distinguishes itself from other resources in the web pages location. > > This has an annoying side-effect that the JSP and static resources are > accessible directly by browsing the web pages. I am not sure if this can be > disabled or not. > > Paul. > > Julio Faerman wrote: >> >> I have tried to write out the resource, but this is troublesome as the >> resource is not on the classpath. I think there is a method to get web >> resources in servlet 2.5, but i also think that the forward should >> work. >> The viewable meta-data seems a good feature, but i think it would need >> to support a transparent and implicit mechanism to access resources. >> Perhaps using reasonable "default" meta-data. >> >> On Mon, Sep 1, 2008 at 1:03 PM, Paul Sandoz <[hidden email]> wrote: >>> >>> Hi, >>> >>> I have a fix, but i am not entirely happy with it. >>> >>> It appears that forwarding to a non-JSP resource does not work. Even >>> though >>> i can create the dispatcher and call forward. Somewhere internally to the >>> Servlet implementation a 404 is returned. If anyone is a servlet expert >>> out >>> there perhaps they can shed some light on this. >>> >>> >>> The fix is for the JSP template processor to write out any existing >>> resource >>> other than a JSP file and dispatch/forward JSP files. Thus you can add >>> images etc and implicitly they will get served as well was explicitly >>> reference then in a Viewable, although the model makes no sense in this >>> respect. But ideally i would like to forward to servlet and let it write >>> out >>> the resource with appropriate meta-data. >>> >>> >>> However, i think template processing is missing the ability in general to >>> supply HTTP meta-data and for the viewable to be processed taking into >>> account the template meta-data (e.g. precondition checking) before the >>> template is written out. I am going to jot down some ideas here so i >>> don't >>> loose them: >>> >>> - If an entity in the ContainerResponse implements >>> ContainerResponseFilter then the filter method is executed >>> before the ContainerResponse is processed to write out the HTTP >>> meta-data and entity. >>> >>> - Viewable is modified to implement ContainerResponseFilter and the >>> filter method resolves the template and handles the meta-data. >>> Resolved state is retained on the Viewable instance for writing >>> out. >>> >>> - TemplateProcessor.resolve is modified to take as a parameter >>> request meta-data and return meta-data plus >>> resolved template path. Such meta-data can be: >>> >>> - content type >>> - content length >>> - expires >>> - last modified >>> - etag >>> >>> hence static data can be differentiated from dynamic data. >>> >>> Paul. >>> >>> Julio Faerman wrote: >>>> >>>> I am using a simple <img> tag. Also tried the URL directly, should be >>>> the >>>> same. >>>> I would suggest adding an static image to the bookstore sample, like a >>>> projetct logo. >>>> Returning a new Viewable for the image was my first attempt, but it >>>> results in an exception saying it could not find the template. >>>> >>>> The exception is: >>>> java.io.IOException: The template name, line-chart.gif, could not be >>>> resolved to the path of a template >>>> >>>> The code: >>>> @Path("/") >>>> public class RootResource { >>>> @GET >>>> public Viewable getJSP(){ >>>> return new Viewable("index.jsp",""); //This works >>>> } >>>> >>>> @GET >>>> @Path("img") >>>> @Produces("image/gif") >>>> public Viewable getImage(){ >>>> return new Viewable("line-chart.gif",""); //This does not. >>>> Files are >>>> in the same directory. >>>> } >>>> } >>>> >>>> >>>> Thank you for the attention and congrats all, this project is awesome. >>>> >>>> >>>> >>>> >>>> On Mon, Sep 1, 2008 at 4:17 AM, Paul Sandoz <[hidden email]> wrote: >>>>> >>>>> Hi Julio, >>>>> >>>>> Could you send me an example? >>>>> >>>>>> I am using implicit JSP Viewables (just like bookstore sample), but i >>>>>> don't know how can i reference a static resource (images, styles, >>>>>> scripts) from the page. >>>>>> >>>>> Does the following describe your problem? >>>>> >>>>> If i have a resource: >>>>> >>>>> com.foo.Foo >>>>> >>>>> and an index.jsp in: >>>>> >>>>> com/foo/Foo/index.jsp >>>>> >>>>> and there is an image at the location: >>>>> >>>>> com/foo/Foo/image.png >>>>> >>>>> how does "index.jsp" reference "image.png". >>>>> >>>>> >>>>>> I am trying a method that fowards to the requested resource, but >>>>>> servletContext.getRequestDispatcher().forward() is failling because >>>>>> the injected HttpServletRequest and Response are null. Is there a >>>>>> better way to do this? >>>>>> >>>>> If you are using Servlet you should be able to do: >>>>> >>>>> @Context HttpServletRequest req; >>>>> >>>>> @Context HttpServletRequest res; >>>>> >>>>> as fields or method parameters. >>>>> >>>>> You should be able to reference a static page using a Viewable. Just >>>>> return >>>>> something like this: >>>>> >>>>> // Absolute reference >>>>> return new Viewable("/static.png", null); >>>>> >>>>> // Reference relative to the resource class or a super class >>>>> return new Viewable("static.png", null); >>>>> >>>>> Paul. >>>>> >>>>> --------------------------------------------------------------------- >>>>> To unsubscribe, e-mail: [hidden email] >>>>> For additional commands, e-mail: [hidden email] >>>>> >>>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: [hidden email] >>>> For additional commands, e-mail: [hidden email] >>>> >>> -- >>> | ? + ? = To question >>> ----------------\ >>> Paul Sandoz >>> x38109 >>> +33-4-76188109 >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [hidden email] >>> For additional commands, e-mail: [hidden email] >>> >>> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [hidden email] >> For additional commands, e-mail: [hidden email] >> > > -- > | ? + ? = To question > ----------------\ > Paul Sandoz > x38109 > +33-4-76188109 > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|||||||||||||||||||
|
jstrachan
|
In reply to this post
by Paul Sandoz
I guess (as Craig says) folks can just map the Jersey servlet to those URL patterns which folks know should only contain JAX-RS or implicit views. e.g. /foo and /bar then leave /css/* /images/* and /js/* to be served up by the Servlet engines default servlet. Though that is a bit icky. Its such a shame in the Servlet spec you can't kinda map specific URIs to being static content. e.g. being able to say that /images/* /css/* and /js/* are static content so don't map them to Jersey's servlet would be great. Its a shame there's not a 'not' in the servlet mapping. I wonder if the servlet spec should be updated to allow a true regex to be used for the URL mapping to make this kinda stuff easier? Basically if folks use JAX-RS as a web framework like Struts/SpringMVC/Stripes et al - being able to easily serve up static content for CSS/JavaScript/images (or regular JSP views outside of the JAX-RS stuff) is gonna be key. So I think we need to figure out some best practice for either (i) only mapping Jersey to specific URI patterns or (ii) telling Jersey to exclude URIs and delegate to the default servlet Anyone else got any ideas of how to come up with a more generic best practice for mixing and matching Jersey with static content & JSPs? |
||||||||||||||||||
|
Paul Sandoz
|
On Jan 26, 2009, at 7:34 PM, jstrachan wrote: > > > > Paul Sandoz wrote: >> >> >> On Sep 2, 2008, at 8:46 AM, Paul Sandoz wrote: >> >>> On Sep 2, 2008, at 8:13 AM, Craig McClanahan wrote: >>> >>>> Paul Sandoz wrote: >>>>> Julio Faerman wrote: >>>>>> I have tried to write out the resource, but this is troublesome >>>>>> as the >>>>>> resource is not on the classpath. I think there is a method to >>>>>> get web >>>>>> resources in servlet 2.5, >>>>> >>>>> You need to use methods on the ServletContext. >>>>> >>>>> >>>>>> but i also think that the forward should >>>>>> work. >>>>> >>>>> I cannot get it to :-( it works for JSPs, but not for "static" >>>>> stuff like HTML and images, perhaps it is bug in the GF servlet >>>>> implementation i am using? >>>>> >>>>> >>>> What servlet mappings do you have defined? >>>> >>> >>> "/" or "/*". I want to avoid a URL for the main application like: >>> >>> http://host:80/<deployment base>/<jersey base> >>> >>> and exposing out the other resources (static or JSP pages) >>> explicitly. >>> >>> I can forward to JSPs but not to static content. >>> >> >> After more investigation >> >> - If the URL pattern is "/" then i can forward to JSPs but not to >> static content. >> >> - If the URL pattern is "/*" then i cannot forward to JSPs nor static >> content. >> > > I guess (as Craig says) folks can just map the Jersey servlet to > those URL > patterns which folks know should only contain JAX-RS or implicit > views. > e.g. /foo and /bar then leave /css/* /images/* and /js/* to be > served up by > the Servlet engines default servlet. Though that is a bit icky. > Agreed. > Its such a shame in the Servlet spec you can't kinda map specific > URIs to > being static content. e.g. being able to say that /images/* /css/* > and /js/* > are static content so don't map them to Jersey's servlet would be > great. > > Its a shame there's not a 'not' in the servlet mapping. I wonder if > the > servlet spec should be updated to allow a true regex to be used for > the URL > mapping to make this kinda stuff easier? > > Basically if folks use JAX-RS as a web framework like > Struts/SpringMVC/Stripes et al - being able to easily serve up static > content for CSS/JavaScript/images (or regular JSP views outside of the > JAX-RS stuff) is gonna be key. So I think we need to figure out > some best > practice for either > > (i) only mapping Jersey to specific URI patterns or > (ii) telling Jersey to exclude URIs and delegate to the default > servlet > > Anyone else got any ideas of how to come up with a more generic best > practice for mixing and matching Jersey with static content & JSPs? Could this be supported by a servlet filter and processes the request before it hits the Jersey servlet, or could we support a Jersey filter (which we could develop if necessary) to manage forwarding to static pages/JSPs as required. I am not knowledgeable enough about the Servlet and Servlet filter details to know what is possible. In any case i really do agree we need to come up with a good solution. Paul. > -- > View this message in context: http://n2.nabble.com/Static- > references-from-JSP-tp794843p2219723.html > Sent from the Jersey mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|||||||||||||||||||
|
Julio Faerman
|
Perhaps the servlet (or future filter) could receive a "ignore"
pattern as a init-param, that when matched would delegate the request. When we have this, plus the "form beans" and the error handling Craig proposed some time ago, many web apps could use jersey without other web frameworks, wich would be really great. On Mon, Jan 26, 2009 at 7:20 PM, Paul Sandoz <[hidden email]> wrote: > > On Jan 26, 2009, at 7:34 PM, jstrachan wrote: > >> >> >> >> Paul Sandoz wrote: >>> >>> >>> On Sep 2, 2008, at 8:46 AM, Paul Sandoz wrote: >>> >>>> On Sep 2, 2008, at 8:13 AM, Craig McClanahan wrote: >>>> >>>>> Paul Sandoz wrote: >>>>>> >>>>>> Julio Faerman wrote: >>>>>>> >>>>>>> I have tried to write out the resource, but this is troublesome >>>>>>> as the >>>>>>> resource is not on the classpath. I think there is a method to >>>>>>> get web >>>>>>> resources in servlet 2.5, >>>>>> >>>>>> You need to use methods on the ServletContext. >>>>>> >>>>>> >>>>>>> but i also think that the forward should >>>>>>> work. >>>>>> >>>>>> I cannot get it to :-( it works for JSPs, but not for "static" >>>>>> stuff like HTML and images, perhaps it is bug in the GF servlet >>>>>> implementation i am using? >>>>>> >>>>>> >>>>> What servlet mappings do you have defined? >>>>> >>>> >>>> "/" or "/*". I want to avoid a URL for the main application like: >>>> >>>> http://host:80/<deployment base>/<jersey base> >>>> >>>> and exposing out the other resources (static or JSP pages) explicitly. >>>> >>>> I can forward to JSPs but not to static content. >>>> >>> >>> After more investigation >>> >>> - If the URL pattern is "/" then i can forward to JSPs but not to >>> static content. >>> >>> - If the URL pattern is "/*" then i cannot forward to JSPs nor static >>> content. >>> >> >> I guess (as Craig says) folks can just map the Jersey servlet to those URL >> patterns which folks know should only contain JAX-RS or implicit views. >> e.g. /foo and /bar then leave /css/* /images/* and /js/* to be served up >> by >> the Servlet engines default servlet. Though that is a bit icky. >> > > Agreed. > > >> Its such a shame in the Servlet spec you can't kinda map specific URIs to >> being static content. e.g. being able to say that /images/* /css/* and >> /js/* >> are static content so don't map them to Jersey's servlet would be great. >> >> Its a shame there's not a 'not' in the servlet mapping. I wonder if the >> servlet spec should be updated to allow a true regex to be used for the >> URL >> mapping to make this kinda stuff easier? >> >> Basically if folks use JAX-RS as a web framework like >> Struts/SpringMVC/Stripes et al - being able to easily serve up static >> content for CSS/JavaScript/images (or regular JSP views outside of the >> JAX-RS stuff) is gonna be key. So I think we need to figure out some best >> practice for either >> >> (i) only mapping Jersey to specific URI patterns or >> (ii) telling Jersey to exclude URIs and delegate to the default servlet >> >> Anyone else got any ideas of how to come up with a more generic best >> practice for mixing and matching Jersey with static content & JSPs? > > Could this be supported by a servlet filter and processes the request before > it hits the Jersey servlet, or could we support a Jersey filter (which we > could develop if necessary) to manage forwarding to static pages/JSPs as > required. I am not knowledgeable enough about the Servlet and Servlet filter > details to know what is possible. > > In any case i really do agree we need to come up with a good solution. > > Paul. > >> -- >> View this message in context: >> http://n2.nabble.com/Static-references-from-JSP-tp794843p2219723.html >> Sent from the Jersey mailing list archive at Nabble.com. >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [hidden email] >> For additional commands, e-mail: [hidden email] >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|||||||||||||||||||
|
Craig McClanahan
|
Some javascript/style in this post has been disabled (why?)
Julio Faerman wrote:
With the servlet api as it is today (<= 2.5), this won't actually work :-(.Perhaps the servlet (or future filter) could receive a "ignore" pattern as a init-param, that when matched would delegate the request. What "delegate the request" means, in terms of servlet, is to use a RequestDispatcher to let the servlet container choose the correct servlet to handle the request. And, because of the servlet mappings, it is going to give the request right back to the Jersey servlet again ... Surprisingly, it doesn't appear that this issue has yet been addressed in the ongoing Servlet 3.0 work (public draft recently got published[1]). The current text on allowed url patterns appears not to have changed (although the proposal is that you can use web.xml, annotations, or programmatic calls on ServletContext to configure the mappings). Craig [1] http://jcp.org/aboutJava/communityprocess/pr/jsr315/index.html When we have this, plus the "form beans" and the error handling Craig proposed some time ago, many web apps could use jersey without other web frameworks, wich would be really great. On Mon, Jan 26, 2009 at 7:20 PM, Paul Sandoz [hidden email] wrote: |
|||||||||||||||||||
|
jstrachan
|
2009/1/26 Craig McClanahan <[hidden email]>:
> Julio Faerman wrote: > > Perhaps the servlet (or future filter) could receive a "ignore" > pattern as a init-param, that when matched would delegate the request. > > > > With the servlet api as it is today (<= 2.5), this won't actually work :-(. > > What "delegate the request" means, in terms of servlet, is to use a > RequestDispatcher to let the servlet container choose the correct servlet to > handle the request. And, because of the servlet mappings, it is going to > give the request right back to the Jersey servlet again ... > > Surprisingly, it doesn't appear that this issue has yet been addressed in > the ongoing Servlet 3.0 work (public draft recently got published[1]). The > current text on allowed url patterns appears not to have changed (although > the proposal is that you can use web.xml, annotations, or programmatic calls > on ServletContext to configure the mappings). > > Craig > > [1] http://jcp.org/aboutJava/communityprocess/pr/jsr315/index.html Maybe we should raise an issue on the servlet 3 spec as its a pretty major flaw IMHO. I'm sure it would be possible to add a minor change to servlet 3.0 to solve this issue. One idea could be just to be able to define the servlet containers handlers as a name to be used in the servlet mapping - so you can explicitly map URIs to the default container servlets (whether its the containers FileServlet or JSP processing servlet or whatever it is) to basically cookie cut holes in the URI space and let them be handled by the servlet container rather than your web apps servlets. e.g. <webapp containerHandler="Default" ...> ... <servlet-mapping> <servlet-name>Default</servlet-name> <url-pattern>/css/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Default</servlet-name> <url-pattern>/js/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Default</servlet-name> <url-pattern>/images/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Default</servlet-name> <url-pattern>*.jsp</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Jersey Web Application</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> So we explicitly map stuff we *don't* want to manage in the web app to the Default container's servlets, then catch all the rest in our Jersey servlet. Another option is to allow real regex to be used to map servlets to URIs; though I'm not sure if its possible to say don't match (.*\.jsp|//images//.*|//js//.*|//css//.*) in a regex :) -- James ------- http://macstrac.blogspot.com/ Open Source Integration http://fusesource.com/ --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|||||||||||||||||||
|
Paul Sandoz
|
Hi,
I have forwarded this email to the relevant people. James, Craig, as of Servlet 2.5 is it possible to utilize a filter from which we decide to forward to static files or JSP pages or forward to Jersey? For example, void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) { if (request is for Jersey) { forward request to Jersey } else { // Handle static files and JSPs chain.doFilter(req, res); } } Paul. On Jan 27, 2009, at 11:00 AM, James Strachan wrote: > 2009/1/26 Craig McClanahan <[hidden email]>: >> Julio Faerman wrote: >> >> Perhaps the servlet (or future filter) could receive a "ignore" >> pattern as a init-param, that when matched would delegate the >> request. >> >> >> >> With the servlet api as it is today (<= 2.5), this won't actually >> work :-(. >> >> What "delegate the request" means, in terms of servlet, is to use a >> RequestDispatcher to let the servlet container choose the correct >> servlet to >> handle the request. And, because of the servlet mappings, it is >> going to >> give the request right back to the Jersey servlet again ... >> >> Surprisingly, it doesn't appear that this issue has yet been >> addressed in >> the ongoing Servlet 3.0 work (public draft recently got >> published[1]). The >> current text on allowed url patterns appears not to have changed >> (although >> the proposal is that you can use web.xml, annotations, or >> programmatic calls >> on ServletContext to configure the mappings). >> >> Craig >> >> [1] http://jcp.org/aboutJava/communityprocess/pr/jsr315/index.html > > Maybe we should raise an issue on the servlet 3 spec as its a pretty > major flaw IMHO. I'm sure it would be possible to add a minor change > to servlet 3.0 to solve this issue. > > One idea could be just to be able to define the servlet containers > handlers as a name to be used in the servlet mapping - so you can > explicitly map URIs to the default container servlets (whether its the > containers FileServlet or JSP processing servlet or whatever it is) to > basically cookie cut holes in the URI space and let them be handled by > the servlet container rather than your web apps servlets. e.g. > > <webapp containerHandler="Default" ...> > ... > > <servlet-mapping> > <servlet-name>Default</servlet-name> > <url-pattern>/css/*</url-pattern> > </servlet-mapping> > <servlet-mapping> > <servlet-name>Default</servlet-name> > <url-pattern>/js/*</url-pattern> > </servlet-mapping> > <servlet-mapping> > <servlet-name>Default</servlet-name> > <url-pattern>/images/*</url-pattern> > </servlet-mapping> > <servlet-mapping> > <servlet-name>Default</servlet-name> > <url-pattern>*.jsp</url-pattern> > </servlet-mapping> > <servlet-mapping> > <servlet-name>Jersey Web Application</servlet-name> > <url-pattern>/</url-pattern> > </servlet-mapping> > > So we explicitly map stuff we *don't* want to manage in the web app to > the Default container's servlets, then catch all the rest in our > Jersey servlet. > > Another option is to allow real regex to be used to map servlets to > URIs; though I'm not sure if its possible to say don't match > (.*\.jsp|//images//.*|//js//.*|//css//.*) in a regex :) > > -- > James > ------- > http://macstrac.blogspot.com/ > > Open Source Integration > http://fusesource.com/ > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|||||||||||||||||||
|
jstrachan
|
2009/1/27 Paul Sandoz <[hidden email]>:
> Hi, > > I have forwarded this email to the relevant people. > > James, Craig, as of Servlet 2.5 is it possible to utilize a filter from > which we decide to forward to static files or JSP pages or forward to > Jersey? > > For example, > > void doFilter(ServletRequest request, ServletResponse response, > FilterChain chain) { > if (request is for Jersey) { > forward request to Jersey > } else { > // Handle static files and JSPs > chain.doFilter(req, res); > } > } Ah cool - so we could maybe specify a list of URI patterns for Jersey to ignore then right - and use Jersey via a filter rather than a Servlet mapping? -- James ------- http://macstrac.blogspot.com/ Open Source Integration http://fusesource.com/ --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|||||||||||||||||||
|
Paul Sandoz
|
On Jan 27, 2009, at 11:59 AM, James Strachan wrote: > 2009/1/27 Paul Sandoz <[hidden email]>: >> Hi, >> >> I have forwarded this email to the relevant people. >> >> James, Craig, as of Servlet 2.5 is it possible to utilize a filter >> from >> which we decide to forward to static files or JSP pages or forward to >> Jersey? >> >> For example, >> >> void doFilter(ServletRequest request, ServletResponse response, >> FilterChain chain) { >> if (request is for Jersey) { >> forward request to Jersey >> } else { >> // Handle static files and JSPs >> chain.doFilter(req, res); >> } >> } > > Ah cool - so we could maybe specify a list of URI patterns for Jersey > to ignore then right - and use Jersey via a filter rather than a > Servlet mapping? Right, that is what i am hoping, need to verify if it works. There is also another possible option: the jersey matching algorithm returns false if nothing can be served for the request (which then results in a 404) so a false could imply do "chain.doFilter(req, res)". That, however, requires more work to integrate. Paul. --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|||||||||||||||||||
|
Marc Hadley
|
On Jan 27, 2009, at 6:07 AM, Paul Sandoz wrote:
>> >> Ah cool - so we could maybe specify a list of URI patterns for Jersey >> to ignore then right - and use Jersey via a filter rather than a >> Servlet mapping? > IIRC, the rails plug-in for glassfish is a filter and works in a similar way. Again IIRC it looks to see if there is a static resource that matches the request URI and if not it hands the request to rails. > Right, that is what i am hoping, need to verify if it works. There > is also another possible option: the jersey matching algorithm > returns false if nothing can be served for the request (which then > results in a 404) so a false could imply do "chain.doFilter(req, > res)". That, however, requires more work to integrate. > That would also be less efficient since you'd have to run through the jersey matching algorithm before serving every static file... Marc. --- Marc Hadley <marc.hadley at sun.com> CTO Office, Sun Microsystems. --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|||||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |