Example #1
0
  @Override
  public final ResourceDocument generateResourceDocument(
      UriInfo uriInfo, Class<?> classOfResource) {
    final ResourceDocument document = new ResourceDocument();

    // Read the path.
    final Path path = this.findAnnotationInClass(Path.class, classOfResource);
    if (null == path)
      throw new IllegalStateException(
          "Couldn't find any class/superclass/interface annotated with @Path for "
              + classOfResource);
    document.setPath(uriInfo.getPath() + path.value());

    this.doWithResourceDocument(document, classOfResource);

    // Process its methods
    for (Method method : classOfResource.getDeclaredMethods()) {
      // Skip methods that are not annotated with @HttpGet
      if (!isHttpMethod(method)) {
        LOG.debug("Skipping method {}, it is not annotated with @HttpMethod", method.getName());
        continue;
      }

      // IllegalStateException is thrown if the method iterated is not
      // annotated with any of the @HttpMethod annotations. This can happen
      // for utility/helper methods found within classOfResource.
      try {
        document.addMethodDocument(this.generateMethodDocument(uriInfo, method));
      } catch (IllegalStateException e) {
        // Ignoring specific methods, as they aren't annotated with @HttpMethod.
        LOG.debug("Skipping method {}, it isn't annotated with any @HttpMethod", method.getName());
      }
    }

    return document;
  }