I use Spring MVC with the filter I posted below, which simply directs all
requests for active pages to the Spring dispatch servlet. The relevant
pieces of the web.xml are:

<filter>
     <filter-name>dojoFilter</filter-name>
     <filter-class>org.appfuse.webapp.filter.DojoFilter</filter-class>
     <init-param>
       <param-name>includes</param-name>
       <param-value>*.html,/reports/*</param-value>
     </init-param>
     <init-param>
       <param-name>excludes</param-name>
       <param-value>/scripts/dojo/*</param-value>
     </init-param>
 </filter>

<filter-mapping>
   <filter-name>dojoFilter</filter-name>
   <url-pattern>/*</url-pattern>
 </filter-mapping>

(the filter by default redirects all matching requests to a servlet called
"action").

Then I changed the following filter mappings:

   <filter-mapping>
       <filter-name>sitemesh</filter-name>
       <url-pattern>/*</url-pattern>
       <dispatcher>REQUEST</dispatcher>
   </filter-mapping>

Only apply SiteMesh to original request - if only want to decorate active
pages, but leave static untouched, change the REQUEST to FOWARD. Note that
in my case the sitemesh filter is defined before the dojo filter.

<filter-mapping>
       <filter-name>hibernateFilter</filter-name>
       <servlet-name>action</servlet-name>
       <dispatcher>FORWARD</dispatcher>
</filter-mapping>

Only start Hibernate sessions for requests that have been fowarded to the
action servlet.

And note that there is NO servlet mapping for the action servlet - it is
only invoked via the dojo filter.

Mike.
P.S. I have CC'ed this respons onto the user list - that way others can
benefit from our conversation!

On 2/1/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

hi Michael:

i still got PageNotFound.noHandlerFound(1005) | No mapping

how do u config ur web.xml?

please help , tks a lot!!!

Michael Horwitz wrote:
>
> Matt,
>
> I have attached a simple filter class which works well with Spring MVC.
> The
> basic operation works on the following principles:
>
> 1) The servlet container retains responsibility for serving all static
> resources. This ensures optimum performance (resources can be cached,
have
> their timestamps checked for updates, etc) and avoids any I/O nasties
that
> might arise if the filter itself tries to read and serve up these
> resources.
> 2) The filter redirects any requests for active pages to the relevant
> processing chain, which includes all filters related to active content,
> e.g.
> Hibernate filter. This helps ensure that the minimum number of filters
are
> applied to static content.
> 3) The filter requires reasonably sophisticated pattern matching
abilities
> to sort active from static page requests. This implies the use of an
> excludes filter on top of the normal include filter provided by default
as
> part of the servlet standard.
>
> The attached implementation is Spring MVC specific. Any request that the
> filter believes matches an active page are redirected to the dispatch
> servlet by name. All other requests are allowed to pass straight through
> for
> normal processing by the servlet container. The solution also relies on
> the
> use of the <dispatcher> filter configuration element available as of the
> servlet 2.4 spec to separate filtering on active page requests from
those
> for static content, which leads me to believe the solution could be made
> to
> work for the other web frameworks.
>
> Let me know what you think.
>
> Mike.
>
>
> On 1/29/07, mraible <[EMAIL PROTECTED]> wrote:
>>
>>
>> Any update on this Mike? It looks like most folks would prefer to stick
>> with
>> *.html (as would I).
>>
>> http://appfuse.org/pages/viewpage.action?pageId=495
>>
>> Thanks,
>>
>> Matt
>>
>>
>> Matt Raible-3 wrote:
>> >
>> > On 1/17/07, Michael Horwitz <[EMAIL PROTECTED]> wrote:
>> >> Matt,
>> >>
>> >> I have successfully used Dojo with SpringMVC while still keeping the
>> >> .html
>> >> extension by using a filter to redirect any non-dojo requests to the
>> >> Spring
>> >> servlet. This approach has two nice side effects: 1) the servlet
>> >> container
>> >> can use its default handling for all static content and 2) one can
>> reduce
>> >> the number of filters that get applied to such content.
>> >>
>> >> If people are interested I would be more than happy to share the
>> >> solution.
>> >
>> > I'd definitely be interested in this and having folks test it with
>> > Struts 2.  It might be best to post it here, as well as in JIRA
>> > (http://issues.appfuse.org/browse/APF-431).
>> >
>> > Matt
>> >
>> >>
>> >> Mike.
>> >>
>> >>
>> >> On 1/17/07, Matt Raible <[EMAIL PROTECTED]> wrote:
>> >> > I've created a poll so everyone can vote on their favorite
>> extension.
>> >> >
>> >> > http://appfuse.org/pages/viewpage.action?pageId=495
>> >> >
>> >> > You'll need to create an account and login to vote. To do this, go
>> to
>> >> > View > Account > Sign Up (or login if you already have an
account).
>> >> >
>> >> > Thanks!
>> >> >
>> >> > Matt
>> >> >
>> >> > On 1/16/07, Sanjiv Jivan <[EMAIL PROTECTED]> wrote:
>> >> > > I like .html but the problem I've faced with using this
extension
>> is
>> >> that
>> >> > > serving static html file with the .html file extension (like
>> >> documentation,
>> >> > > Dojo templates or FckEditor files) becomes very hard to map to
not
>> go
>> >> to
>> >> the
>> >> > > applications MVC controller. I've spent countless number of
hours
>> >> messing
>> >> > > with the url-pattern in web.xml without much success.
>> >> > >
>> >> > >  So I usually use .htm for the application extension.
>> >> > >
>> >> > >  Sanjiv
>> >> > >
>> >> > >
>> >> > > On 9/20/06, Matt Raible < [EMAIL PROTECTED]> wrote:
>> >> > > >
>> >> > > > Dear AppFuse users,
>> >> > > >
>> >> > > > As many of you likely know, there are a couple of issues with
>> using
>> >> > > > the *.html extension with some frameworks in AppFuse.  For
>> example,
>> >> > > > with WebWork - it loads Dojo template files from a *.html
>> >> extension.
>> >> > > > If you want to use Dojo with WebWork, you have to modify your
>> >> default
>> >> > > > extension.
>> >> > > >
>> >> > > > http://issues.appfuse.org/browse/APF-431
>> >> > > >
>> >> > > > Because of this, we're starting to look at other extensions.
>> I'd
>> >> > > > rather use one for all frameworks, rather than the recommended
>> ones
>> >> > > > for each framework b/c it allows us to have one
>> security.xmlfiles,
>> >> > > > rather than one for each framework.  Another option is to use
>> >> > > > path-based mapping, for example:
>> >> > > >
>> >> > > > http://localhost:8080/yourapp/go/users
>> >> > > >
>> >> > > > Where "/go/*" is the path that front-controller
servlet/filters
>> are
>> >> > > > mapped to.  The only problem with this is stat trackers
>> typically
>> >> like
>> >> > > > to track extensions, and so we'd be unfriendly to those
>> companies
>> >> who
>> >> > > > like to watch their stats.
>> >> > > >
>> >> > > > Here's a couple thoughts - feel free to add your own
suggestions
>> >> and
>> >> > > thoughts:
>> >> > > >
>> >> > > > 1. *.htm
>> >> > > > 2. *.aspx
>> >> > > > 3. *.php
>> >> > > > 4. *.app
>> >> > > > 5. *.a
>> >> > > > 6. *.o
>> >> > > > 7. *.apf (would help us track AppFuse-based applications, but
>> it's
>> >> a
>> >> > > > pretty ugly extension)
>> >> > > > 8. *.em
>> >> > > > 9. *.fun
>> >> > > > 10. *.page
>> >> > > >
>> >> > > > I still like *.html the best b/c it doesn't give away the
>> >> underlying
>> >> > > > technology, so *.htm seems like the best option after
that.  But
>> of
>> >> > > > course, I'm open to suggestions. ;-)
>> >> > > >
>> >> > > > Matt
>> >> > > >
>> >> > > >
>> >> > >
>> >>
---------------------------------------------------------------------
>> >> > > > To unsubscribe, e-mail:
>> >> > > [EMAIL PROTECTED]
>> >> > > > For additional commands, e-mail:
[EMAIL PROTECTED]
>> >> > > >
>> >> > > >
>> >> > >
>> >> > >
>> >> >
>> >> >
>> >> > --
>> >> > http://raibledesigns.com
>> >> >
>> >> >
>> >>
---------------------------------------------------------------------
>> >> > To unsubscribe, e-mail:
>> >> [EMAIL PROTECTED]
>> >> > For additional commands, e-mail: [EMAIL PROTECTED]
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >
>> > --
>> > http://raibledesigns.com
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: [EMAIL PROTECTED]
>> > For additional commands, e-mail: [EMAIL PROTECTED]
>> >
>> >
>> >
>>
>> --
>> View this message in context:
>>
http://www.nabble.com/Changing-default-extension-from-*.html-to-*.---tf2307780s2369.html#a8699069
>> Sent from the AppFuse - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
> package org.appfuse.webapp.filter;
>
> import org.apache.commons.lang.StringUtils;
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> import org.springframework.util.PatternMatchUtils;
> import org.springframework.web.util.UrlPathHelper;
>
> import javax.servlet.Filter;
> import javax.servlet.FilterChain;
> import javax.servlet.FilterConfig;
> import javax.servlet.RequestDispatcher;
> import javax.servlet.ServletContext;
> import javax.servlet.ServletException;
> import javax.servlet.ServletRequest;
> import javax.servlet.ServletResponse;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> import java.io.IOException;
> import java.util.Iterator;
> import java.util.Set;
>
> /**
>  * A simple filter that allows the application to continue using the
.html
> prefix for active
>  * pages but still allows Dojo to serve up its HTML template code. The
> filter works on an
>  * include/exclude basis where all requests for active pages are
> redirected by the filter to
>  * the dispatch servlet. All Dojo related .html requests are allowed to
> pass straight through
>  * to be processed by the servlet container as per normal.
>  */
> public class DojoFilter implements Filter {
>
>  private static Log log = LogFactory.getLog(DojoFilter.class);
>
>  private final static String DEFAULT_INCLUDES = "*.html";
>
>  private final static String DEFAULT_EXCLUDES = "";
>
>  public static final String INCLUDES_PARAMETER="includes";
>
>  public static final String EXCLUDES_PARAMETER="excludes";
>
>  public static final String
> ACTION_SERVLET_NAME_PARAMETER="action_servlet_name";
>
>  public static final String _REQUEST_PARSED =
> "org.appfuse.webapp.request.parsed";
>
>  private String[] excludes;
>
>  private String[] includes;
>
>  private String actionServletName = "action";
>
>  private RequestDispatcher actionServletRequestDispatcher;
>
>   /**
>    * Read the includes/excludes paramters and set the filter
accordingly.
>    */
>   public void init(FilterConfig filterConfig)
>   {
>    String includesParam =
> filterConfig.getInitParameter(INCLUDES_PARAMETER);
>     if (StringUtils.isEmpty(includesParam))
>     {
>       includes = parsePatterns(DEFAULT_INCLUDES);
>     }
>     else
>     {
>       includes = parsePatterns(includesParam);
>     }
>     String excludesParam =
> filterConfig.getInitParameter(EXCLUDES_PARAMETER);
>     if (StringUtils.isEmpty(excludesParam))
>     {
>       excludes = parsePatterns(DEFAULT_EXCLUDES);
>     }
>     else
>     {
>       excludes = parsePatterns(excludesParam);
>     }
>     String actionServletNameParam =
> filterConfig.getInitParameter(ACTION_SERVLET_NAME_PARAMETER);
>     if (StringUtils.isNotEmpty(actionServletNameParam))
>     {
>       actionServletName = actionServletNameParam;
>     }
>     ServletContext servletContext = filterConfig.getServletContext();
>     actionServletRequestDispatcher =
> servletContext.getNamedDispatcher(actionServletName);
>     if (actionServletRequestDispatcher == null)
>     {
>       log.error("No action servlet named [" + actionServletName + "]
could
> be found. Please check configuration in web.xml.");
>       throw new RuntimeException("Could not instantiate dojo filter: no
> valid action servlet specified, or action servlet not found.");
>     }
>   }
>
>   private String[] parsePatterns(String delimitedPatterns)
>   {
>     //make sure no patterns are repeated.
>     Set patternSet =
> org.springframework.util.StringUtils.commaDelimitedListToSet
(delimitedPatterns);
>     String[] patterns = new String[patternSet.size()];
>     int i = 0;
>     for (Iterator iterator = patternSet.iterator(); iterator.hasNext();
> i++)
>     {
>       //no trailing/leading white space.
>       String pattern = (String) iterator.next();
>       patterns[i] = pattern.trim();
>     }
>     return patterns;
>   }
>
>   public void doFilter(ServletRequest request, ServletResponse response,
>                        FilterChain chain) throws IOException,
> ServletException {
>
>    if (request.getAttribute(_REQUEST_PARSED) != null)
>    {
>      chain.doFilter(request, response);
>      return;
>    }
>
>    final HttpServletRequest req = (HttpServletRequest) request;
>    final HttpServletResponse res = (HttpServletResponse) response;
>
>    UrlPathHelper urlPathHelper = new UrlPathHelper();
>    String path = urlPathHelper.getPathWithinApplication(req);
>    boolean pathExcluded = PatternMatchUtils.simpleMatch(excludes, path);
>    boolean pathIncluded = PatternMatchUtils.simpleMatch(includes, path);
>
>    if (pathIncluded && ! pathExcluded)
>    {
> //     req.setAttribute(_REQUEST_PARSED, Boolean.TRUE);
>      actionServletRequestDispatcher.forward(req, res);
>      return;
>    }
>
>    chain.doFilter(req, res);
>   }
>
>   public void destroy() {
>     actionServletRequestDispatcher = null;
>   }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
Quoted from:

http://www.nabble.com/Changing-default-extension-from-*.html-to-*.---tf2307780s2369.html#a8706377


Reply via email to