Permalink
Browse files

Merge branch '2.4.x'

Conflicts:
	grails-plugin-controllers/src/main/groovy/org/codehaus/groovy/grails/plugins/web/api/ControllersApi.java
	grails-web-jsp/build.gradle
  • Loading branch information...
2 parents 539b5cb + 5dd77fd commit f1d3cfb1e56551a30959941d361053a2db265d6c @jeffbrown jeffbrown committed Jul 16, 2014
@@ -130,7 +130,14 @@ trait Controller {
final HttpMethod requestMethod = HttpMethod.valueOf(request.getMethod())
if(entityIdentifierValue != null) {
- commandObjectInstance = InvokerHelper.invokeStaticMethod(type, "get", entityIdentifierValue)
+ try {
+ commandObjectInstance = InvokerHelper.invokeStaticMethod(type, "get", entityIdentifierValue);
+ } catch (Exception e) {
+ final Errors errors = getErrors(controllerInstance);
+ if(errors != null) {
+ errors.reject(controllerInstance.getClass().getName() + ".commandObject." + commandObjectParameterName + ".error", e.getMessage());
+ }
+ }
} else if(requestMethod == HttpMethod.POST || !isDomainClass){
commandObjectInstance = type.newInstance()
}
@@ -359,13 +359,22 @@ private MethodNode convertToMethodAction(ClassNode classNode, MethodNode methodN
MethodNode method = null;
if (methodNode.getParameters().length > 0) {
+ final BlockStatement methodCode = new BlockStatement();
+
+ final BlockStatement codeToHandleAllowedMethods = getCodeToHandleAllowedMethods(classNode, methodNode.getName());
+ final Statement codeToCallOriginalMethod = addOriginalMethodCall(methodNode, initializeActionParameters(
+ classNode, methodNode, methodNode.getName(), parameters, source, context));
+
+ methodCode.addStatement(codeToHandleAllowedMethods);
+ methodCode.addStatement(codeToCallOriginalMethod);
+
method = new MethodNode(
methodNode.getName(),
Modifier.PUBLIC, returnType,
ZERO_PARAMETERS,
EMPTY_CLASS_ARRAY,
- addOriginalMethodCall(methodNode, initializeActionParameters(
- classNode, methodNode, methodNode.getName(), parameters, source, context)));
+ methodCode);
+
GrailsASTUtils.copyAnnotations(methodNode, method);
annotateActionMethod(classNode, parameters, method);
} else {
@@ -469,7 +478,7 @@ protected void annotateActionMethod(ClassNode controllerClassNode, final Paramet
}
}
- protected BlockStatement getCodeToHandleAllowedMethods(ClassNode controllerClass, MethodNode methodNode) {
+ protected BlockStatement getCodeToHandleAllowedMethods(ClassNode controllerClass, String methodName) {
GrailsASTUtils.addEnhancedAnnotation(controllerClass, DefaultGrailsControllerClass.ALLOWED_HTTP_METHODS_PROPERTY);
final BlockStatement checkAllowedMethodsBlock = new BlockStatement();
@@ -483,7 +492,6 @@ protected BlockStatement getCodeToHandleAllowedMethods(ClassNode controllerClass
final List<String> allowedMethodNames = new ArrayList<String>();
final MapExpression allowedMethodsMapExpression = (MapExpression) initialAllowedMethodsExpression;
final List<MapEntryExpression> allowedMethodsMapEntryExpressions = allowedMethodsMapExpression.getMapEntryExpressions();
- final String methodName = methodNode.getName();
for(MapEntryExpression allowedMethodsMapEntryExpression : allowedMethodsMapEntryExpressions) {
final Expression allowedMethodsMapEntryKeyExpression = allowedMethodsMapEntryExpression.getKeyExpression();
if(allowedMethodsMapEntryKeyExpression instanceof ConstantExpression) {
@@ -536,7 +544,7 @@ protected BlockStatement getCodeToHandleAllowedMethods(ClassNode controllerClass
final ArgumentListExpression argumentListExpression = new ArgumentListExpression();
argumentListExpression.addExpression(new ConstantExpression(ALLOWED_METHODS_HANDLED_ATTRIBUTE_NAME));
- argumentListExpression.addExpression(new ConstantExpression(methodNode.getName()));
+ argumentListExpression.addExpression(new ConstantExpression(methodName));
final Expression setAttributeMethodCall = new MethodCallExpression(requestPropertyExpression, "setAttribute", argumentListExpression);
@@ -599,7 +607,7 @@ protected void wrapMethodBodyWithExceptionHandling(final ClassNode controllerCla
final Statement methodBody = methodNode.getCode();
BlockStatement tryBlock = new BlockStatement();
- BlockStatement codeToHandleAllowedMethods = getCodeToHandleAllowedMethods(controllerClassNode, methodNode);
+ BlockStatement codeToHandleAllowedMethods = getCodeToHandleAllowedMethods(controllerClassNode, methodNode.getName());
tryBlock.addStatement(codeToHandleAllowedMethods);
tryBlock.addStatement(methodBody);
@@ -808,7 +816,7 @@ protected void initializeCommandObjectParameter(final BlockStatement wrapper,
final TryCatchStatement tryCatchStatement = new TryCatchStatement(tryBlock, new EmptyStatement());
tryCatchStatement.addCatch(new CatchStatement(new Parameter(new ClassNode(DataBindingSourceCreationException.class), "$dataBindingSourceInitializationException"), catchBlock));
-
+
wrapper.addStatement(tryCatchStatement);
}

0 comments on commit f1d3cfb

Please sign in to comment.