webtier@glassfish.java.net

Re: [webtier] Way to "Find" Faces Servlet?

From: Lincoln Baxter, III <lincolnbaxter_at_gmail.com>
Date: Wed, 6 Jan 2010 02:04:17 -0500

I was actually hoping for a pre-made web.xml parser ;) but I'll just figure
something out. This is a great start for the 3.0 stuff, though, thanks!

--lb

On Mon, Jan 4, 2010 at 5:26 PM, Ryan Lubke <Ryan.Lubke_at_sun.com> wrote:

> On 1/4/10 2:02 PM, Lincoln Baxter, III wrote:
>
> Any good examples out there on how to do this? Any reusable libs that you
> know of?
>
> Of the servlet 3.0 API?
>
> Map<String,? extends ServletRegistration> existing =
> servletContext.getServletRegistrations();
> for (ServletRegistration registration : existing.values()) {
> if
> ("javax.faces.webapp.FacesServlet".equals(registration.getClassName())) {
> Collection<String> mappings =
> registration.getMappings();
> // do something with the mappings.
>
> }
> }
>
>
>
> I assume this is the identifier I would be looking for, then grab the
> mapping and build a URL, since it's the spec'd (final/un-subclassable)
> servlet-class.
>
> <servlet-class>*javax.faces.webapp.FacesServlet*</servlet-class>
>
>
> In 95% of the cases this would be true. However, there are some JSF
> applications that wrap the FacesServlet so that they can provide custom
> features. For example, the GlassFish admin gui has such a wrapper to defer
> initialization until the first request to the servlet.
>
> That said, relying on the servlet class vs the name is the better choice.
>
> Additionally, I have a potentially basic Java question:
>
> Just for confirmation, I can test this when I try it out: Assuming that I'm
> using servletContext.getMajorVersion() to detect the current Servlet version
> and take appropriate action, since I've never attempted to write a portable
> lib between servlet versions... if I reference servlet 3.0, 2.5 APIs will
> work in a 3.0 environment (unless deprecated), and make sure no 3.0 APIs are
> accessed in 2.5 environments, I should be OK without runtime failures?
>
> Mojarra does this. As long as you compile with the latest version and
> guard against calling methods that shouldn't be depending on the version,
> you'll be fine.
>
>
> Thanks,
> --Lincoln
>
>
> On Mon, Jan 4, 2010 at 12:01 PM, Ryan Lubke <Ryan.Lubke_at_sun.com> wrote:
>
>> If you're using Servlet 3.0, you can use the new programmatic APIs
>> available on the ServletContext to
>> obtain information on all registered Servlets.
>>
>> Anything earlier than 3.0, probably means parsing the web.xml yourself.
>>
>>
>> On 1/3/10 12:23 PM, Lincoln Baxter, III wrote:
>>
>>> I'm trying to figure out a way to dispatch a request to Faces Servlet,
>>> but I'm not sure how to discover how Faces Servlet is mapped. Is there
>>> any way to do this?
>>>
>>> Basically, I want to be able to do something like this:
>>>
>>> 1. Request comes in for /some/url/
>>> 2. Filter intercepts /some/url/ and understands that it belongs to Faces
>>> 3. Filter forwards request to Faces Servlet (even though Faces Servlet
>>> is not mapped to /some/url/ )
>>>
>>> So that means that I need either a blind forward, or a way of
>>> determining some URL that *does* resolve to Faces Servlet. Once the
>>> request is in Faces, it does not matter that there is no view file
>>> corresponding to the address.
>>>
>>> Thanks,
>>> Lincoln
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: webtier-unsubscribe_at_glassfish.dev.java.net
>>> For additional commands, e-mail: webtier-help_at_glassfish.dev.java.net
>>>
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: webtier-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: webtier-help_at_glassfish.dev.java.net
>>
>>
>
>
> --
> Lincoln Baxter, III
> http://ocpsoft.com
> http://scrumshark.com
> "Keep it Simple"
>
>
>


-- 
Lincoln Baxter, III
http://ocpsoft.com
http://scrumshark.com
"Keep it Simple"