Skip to content

Commit

Permalink
fix for GRAILS-7664 "g:actionSubmit causes exception handling to break"
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher committed Aug 23, 2011
1 parent 74befc1 commit 8eb58bf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
Expand Up @@ -24,6 +24,7 @@
import javax.servlet.http.HttpServletRequest;

import org.codehaus.groovy.grails.commons.GrailsApplication;
import org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver;
import org.codehaus.groovy.grails.web.mapping.exceptions.UrlMappingException;
import org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequest;
import org.codehaus.groovy.grails.web.util.WebUtils;
Expand Down Expand Up @@ -135,6 +136,7 @@ public String getId() {

@SuppressWarnings("unchecked")
private String checkDispatchAction(HttpServletRequest request) {
if(request.getAttribute(GrailsExceptionResolver.EXCEPTION_ATTRIBUTE)!= null) return null;
String dispatchActionName = null;
Enumeration<String> paramNames = tryMultipartParams(request, request.getParameterNames());

Expand Down
Expand Up @@ -3,6 +3,8 @@ package org.codehaus.groovy.grails.web.mapping
import org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerTests
import org.springframework.core.io.ByteArrayResource
import org.springframework.mock.web.MockServletContext
import org.codehaus.groovy.grails.web.util.WebUtils
import org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver

/**
* @author Graeme Rocher
Expand Down Expand Up @@ -49,6 +51,38 @@ class UrlMappings {
}
}
'''
void testDontUseDispatchActionIfExceptionPresent() {
Closure closure = new GroovyClassLoader().parseClass(test1).mappings
def mappings = evaluator.evaluateMappings(closure)

webRequest.currentRequest.addParameter("${WebUtils.DISPATCH_ACTION_PARAMETER}foo", "true")
webRequest.currentRequest.setAttribute(GrailsExceptionResolver.EXCEPTION_ATTRIBUTE, new RuntimeException("bad"))
def holder = new DefaultUrlMappingsHolder(mappings)
def info = holder.match('/foo/list')

assert info != null

info.configure webRequest

assert info.actionName == 'list'

}
void testUseDispatchAction() {
Closure closure = new GroovyClassLoader().parseClass(test1).mappings
def mappings = evaluator.evaluateMappings(closure)

webRequest.currentRequest.addParameter("${WebUtils.DISPATCH_ACTION_PARAMETER}foo", "true")
def holder = new DefaultUrlMappingsHolder(mappings)
def info = holder.match('/foo/list')

assert info != null

info.configure webRequest

assert info.actionName == 'foo'

assertEquals "de", webRequest.params.lang
}

void testNotEqual() {
Closure closure = new GroovyClassLoader().parseClass(test3).mappings
Expand Down
Expand Up @@ -271,6 +271,9 @@ public static String forwardRequestForUrlMappingInfo(HttpServletRequest request,
@SuppressWarnings({ "unchecked", "rawtypes" })
public static String forwardRequestForUrlMappingInfo(HttpServletRequest request,
HttpServletResponse response, UrlMappingInfo info, Map model, boolean includeParams) throws ServletException, IOException {
exposeForwardRequestAttributes(request);
exposeRequestAttributes(request, model);

String forwardUrl = buildDispatchUrlForMapping(info, includeParams);

//populateParamsForMapping(info);
Expand All @@ -284,8 +287,6 @@ public static String forwardRequestForUrlMappingInfo(HttpServletRequest request,
webRequest.removeAttribute(GrailsApplicationAttributes.MODEL_AND_VIEW, 0);
webRequest.setActionName(info.getActionName());

exposeForwardRequestAttributes(request);
exposeRequestAttributes(request, model);
dispatcher.forward(request, response);
return forwardUrl;
}
Expand Down

0 comments on commit 8eb58bf

Please sign in to comment.