Skip to content

Commit

Permalink
WW-3986 Reverts partially changes introduced with WW-3363 to use @Inject
Browse files Browse the repository at this point in the history
 MultiPartRequest instead of name of MultiPartRequest

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1447453 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
lukaszlenart committed Feb 18, 2013
1 parent e6e1976 commit 1c55798
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ public class Dispatcher {
private String multipartSaveDir;

/**
* Stores reference to instance of {@link MultiPartRequest} implementation defined by {@link StrutsConstants#STRUTS_MULTIPART_PARSER}
* Stores the value of StrutsConstants.STRUTS_MULTIPART_HANDLER setting
*/
private MultiPartRequest multipartHandler;
private String multipartHandlerName;

/**
* Provide list of default configuration files.
Expand Down Expand Up @@ -252,9 +252,9 @@ public void setMultipartSaveDir(String val) {
multipartSaveDir = val;
}

@Inject
public void setMultipartHandler(MultiPartRequest multiPartRequest) {
this.multipartHandler = multiPartRequest;
@Inject(StrutsConstants.STRUTS_MULTIPART_PARSER)
public void setMultipartHandler(String val) {
multipartHandlerName = val;
}

@Inject
Expand Down Expand Up @@ -774,15 +774,37 @@ public HttpServletRequest wrapRequest(HttpServletRequest request, ServletContext

String content_type = request.getContentType();
if (content_type != null && content_type.contains("multipart/form-data")) {
MultiPartRequest mpr = getMultiPartRequest();
LocaleProvider provider = getContainer().getInstance(LocaleProvider.class);
request = new MultiPartRequestWrapper(multipartHandler, request, getSaveDir(servletContext), provider);
request = new MultiPartRequestWrapper(mpr, request, getSaveDir(servletContext), provider);
} else {
request = new StrutsRequestWrapper(request);
}

return request;
}

/**
* On each request it must return a new instance as implementation could be not thread safe
* and thus ensure of resource clean up
*
* @return
*/
protected MultiPartRequest getMultiPartRequest() {
MultiPartRequest mpr = null;
//check for alternate implementations of MultiPartRequest
Set<String> multiNames = getContainer().getInstanceNames(MultiPartRequest.class);
for (String multiName : multiNames) {
if (multiName.equals(multipartHandlerName)) {
mpr = getContainer().getInstance(MultiPartRequest.class, multiName);
}
}
if (mpr == null ) {
mpr = getContainer().getInstance(MultiPartRequest.class);
}
return mpr;
}

/**
* Removes all the files created by MultiPartRequestWrapper.
*
Expand Down

0 comments on commit 1c55798

Please sign in to comment.