You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Alternatively, if you only need to set the status code and / or HTTP headers with static values, you can use `@org.jboss.resteasy.reactive.ResponseStatus` and /or `ResponseHeader` respectively.
Copy file name to clipboardExpand all lines: _versions/main/guides/spring-web.adoc
+40Lines changed: 40 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -469,6 +469,46 @@ The following parameter types are supported, in arbitrary order:
469
469
470
470
Other parameter types mentioned in the Spring `https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/ExceptionHandler.html[ExceptionHandler javadoc]` are not supported.
471
471
472
+
==== Using `HttpServerRequest` and `HttpServerResponse` in Spring Web-style exception handlers
473
+
474
+
When using the Quarkus Spring Web compatibility layer on top of the reactive stack (`quarkus-rest-jackson`),
475
+
you cannot inject servlet-based request and response types such as `jakarta.servlet.http.HttpServletRequest` or `jakarta.servlet.http.HttpServletResponse`.
476
+
These types are only available when using the Classic RESTEasy stack (quarkus-resteasy / quarkus-resteasy-jackson), which relies on the Servlet API provided by `quarkus-undertow` dependency.
477
+
478
+
To provide a Spring-friendly experience while staying reactive, Quarkus allows you to inject the following types into your `@ExceptionHandler` methods:
479
+
480
+
- io.vertx.core.http.HttpServerRequest
481
+
482
+
- io.vertx.core.http.HttpServerResponse
483
+
484
+
These types give you direct access to the underlying Vert.x HTTP layer.
485
+
This allows you to manipulate the response (e.g. set headers, cookies, or status codes) or enrich the returned information using details from the request.
486
+
487
+
For example:
488
+
489
+
[source, java]
490
+
----
491
+
@ExceptionHandler(IllegalArgumentException.class)
492
+
public ResponseEntity<Object> handleException(Exception ex,
// Build a response body enriched with request details
499
+
String body = String.format("Request %s %s failed",
500
+
request.method().name(),
501
+
request.uri());
502
+
503
+
return new ResponseEntity<>(body, HttpStatus.BAD_REQUEST);
504
+
}
505
+
506
+
----
507
+
508
+
**Warning:** This is potentially dangerous.
509
+
Users should only do this if they understand the reactive model, and are aware that writing directly to the response can bypass normal handling of status codes, headers, and serialization.
510
+
511
+
472
512
== Important Technical Note
473
513
474
514
Please note that the Spring support in Quarkus does not start a Spring Application Context nor are any Spring infrastructure classes run.
0 commit comments