mirror of
https://github.com/jlengrand/quarkus.git
synced 2026-03-10 08:41:22 +00:00
Fixes #5018 and enables last MP REST TCK test
This commit is contained in:
@@ -11,6 +11,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.SessionScoped;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.client.ClientRequestFilter;
|
||||
import javax.ws.rs.client.ClientResponseFilter;
|
||||
@@ -47,6 +48,7 @@ import io.quarkus.arc.processor.BeanConfigurator;
|
||||
import io.quarkus.arc.processor.BeanRegistrar;
|
||||
import io.quarkus.arc.processor.BuiltinScope;
|
||||
import io.quarkus.arc.processor.ScopeInfo;
|
||||
import io.quarkus.deployment.Capabilities;
|
||||
import io.quarkus.deployment.annotations.BuildProducer;
|
||||
import io.quarkus.deployment.annotations.BuildStep;
|
||||
import io.quarkus.deployment.annotations.ExecutionTime;
|
||||
@@ -125,6 +127,7 @@ class RestClientProcessor {
|
||||
@Record(ExecutionTime.STATIC_INIT)
|
||||
void processInterfaces(CombinedIndexBuildItem combinedIndexBuildItem,
|
||||
SslNativeConfigBuildItem sslNativeConfig,
|
||||
Capabilities capabilities,
|
||||
BuildProducer<NativeImageProxyDefinitionBuildItem> proxyDefinition,
|
||||
BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
|
||||
BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchy,
|
||||
@@ -184,7 +187,7 @@ class RestClientProcessor {
|
||||
configurator.addType(restClientName);
|
||||
configurator.addQualifier(REST_CLIENT);
|
||||
final String configPrefix = computeConfigPrefix(restClientName.toString(), entry.getValue());
|
||||
final ScopeInfo scope = computeDefaultScope(config, entry, configPrefix);
|
||||
final ScopeInfo scope = computeDefaultScope(capabilities, config, entry, configPrefix);
|
||||
configurator.scope(scope);
|
||||
configurator.creator(m -> {
|
||||
// return new RestClientBase(proxyType, baseUri).create();
|
||||
@@ -258,33 +261,46 @@ class RestClientProcessor {
|
||||
return interfaceName;
|
||||
}
|
||||
|
||||
private ScopeInfo computeDefaultScope(Config config, Map.Entry<DotName, ClassInfo> entry, String configPrefix) {
|
||||
// Initialize a default @Dependent scope as per the spec
|
||||
ScopeInfo scopeInfo = BuiltinScope.DEPENDENT.getInfo();
|
||||
private ScopeInfo computeDefaultScope(Capabilities capabilities, Config config, Map.Entry<DotName, ClassInfo> entry,
|
||||
String configPrefix) {
|
||||
ScopeInfo scopeToUse = null;
|
||||
final Optional<String> scopeConfig = config
|
||||
.getOptionalValue(String.format(RestClientBase.REST_SCOPE_FORMAT, configPrefix), String.class);
|
||||
|
||||
if (scopeConfig.isPresent()) {
|
||||
final DotName scope = DotName.createSimple(scopeConfig.get());
|
||||
final BuiltinScope builtinScope = BuiltinScope.from(scope);
|
||||
if (builtinScope != null) { // override default @Dependent scope with user defined one.
|
||||
scopeInfo = builtinScope.getInfo();
|
||||
} else {
|
||||
scopeToUse = builtinScope.getInfo();
|
||||
} else if (capabilities.isCapabilityPresent(Capabilities.SERVLET)) {
|
||||
if (scope.toString().equals("javax.enterprise.context.SessionScoped")) {
|
||||
scopeToUse = new ScopeInfo(SessionScoped.class, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (scopeToUse == null) {
|
||||
log.warn(String.format(
|
||||
"Unsupported default scope %s provided for rest client %s. Defaulting to @Dependent.",
|
||||
scope, entry.getKey()));
|
||||
scopeToUse = BuiltinScope.DEPENDENT.getInfo();
|
||||
}
|
||||
} else {
|
||||
final Set<DotName> annotations = entry.getValue().annotations().keySet();
|
||||
for (final DotName annotationName : annotations) {
|
||||
final BuiltinScope builtinScope = BuiltinScope.from(annotationName);
|
||||
if (builtinScope != null) {
|
||||
scopeInfo = builtinScope.getInfo();
|
||||
scopeToUse = builtinScope.getInfo();
|
||||
break;
|
||||
}
|
||||
if (annotationName.toString().equals("javax.enterprise.context.SessionScoped")) {
|
||||
scopeToUse = new ScopeInfo(SessionScoped.class, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return scopeInfo;
|
||||
// Initialize a default @Dependent scope as per the spec
|
||||
return scopeToUse != null ? scopeToUse : BuiltinScope.DEPENDENT.getInfo();
|
||||
}
|
||||
|
||||
private String getAnnotationParameter(ClassInfo classInfo, String parameterName) {
|
||||
|
||||
@@ -5,6 +5,10 @@ import java.lang.annotation.Inherited;
|
||||
import java.util.Objects;
|
||||
import org.jboss.jandex.DotName;
|
||||
|
||||
/**
|
||||
* {@link ScopeInfo} is used to create a custom scope for use with {@link BeanConfigurator}.
|
||||
* If using built in scopes, use {@link BuiltinScope} instead to get a {@link ScopeInfo} instance.
|
||||
*/
|
||||
public class ScopeInfo {
|
||||
|
||||
private final DotName dotName;
|
||||
@@ -13,10 +17,10 @@ public class ScopeInfo {
|
||||
|
||||
private boolean declaresInherited;
|
||||
|
||||
ScopeInfo(Class<? extends Annotation> clazz, boolean isNormal) {
|
||||
public ScopeInfo(Class<? extends Annotation> clazz, boolean isNormal) {
|
||||
this.dotName = DotName.createSimple(clazz.getName());
|
||||
this.isNormal = isNormal;
|
||||
declaresInherited = clazz.getAnnotation(Inherited.class) == null ? false : true;
|
||||
declaresInherited = clazz.getAnnotation(Inherited.class) != null;
|
||||
}
|
||||
|
||||
public DotName getDotName() {
|
||||
|
||||
@@ -38,9 +38,8 @@
|
||||
<exclude>org.eclipse.microprofile.rest.client.tck.WiremockArquillianTest</exclude>
|
||||
<exclude>org.eclipse.microprofile.rest.client.tck.ssl.AbstractSslTest</exclude>
|
||||
|
||||
<!-- mp/scope not supported for ConversationScope and SessionScope-->
|
||||
<!-- ConversationScope not supported in Quarkus -->
|
||||
<exclude>org.eclipse.microprofile.rest.client.tck.cditests.HasConversationScopeTest</exclude>
|
||||
<exclude>org.eclipse.microprofile.rest.client.tck.cditests.HasSessionScopeTest</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
@@ -88,6 +87,10 @@
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-json-binding-provider</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-undertow</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.microprofile.rest.client</groupId>
|
||||
<artifactId>microprofile-rest-client-tck</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user