[
https://issues.apache.org/struts/browse/WW-2969?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45538#action_45538
]
Brian Curnow commented on WW-2969:
----------------------------------
In an attempt to build to very small applications that illustrate the problem I
was seeing I found that the Convention plugin isn't required to get this to not
work. It looks like since the main DWR page
(http://localhost:8080/dwr/index.html) has an extension, that Struts is smart
enough to just delegate to the container. However, when the URL doesn't contain
an extension (http://localhost:8080/dwr/test/validator) there isn't enough
information there to tell Struts that it shouldn't be handling that URL.
I've worked around this problem by building a filter that you can map to URLs
you want the container to handle:
{code}
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.RequestUtils;
import org.apache.struts2.dispatcher.ServletDispatcherResult;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
/**
* Ensures that the request is handled correctly by the servlet container
instead of by Struts
*/
public class Struts2SkipFilter implements Filter {
public void destroy() {
// do nothing
}
public void doFilter(ServletRequest servletRequest, ServletResponse
servletReponse, FilterChain filterChain)
throws IOException, ServletException {
String requestPath =
RequestUtils.getServletPath((HttpServletRequest) servletRequest);
// Create a new ActionMapping that points to the request path
and indicates that the ServletDispatcher should handle it
ActionMapping actionMapping = new ActionMapping(new
ServletDispatcherResult(requestPath));
// Set the name to "" to ensure we skip some of the find
requests for JSPs
actionMapping.setName("");
// Put the action mapping in the request where the
PrepareFilter will find it
servletRequest.setAttribute("struts.actionMapping",
actionMapping);
filterChain.doFilter(servletRequest, servletReponse);
}
public void init(FilterConfig filterConfig) throws ServletException {
// do nothing
}
}
{code}
By mapping this filter to the /dwr/* pattern, I seem to get what I want. All
the functionality of Struts2 and all the functionality of DWR. While the core
DWR functionality (remoting) was working fine before this filter, the handle
information pages were not. This isn't a big deal except I was also using the
DWR namespace in my Spring application context to map the classes. Without
those information page I didn't have a good way to view that information.
Is there a better way to get the Struts2 filters to ignore requests? If not,
then I think this issue can be closed, it's resolved from my end.
> DWR class information pages don't work with Struts2
> ---------------------------------------------------
>
> Key: WW-2969
> URL: https://issues.apache.org/struts/browse/WW-2969
> Project: Struts 2
> Issue Type: Bug
> Affects Versions: 2.1.6
> Environment: Jetty 6.1.14 on Windows XP Pro
> Struts2 2.1.6 with Convention plugin
> DWR 2.0.3
> Reporter: Brian Curnow
>
> This may not be an actual bug and be "broken" this way be design. In reading
> through the documentation (http://struts.apache.org/2.1.6/docs/webxml.html)
> it's recommended that you map the Struts
> FilterDispatcher/StrutsPrepareAndExecuteFilter to the URL pattern "/*". This
> seems to work fine with what I'll call traditional Struts2 (i.e. no
> Convention plugin) and also with the Convention plugin.
> I'm attempting to use DWR 2.0 and their documentation has you map the
> dwr-invoker (I'm using the Spring version:
> org.directwebremoting.spring.DwrSpringServlet) to the URL pattern "/dwr/*"
> (http://directwebremoting.org/dwr/server/servlet). This works fine in
> traditional Struts2 but breaks when using the Convention plugin.
> What I get when I attempt to hit http://localhost:8080/dwr is an error:
> "There is no Action mapped for namespace / and action name dwr." I can work
> around that error by using http://localhost:8080/dwr/index.html however, when
> clicking on a link on the DWR page (to see information about one of my
> exposed classes) I get a similar error: "There is no Action mapped for
> namespace /dwr/test and action name MessageBean."
> I believe this is caused because the Convention plugin treats URLs it can't
> resolve as errors instead of falling back on the web container to handle
> them. This doesn't seem to be an issue for URLs which actually map back to
> files, for example, http://localhost:8080/styles/menu.css works just fine and
> returns the menu.css file in my <web app root>/styles directory. Like I said
> earlier, this may have been by design.
> I've worked around this two ways:
> 1. Resetting struts.action.extension to be simply "action", since none of the
> DWR URLs using .action, this is working but now I have that darn .action in
> my URLs again
> 2. Adding a package-info.java to my base Action package and setting a
> namespace
> (@org.apache.struts2.convention.annotation.Namespace(value="/action")) and
> then changing the filter mapping in web.xml to only look for /action/* (and
> moving the results files as well)
> Neither of those solutions is, in my opinion, very attractive and it seems
> that if traditional struts2 can support the DWR URLs that the Convention
> plugin should be able to support them too.
> Is this an actual bug and can it be fixed or is there another workaround?
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.