title: handleMessage method of SOAPHandler not getting invoked,rather getHeaders get invoked
body: <p>I am new to the SOAP world.</p>
  
  <p>I have coverted the <code>wsdl</code> file to <code>java</code> class using maven plugin</p>
  
  <p>Below is the pom.xml configuration.</p>
  
  <pre><code>&lt;plugin&gt;
              &lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
              &lt;artifactId&gt;cxf-codegen-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.1.12&lt;/version&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;id&gt;generate-sources&lt;/id&gt;
                      &lt;phase&gt;generate-sources&lt;/phase&gt;
                      &lt;configuration&gt;
                          &lt;sourceRoot&gt;${project.basedir}/src/main/java&lt;/sourceRoot&gt;
                          &lt;wsdlOptions&gt;
                              &lt;wsdlOption&gt;
                                  &lt;wsdl&gt;${project.basedir}/src/main/resources/EIAproxy.wsdl&lt;/wsdl&gt;
                                  &lt;wsdlLocation&gt;classpath:EIAproxy.wsdl&lt;/wsdlLocation&gt;
                              &lt;/wsdlOption&gt;
                          &lt;/wsdlOptions&gt;
                      &lt;/configuration&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;wsdl2java&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
  </code></pre>
  
  <p>below is the class files</p>
  
  <p>Interface definition</p>
  
  <pre><code>@WebService(targetNamespace = "http://schema.concierge.com", name = "EaiEnvelopeSoap")
  @XmlSeeAlso({com.concierge.schema.envelope.ObjectFactory.class, ObjectFactory.class})
  @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
  public interface EaiEnvelopeSoap {
  
  @WebResult(name = "clientRequestResponse", targetNamespace = "http://schema.concierge.com", partName = "parameters")
  @WebMethod(action = "http://www.openuri.org/clientRequest")
    public ClientRequestResponse clientRequest(
      @WebParam(partName = "parameters", name = "clientRequest", targetNamespace = "http://schema.concierge.com")
      ClientRequest parameters
  );
  }
  </code></pre>
  
  <p>Here is class file that extends service</p>
  
  <pre><code>    @WebServiceClient(name = "EaiEnvelope", 
                       wsdlLocation = "classpath:EIAproxy.wsdl",
                       targetNamespace = "http://schema.concierge.com") 
      public class EaiEnvelope extends Service {
  
         public final static URL WSDL_LOCATION;
  
         public final static QName SERVICE = new QName("http://schema.concierge.com", "EaiEnvelope");
         public final static QName EaiEnvelopeSoap = new QName("http://schema.concierge.com", "EaiEnvelopeSoap");
         static {
             URL url = EaiEnvelope.class.getClassLoader().getResource("EIAproxy.wsdl");
             if (url == null) {
                 java.util.logging.Logger.getLogger(EaiEnvelope.class.getName())
                     .log(java.util.logging.Level.INFO, 
                          "Can not initialize the default wsdl from {0}", "classpath:EIAproxy.wsdl");
             }       
             WSDL_LOCATION = url;   
         }
  
         public EaiEnvelope(URL wsdlLocation) {
             super(wsdlLocation, SERVICE);
         }
  
         public EaiEnvelope(URL wsdlLocation, QName serviceName) {
             super(wsdlLocation, serviceName);
         }
  
         public EaiEnvelope() {
             super(WSDL_LOCATION, SERVICE);
         }
  
         public EaiEnvelope(WebServiceFeature ... features) {
             super(WSDL_LOCATION, SERVICE, features);
         }
  
         public EaiEnvelope(URL wsdlLocation, WebServiceFeature ... features) {
             super(wsdlLocation, SERVICE, features);
         }
  
         public EaiEnvelope(URL wsdlLocation, QName serviceName, WebServiceFeature ... features) {
             super(wsdlLocation, serviceName, features);
         }    
  
  
  
  
         /**
          *
          * @return
          *     returns EaiEnvelopeSoap
          */
         @WebEndpoint(name = "EaiEnvelopeSoap")
         public EaiEnvelopeSoap getEaiEnvelopeSoap() {
             return super.getPort(EaiEnvelopeSoap, EaiEnvelopeSoap.class);
         }
  
         /**
          * 
          * @param features
          *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the &lt;code&gt;features&lt;/code&gt; parameter will have their default values.
          * @return
          *     returns EaiEnvelopeSoap
          */
         @WebEndpoint(name = "EaiEnvelopeSoap")
         public EaiEnvelopeSoap getEaiEnvelopeSoap(WebServiceFeature... features) {
             return super.getPort(EaiEnvelopeSoap, EaiEnvelopeSoap.class, features);
         }
  
      }       
  </code></pre>
  
  <p>My SoapHandler file is </p>
  
  <pre><code>       import java.io.ByteArrayOutputStream;
         import java.io.IOException;
         import java.io.OutputStream;
         import java.io.StringWriter;
         import java.util.Set;
  
         import javax.xml.namespace.QName;
         import javax.xml.soap.SOAPBody;
         import javax.xml.soap.SOAPElement;
         import javax.xml.soap.SOAPEnvelope;
         import javax.xml.soap.SOAPHeader;
         import javax.xml.soap.SOAPMessage;
         import javax.xml.ws.handler.MessageContext;
         import javax.xml.ws.handler.soap.SOAPHandler;
         import javax.xml.ws.handler.soap.SOAPMessageContext;
  
         import com.xxx.fdp.common.LoggerManager;
         import com.xxx.fdp.constants.LoggerConstantEnum;
         import com.xxx.fdp.property.config.AbilityConfig;
  
         public class HeaderHandler implements SOAPHandler&lt;SOAPMessageContext&gt; {
  
             /** The logger manager. */
             LoggerManager loggerManager = new LoggerManager();
  
             @Override
             public boolean handleMessage(SOAPMessageContext smc) {
  
                 Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
                 loggerManager.info(LoggerConstantEnum.AbilityDailySyncUp, "Entered in handleMessage with outBoundProperty : " + outboundProperty);
                 if (outboundProperty.booleanValue()) {
  
                     SOAPMessage message = smc.getMessage();
                     loggerManager.info(LoggerConstantEnum.AbilityDailySyncUp, " Message : " + message);
  
                     try {
                         message.writeTo(System.out);
                         SOAPEnvelope envelope = smc.getMessage().getSOAPPart().getEnvelope();
                         envelope.addNamespaceDeclaration("com", "http://schema.concierge.com");
                         message.getMimeHeaders().setHeader("Content-Type", "application/soap+xml; charset=utf-8");
                         SOAPHeader header = envelope.addHeader();
  
                         SOAPElement authentication = header.addChildElement("authentication", "auth", "http://schemas.eia.org/middleware/AuthInfo");
  
                         SOAPElement username = authentication.addChildElement("user", "auth");
                         username.addTextNode(AbilityConfig.getInstance().getSoapUser());
  
                         SOAPElement password = authentication.addChildElement("password", "auth");
                         password.addTextNode(AbilityConfig.getInstance().getSoapPassword());
  
                         SOAPElement authType = authentication.addChildElement("type", "auth");
                         authType.addTextNode(AbilityConfig.getInstance().getSoapAuthType());
                         SOAPBody body = envelope.getBody();
  
                         // Print out the outbound SOAP message to System.out
                         message.saveChanges();
  
                         loggerManager.info(LoggerConstantEnum.AbilityDailySyncUp, "Request Format : " + envelope.getBody() + ",Header : " + envelope.getHeader());
                         ByteArrayOutputStream out = new ByteArrayOutputStream();
                         message.writeTo(out);
                         String strMsg = new String(out.toByteArray());
                         loggerManager.info(LoggerConstantEnum.AbilityDailySyncUp, "Request Format Message: " + strMsg);
                         StringWriter writer = new StringWriter();
                         message.writeTo(new StringOutputStream(writer));
                         // message.writeTo(System.out);
                         System.out.println("");
  
                     } catch (Exception e) {
                         e.printStackTrace();
                     }
  
                 } else {
                     try {
  
                         // This handler does nothing with the response from the Web
                         // Service so
                         // we just print out the SOAP message.
                         SOAPMessage message = smc.getMessage();
                         loggerManager.info(LoggerConstantEnum.AbilityDailySyncUp, "Response Message : " + message);
                         message.writeTo(System.out);
                         System.out.println("");
  
                     } catch (Exception ex) {
                         ex.printStackTrace();
                     }
                 }
                 loggerManager.info(LoggerConstantEnum.AbilityDailySyncUp, "Exit in handleMessage with outBoundProperty : " + outboundProperty);
                 return outboundProperty;
  
             }
  
             private static class StringOutputStream extends OutputStream {
  
                 private StringWriter writer;
  
                 public StringOutputStream(StringWriter writer) {
                     this.writer = writer;
                 }
  
                 @Override
                 public void write(int b) throws IOException {
                     writer.write(b);
                 }
             }
  
             @Override
             public boolean handleFault(SOAPMessageContext context) {
                 loggerManager.info(LoggerConstantEnum.AbilityDailySyncUp, "Entered in handleFault ");
                 return false;
             }
  
             @Override
             public void close(MessageContext context) {
                 loggerManager.info(LoggerConstantEnum.AbilityDailySyncUp, "Entered in close ");
             }
  
             @Override
             public Set&lt;QName&gt; getHeaders() {
                 // TODO Auto-generated method stub
                 return null;
             }
  
         }
  </code></pre>
  
  <p>My handlerResolver file is </p>
  
  <pre><code>     import java.util.ArrayList;
       import java.util.List;
  
       import javax.xml.ws.handler.Handler;
       import javax.xml.ws.handler.HandlerResolver;
       import javax.xml.ws.handler.PortInfo;
  
       import com.xxx.fdp.common.LoggerManager;
       import com.xxx.fdp.constants.LoggerConstantEnum;
  
  
       public class HeaderHandlerResolver implements HandlerResolver {
  
           LoggerManager loggerManager = new LoggerManager();
  
           @SuppressWarnings("rawtypes")
           @Override
           public List&lt;Handler&gt; getHandlerChain(PortInfo portInfo) {
               loggerManager.info(LoggerConstantEnum.AbilityDailySyncUp,"Entered in getHandlerChain");
               List&lt;Handler&gt; handlerChain = new ArrayList&lt;Handler&gt;();
               loggerManager.info(LoggerConstantEnum.AbilityDailySyncUp,"Created handlerChanin object");
               HeaderHandler headerHandler = new HeaderHandler();
               loggerManager.info(LoggerConstantEnum.AbilityDailySyncUp,"Created HeaderHandler object");
  
               handlerChain.add(headerHandler);
               loggerManager.info(LoggerConstantEnum.AbilityDailySyncUp,"returned handlerChain");
  
               return handlerChain;
           }
  
       }
  </code></pre>
  
  <p>Method which is used to call service</p>
  
  <pre><code>        public void processRequest(EaiEnvelope envelope,AbilitySyncUpData abilityObject) {
           loggerManager.info(LoggerConstantEnum.AbilityDailySyncUp, "| processing ability async up starts with TranactionId : "+abilityObject.getTransactionId());
           try {
               com.concierge.schema.EaiEnvelope service=new com.concierge.schema.EaiEnvelope();
               HeaderHandlerResolver handlerResolver = new HeaderHandlerResolver();
               service.setHandlerResolver(handlerResolver);
               EaiEnvelopeSoap port=service.getEaiEnvelopeSoap(); 
              ClientRequest request=new ClientRequest();
               request.setEaiEnvelope(envelope);
               loggerManager.info(LoggerConstantEnum.AbilityDailySyncUp,"Sending request to web service with TranactionId : "+abilityObject.getTransactionId());
               ClientRequestResponse response=port.clientRequest(request);
               loggerManager.info(LoggerConstantEnum.AbilityDailySyncUp,"Response received "+response+" After sending request to web service with TranactionId : "+abilityObject.getTransactionId());
           } catch (Exception e) {
               loggerManager.error(LoggerConstantEnum.AbilityDailySyncUp, "|  Exception occured  :  " + e.fillInStackTrace(), e);
               writeCsvFile(abilityObject);
           }
           loggerManager.info(LoggerConstantEnum.AbilityDailySyncUp, "| processRequest method ends here with TranactionId : "+abilityObject.getTransactionId());
  </code></pre>
  
  <p>I am not able to get call in <code>soapHandler</code>'s <code>handleMessage</code> method
  and call is going on getHeaders<code>method when the service method</code>ClientRequestResponse response=port.clientRequest(request);` is called.</p>
  
  <p>I have reffered from several answers that are present on stackoverflow:</p>
  
  <p><a href="https://stackoverflow.com/questions/5019039/soaphandler-not-called-after-ws-operation-is-executed">SoapHandler not called after WS operation is executed</a></p>
  
  <p><a href="https://stackoverflow.com/a/12712728/1569443">https://stackoverflow.com/a/12712728/1569443</a></p>
  
  <p><a href="https://stackoverflow.com/a/14523921/1569443">https://stackoverflow.com/a/14523921/1569443</a></p>
  
  <p><a href="http://www.javadb.com/using-a-message-handler-to-alter-the-soap-header-in-a-web-service-client/" rel="noreferrer">http://www.javadb.com/using-a-message-handler-to-alter-the-soap-header-in-a-web-service-client/</a></p>
  
  <p><a href="https://soa2world.blogspot.com/2009/05/direct-web-service-client-using-java.html" rel="noreferrer">https://soa2world.blogspot.com/2009/05/direct-web-service-client-using-java.html</a></p>
  
  <p>I am still not able to call <code>handleMessage</code> method of handler as no logs gets printed. Call is made in <code>handlerResolver</code> class but not in <code>HeaderHandler</code> class.</p>
  
  <p>How can I resolve this issue?</p>