Stan Kurilin
Stan Kurilin

Reputation: 15792

Add header to SOAP message

I need add custom soap header, like login I do it in way like this

class Foo implements SOAPHandler<SOAPMessageContext> {
    public boolean handleMessage(SOAPMessageContext context) {
        try {
            SOAPMessage soapMsg = context.getMessage();
            SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
            soapEnv.addHeader().addAttribute(new QName("login"), "bob");

            soapMsg.writeTo(System.out);//tracing OUT
            return true;
        } catch (SOAPException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

@HandlerChain(file="handler-chain.xml")//I describe Foo in this file
public class GreeterService

By tracing out I get message

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Header login="bob"/><S:Body><ns2:sayGoodbye xmlns:ns2="http://example.com/"><arg0>SOAP</arg0></ns2:sayGoodbye></S:Body></S:Envelope>

with header

 <S:Header login="bob"/>

But server received it without any header

 <?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:sayGoodbye xmlns:ns2="http://example.com/"><arg0 xmlns="">SOAP</arg0></ns2:sayGoodbye></S:Body></S:Envelope>

What I make wrong?

Upvotes: 1

Views: 5814

Answers (1)

StKiller
StKiller

Reputation: 7941

I had the similar issue few days ago, there was a need to send user id by header.

I resolved this problem with special parameter - wsimport -XadditionalHeaders when generating code.

Upvotes: 4

Related Questions