Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think you need another way to create the header, it looks like jax-ws, so i'll go with a jax ws implementation i did a couple of months ago.</p> <p>First you need a HeaderHandler class , wich creates the soap header element, it should look like this:</p> <hr> <pre><code> import javax.xml.namespace.QName; import javax.xml.soap.SOAPElement; import javax.xml.soap.SOAPEnvelope; import javax.xml.soap.SOAPHeader; import javax.xml.ws.handler.MessageContext; import javax.xml.ws.handler.soap.SOAPHandler; import javax.xml.ws.handler.soap.SOAPMessageContext; public class HeaderHandler implements SOAPHandler&lt;SOAPMessageContext&gt; { public boolean handleMessage(SOAPMessageContext smc) { Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); String AUTH_TK = "http://www.avectra.com/2005/"; String PREFIX="";//no prefix String PREFIX_XMLNS="xmlns"; String value = "123456"; if (outboundProperty.booleanValue()) { try { SOAPEnvelope envelope = smc.getMessage().getSOAPPart().getEnvelope(); SOAPHeader header = envelope.addHeader(); //&lt;AuthorizationToken xmlns="http://www.avectra.com/2005/"&gt; SOAPElement authorizationToken = header.addChildElement("AuthorizationToken", PREFIX_XMLNS, AUTH_TK); //&lt;Token&gt;value&lt;/Token&gt; SOAPElement usernameToken = authorizationToken.addChildElement("Token", PREFIX); usernameToken.addTextNode(value); } catch (Exception e) { e.printStackTrace(); } } return outboundProperty; } public Set&lt;QName&gt; getHeaders() { return null; } public void close(MessageContext arg0) { } public boolean handleFault(SOAPMessageContext arg0) { return false; } } </code></pre> <p>After that you create a HeaderHandlerResolver to handle the header creation and insert it in a handler chain: </p> <hr> <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; public class HeaderHandlerResolver implements HandlerResolver { @SuppressWarnings("unchecked") public List&lt;Handler&gt; getHandlerChain(PortInfo portInfo) { List&lt;Handler&gt; handlerChain = new ArrayList&lt;Handler&gt;(); HeaderHandler hh = new HeaderHandler(); handlerChain.add(hh); return handlerChain; } } </code></pre> <p>After that, you add in the Client:</p> <hr> <pre><code> try{ //new service instance (your service should be extending javax.xml.ws.Service;) YourServiceProxy service = new YourServiceProxy(); //calls the header handler resolver ;) service.setHandlerResolver(new HeaderHandlerResolver()); //get the service YourService port = (YourService)service.getYourService(); //call the service port.yourMethod() } catch (Exception e) { e.printStackTrace(); } </code></pre> <p>By the way, i didn't tested this particular header, i modified a previous header handler i had, so it may be not accurate, but i think it's pretty close, i really hope it helps you, try it out and tell us how it comes, i'll try to help you if it still doesn't works.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload