Mapping Stripes Filter with Guice ServletModule

591 views
Skip to first unread message

senny

unread,
Apr 23, 2010, 10:38:03 AM4/23/10
to google-guice
Hey there

I am very new to Guice and would like to use it with our Stripes
Application. I would like to add the StripesFilter and the
DispatcherServilet inside the ServletModule. Can anyone tell me how to
do that? Or do i still need to define the StripesFilter and the
Dispatcher in the web xml? It is important that the StripesFilter also
gets used for ServerSide includes and forwards.My currend web.xml
Mappings look like:

<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-
class>net.sourceforge.stripes.controller.DispatcherServlet</servlet-
class>
<load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<filter>
<filter-name>StripesFilter</filter-name>
<filter-class>net.sourceforge.stripes.controller.StripesFilter</
filter-class>
</filter>

<filter-mapping>
<filter-name>StripesFilter</filter-name>
<servlet-name>DispatcherServlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>

Cheers,
-- Yves

--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To post to this group, send email to google...@googlegroups.com.
To unsubscribe from this group, send email to google-guice...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.

Dhanji R. Prasanna

unread,
Apr 23, 2010, 7:41:03 PM4/23/10
to google...@googlegroups.com
Yes you can do that. You will need to setup Guice Filter in web.xml as shown here:

Then you can bind Stripes' filters and servlets as shown in the "Configuring Guice Servlet" section.

Dhanji.

senny

unread,
Apr 24, 2010, 8:04:23 AM4/24/10
to google-guice
Hey Dhanji

I tried that but ended in a endless dispatcher loop somehow. Do I need
to set the additional <dispatcher> tags for the Guice Filter to make
it work for server side includes? Another Question I got is, How can I
apply a filter to a given servlet with ServletModule like the <servlet-
name> tag does in the wex.xml? Is this possible or do I need to
specify the same patterns for both?
> > google-guice...@googlegroups.com<google-guice%2Bunsubscribe@google groups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/google-guice?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "google-guice" group.
> To post to this group, send email to google...@googlegroups.com.
> To unsubscribe from this group, send email to google-guice...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/google-guice?hl=en.

Dhanji R. Prasanna

unread,
Apr 24, 2010, 6:39:02 PM4/24/10
to google...@googlegroups.com
On Sat, Apr 24, 2010 at 10:04 PM, senny <yves...@gmail.com> wrote:
Hey Dhanji

I tried that but ended in a endless dispatcher loop somehow. Do I need
to set the additional <dispatcher> tags for the Guice Filter to make
it work for server side includes?

Hmm, try the same tags you have for stripes filter on GuiceFilter. Unfortunately we don't officially support some of the lesser used arcane features of the servlet spec, so it may take a couple of roundtrips on this list to get it right =(

Also if need be, and justifiable we can apply a patch to support it.

Another Question I got is, How can I
apply a filter to a given servlet with ServletModule like the <servlet-
name> tag does in the wex.xml? Is this possible or do I need to
specify the same patterns for both?

You need to specify a filter. We deliberately chose not to use the name binding route for type safety and clarity. Otoh, we support regex matching so that should be fairly easy.

Dhanji.

senny

unread,
Apr 26, 2010, 4:47:31 AM4/26/10
to google-guice
It looks like there is something wrong in the ServletDefinition Class
when I do server side includes or forwards. I receive the following
stack-trace:
java.lang.StringIndexOutOfBoundsException: String index out of range:
-12
at java.lang.String.substring(String.java:1938)
at java.lang.String.substring(String.java:1905)
at com.google.inject.servlet.ServletDefinition
$2.getPathInfo(ServletDefinition.java:173)
at
net.sourceforge.stripes.util.HttpUtil.getRequestedPath(HttpUtil.java:
53)
at
net.sourceforge.stripes.controller.DispatcherServlet.service(DispatcherServlet.java:
94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:
820)
at
com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:
216)
at
com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:
141)
at
com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:
93)
at
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:
63)
at
net.sourceforge.stripes.controller.StripesFilter.doFilter(StripesFilter.java:
247)
at
com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:
129)
at
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:
59)
at
com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:
122)
at
com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:110)
at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:
42)
at
weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:
503)
at
weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:
251)
at
net.sourceforge.stripes.action.ForwardResolution.execute(ForwardResolution.java:
110)
at net.sourceforge.stripes.exception.DefaultExceptionHandler
$HandlerProxy.handle(DefaultExceptionHandler.java:107)
at
net.sourceforge.stripes.exception.DefaultExceptionHandler.handle(DefaultExceptionHandler.java:
140)
at
net.sourceforge.stripes.controller.StripesFilter.doFilter(StripesFilter.java:
250)
at
com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:
129)
at
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:
59)
at
com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:
122)
at
com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:110)

Since I catch all exceptions and forward to a error.jsp page, the
cycle is endless and blows up in an java.lang.StackOverflowError
eventually.

On 25 Apr., 00:39, "Dhanji R. Prasanna" <dha...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages