在创建Web服务客户端时接收“未处理的'mustUnderstand'头元素”

时间:2013-04-16 10:08:00

标签: java web-services resteasy webservice-client webservices-client

我正在开发一个Web服务客户端。

Unprocessed 'mustUnderstand' header element: {http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Security

只要它在SoapUI中正常工作,就会返回正确的响应,并带有以下标题:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <S:Header>
      <wsse:Security S:mustUnderstand="1">
         <wsu:Timestamp wsu:Id="XWSSGID-13660988101781895308327" xmlns:ns15="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity" xmlns:ns14="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512" xmlns:ns13="http://www.w3.org/2003/05/soap-envelope">
            <wsu:Created>2013-04-16T08:02:05Z</wsu:Created>
            <wsu:Expires>2013-04-16T08:07:05Z</wsu:Expires>
         </wsu:Timestamp>
      </wsse:Security>
   </S:Header>

我不能使用wsHttpBinding。我的要求是:

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
   <env:Header>
      <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <wsse:UsernameToken>
            <wsse:Username>wstest</wsse:Username>
            <wsse:Password>wstest</wsse:Password>
         </wsse:UsernameToken>
      </wsse:Security>
   </env:Header>
   <env:Body>
     <-- client method call implementation>
   </env:Body>
</env:Envelope>

请帮助我。

1 个答案:

答案 0 :(得分:0)

在getHeaders()方法中,您需要返回一个包含根元素的XML元素。在这种情况下,我将使用以下实例化构建一个QName元素并添加到Set并在getHeaders元素中返回该元素:

@Override
public Set<QName> getHeaders(){
Set<QName> headers = new HashSet<QName>();
QName ck = new QName("http://coldyak.com", "coldyak", "cyk");
headers.add(ck);
return headers;
}

这就是处理mustunderstand属性所需的全部内容。它有点像强制Web服务处理标题元素的契约。