Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StandardServletMultipartResolver.resolveMultipart invoked multiple times for same request #13841

Open
codeconsole opened this issue Nov 15, 2024 · 0 comments
Labels

Comments

@codeconsole
Copy link
Contributor

codeconsole commented Nov 15, 2024

The following should be analyzed because off hand it seems inefficient. Multipart requests are resolved multiple times for handling url mappings which appears to be real inefficient.

def infos = urlMappingsHolder.matchAll(uri, request.getMethod(), version != null ? version : UrlMapping.ANY_VERSION)

public UrlMappingInfo[] matchAll(String uri) {
return collectControllerMappings( getUrlMappingsHolderDelegate().matchAll(uri) );
}
@Override
public UrlMappingInfo[] matchAll(String uri, String httpMethod) {
return collectControllerMappings( getUrlMappingsHolderDelegate().matchAll(uri, httpMethod) );
}
@Override
public UrlMappingInfo[] matchAll(String uri, String httpMethod, String version) {
return collectControllerMappings( getUrlMappingsHolderDelegate().matchAll(uri, httpMethod, version) );
}
@Override
public UrlMappingInfo[] matchAll(String uri, HttpMethod httpMethod) {
return collectControllerMappings( getUrlMappingsHolderDelegate().matchAll(uri, httpMethod) );
}
@Override
public UrlMappingInfo[] matchAll(String uri, HttpMethod httpMethod, String version) {
return collectControllerMappings( getUrlMappingsHolderDelegate().matchAll(uri, httpMethod, version) );
}

protected UrlMappingInfo[] collectControllerMappings(UrlMappingInfo[] infos) {
def webRequest = GrailsWebRequest.lookup()
infos.collect({ UrlMappingInfo info ->
if (info.redirectInfo) {
return info
}
if (webRequest != null) {
webRequest.resetParams()
info.configure(webRequest)
}
ControllerKey controllerKey = new ControllerKey(info.namespace, info.controllerName, info.actionName, info.pluginName)
GrailsControllerClass controllerClass = info ? mappingsToGrailsControllerMap.get(controllerKey) : null
if (controllerClass) {
return new GrailsControllerUrlMappingInfo(controllerClass, info)
} else {
return info
}
}) as UrlMappingInfo[]
}

-> DefaultUrlMappingInfo.tryMultipartParams is invoked for every UrlMappingInfo because of the call to getActionName()

public void configure(GrailsWebRequest webRequest) {
populateParamsForMapping(webRequest);
}
/**
* Populates request parameters for the given UrlMappingInfo instance using the GrailsWebRequest
*
* @param webRequest The Map instance
* @see org.grails.web.servlet.mvc.GrailsWebRequest
*/
protected void populateParamsForMapping(GrailsWebRequest webRequest) {
Map dispatchParams = webRequest.getParams();
String encoding = webRequest.getRequest().getCharacterEncoding();
if (encoding == null) encoding = "UTF-8";
for (Map.Entry<String, Object> entry : params.entrySet()) {
String name = entry.getKey();
Object param = entry.getValue();
if (param instanceof Closure) {
param = evaluateNameForValue(param);
}
if (param instanceof CharSequence) {
param = param.toString();
}
dispatchParams.put(name, param);
}
final String viewName = getViewName();
if (viewName == null && getURI() == null) {
webRequest.setControllerNamespace(getNamespace());
webRequest.setControllerName(getControllerName());
webRequest.setActionName(getActionName());
}

public String getActionName() {
GrailsWebRequest webRequest = (GrailsWebRequest) RequestContextHolder.getRequestAttributes();
String name = webRequest == null ? null : checkDispatchAction(webRequest.getCurrentRequest());
if (name == null) {
name = evaluateNameForValue(actionName, webRequest);
}
return urlConverter.toUrlElement(name);
}

due to checkDispatchAction(webRequest.getCurrentRequest());

private String checkDispatchAction(HttpServletRequest request) {
if (request.getAttribute(WebUtils.EXCEPTION_ATTRIBUTE) != null || WebUtils.isForwardOrInclude(request)) {
return null;
}
String dispatchActionName = null;
Enumeration<String> paramNames = tryMultipartParams(request, request.getParameterNames());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Todo
Development

No branches or pull requests

1 participant