SiteMesh 3 breaks Struts 2 FileUploadInterceptor?

226 views
Skip to first unread message

xtian

unread,
Feb 3, 2011, 9:30:38 AM2/3/11
to SiteMesh 3 Users
Since I upgraded from SiteMesh 2 to SiteMesh 3, my upload forms
stopped working.
Removing the SiteMesh filter brings them back to life, so there must
be a connection...

I'm using Struts2 FileUploadInterceptor. The interceptor is ignoring
my upload requests.
The relevant code is the following:

public String intercept(ActionInvocation invocation) throws
Exception {
ActionContext ac = invocation.getInvocationContext();
HttpServletRequest request = (HttpServletRequest)
ac.get(ServletActionContext.HTTP_REQUEST);
if (!(request instanceof MultiPartRequestWrapper)) {
if (LOG.isDebugEnabled()) {
LOG.debug(... very long debug message here ...)
}
return invocation.invoke();
}

When I click on my upload button, I get the debug message saying that
the action in bypassed.
That's because SiteMesh 3 is replacing the MultiPartRequestWrapper
with org.sitemesh.webapp.contentfilter.HttpServletRequestFilterable

Any way to fix this?
I tried with the Apache ActionContextCleanUp filter as suggested here
(http://osdir.com/ml/java.appfuse.user/2007-02/msg00096.html) but it
breaks everything.

xtian

unread,
Feb 3, 2011, 9:32:06 AM2/3/11
to SiteMesh 3 Users
P.S. I'm using sitemesh-3.0-alpha-1.zip

Richard L. Burton III

unread,
Feb 3, 2011, 9:34:36 AM2/3/11
to sitemes...@googlegroups.com
If you can send over a test case, I'll look into it what's going on.
--
-Richard L. Burton III

xtian

unread,
Feb 3, 2011, 10:06:19 AM2/3/11
to SiteMesh 3 Users
I wrote a small webapp. How do I send it over?

Apparently the behavior of struts with sitemesh 3 depends on the
invocation sequence of the filters.

This sequence works with sitemesh not with struts upload:

struts-prepare
sitemesh
struts-execute

This sequence works with struts upload, not with sitemesh:

sitemesh
struts-prepare
struts-execute

Richard L. Burton III

unread,
Feb 3, 2011, 10:10:47 AM2/3/11
to sitemes...@googlegroups.com
mrburton (at) gmail.com would work.

xtian

unread,
Feb 8, 2011, 6:37:30 AM2/8/11
to SiteMesh 3 Users
While I wait for an official fix, I patched the struts
FileUploadInterceptor with a dirty hack:

if (request instanceof
org.sitemesh.webapp.contentfilter.HttpServletRequestFilterable) {
request = (HttpServletRequest)
((org.sitemesh.webapp.contentfilter.HttpServletRequestFilterable)request).getRequest();
}

These lines must be added to
org.apache.struts2.interceptor.FileUploadInterceptor, in the "public
String intercept(ActionInvocation invocation)" method, just after
"HttpServletRequest request = ..."

To patch this class you just need to copy its source to your
application, keeping it in the original package.

crashworx

unread,
Jan 4, 2013, 7:09:35 PM1/4/13
to sitemes...@googlegroups.com
Hi,

did you ever find a solution to this ... i've got the same issue, using sitemesh 3 alpha 2..

Subham Kumar Saha

unread,
Sep 5, 2014, 2:21:39 PM9/5/14
to sitemes...@googlegroups.com
We had the same issue when we upgraded to sitemesh 3. File uploads were not working.
Below is a custom interceptor we used as a workaround.

public class SitemeshFileUploadInterceptor extends AbstractInterceptor {


 
@Override

 
public String intercept(ActionInvocation invocation) throws Exception {

   
ActionContext actionContext = invocation.getInvocationContext();
   
Object request = actionContext.get(ServletActionContext.HTTP_REQUEST);
   
if (request instanceof HttpServletRequestFilterable) {
     
ServletRequest wrappedRequest = ((HttpServletRequestWrapper) request).getRequest();
     
if (wrappedRequest instanceof MultiPartRequestWrapper) {

        actionContext
.put(ServletActionContext.HTTP_REQUEST, wrappedRequest);
     
}
   
}
   
return invocation.invoke();
 
}
}

Reply all
Reply to author
Forward
0 new messages