use of org.apache.struts.upload.MultipartRequestHandler in project sonar-java by SonarSource.
the class RequestUtils method getMultipartHandler.
/**
* <p>Try to locate a multipart request handler for this request. First,
* look for a mapping-specific handler stored for us under an attribute.
* If one is not present, use the global multipart handler, if there is
* one.</p>
*
* @param request The HTTP request for which the multipart handler should
* be found.
* @return the multipart handler to use, or null if none is found.
* @throws ServletException if any exception is thrown while attempting to
* locate the multipart handler.
*/
private static MultipartRequestHandler getMultipartHandler(HttpServletRequest request) throws ServletException {
MultipartRequestHandler multipartHandler = null;
String multipartClass = (String) request.getAttribute(Globals.MULTIPART_KEY);
request.removeAttribute(Globals.MULTIPART_KEY);
// Try to initialize the mapping specific request handler
if (multipartClass != null) {
try {
multipartHandler = (MultipartRequestHandler) applicationInstance(multipartClass);
} catch (ClassNotFoundException cnfe) {
log.error("MultipartRequestHandler class \"" + multipartClass + "\" in mapping class not found, " + "defaulting to global multipart class");
} catch (InstantiationException ie) {
log.error("InstantiationException when instantiating " + "MultipartRequestHandler \"" + multipartClass + "\", " + "defaulting to global multipart class, exception: " + ie.getMessage());
} catch (IllegalAccessException iae) {
log.error("IllegalAccessException when instantiating " + "MultipartRequestHandler \"" + multipartClass + "\", " + "defaulting to global multipart class, exception: " + iae.getMessage());
}
if (multipartHandler != null) {
return multipartHandler;
}
}
ModuleConfig moduleConfig = ModuleUtils.getInstance().getModuleConfig(request);
multipartClass = moduleConfig.getControllerConfig().getMultipartClass();
// Try to initialize the global request handler
if (multipartClass != null) {
try {
multipartHandler = (MultipartRequestHandler) applicationInstance(multipartClass);
} catch (ClassNotFoundException cnfe) {
throw new ServletException("Cannot find multipart class \"" + multipartClass + "\"" + ", exception: " + cnfe.getMessage());
} catch (InstantiationException ie) {
throw new ServletException("InstantiationException when instantiating " + "multipart class \"" + multipartClass + "\", exception: " + ie.getMessage());
} catch (IllegalAccessException iae) {
throw new ServletException("IllegalAccessException when instantiating " + "multipart class \"" + multipartClass + "\", exception: " + iae.getMessage());
}
if (multipartHandler != null) {
return multipartHandler;
}
}
return multipartHandler;
}
Aggregations