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

RESTEasy Reactive request filter ctx.abortWith() exception #17998

Closed
ThoSap opened this issue Jun 18, 2021 · 3 comments · Fixed by #17999
Closed

RESTEasy Reactive request filter ctx.abortWith() exception #17998

ThoSap opened this issue Jun 18, 2021 · 3 comments · Fixed by #17999
Labels
area/kotlin area/rest env/windows Impacts Windows machines kind/bug Something isn't working
Milestone

Comments

@ThoSap
Copy link

ThoSap commented Jun 18, 2021

Describe the bug

With the new RESTEasy Reactive @ServerRequestFilter annotation ctx.abortWith() as shown in the example of the guide https://quarkus.io/guides/resteasy-reactive#request-or-response-filters is not working, I get an internal server error.

Expected behavior

The RESTEasy Reactive @ServerRequestFilter should abort the request with HTTP 405 when ctx.abortWith(Response.status(Response.Status.METHOD_NOT_ALLOWED).build()); is called

Actual behavior

2021-06-18 10:42:05,162 ERROR [org.jbo.res.rea.ser.cor.ExceptionMapping] (vert.x-eventloop-thread-10) Request failed : java.lang.IllegalStateException: Calling 'abortWith' is not permitted when using @ServerRequestFilter or @ServerResponseFilter. If you need to abort processing, consider returning 'Response' or 'Uni<Response>'
        at io.quarkus.resteasy.reactive.server.runtime.filters.PreventAbortResteasyReactiveContainerRequestContext.abortWith(PreventAbortResteasyReactiveContainerRequestContext.java:154)
        at Filter.getFilter(Filter.java:12)
        at Filter$GeneratedServerRequestFilter$getFilter.filter(Filter$GeneratedServerRequestFilter$getFilter.zig:59)
        at Filter$GeneratedServerRequestFilter$getFilter_Subclass.filter$$superaccessor1(Filter$GeneratedServerRequestFilter$getFilter_Subclass.zig:201)
        at Filter$GeneratedServerRequestFilter$getFilter_Subclass$$function$$1.apply(Filter$GeneratedServerRequestFilter$getFilter_Subclass$$function$$1.zig:33)
        at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:62)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(InvocationInterceptor_Bean.zig:521)
        at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
        at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
        at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
        at Filter$GeneratedServerRequestFilter$getFilter_Subclass.filter(Filter$GeneratedServerRequestFilter$getFilter_Subclass.zig:158)
        at org.jboss.resteasy.reactive.server.handlers.ResourceRequestFilterHandler.handle(ResourceRequestFilterHandler.java:40)
        at org.jboss.resteasy.reactive.server.handlers.ResourceRequestFilterHandler.handle(ResourceRequestFilterHandler.java:8)
        at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:122)
        at org.jboss.resteasy.reactive.server.handlers.RestInitialHandler.beginProcessing(RestInitialHandler.java:47)
        at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:17)
        at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:7)
        at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1038)
        at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:137)
        at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
        at io.quarkus.vertx.http.runtime.StaticResourcesRecorder.lambda$start$1(StaticResourcesRecorder.java:65)
        at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1038)
        at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:101)
        at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
        at io.vertx.ext.web.handler.impl.StaticHandlerImpl.lambda$sendStatic$1(StaticHandlerImpl.java:206)
        at io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:327)
        at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:366)
        at io.vertx.core.impl.EventLoopContext.lambda$executeAsync$0(EventLoopContext.java:38)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:829)

To Reproduce

Steps to reproduce the behavior:

  1. Download the RESTEasy Reactive example from https://code.quarkus.io/?e=resteasy-reactive
  2. Add Filters.java (with all imports) filter from the guide https://quarkus.io/guides/resteasy-reactive#request-or-response-filters
package org.acme;

import org.jboss.resteasy.reactive.server.ServerRequestFilter;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.core.Response;
import javax.ws.rs.HttpMethod;

public class Filters {

    @ServerRequestFilter
    public void getFilter(ContainerRequestContext ctx) {
        // only allow GET methods for now
        if(ctx.getMethod().equals(HttpMethod.GET)) {
            ctx.abortWith(Response.status(Response.Status.METHOD_NOT_ALLOWED).build());
        }
    }

}
  1. curl -v -X GET 'http://localhost:8080/hello-resteasy-reactive'

Configuration

# Quarkus - Core #
quarkus.log.metrics.enabled=true
quarkus.package.manifest.add-implementation-entries=true
quarkus.package.type=jar

# Logging #
quarkus.log.level=INFO
quarkus.log.min-level=DEBUG

# Eclipse Vert.x - Core #
quarkus.vertx.max-event-loop-execute-time=PT0.25S
quarkus.vertx.max-worker-execute-time=PT60S

# Eclipse Vert.x - HTTP #
quarkus.http.root-path=/
quarkus.http.non-application-root-path=api
quarkus.http.host-enabled=true
quarkus.http.http2=true
quarkus.http.port=8080
quarkus.http.proxy.enable-forwarded-host=true
%dev.quarkus.http.proxy.enable-forwarded-host=false
%test.quarkus.http.proxy.enable-forwarded-host=false
quarkus.http.proxy.proxy-address-forwarding=true
%dev.quarkus.http.proxy.proxy-address-forwarding=false
%test.quarkus.http.proxy.proxy-address-forwarding=false
quarkus.http.limits.max-body-size=25600K
quarkus.http.limits.max-chunk-size=16384
quarkus.http.limits.max-header-size=128K
quarkus.http.limits.max-initial-line-length=8192

Environment (please complete the following information):

Output of uname -a or ver

Microsoft Windows [Version 10.0.18363.1621]

Output of java -version

openjdk version "11.0.11" 2021-04-20 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.11+9-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.11+9-LTS, mixed mode)

GraalVM version (if different from Java)

Quarkus version or git rev

1.13.7.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Gradle 6.8.3

Build time: 2021-02-22 16:13:28 UTC
Revision: 9e26b4a9ebb910eaa1b8da8ff8575e514bc61c78

Kotlin: 1.4.20
Groovy: 2.5.12
Ant: Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM: 11.0.11 (ojdkbuild 11.0.11+9-LTS)
OS: Windows 10 10.0 amd64

Additional context

(Add any other context about the problem here.)

@ThoSap ThoSap added the kind/bug Something isn't working label Jun 18, 2021
@quarkus-bot quarkus-bot bot added area/kotlin area/rest env/windows Impacts Windows machines labels Jun 18, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Jun 18, 2021

@geoand
Copy link
Contributor

geoand commented Jun 18, 2021

Thanks, I'll fix the documentation!

@ThoSap
Copy link
Author

ThoSap commented Jun 18, 2021

Wow that was fast, thanks 😋😍
See my comments on geoand@9db7d30

geoand added a commit to geoand/quarkus that referenced this issue Jun 18, 2021
geoand added a commit that referenced this issue Jun 21, 2021
Fix RESTEasy Reactive documentation on how to abort with @ServerRequestFilter
@quarkus-bot quarkus-bot bot added this to the 2.1 - main milestone Jun 21, 2021
@gsmet gsmet modified the milestones: 2.1 - main, 2.0.0.Final Jun 21, 2021
gsmet pushed a commit to gsmet/quarkus that referenced this issue Jun 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kotlin area/rest env/windows Impacts Windows machines kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants