Tim,
I have attached the filter source. A few notes:
1) The filter is designed for SpringMVC - it attempts to forward to a
servlet. You will need to change this to forward to the original request URL
or a modified URL as you choose.
2) In my web.xml I change all filters that apply only to active content to
have the dispatcher attribute set to FORWARD:
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<servlet-name>action</servlet-name>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
Again, here it is set on the servlet, you will need to change it to work on
a URL.
3) The filter accepts includes/excludes patterns as init parameters, with
the default includes being "*.html". Excludes takes precedence over
includes. Requests that match the set get forwarded, all others propogate
straight down the filter chain so that the servlet container can use its
native handling of static resources, caching, etc. So in my case to have all
html in the dojo src directory served up as static resources:
<filter>
<filter-name>dojoFilter</filter-name>
<filter-class>org.appfuse.webapp.filter.DojoFilter</filter-class>
<init-param>
<param-name>excludes</param-name>
<param-value>/scripts/dojo/*</param-value>
</init-param>
</filter>
Hope this will do the trick!
Mike.
On 12/5/06, Tim Azzopardi <[EMAIL PROTECTED]> wrote:
Michael Horwitz wrote:
>
> There are two possible ways to work around this (at least I think so - I
> have done no 2 for SpringMVC, but have not yet tried struts):
>
> 1) Use the packages init parameter on the FilterDispatcher and include
> dojo
> as a package. More details in the FilterDispatcher javadoc:
>
http://struts.apache.org/2.x/struts2-core/apidocs/org/apache/struts2/dispatcher/FilterDispatcher.html
>
> 2) Build a filter that forwards all requests not for dojo to the
> dispatcher
> and set the dispatcher to only operate on forwarded requests. I have
coded
> an include/exclude filter that allows me to do this. Let me know if you
> are
> interested in the code and I will post it up here. This method has the
> advantage that you can code filters to only operate on active content,
> thereby shortening the filter chain for static content.
>
> Mike.
>
I had no need to add the packages init parameter on the FilterDispatcher,
because I'm now using dojo that comes with struts2 (which according to the
struts2 doc is 0.4, the latest to date).
To begin with, I was naively (doh!) assuming I could just say
/struts/dojo/dojo.js" click here for dojo source B
But you have to allow struts2 to do its work by using struts tags
(obviously!),
'<s:url value="/struts/dojo/dojo.js" '>click here for dojo source B
(or more verbosely:
<s:url id="bozo" value="/struts/dojo/dojo.js" />
'<s:property value="%{bozo}" '>click here for dojo source A
)
and webwork does indeed serve it straight out of the struts2 jar as
described in the doc
(
http://struts.apache.org/2.x/struts2-core/apidocs/org/apache/struts2/dispatcher/FilterDispatcher.html
)
BUT I still cannot make my simple dojo *button* work. It fails at this
javascript line:
dojo.require("dojo.widget.Button");
which tries to include
"struts/dojo/src/widget/templates/HtmlButtonTemplate.html"
and I get the good old message
"There is no Action mapped for action name
struts/dojo/src/widget/templates/HtmlButtonTemplate."
So, could you post your filter code, so I can give that a go?
--
View this message in context:
http://www.nabble.com/appfuse-1.9.4-webwork-migration-to-struts2-tf2761053s2369.html#a7702208
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;
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 =
"com.abnamro.appinv.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]