title: Passing Information from the Application to the Handler Level SOAP
body: <p>I am working with a SOAP Web Service and I need to pass information from the Application level which is my Main Client Class to the Client Handler Level for further evaluation. I have listed below my Client and my Client Handler. I want to scan in a value from the user and store in the "discountVal" variable that is located in the Handler so that I can add a Text Node to the SOAPHeader.</p>
  
  <p>CLIENT:</p>
  
  <pre><code>/*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  package client;
  
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Scanner;
  import javax.xml.ws.handler.Handler;
  import javax.xml.ws.handler.HandlerResolver;
  import javax.xml.ws.handler.PortInfo;
  
  /**
   *
   * @author Jack
   */
  public class Client 
  {
  
      /**
       * @param args the command line arguments
       */
      public static void main(String[] args) {
  
         client.ItemPriceServiceService service = new client.ItemPriceServiceService();
         service.setHandlerResolver(new ClientHandlerResolver());
         client.ItemPriceService port = service.getItemPriceServicePort();
  
  
  
  
         String discount = "25";
  
  
         Scanner scan = new Scanner(System.in);  
         String item = scan.next();
         while(!item.equals("bye"))
         {
          double price = getPrice(item);
  
          System.out.println(price);
  
          item = scan.next();
         }
         if(item.equals("bye"))
         {
             System.exit(0);
         }
      }
  
      private static double getPrice(java.lang.String arg0) {
          client.ItemPriceServiceService service = new client.ItemPriceServiceService();
          client.ItemPriceService port = service.getItemPriceServicePort();
          return port.getPrice(arg0);
      }
  
      private static class ClientHandlerResolver implements HandlerResolver {
  
          public ClientHandlerResolver() {
          }
  
          @Override
          public List&lt;Handler&gt; getHandlerChain(PortInfo portInfo) {
  
              List&lt;Handler&gt; hchain = new ArrayList&lt;Handler&gt;();
              hchain.add(new clientHandler());
              return hchain;
          }
      }
  }
  </code></pre>
  
  <p>CLIENT HANDLER</p>
  
  <pre><code>/*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  package client;
  
  
  
  import java.util.Collections;
  import java.util.Set;
  import javax.xml.namespace.QName;
  import javax.xml.soap.*;
  import javax.xml.ws.handler.MessageContext;
  import javax.xml.ws.handler.soap.SOAPHandler;
  import javax.xml.ws.handler.soap.SOAPMessageContext;
  
  /**
   *
   * @author Jack
   */
  public class clientHandler implements SOAPHandler&lt;SOAPMessageContext&gt; {
  
       public boolean handleMessage(SOAPMessageContext context) 
       {
      Boolean outgoing = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
         if(outgoing){
  
      try{
          SOAPMessage soapMsg = context.getMessage();
              SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
              SOAPHeader soapHeader = soapEnv.getHeader();
  
              if (soapHeader == null){
                  soapHeader = soapEnv.addHeader();
              }
  
  
              //get discount value FROM CLIENT
              String discountVal = "25";
  
  
              QName qname = new QName("http://testOne", "discount");
              SOAPHeaderElement soapHeaderElement = soapHeader.addHeaderElement(qname);
  
              soapHeaderElement.setActor(SOAPConstants.URI_SOAP_ACTOR_NEXT);
              soapHeaderElement.addTextNode(discountVal);
              soapMsg.saveChanges();
  
         }catch(SOAPException e){
          System.err.println(e);
         }
  
           }
  
         //continue other handler chain
         return true;
     }
  
      public Set&lt;QName&gt; getHeaders() {
          return Collections.EMPTY_SET;
      }
  
      public boolean handleFault(SOAPMessageContext messageContext) {
          return true;
      }
  
      public void close(MessageContext context) {
      }
  }
  </code></pre>
  
  <p>Any help would be greatly appreciated! I have a feeling that using the MessageContext would be a way to do this but I am unsure as to where to start.</p>