private void checkForNonPublicMethodIssues() {
    final MethodList allDeclaredMethods = new MethodList(getAllDeclaredMethods(handlerClass));

    // non-public resource methods
    for (AnnotatedMethod m :
        allDeclaredMethods
            .withMetaAnnotation(HttpMethod.class)
            .withoutAnnotation(Path.class)
            .isNotPublic()) {
      Errors.warning(
          handlerClass, LocalizationMessages.NON_PUB_RES_METHOD(m.getMethod().toGenericString()));
    }
    // non-public subres methods
    for (AnnotatedMethod m :
        allDeclaredMethods
            .withMetaAnnotation(HttpMethod.class)
            .withAnnotation(Path.class)
            .isNotPublic()) {
      Errors.warning(
          handlerClass,
          LocalizationMessages.NON_PUB_SUB_RES_METHOD(m.getMethod().toGenericString()));
    }
    // non-public subres locators
    for (AnnotatedMethod m :
        allDeclaredMethods
            .withoutMetaAnnotation(HttpMethod.class)
            .withAnnotation(Path.class)
            .isNotPublic()) {
      Errors.warning(
          handlerClass, LocalizationMessages.NON_PUB_SUB_RES_LOC(m.getMethod().toGenericString()));
    }
  }
Esempio n. 2
0
 private void validate(ResourceModel resourceModel) {
   final ComponentModelValidator validator = new ComponentModelValidator(locator);
   validator.validate(resourceModel);
   if (Errors.fatalIssuesFound()) {
     throw new ModelValidationException(ModelErrors.getErrorsAsResourceModelIssues());
   }
 }
 /**
  * Create a new resource model builder for the introspected class.
  *
  * <p>The model returned is filled with the introspected data.
  *
  * @return new resource model builder for the introspected class.
  */
 public Resource.Builder createResourceBuilder() {
   return Errors.processWithException(
       new Producer<Resource.Builder>() {
         @Override
         public Resource.Builder call() {
           return doCreateResourceBuilder();
         }
       });
 }
Esempio n. 4
0
  /**
   * Create a new Jersey server-side application handler configured by a {@link Application JAX-RS
   * Application (sub-)class}.
   *
   * @param jaxrsApplicationClass JAX-RS {@code Application} (sub-)class that will be instantiated
   *     and used to configure the new Jersey application handler.
   */
  public ApplicationHandler(Class<? extends Application> jaxrsApplicationClass) {
    this.locator = Injections.createLocator(new ServerBinder(), new ApplicationBinder());
    this.application = createApplication(jaxrsApplicationClass);
    this.runtimeConfig = ResourceConfig.createRuntimeConfig(application);

    Errors.processWithException(
        new Runnable() {
          @Override
          public void run() {
            initialize();
          }
        });
  }
Esempio n. 5
0
 @Override
 public void visitInvocable(final Invocable invocable) {
   // TODO: check invocable.
   Class resClass = invocable.getHandler().getHandlerClass();
   if (resClass != null && !checkedClasses.contains(resClass)) {
     checkedClasses.add(resClass);
     final boolean provider = Providers.isProvider(resClass);
     int counter = 0;
     for (Annotation annotation : resClass.getAnnotations()) {
       if (SCOPE_ANNOTATIONS.contains(annotation.annotationType())) {
         counter++;
       }
     }
     if (counter == 0 && provider) {
       Errors.warning(
           resClass,
           LocalizationMessages.RESOURCE_IMPLEMENTS_PROVIDER(
               resClass, Providers.getProviderContracts(resClass)));
     } else if (counter > 1) {
       Errors.fatal(resClass, LocalizationMessages.RESOURCE_MULTIPLE_SCOPE_ANNOTATIONS(resClass));
     }
   }
 }
Esempio n. 6
0
  /**
   * Create a new Jersey server-side application handler configured by an instance of a {@link
   * Application JAX-RS Application sub-class}.
   *
   * @param application an instance of a JAX-RS {@code Application} (sub-)class that will be used to
   *     configure the new Jersey application handler.
   */
  public ApplicationHandler(Application application) {
    this.locator = Injections.createLocator(new ServerBinder(), new ApplicationBinder());
    this.application = application;
    if (application instanceof ResourceConfig) {
      final ResourceConfig rc = (ResourceConfig) application;
      if (rc.getApplicationClass() != null) {
        rc.setApplication(createApplication(rc.getApplicationClass()));
      }
    }
    this.runtimeConfig = ResourceConfig.createRuntimeConfig(application);

    Errors.processWithException(
        new Runnable() {
          @Override
          public void run() {
            initialize();
          }
        });
  }