我需要添加自定義的肥皂頭,就像登錄 我做的方式是這樣添加標題到SOAP消息
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
通過tracing out
我得到消息
<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>
與頭
<S:Header login="bob"/>
但服務器收到它沒有任何標題
<?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>
我做錯了什麼?
它是由wsimport生成代碼嗎? – StKiller 2011-04-14 19:30:56
@StKiller,正確。我只添加SOAPHandler。 – 2011-04-14 19:35:08