use of org.springframework.web.multipart.support.DefaultMultipartHttpServletRequest in project com.revolsys.open by revolsys.
the class PathAliasController method forward.
public static boolean forward(final HttpServletRequest request, final HttpServletResponse response, final String path) throws IOException, ServletException {
final RequestDispatcher requestDispatcher = request.getRequestDispatcher(path);
if (requestDispatcher == null) {
return false;
} else {
final HttpServletRequest wrappedRequest;
if (request instanceof DefaultMultipartHttpServletRequest) {
final DefaultMultipartHttpServletRequest multiPartRequest = (DefaultMultipartHttpServletRequest) request;
wrappedRequest = new DefaultMultipartHttpServletRequest(multiPartRequest, multiPartRequest.getMultiFileMap(), new HashMap<String, String[]>(), new HashMap<String, String>()) {
@Override
public String getPathInfo() {
return path;
}
};
} else {
wrappedRequest = new HttpServletRequestWrapper(request) {
@Override
public String getPathInfo() {
return path;
}
};
}
final Object forwardPath = request.getAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE);
if (forwardPath == null) {
final String originalUri = request.getRequestURI();
wrappedRequest.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, originalUri);
}
requestDispatcher.forward(wrappedRequest, response);
wrappedRequest.setAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE, forwardPath);
}
return true;
}
use of org.springframework.web.multipart.support.DefaultMultipartHttpServletRequest in project Gemma by PavlidisLab.
the class CommonsMultipartMonitoredResolver method resolveMultipart.
@Override
public MultipartHttpServletRequest resolveMultipart(HttpServletRequest request) throws MultipartException {
String enc = determineEncoding(request);
ServletFileUpload fileUpload = this.newFileUpload(request);
DiskFileItemFactory newFactory = (DiskFileItemFactory) fileUpload.getFileItemFactory();
fileUpload.setSizeMax(sizeMax);
newFactory.setRepository(this.uploadTempDir);
fileUpload.setHeaderEncoding(enc);
try {
MultiValueMap<String, MultipartFile> multipartFiles = new LinkedMultiValueMap<>();
Map<String, String[]> multipartParams = new HashMap<>();
// Extract multipart files and multipart parameters.
List<?> fileItems = fileUpload.parseRequest(request);
for (Object fileItem1 : fileItems) {
FileItem fileItem = (FileItem) fileItem1;
if (fileItem.isFormField()) {
String value;
String fieldName = fileItem.getFieldName();
try {
value = fileItem.getString(enc);
} catch (UnsupportedEncodingException ex) {
logger.warn("Could not decode multipart item '" + fieldName + "' with encoding '" + enc + "': using platform default");
value = fileItem.getString();
}
String[] curParam = multipartParams.get(fieldName);
if (curParam == null) {
// simple form field
multipartParams.put(fieldName, new String[] { value });
} else {
// array of simple form fields
String[] newParam = StringUtils.addStringToArray(curParam, value);
multipartParams.put(fieldName, newParam);
}
} else {
// multipart file field
MultipartFile file = new CommonsMultipartFile(fileItem);
multipartFiles.set(file.getName(), file);
if (logger.isDebugEnabled()) {
logger.debug("Found multipart file [" + file.getName() + "] of size " + file.getSize() + " bytes with original filename [" + file.getOriginalFilename() + "]");
}
}
}
return new DefaultMultipartHttpServletRequest(request, multipartFiles, multipartParams, null);
} catch (FileUploadException ex) {
return new FailedMultipartHttpServletRequest(request, ex.getMessage());
}
}
Aggregations