Uploaded image for project: 'Thorntail'
  1. Thorntail
  2. THORN-1052

Wrong path is resolved in the HealthAnnotationProcessor.processArchive()

    Details

    • Steps to Reproduce:
      Hide
      1. create a project from the generator by selecting 2 dependencies: jax-rs and health
      2. run mvn wildfly-swarm:run
      3. after deploy success, visit http://localhost:8080/hello and http://localhost:8080/node to make sure the jax-rs and health fractions are working
      4. stop the server
      5. go to the HelloWorldEndpoint and add one method
        @GET
        @Path("/health-check")
        @Health
        public HealthStatus healthCheck() {
            return HealthStatus.named("health check").up();
        }
        
      6. re-run the mvn wildfly-swarm:run
      7. visit http://localhost:8080/health and you would see something like
        {"checks": [
        {"id":"health check","result":"UP",}],
        "outcome": "UP"
        }
        
      8. now stop the server again, and modify the @Path to "without leading slash"
        @Path("health-check")
        
      9. now visit http://localhost:8080/health again and you would encounter 500 server error
        check the log, you would see

        ERROR [org.wildfly.swarm.monitor.health] (default I/O-48) Health check failed: java.lang.RuntimeException: Unexpected status code: 404

      Show
      create a project from the generator by selecting 2 dependencies: jax-rs and health run mvn wildfly-swarm:run after deploy success, visit http://localhost:8080/hello and http://localhost:8080/node to make sure the jax-rs and health fractions are working stop the server go to the HelloWorldEndpoint and add one method @GET @Path( "/health-check" ) @Health public HealthStatus healthCheck() { return HealthStatus.named( "health check" ).up(); } re-run the mvn wildfly-swarm:run visit http://localhost:8080/health and you would see something like { "checks" : [ { "id" : "health check" , "result" : "UP" ,}], "outcome" : "UP" } now stop the server again, and modify the @Path to "without leading slash" @Path( "health-check" ) now visit http://localhost:8080/health again and you would encounter 500 server error check the log, you would see ERROR [org.wildfly.swarm.monitor.health] (default I/O-48) Health check failed: java.lang.RuntimeException: Unexpected status code: 404

      Description

      The HealthAnnotationProcessor.processArchive() resolves the path Health endpoint wrongly to cause internal error during listing the available health endpoints by http://localhost:8080/health

      After some debugging, I found that it is caused by HealthAnnotationProcessor.processArchive() where it provides WRONG URL for the health check fraction. When the @Path on method has leading slash, the URL is correct = /hello/health-check.

      However, without leading slash, the URL becomes /hellohealth-check. I think it is a bug.
      First of all, in the Oracle JAX-RS tutorial(JEE 7), it claims that

      A @Path value isn't required to have leading or trailing slashes (/). The JAX-RS runtime parses URI path templates the same way, whether or not they have leading or trailing slashes.

      I think the Health/Monitor fraction should follow this behaviour.

      Secondly, the issue is caused by

      // the class level @Path
      for (AnnotationInstance classAnnotation : classInfo.classAnnotations()) {
          if (classAnnotation.name().equals(PATH)) {
              String methodPathValue = classAnnotation.value().asString();
              if (!methodPathValue.equals("/"))
                  safeAppend(sb, methodPathValue);
          }
      }
      
      if (methodInfo.hasAnnotation(PATH)) {
      
          // the method level @Path
          sb.append(methodInfo.annotation(PATH).value().asString());
      
          // the method level @Health
          AnnotationInstance healthAnnotation = methodInfo.annotation(HEALTH);
          isSecure = healthAnnotation.value("inheritSecurity") != null ? healthAnnotation.value("inheritSecurity").asBoolean() : true;
      

      the line sb.append(methodInfo.annotation(PATH).value().asString());
      where i think it should use safeAppend same as the class level @Path

      This issue is firstly reported in the google group

      The attached monitor.health.zip is the project to reproduce the issue

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                hei1233212000 Harry Chan
                Reporter:
                hei1233212000 Harry Chan
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: