4 Replies Latest reply on May 1, 2014 12:46 PM by sukoor

    Interceptor called twice

    sanghakanwar

      Hi,


      I have written a interceptor for my webservices which is exposed as a stateless EJB endpoint. All works fine , but in the logs i see that the interceptor is getting called twice !


      My interceptor class -



      public class CheckStateInterceptorForSubscriberProfile {
           
           Logger log = Logger.getLogger(CheckStateInterceptorForGlobalProfile.class);
           private ManagementStateManager appServerStateManager;
           @AroundInvoke
           
           public Object test(InvocationContext invocation) throws SubscriberServiceException,Exception {
             
                appServerStateManager = new ManagementStateManager();
                
                
                log.info("Inside Interceptor for EJB webservice method invocation");
                
                // Populate the message string with the correct state of the app server (Lock,OSS..)
                String message = "Server is not in a valid state ! It is either in a LOCKED/SHUTDOWN/STANDBY/OSS state. Please " +
                          "try after some time.";
                // Method call to get the state of the app server
                if(appServerStateManager.isInValidState()){
                     log.info("AppServer is in a valid state");
                     return invocation.proceed();
                }
                else{
                     log.info("AppServer is in a in-valid state");
                     throw new SubscriberServiceException(message,ExceptionUtil.newSPSError(ExceptionCode.INVALID_SESSION,message));
                }
           }
      }
      
      
      



      and my webservice endpoint ejb -



      @WebService(endpointInterface = "com.xyz.sps.services.profile.GlobalProfileService", portName = "GlobalProfileService", serviceName = "GlobalProfileService")
      @Stateless(name = "GlobalProfileService", mappedName = "GlobalProfileService")
      @Local(GlobalProfileService.class)
      @TransactionManagement(TransactionManagementType.CONTAINER)
      @Interceptors(CheckStateInterceptorForGlobalProfile.class)
      public class GlobalProfileServiceImpl extends AbstractServiceImpl
                implements GlobalProfileService {
      
           private ProfileDAO profileDAO;     
      
           @TransactionAttribute(TransactionAttributeType.REQUIRED)
           @RolesAllowed({"spsadmin"})
           public void deleteGlobalProfile(ProfileReference profileReference) throws ProfileServiceException {
                boolean success = false;
                try {
                     validate(profileReference);                              
                     profileDAO.deleteGlobalProfile(new DeleteGlobalProfileParams(profileReference));
                     success = true;
                } catch (ProfileServiceException profileServiceEx) {
                     throw profileServiceEx;
                } catch (Throwable thrown) {               
                     throw newProfileServiceException(
                          ExceptionCode.PROFILE_DELETE_FAILED, 
                          "Failed to delete profile by reference " + profileReference,
                          thrown); 
                } finally {
                     if (!success) {
                          sessionContext.setRollbackOnly();
                     }
                }
           }
      


        • 1. Re: Interceptor called twice
          sanghakanwar
          server log -

          "
          |[#|2008-07-09T15:37:27.897+0530|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=22;_ThreadName=httpSSLWorkerThread-8181-1;|
          Inside Interceptor for EJB webservice method invocation|#]

          [#|2008-07-09T15:37:27.897+0530|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=22;_ThreadName=httpSSLWorkerThread-8181-1;|
          Inside Interceptor for EJB webservice method invocation|#]

          [#|2008-07-09T15:37:27.915+0530|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=22;_ThreadName=httpSSLWorkerThread-8181-1;|
          AppServer is in a valid state|#]

          [#|2008-07-09T15:37:27.915+0530|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=22;_ThreadName=httpSSLWorkerThread-8181-1;|
          AppServer is in a valid state|#]|"

          • 2. Re: Interceptor called twice
            accless

            Does your service GlobalProfileServiceImpl contain more public - methods ?


            I recommend you to add an if-else statement (like the following) to your interceptor implementation and check your logs again:


            if (!invocation.getMethod().getName().equalsIgnoreCase("deleteGlobalProfile")) {
            
            }
            





            greetings

            • 3. Re: Interceptor called twice
              sanghakanwar

              No. Am testing with only 1 method. Tried ur suggestion but still see it happening twice...

              • 4. Re: Interceptor called twice
                sukoor

                I am facing the exact same Problem when using Interceptors with EJB-Webservice. I am using App-Server Jboss 6.2 eap. Did you solve your problem?

                 

                Greetings