use of jodd.servlet.upload.MultipartRequestWrapper in project jodd by oblac.
the class ServletConfigInterceptor method intercept.
/**
* {@inheritDoc}
*/
public Object intercept(ActionRequest actionRequest) throws Exception {
HttpServletRequest servletRequest = actionRequest.getHttpServletRequest();
// detect multipart request
if (ServletUtil.isMultipartRequest(servletRequest)) {
servletRequest = new MultipartRequestWrapper(servletRequest, madvocConfig.getFileUploadFactory(), madvocConfig.getEncoding());
actionRequest.setHttpServletRequest(servletRequest);
}
// do it
inject(actionRequest);
Object result = actionRequest.invoke();
outject(actionRequest);
return result;
}
use of jodd.servlet.upload.MultipartRequestWrapper in project jodd by oblac.
the class RequestScopeInjector method injectUploadedFiles.
/**
* Inject uploaded files from multipart request parameters.
*/
protected void injectUploadedFiles(Target[] targets, ScopeData[] injectData, HttpServletRequest servletRequest) {
if (!(servletRequest instanceof MultipartRequestWrapper)) {
return;
}
MultipartRequestWrapper multipartRequest = (MultipartRequestWrapper) servletRequest;
if (!multipartRequest.isMultipart()) {
return;
}
Enumeration paramNames = multipartRequest.getFileParameterNames();
while (paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
if (servletRequest.getAttribute(paramName) != null) {
continue;
}
for (int i = 0; i < targets.length; i++) {
Target target = targets[i];
if (injectData[i] == null) {
continue;
}
ScopeData.In[] scopes = injectData[i].in;
if (scopes == null) {
continue;
}
for (ScopeData.In in : scopes) {
String name = getMatchedPropertyName(in, paramName);
if (name != null) {
FileUpload[] paramValues = multipartRequest.getFiles(paramName);
if (ignoreInvalidUploadFiles) {
for (int j = 0; j < paramValues.length; j++) {
FileUpload paramValue = paramValues[j];
if ((!paramValue.isValid()) || (!paramValue.isUploaded())) {
paramValues[j] = null;
}
}
}
Object value = (paramValues.length == 1 ? paramValues[0] : paramValues);
setTargetProperty(target, name, value);
}
}
}
}
}
use of jodd.servlet.upload.MultipartRequestWrapper in project jodd by oblac.
the class ServletUtil method copyParamsToAttributes.
// ---------------------------------------------------------------- copy
/**
* Copies all request parameters to attributes.
*/
public static void copyParamsToAttributes(HttpServletRequest servletRequest, boolean trimParams, boolean treatEmptyParamsAsNull, boolean ignoreEmptyRequestParams) {
Enumeration paramNames = servletRequest.getParameterNames();
while (paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
if (servletRequest.getAttribute(paramName) != null) {
continue;
}
String[] paramValues = servletRequest.getParameterValues(paramName);
paramValues = prepareParameters(paramValues, trimParams, treatEmptyParamsAsNull, ignoreEmptyRequestParams);
if (paramValues == null) {
continue;
}
servletRequest.setAttribute(paramName, paramValues.length == 1 ? paramValues[0] : paramValues);
}
// multipart
if (!(servletRequest instanceof MultipartRequestWrapper)) {
return;
}
MultipartRequestWrapper multipartRequest = (MultipartRequestWrapper) servletRequest;
if (!multipartRequest.isMultipart()) {
return;
}
paramNames = multipartRequest.getFileParameterNames();
while (paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
if (servletRequest.getAttribute(paramName) != null) {
continue;
}
FileUpload[] paramValues = multipartRequest.getFiles(paramName);
servletRequest.setAttribute(paramName, paramValues.length == 1 ? paramValues[0] : paramValues);
}
}
Aggregations