Skip to content

Commit

Permalink
Merge pull request #13763 from codeconsole/7.0.x-servlet-api-fix
Browse files Browse the repository at this point in the history
HttpServletResponse should not be required when using @AstTransformer
  • Loading branch information
codeconsole authored Oct 16, 2024
2 parents 621e905 + fc248d4 commit 0668f66
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions grails-plugin-controllers/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ dependencies {
project(':grails-plugin-domain-class')

api("org.springframework.boot:spring-boot-autoconfigure:$springBootVersion")
compileOnlyApi "jakarta.servlet:jakarta.servlet-api:$servletApiVersion"

runtimeOnly project(':grails-plugin-i18n')

testRuntimeOnly "jline:jline:$jlineVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@
import org.grails.io.support.GrailsResourceUtils;
import org.grails.plugins.web.controllers.DefaultControllerExceptionHandlerMetaData;
import org.grails.web.databinding.DefaultASTDatabindingHelper;
import org.grails.web.util.WebUtils;
import org.springframework.validation.Errors;
import org.springframework.validation.MapBindingResult;

import jakarta.servlet.http.HttpServletResponse;
import java.io.File;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
Expand Down Expand Up @@ -543,7 +543,7 @@ protected BlockStatement getCodeToHandleAllowedMethods(ClassNode controllerClass
isAllowedArgumentList.addExpression(new PropertyExpression(new VariableExpression("this"), DefaultGrailsControllerClass.ALLOWED_HTTP_METHODS_PROPERTY));
final Expression isAllowedMethodCall = new StaticMethodCallExpression(ClassHelper.make(AllowedMethodsHelper.class), "isAllowed", isAllowedArgumentList);
final BooleanExpression isValidRequestMethod = new BooleanExpression(isAllowedMethodCall);
final MethodCallExpression sendErrorMethodCall = new MethodCallExpression(responsePropertyExpression, "sendError", new ConstantExpression(HttpServletResponse.SC_METHOD_NOT_ALLOWED));
final MethodCallExpression sendErrorMethodCall = new MethodCallExpression(responsePropertyExpression, "sendError", new ConstantExpression(WebUtils.SC_METHOD_NOT_ALLOWED));
final ReturnStatement returnStatement = new ReturnStatement(new ConstantExpression(null));
final BlockStatement blockToSendError = new BlockStatement();
blockToSendError.addStatement(new ExpressionStatement(sendErrorMethodCall));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.grails.web.servlet.mvc.GrailsWebRequest;
import org.grails.web.servlet.view.CompositeViewResolver;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -67,6 +68,8 @@ public class WebUtils extends org.springframework.web.util.WebUtils {
public static final String EXCEPTION_ATTRIBUTE = "exception";
public static final String ASYNC_REQUEST_URI_ATTRIBUTE = "jakarta.servlet.async.request_uri";

public static final int SC_METHOD_NOT_ALLOWED = HttpServletResponse.SC_METHOD_NOT_ALLOWED;

public static ViewResolver lookupViewResolver(ServletContext servletContext) {
WebApplicationContext wac = WebApplicationContextUtils
.getRequiredWebApplicationContext(servletContext);
Expand Down

0 comments on commit 0668f66

Please sign in to comment.