diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/types/Types.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/types/Types.java index 8167c40588a4c..ce6837b7115e4 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/types/Types.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/types/Types.java @@ -1,5 +1,7 @@ package org.jboss.resteasy.reactive.common.util.types; +import io.smallrye.mutiny.Multi; +import io.smallrye.mutiny.Uni; import java.lang.reflect.GenericArrayType; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; @@ -7,6 +9,8 @@ import java.lang.reflect.WildcardType; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.CompletionStage; +import org.jboss.resteasy.reactive.RestResponse; /** * Type conversions and generic type manipulations @@ -168,6 +172,35 @@ private static Type[] extractTypes(Map, Type> typeVarMap, Type g } } + public static Type getEffectiveReturnType(Type returnType) { + if (returnType instanceof Class) + return returnType; + if (returnType instanceof ParameterizedType) { + ParameterizedType type = (ParameterizedType) returnType; + Type firstTypeArgument = type.getActualTypeArguments()[0]; + if (type.getRawType() == CompletionStage.class) { + return getEffectiveReturnType(firstTypeArgument); + } + if (type.getRawType() == Uni.class) { + return getEffectiveReturnType(firstTypeArgument); + } + if (type.getRawType() == Multi.class) { + return getEffectiveReturnType(firstTypeArgument); + } + if (type.getRawType() == RestResponse.class) { + return getEffectiveReturnType(firstTypeArgument); + } + return returnType; + } + if (returnType instanceof WildcardType) { + Type[] bounds = ((WildcardType) returnType).getLowerBounds(); + if (bounds.length > 0) + return getRawType(bounds[0]); + return getRawType(((WildcardType) returnType).getUpperBounds()[0]); + } + throw new UnsupportedOperationException("Endpoint return type not supported yet: " + returnType); + } + public static Class getRawType(Type type) { if (type instanceof Class) return (Class) type; diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeResourceDeployment.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeResourceDeployment.java index d8b8aa906779a..e155cc0c16a5a 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeResourceDeployment.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeResourceDeployment.java @@ -1,14 +1,12 @@ package org.jboss.resteasy.reactive.server.core.startup; import static org.jboss.resteasy.reactive.common.util.DeploymentUtils.loadClass; +import static org.jboss.resteasy.reactive.common.util.types.Types.getEffectiveReturnType; +import static org.jboss.resteasy.reactive.common.util.types.Types.getRawType; -import io.smallrye.mutiny.Multi; -import io.smallrye.mutiny.Uni; import java.lang.annotation.Annotation; import java.lang.reflect.Method; -import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -import java.lang.reflect.WildcardType; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; @@ -19,7 +17,6 @@ import java.util.Map; import java.util.Optional; import java.util.Set; -import java.util.concurrent.CompletionStage; import java.util.concurrent.Executor; import java.util.function.Supplier; import javax.ws.rs.RuntimeType; @@ -28,7 +25,6 @@ import javax.ws.rs.core.Response; import javax.ws.rs.ext.MessageBodyWriter; import org.jboss.logging.Logger; -import org.jboss.resteasy.reactive.RestResponse; import org.jboss.resteasy.reactive.common.ResteasyReactiveConfig; import org.jboss.resteasy.reactive.common.model.MethodParameter; import org.jboss.resteasy.reactive.common.model.ParameterType; @@ -617,43 +613,4 @@ public Map buildParamIndexMap(URITemplate classPathTemplate, UR return pathParameterIndexes; } - private Class getRawType(Type type) { - if (type instanceof Class) - return (Class) type; - if (type instanceof ParameterizedType) { - ParameterizedType ptype = (ParameterizedType) type; - return (Class) ptype.getRawType(); - } - throw new UnsupportedOperationException("Endpoint return type not supported yet: " + type); - } - - private Type getEffectiveReturnType(Type returnType) { - if (returnType instanceof Class) - return returnType; - if (returnType instanceof ParameterizedType) { - ParameterizedType type = (ParameterizedType) returnType; - Type firstTypeArgument = type.getActualTypeArguments()[0]; - if (type.getRawType() == CompletionStage.class) { - return getEffectiveReturnType(firstTypeArgument); - } - if (type.getRawType() == Uni.class) { - return getEffectiveReturnType(firstTypeArgument); - } - if (type.getRawType() == Multi.class) { - return getEffectiveReturnType(firstTypeArgument); - } - if (type.getRawType() == RestResponse.class) { - return getEffectiveReturnType(firstTypeArgument); - } - return returnType; - } - if (returnType instanceof WildcardType) { - Type[] bounds = ((WildcardType) returnType).getLowerBounds(); - if (bounds.length > 0) - return getRawType(bounds[0]); - return getRawType(((WildcardType) returnType).getUpperBounds()[0]); - } - throw new UnsupportedOperationException("Endpoint return type not supported yet: " + returnType); - } - }