标题没有被注入请求

时间:2013-04-17 12:26:05

标签: java web-services soap jax-ws

我正在使用SOAPHandler,这是客户端的getHeaders方法:

@Override
public Set<QName> getHeaders() {
    String uri = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
    QName security_hdr = new QName(uri, "Security", "wsse");
    HashSet<QName> headers = new HashSet<QName>();
    headers.add(security_hdr);
    System.out.println("Headers: " + headers);
    return headers;
}

上面一行中的SystemOut产生了这段代码,所以我确实从我的方法中返回了一些内容:

Headers: [{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Security]

但是,当尝试在 TCPMon 中捕获请求时,我根本看不到标题。

POST /ws/server HTTP/1.1
Content-type: text/xml;charset="utf-8"
Soapaction: ""
Accept: text/xml, multipart/related, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
User-Agent: JAX-WS RI 2.1.6 in JDK 6
Host: 127.0.0.1:4027
Connection: keep-alive
Content-Length: 170

<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body><ns2:getServerName xmlns:ns2="http://ws.ronixus.com/"/></S:Body>
</S:Envelope>

知道我在这里缺少什么吗?我已经注释掉了其他回调方法handleMessage中的代码,以确保没有覆盖标题。

1 个答案:

答案 0 :(得分:0)

也许在handleMessage中尝试这个,只是为了确认?

SOAPHeader soapHeader = soapEnv.getHeader();

Iterator headers = soapHeader.extractAllHeaderElements();
while(headers.hasNext() ){
    SOAPHeaderElement headerElement = (SOAPHeaderElement) headers.next();

    Name name = headerElement.getElementName();
    System.out.println(name)
}