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

Port Spring Web to RESTEasy Reactive #20195

Merged
merged 4 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions docs/src/main/asciidoc/spring-web.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -429,12 +429,6 @@ The following method return types are supported:
* POJO classes which will be serialized via JSON
* `org.springframework.http.ResponseEntity`

=== Controller method parameter types

In addition to the method parameters that can be annotated with the appropriate Spring Web annotations from the previous table,
`javax.servlet.http.HttpServletRequest` and `javax.servlet.http.HttpServletResponse` are also supported.
For this to function however, users need to add the `quarkus-undertow` dependency.

=== Exception handler method return types

The following method return types are supported:
Expand All @@ -449,7 +443,7 @@ Other return types mentioned in the Spring `https://docs.spring.io/spring-framew
The following parameter types are supported, in arbitrary order:

* An exception argument: declared as a general `Exception` or as a more specific exception. This also serves as a mapping hint if the annotation itself does not narrow the exception types through its `value()`.
* Request and/or response objects (typically from the Servlet API). You may choose any specific request/response type, e.g. `ServletRequest` / `HttpServletRequest`. To use Servlet API, the `quarkus-undertow` dependency needs to be added.
* The following JAX-RS Types: `javax.ws.rs.core.Request` and `javax.ws.rs.core.UriInfo`

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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
Expand Down Expand Up @@ -51,6 +53,7 @@
import io.quarkus.resteasy.reactive.common.runtime.JaxRsSecurityConfig;
import io.quarkus.resteasy.reactive.common.runtime.ResteasyReactiveConfig;
import io.quarkus.resteasy.reactive.spi.AbstractInterceptorBuildItem;
import io.quarkus.resteasy.reactive.spi.AdditionalResourceClassBuildItem;
import io.quarkus.resteasy.reactive.spi.ContainerRequestFilterBuildItem;
import io.quarkus.resteasy.reactive.spi.ContainerResponseFilterBuildItem;
import io.quarkus.resteasy.reactive.spi.GeneratedJaxRsResourceBuildItem;
Expand Down Expand Up @@ -238,10 +241,18 @@ JaxRsResourceIndexBuildItem resourceIndex(CombinedIndexBuildItem combinedIndex,
@BuildStep
void scanResources(
JaxRsResourceIndexBuildItem jaxRsResourceIndexBuildItem,
List<AdditionalResourceClassBuildItem> additionalResourceClassBuildItems,
BuildProducer<AnnotationsTransformerBuildItem> annotationsTransformerBuildItemBuildProducer,
BuildProducer<ResourceScanningResultBuildItem> resourceScanningResultBuildItemBuildProducer) {

ResourceScanningResult res = ResteasyReactiveScanner.scanResources(jaxRsResourceIndexBuildItem.getIndexView());
Map<DotName, ClassInfo> additionalResources = new HashMap<>();
Map<DotName, String> additionalResourcePaths = new HashMap<>();
for (AdditionalResourceClassBuildItem bi : additionalResourceClassBuildItems) {
additionalResources.put(bi.getClassInfo().name(), bi.getClassInfo());
additionalResourcePaths.put(bi.getClassInfo().name(), bi.getPath());
}
ResourceScanningResult res = ResteasyReactiveScanner.scanResources(jaxRsResourceIndexBuildItem.getIndexView(),
additionalResources, additionalResourcePaths);
if (res == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.quarkus.resteasy.reactive.spi;

import org.jboss.jandex.ClassInfo;

import io.quarkus.builder.item.MultiBuildItem;

/**
* Can be used by extensions that want to make classes not annotated with JAX-RS {@code @Path}
* part of the ResourceClass scanning process.
* This will likely be used in conjunction with {@code io.quarkus.resteasy.reactive.server.spi.AnnotationsTransformerBuildItem}
*/
public final class AdditionalResourceClassBuildItem extends MultiBuildItem {

private final ClassInfo classInfo;
private final String path;

public AdditionalResourceClassBuildItem(ClassInfo classInfo, String path) {
this.classInfo = classInfo;
this.path = path;
}

public ClassInfo getClassInfo() {
return classInfo;
}

public String getPath() {
return path;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ public void setupEndpoints(Capabilities capabilities, BeanArchiveIndexBuildItem
.setGeneratedClassBuildItemBuildProducer(generatedClassBuildItemBuildProducer)
.setBytecodeTransformerBuildProducer(bytecodeTransformerBuildItemBuildProducer)
.setReflectiveClassProducer(reflectiveClassBuildItemBuildProducer)
.setExistingConverters(existingConverters).setScannedResourcePaths(scannedResourcePaths)
.setExistingConverters(existingConverters)
.setScannedResourcePaths(scannedResourcePaths)
.setConfig(createRestReactiveConfig(config))
.setAdditionalReaders(additionalReaders)
.setHttpAnnotationToMethod(result.getHttpAnnotationToMethod())
Expand Down
5 changes: 0 additions & 5 deletions extensions/smallrye-openapi/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@
<artifactId>quarkus-resteasy-deployment</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-spring-web-deployment</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-routes-deployment</artifactId>
Expand Down

This file was deleted.

This file was deleted.

6 changes: 1 addition & 5 deletions extensions/spring-web/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-common-spi</artifactId>
<artifactId>quarkus-resteasy-reactive-jackson-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
Expand Down Expand Up @@ -36,8 +35,6 @@ abstract class AbstractExceptionMapperGenerator {
String generate() {
String generatedClassName = "io.quarkus.spring.web.mappers." + exceptionDotName.withoutPackagePrefix() + "_Mapper_"
+ HashUtil.sha1(exceptionDotName.toString());
String generatedSubtypeClassName = "io.quarkus.spring.web.mappers.Subtype" + exceptionDotName.withoutPackagePrefix()
+ "Mapper_" + HashUtil.sha1(exceptionDotName.toString());
String exceptionClassName = exceptionDotName.toString();

try (ClassCreator cc = ClassCreator.builder()
Expand All @@ -64,15 +61,7 @@ String generate() {
}
}

// additionally generate a dummy subtype to get past the RESTEasy's ExceptionMapper check for synthetic classes
try (ClassCreator cc = ClassCreator.builder()
.classOutput(classOutput).className(generatedSubtypeClassName)
.superClass(generatedClassName)
.build()) {
cc.addAnnotation(Provider.class);
}

return generatedSubtypeClassName;
return generatedClassName;
}

protected void preGenerateMethodBody(ClassCreator cc) {
Expand All @@ -93,6 +82,7 @@ protected int getHttpStatusFromAnnotation(AnnotationInstance responseStatusInsta
return 500; // the default value of @ResponseStatus
}

@SuppressWarnings({ "rawtypes", "unchecked" })
private int enumValueToHttpStatus(String enumValue) {
try {
Class<?> httpStatusClass = Class.forName("org.springframework.http.HttpStatus");
Expand Down
Loading