Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-286

Order dependency in ResteasyDeployment#processApplication with respect to registering PreProcessInterceptor, PostProcessInterceptor

    XMLWordPrintable

Details

    Description

      I am using 'Application.getClasses()' to register Provider classes, not automatic scanning. I decided to add a PreProcessInterceptor in order to implement custom security. Call it 'MySecurityIntercepter'.

      First attempt was to return it via Application#getSingletons;. No effect. As I could not find any full implementation examples, I figured I may as well read the code.

      I first noticed that ResourceMethod.preProcessInterceptors had a length of zero in the invokeOnTargetMethod. But using the debugger to call the original init code for preProcessInterceptors returned an array with 'MySecurityIntercepter' in it. Hm.

      Long story short, with respect to Application#getClasses(), this fails to invoke the Interceptor correctly:
      ---------------------
      public ... getClasses() {
      Set<Class<?>> set = new HashSet<Class<?>>();
      set.add( MySecurityInterceptor.class );
      set.add( MyService.class);
      ... ( add ten or so more services )
      return set;
      }
      ---------------

      But the following DOES invoke the interceptor correctly:
      Set<Class<?>> set = new TreeSet<Class<?>>(new Comparator<Class>(){
      public int compare( Class o1, Class o2 )
      { // make sure that my interceptors are always first to be processed:
      if( o1 == MySecurityInterceptor.class )

      { return -1; }

      else if ( o2 == MySecurityInterceptor.class )

      { return 1; }

      return o1.getName().compareTo( o2.getName() );
      }
      });
      set.add(MyService.class);
      ... ( ten or so more services )
      return set;
      }
      -------------------

      The reason is that the calling code ( ResteasyDeployment#processApplication) must add the Security provider to the list before registering any root resource classes, due to the initialization of ResourceMethod.preProcessInterceptors in the constructor.

      I interpreted the docs imply that using the Application getClasses method in this manner is supported. Perhaps I missed something.

      This is 1.1GA, but I pulled the source down as a Tar on 7~24-2009. ( Don't see a Rev number, sorry ). I only used the source to do debugging against the released jars.

      Attachments

        Activity

          People

            patriot1burke@gmail.com Bill Burke (Inactive)
            ggranum_jira Geoff Granum (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: