Stripes and UrlBinding

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Stripes and UrlBinding

Chris Molozian
Hey all,

You might have seen me on the IRC channel asking about this. I'm quite confused about how to configure the DynamicMappingFilter and how it fits together with StripesDispatcher and StripesFilter. I've searching around online and there are many slightly different configurations that are "recommended".

I'd like to achieve the following:
  • HomeBean.java uses UrlBinding("/") to match requests for the home page.
  • LoginBean.java uses UrlBinding("/login")
  • Any requests that do not match a binding reach a 404 page, I've created a /WEB-INF/jsp/404.jsp .
The web.xml I've configured so far is:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

<filter>
  <filter-name>StripesFilter</filter-name>
  <filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class>
  <init-param>
    <param-name>ActionResolver.Packages</param-name>
    <param-value>com.webapp.action</param-value>
  </init-param>
  <init-param>
    <param-name>Extension.Packages</param-name>
    <param-value>com.webapp.ext</param-value>
  </init-param>
</filter>

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

<filter-mapping>
  <filter-name>DynamicMappingFilter</filter-name>
  <url-pattern>/*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
  <dispatcher>FORWARD</dispatcher>
  <dispatcher>INCLUDE</dispatcher>
</filter-mapping>

<welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<error-page>
  <error-code>404</error-code>
  <location>/WEB-INF/jsp/404.jsp</location>
</error-page>

</web-app>




I have the following questions:
  • Do I need an index.jsp that forwards requests to the HomeBean ? Couldn't the UrlBinding simply handle the Url request?
  • At the moment any url pattern e.g. /testme requests are handled by the HomeBean apart from /login. My 404 handler is never being used ?
I'd like to follow idiomatic practices when using Stripes all help is appreciated.

Kind Regards,

Chris


------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Stripes and UrlBinding

Ben Gunter
You can't bind to "/" using DMF because DMF operates by allowing the request to go through and then looking for a 404 from the container before it forwards to the ActionBean (if one is bound to the requested path). Therefore, if you bind to "/" all of your 404 errors will get routed through your ActionBean instead of the error handler you've configured. So yes, you should add a "/index.jsp" that forwards to your ActionBean, which is bound to something other than "/".

-Ben

On Sun, Oct 2, 2011 at 9:01 AM, Chris Molozian <[hidden email]> wrote:
Hey all,

You might have seen me on the IRC channel asking about this. I'm quite confused about how to configure the DynamicMappingFilter and how it fits together with StripesDispatcher and StripesFilter. I've searching around online and there are many slightly different configurations that are "recommended".

I'd like to achieve the following:
  • HomeBean.java uses UrlBinding("/") to match requests for the home page.
  • LoginBean.java uses UrlBinding("/login")
  • Any requests that do not match a binding reach a 404 page, I've created a /WEB-INF/jsp/404.jsp .
The web.xml I've configured so far is:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

<filter>
  <filter-name>StripesFilter</filter-name>
  <filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class>
  <init-param>
    <param-name>ActionResolver.Packages</param-name>
    <param-value>com.webapp.action</param-value>
  </init-param>
  <init-param>
    <param-name>Extension.Packages</param-name>
    <param-value>com.webapp.ext</param-value>
  </init-param>
</filter>

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

<filter-mapping>
  <filter-name>DynamicMappingFilter</filter-name>
  <url-pattern>/*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
  <dispatcher>FORWARD</dispatcher>
  <dispatcher>INCLUDE</dispatcher>
</filter-mapping>

<welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<error-page>
  <error-code>404</error-code>
  <location>/WEB-INF/jsp/404.jsp</location>
</error-page>

</web-app>




I have the following questions:
  • Do I need an index.jsp that forwards requests to the HomeBean ? Couldn't the UrlBinding simply handle the Url request?
  • At the moment any url pattern e.g. /testme requests are handled by the HomeBean apart from /login. My 404 handler is never being used ?
I'd like to follow idiomatic practices when using Stripes all help is appreciated.

Kind Regards,

Chris


------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users



------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users
Reply | Threaded
Open this post in threaded view
|

Re: Stripes and UrlBinding

Chris Molozian
Thanks for the prompt reply. I've changed the HomeBean's binding to be "/home" and have this index.jsp page:

<%@page pageEncoding="UTF-8" contentType="text/html;charset=utf-8" language="java" %>
<jsp:forward page="/home"/>

The HomeBean has it's view in /WEB-INF/jsp/home.jsp .

This now allows urls like "/testme" to not match the url pattern for the home page. These requests are being handled by the 404 page defined in my web.xml.

Thanks for the help,

Chris


On 10/02/11 18:43, Ben Gunter wrote:
You can't bind to "/" using DMF because DMF operates by allowing the request to go through and then looking for a 404 from the container before it forwards to the ActionBean (if one is bound to the requested path). Therefore, if you bind to "/" all of your 404 errors will get routed through your ActionBean instead of the error handler you've configured. So yes, you should add a "/index.jsp" that forwards to your ActionBean, which is bound to something other than "/".

-Ben

On Sun, Oct 2, 2011 at 9:01 AM, Chris Molozian <[hidden email]> wrote:
Hey all,

You might have seen me on the IRC channel asking about this. I'm quite confused about how to configure the DynamicMappingFilter and how it fits together with StripesDispatcher and StripesFilter. I've searching around online and there are many slightly different configurations that are "recommended".

I'd like to achieve the following:
  • HomeBean.java uses UrlBinding("/") to match requests for the home page.
  • LoginBean.java uses UrlBinding("/login")
  • Any requests that do not match a binding reach a 404 page, I've created a /WEB-INF/jsp/404.jsp .
The web.xml I've configured so far is:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

<filter>
  <filter-name>StripesFilter</filter-name>
  <filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class>
  <init-param>
    <param-name>ActionResolver.Packages</param-name>
    <param-value>com.webapp.action</param-value>
  </init-param>
  <init-param>
    <param-name>Extension.Packages</param-name>
    <param-value>com.webapp.ext</param-value>
  </init-param>
</filter>

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

<filter-mapping>
  <filter-name>DynamicMappingFilter</filter-name>
  <url-pattern>/*</url-pattern>
  <dispatcher>REQUEST</dispatcher>
  <dispatcher>FORWARD</dispatcher>
  <dispatcher>INCLUDE</dispatcher>
</filter-mapping>

<welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<error-page>
  <error-code>404</error-code>
  <location>/WEB-INF/jsp/404.jsp</location>
</error-page>

</web-app>




I have the following questions:
  • Do I need an index.jsp that forwards requests to the HomeBean ? Couldn't the UrlBinding simply handle the Url request?
  • At the moment any url pattern e.g. /testme requests are handled by the HomeBean apart from /login. My 404 handler is never being used ?
I'd like to follow idiomatic practices when using Stripes all help is appreciated.

Kind Regards,

Chris


------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users




------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2


_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
_______________________________________________
Stripes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/stripes-users