[
https://issues.apache.org/jira/browse/WW-4239?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13819917#comment-13819917
]
Letizia Cazora commented on WW-4239:
------------------------------------
Hi all,
I developed a work-around, as I cannot wait for a new release and I have no
time to test for an upgrade.
In my custom interceptor I added the following:
import javax.servlet.http.HttpServletRequest;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import org.apache.struts2.StrutsStatics;
import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.Map;
import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper;
import org.apache.struts2.interceptor.ParameterAware;
public class CustomInterceptor extends AbstractInterceptor implements
StrutsStatics {
@Override
public void init() {
}
@Override
public void destroy() {
}
@Override
public String intercept(ActionInvocation invocation) throws Exception {
public String intercept(ActionInvocation invocation) throws Exception {
final ActionContext context = invocation.getInvocationContext();
HttpServletRequest request = (HttpServletRequest)
context.get(HTTP_REQUEST);
Object action = invocation.getAction();
if (action instanceof ParameterAware) {
Method m =
action.getClass().getDeclaredMethod("setMultiPartParameters", Map.class);
if (m!=null){
Map<String,Object> mpp = context.getParameters();
if (request instanceof MultiPartRequestWrapper) {
MultiPartRequestWrapper mpr =
(MultiPartRequestWrapper)request;
Enumeration<String> fileParams =
mpr.getFileParameterNames();
while (fileParams.hasMoreElements()){
String fileParam = fileParams.nextElement();
mpp.put(fileParam, mpr.getFiles(fileParam));
mpp.put(fileParam+"FileName",
mpr.getFileNames(fileParam));
mpp.put(fileParam+"ContentType",
mpr.getContentTypes(fileParam));
}
}
m.invoke(action,mpp);
}
}
...
return invocation.invoke();
}
in my action, which already implements ParameterAware, I added:
private Map<String,Object> multiPartParameters;
and the setter method:
public void setMultiPartParameters(Map<String, Object> multiPartParameters)
{
this.multiPartParameters = multiPartParameters;
}
and use this new field instead of parameters
> Using ParameterAware with FileUploadInterceptor leads to ClassCastException
> ---------------------------------------------------------------------------
>
> Key: WW-4239
> URL: https://issues.apache.org/jira/browse/WW-4239
> Project: Struts 2
> Issue Type: Bug
> Affects Versions: 2.3.15.1
> Reporter: Ilya
> Fix For: 2.3.17
>
>
> Ljava.io.File; cannot be cast to [Ljava.lang.String;
> ---------
> According to ParameterAware I should have method
> {code}
> public void setParameters(Map<String, String[]> parameters);
> {code}
> But I also have _File_ field and FileUploadInterceptor sets file there.
> So, I am getting File[] instead of String[].
--
This message was sent by Atlassian JIRA
(v6.1#6144)