开发者

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>

wi开发者_如何学JAVAth 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜