Uploaded image for project: 'JBoss Web Services'
  1. JBoss Web Services
  2. JBWS-4444

Sever throws IllegalStateException when call a getHeaders/handleFault/close in soap handler with the CDI bean invocation

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • None
    • jbossws-cxf
    • None
    • Hide

      Set the application module classloader to TCCL before CDI.current(); in SOAPHandler

      // As a workaround, set TCCL to application module class loader
      ClassLoader old = Thread.currentThread().getContextClassLoader();Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
      CDI.current();Thread.currentThread().setContextClassLoader(old);
      
      Show
      Set the application module classloader to TCCL before CDI.current(); in SOAPHandler // As a workaround, set TCCL to application module class loader ClassLoader old = Thread .currentThread().getContextClassLoader(); Thread .currentThread().setContextClassLoader( this .getClass().getClassLoader()); CDI.current(); Thread .currentThread().setContextClassLoader(old);

      When call a getHeaders/handleFault/close method in soap handler with the CDI bean invocation, IllegalStateException has been thrown since .This issue asks to fix thread context classloader during execution of getHeaders/handleFault/close methods.

      public class LoggingHandler implements SOAPHandler<SOAPMessageContext> {
          private static final Logger LOG = LoggerFactory.getLogger(LoggingHandler.class);
      
          @Override
          public boolean handleMessage(SOAPMessageContext soapMessageContext) {
              boolean isOutBound = (boolean) soapMessageContext.get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY);
              if (isOutBound) {
                  LOG.info("### TCCL in SOAPHandler.handleMessage = " + Thread.currentThread().getContextClassLoader().toString());
                  new DelegateBean();   
                  // As a workaround, set TCCL to application module class loader for 
      //            ClassLoader old = Thread.currentThread().getContextClassLoader();
      //            Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
      //            new DelegateBean();
      //            Thread.currentThread().setContextClassLoader(old);
              }
              return true;
          }
      
          @Override
          public Set<QName> getHeaders() {
              LOG.info("### TCCL in SOAPHandler.getHeaders = " + Thread.currentThread().getContextClassLoader().toString());
              new DelegateBean();  
               // the same workaround 
      //        ClassLoader old = Thread.currentThread().getContextClassLoader();
      //        Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
      //        new DelegateBean();
      //        Thread.currentThread().setContextClassLoader(old);
      
              return Collections.emptySet();
          }
      
          @Override
          public boolean handleFault(SOAPMessageContext soapMessageContext) {
              LOG.info("### TCCL in SOAPHandler.handleFault = " + Thread.currentThread().getContextClassLoader().toString());
              new DelegateBean();  
          }
      
          @Override
          public void close(MessageContext messageContext) {
              LOG.info("### TCCL in SOAPHandler.close = " + Thread.currentThread().getContextClassLoader().toString());
              new DelegateBean(); 
          }
      }
      

      DelegateBean.java

      @Dependent
      public class DelegateBean {
          EmptyBean logic = CDI.current().select(EmptyBean.class).get();
      } 
      

              rhn-engineering-ema Jim Ma
              rhn-engineering-ema Jim Ma
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated: