Skip to content

Commit

Permalink
Merge pull request #22681 from jmartisk/main-issue-22662
Browse files Browse the repository at this point in the history
Make sure REST methods can be called without an active CDI context
  • Loading branch information
jmartisk authored Jan 6, 2022
2 parents 63d29a6 + 6c61302 commit 300d2a3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import io.micrometer.core.instrument.Tags;

class MetricDescriptor {
public class MetricDescriptor {
final String name;
final Tags tags;
ExtendedMetricID metricId = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Set;

import javax.annotation.Priority;
import javax.enterprise.context.ContextNotActiveException;
import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
Expand All @@ -12,6 +13,7 @@
import io.quarkus.arc.ArcInvocationContext;
import io.quarkus.vertx.http.runtime.CurrentVertxRequest;
import io.vertx.core.http.impl.HttpServerRequestInternal;
import io.vertx.ext.web.RoutingContext;

@SuppressWarnings("unused")
@QuarkusRestPathTemplate
Expand All @@ -24,7 +26,13 @@ public class QuarkusRestPathTemplateInterceptor {
@AroundInvoke
Object restMethodInvoke(InvocationContext context) throws Exception {
QuarkusRestPathTemplate annotation = getAnnotation(context);
if ((annotation != null) && (request.getCurrent() != null)) {
RoutingContext routingContext = null;
try {
routingContext = request.getCurrent();
} catch (ContextNotActiveException ex) {
// just leave routingContext as null
}
if ((annotation != null) && (routingContext != null)) {
((HttpServerRequestInternal) request.getCurrent().request()).context().putLocal("UrlPathTemplate",
annotation.value());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ String checkPrime(long number) {
}

@Gauge(name = "highestPrimeNumberSoFar", unit = MetricUnits.NONE, description = "Highest prime number so far.")
@GET
@Path("/blabla") // make this a REST method just to verify that a gauge will still work on it
public Long highestPrimeNumberSoFar() {
return highestPrimeSoFar.get();
}
Expand Down

0 comments on commit 300d2a3

Please sign in to comment.