title: Retrieving Soap Header on JAXWS Server Side
body: <p>We are trying to do a security implementation in our JAX web services and are passing the UserName and Password in the header as below.</p>
  
  <pre><code>&lt;soapenv:Header&gt;
      &lt;wsse:Security soapenv:mustUnderstand="0" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"&gt;
          &lt;wsse:UsernameToken wsu:Id="Id-8zvykuwmK8yg6dxn3632nQJB" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"&gt;
              &lt;wsse:Username&gt;gears_user&lt;/wsse:Username&gt;
              &lt;wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"&gt;##########&lt;/wsse:Password&gt;
          &lt;/wsse:UsernameToken&gt;
      &lt;/wsse:Security&gt;
  &lt;/soapenv:Header&gt;
  </code></pre>
  
  <p>In the Java we are trying the retrieve the Username and the password but we are not sure how to do it as, its a part of Soap Header and we have not retrieved header information before.</p>
  
  <pre><code>    .....
       @Resource
  WebServiceContext wsctx;
  
  
  public ServiceAvailabilityResponseType inquireGeographicEligibility(ServiceAvailabilityRequestType inquireGeographicEligibilityRequest)
      throws WSException
  {
  
       HeaderList hl=(HeaderList)wsctx.getMessageContext().get(JAXWSProperties.INBOUND_HEADER_LIST_PROPERTY);
       QName security = new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", 
              "Security");    
       Header hd = hl.get(security, false);
  
  
       QName userName = new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", 
          "Username");
       try
       {
           System.out.println(hd.readHeader());    
           System.out.println(hd.getAttribute(userName));
       }catch (Exception e) {
          System.out.println(e.getMessage());
      }
  
     }
  </code></pre>
  
  <p>We are trying to do as above and get the header elements but its not returning us the value. Any help on the way to retrieve the Username and Password will be appreciated.</p>