title: how add Message context headers to apache axis 2 Java
body: <p>I am working on web services. I want to know how do we add headers to SOAP request in JAX-WS type web services.</p>
  
  <p>Consider My header like this.</p>
  
  <pre><code>    Map&lt;String, List&lt;String&gt;&gt; headers = new HashMap&lt;String, List&lt;String&gt;&gt;();
      headers.put("Username", Collections.singletonList("aaaa"));
      headers.put("Password", Collections.singletonList("aaaa"));
  </code></pre>
  
  <p>I have stub object in my client class. I am using Apache Axis 2. All the classes are automatically generated.</p>
  
  <pre><code>SimpleSTub stub = new Simplestub();
  </code></pre>
  
  <p>I want to add this header information in client.</p>
  
  <pre><code>MessageContext.HTTP_REQUEST_HEADERS, headers
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <p>The actual implementation in a normal class found as</p>
  
  <p>private static final String WS_URL = "http://localhost:9999/ws/hello?wsdl";</p>
  
  <p>public static void main(String[] args) throws Exception {</p>
  
  <p>URL url = new URL(WS_URL);
      QName qname = new QName("http://ws.mkyong.com/", "HelloWorldImplService");</p>
  
  <pre><code>Service service = Service.create(url, qname);
  HelloWorld hello = service.getPort(HelloWorld.class);
  
  /*******************UserName &amp; Password ******************************/
  Map&lt;String, Object&gt; req_ctx = ((BindingProvider)hello).getRequestContext();
  req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, WS_URL);
  
  Map&lt;String, List&lt;String&gt;&gt; headers = new HashMap&lt;String, List&lt;String&gt;&gt;();
  headers.put("Username", Collections.singletonList("mkyong"));
  headers.put("Password", Collections.singletonList("password"));
  req_ctx.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
  /**********************************************************************/
  
  System.out.println(hello.getHelloWorldAsString());
  </code></pre>
  
  <p>Can any one tell how to achieve this.</p>
  
  <p>Thanks.</p>