From 8d370783c7c20275b83ce5d01c5eb7e4647130c5 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Thu, 23 Jul 2020 11:14:51 +0300 Subject: [PATCH] Warn when JAX-RS @Path is used along with MP Health annotations It's not unreasonable for users to expect these annotations to work together, so let's be explicit that they don't. Resolves: #10720 --- .../deployment/SmallRyeHealthProcessor.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java index 8e23b88f2c785..78257564cd248 100644 --- a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java +++ b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java @@ -28,6 +28,7 @@ import org.eclipse.microprofile.health.Readiness; import org.eclipse.microprofile.health.spi.HealthCheckResponseProvider; import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.AnnotationTarget.Kind; import org.jboss.jandex.DotName; import org.jboss.jandex.IndexView; @@ -88,6 +89,7 @@ class SmallRyeHealthProcessor { private static final DotName READINESS = DotName.createSimple(Readiness.class.getName()); private static final DotName HEALTH_GROUP = DotName.createSimple(HealthGroup.class.getName()); private static final DotName HEALTH_GROUPS = DotName.createSimple(HealthGroups.class.getName()); + private static final DotName JAX_RS_PATH = DotName.createSimple("javax.ws.rs.Path"); // For the UI private static final String HEALTH_UI_WEBJAR_GROUP_ID = "io.smallrye"; @@ -176,6 +178,10 @@ public void defineHealthRoutes(BuildProducer routes, BeanArchiveIndexBuildItem beanArchiveIndex) { IndexView index = beanArchiveIndex.getIndex(); + // log a warning if users try to use @Liveness or @Readiness with JAX-RS @Path + warnIfJaxRsPathUsed(index, LIVENESS); + warnIfJaxRsPathUsed(index, READINESS); + // Register the health handler routes.produce(new RouteBuildItem(health.rootPath, new SmallRyeHealthHandler(), HandlerType.BLOCKING)); @@ -215,6 +221,29 @@ public void defineHealthRoutes(BuildProducer routes, } } + private void warnIfJaxRsPathUsed(IndexView index, DotName healthAnnotation) { + Collection instances = index.getAnnotations(healthAnnotation); + for (AnnotationInstance instance : instances) { + boolean containsPath = false; + + AnnotationTarget target = instance.target(); + if (target.kind() == Kind.CLASS) { + if (target.asClass().classAnnotation(JAX_RS_PATH) != null) { + containsPath = true; + } + } else if (target.kind() == Kind.METHOD) { + if (target.asMethod().hasAnnotation(JAX_RS_PATH)) { + containsPath = true; + } + } + if (containsPath) { + LOG.warnv( + "The use of @Path has no effect when @{0} is used and should therefore be removed. Offending target is {1}: {2}", + healthAnnotation.withoutPackagePrefix(), target.kind(), target); + } + } + } + @BuildStep public void kubernetes(HttpBuildTimeConfig httpConfig, BuildProducer livenessPathItemProducer,