How do I add a SOAP Header using Java JAX-WS?

Thanks Nuno, Just as soon as I work out how to log in properly to stackoverflow. Com I'll do the right thing with your reply. In the mean time here's the code I ended up with: FooService service = new FooService(); service.

SetHandlerResolver(new HandlerResolver() { public List getHandlerChain(PortInfo portInfo) { List handlerList = new ArrayList(); handlerList. Add(new RGBSOAPHandler()); return handlerList; } }); FooPort port = service.getFooPort(); FooPayload payload = new FooPayload(); payload. SetHatSize(3); payload.

SetAlias("The Hat"); ... port. ProcessRequest(payload); and class RGBSOAPHandler implements SOAPHandler { public Set getHeaders() { return new TreeSet(); } public boolean handleMessage(SOAPMessageContext context) { Boolean outboundProperty = (Boolean) context. Get(MessageContext.

MESSAGE_OUTBOUND_PROPERTY); if (outboundProperty.booleanValue()) { SOAPMessage message = context.getMessage(); try { SOAPEnvelope envelope = context.getMessage() .getSOAPPart().getEnvelope(); SOAPFactory factory = SOAPFactory.newInstance(); String prefix = "X"; String uri = "http://...wsssecurity..."; SOAPElement securityElem = factory. CreateElement("Security",prefix,uri); SOAPElement tokenElem = factory. CreateElement("BinarySecurityToken",prefix,uri); tokenElem.

AddTextNode("kjh...897="); securityElem. AddChildElement(tokenElem); SOAPHeader header = envelope.addHeader(); header. AddChildElement(securityElem); } catch (Exception e) { System.out.

Println("Exception in handler: " + e); } } else { // inbound } return true; } public boolean handleFault(SOAPMessageContext context) { throw new UnsupportedOperationException("Not supported yet. "); } public void close(MessageContext context) { // } }.

I'm taking the same exact steps as you, but I'm getting the following exception: org. W3c.dom. DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted.

Have you encountered this issue? The app is running on weblogic 10.1 – Vladimir Feb 3 at 17:36.

You might want to look at handlers and handler chains. - I recently had to add a cookie to a given Webservice call and that was how I did it, just created a handler that intercepted the initial call and injected the cookie, you can also manipulate the call headers with a Pivot Handler.

Re John Saunders questions in his comment to my original question: It seems I require 50 reputation points before I can comment. Also stackoverflow's registration of new IDs is broken (pages says something's broken in web site). So I'm replying using "Your answer".

Does the WSDL describe the headers? Yes. It also uses SOAP 1.2 bindings that causes some grief.

I don't know how good the WSDL is. There is a lot of heavy duty XSD (in separate files). If so, then doesn't JAX-WS generate the code to add them?

The only tool I've tried that could digest the WSDL was NetBeans 6.5.1 and I asked it to generate classes from the WSDL and to insert the web-service client code for me. That code doesn't add SOAP Headers.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions