title: How to read SOAP Header information from request and add it to response in spring web services
body: <p>I am working on spring web services. I need to add some custom elements in the request and response message.which should look like this:</p>
  
  <pre><code>&lt;soapenv:Envelope&gt;
     &lt;soapenv:Header&gt;
        &lt;tid:SplsTID&gt;
           &lt;tid:Trantype&gt;123&lt;/tid:Trantype&gt;
           &lt;tid:Tranver&gt;234&lt;/tid:Tranver&gt;
        &lt;/tid:SplsTID&gt;
     &lt;/soapenv:Header&gt;
     &lt;soapenv:Body&gt;
        &lt;get:GetOrderNumberRequest LoggingLevel="REGULAR" MonitorFlag="Y"&gt;
           &lt;get:Header&gt;
              &lt;get:TransactionId&gt;111&lt;/get:TransactionId&gt;
              &lt;get:SourceSystemId&gt;SOMS&lt;/get:SourceSystemId&gt;
              &lt;get:DateTime&gt;2011-11-11T11:11:11&lt;/get:DateTime&gt;
           &lt;/get:Header&gt;
           &lt;get:Body&gt;
              &lt;get:StaplesOrderNumber RangeFlag="N" ReleaseFlag="N"&gt;
                 &lt;get:OrderNumber Count="1" End="11" Start="9"/&gt;
              &lt;/get:StaplesOrderNumber&gt;
           &lt;/get:Body&gt;
        &lt;/get:GetOrderNumberRequest&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>i am able to append <code>&lt;tid:SplsTID&gt;</code> under <code>&lt;soapenv:Header&gt;</code> in request by modifying the WSDL file. which looks like this:</p>
  
  <pre><code>&lt;wsdl:message name="GetOrderNumberRequest"&gt;
          &lt;wsdl:part element="tns:GetOrderNumberRequest" name="GetOrderNumberRequest"&gt;
          &lt;/wsdl:part&gt;
          &lt;wsdl:part element="sch1:SplsTID" name="SplsTID"&gt;
          &lt;/wsdl:part&gt;
      &lt;/wsdl:message&gt;
      &lt;wsdl:message name="GetOrderNumberResponse"&gt;
          &lt;wsdl:part element="tns:GetOrderNumberResponse" name="GetOrderNumberResponse"&gt;
          &lt;/wsdl:part&gt;
          &lt;wsdl:part element="sch1:SplsTID" name="SplsTID"&gt;
          &lt;/wsdl:part&gt;
      &lt;/wsdl:message&gt;
      &lt;wsdl:portType name="ONAS"&gt;
          &lt;wsdl:operation name="GetOrderNumber"&gt;
              &lt;wsdl:input message="tns:GetOrderNumberRequest" name="GetOrderNumberRequest"&gt;
              &lt;/wsdl:input&gt;
              &lt;wsdl:output message="tns:GetOrderNumberResponse" name="GetOrderNumberResponse"&gt;
              &lt;/wsdl:output&gt;
          &lt;/wsdl:operation&gt;
      &lt;/wsdl:portType&gt;
  </code></pre>
  
  <p>The problem is, i want to read <code>&lt;tid:SplsTID&gt;</code> part from the request and wanted to append it under soap header part of the response, which is not happening. i am using annotation based end point. what is the code which will read the soap header and will append the same in the response.</p>
  
  <p>currently my end point class is:</p>
  
  <pre><code>@Endpoint
  public class OrderNumberServiceEndPoint {
      public static final String NAMESPACE_URI = "http://schemas.staples.com/onas/getOrderNumber";
  
      /**
       * The local name of the expected request.
       */
      public static final String REQUEST_LOCAL_NAME = "GetOrderNumberRequest";
  
      /**
       * The local name of the created response.
       */
      public static final String RESPONSE_LOCAL_NAME = "GetOrderNumberResponse";
  
      private GetOrderNumberService getOrderNumberService;
  
      public void setGetOrderNumberService(
              GetOrderNumberService getOrderNumberService) {
          this.getOrderNumberService = getOrderNumberService;
      }
  
      @PayloadRoot(localPart = REQUEST_LOCAL_NAME, namespace = NAMESPACE_URI)
      public GetOrderNumberResponse processOrderNumberRequest(
              GetOrderNumberRequest request) throws Exception {
          GetOrderNumberResponse response = null;
          try{
          response = getOrderNumberService.executeRequest(request);
          }catch(CannotCreateTransactionException e){
              logger.error(ErrorConstants.ERROR_E17);
              throw new ServiceException(ErrorConstants.ERROR_E17);
          }
          return response;
      }
  
  }
  </code></pre>
  
  <p>Let me know if more details are required. Any help would be appreciated.</p>