繁体   English   中英

SharePoint Web Services jax-ws命名空间冲突

[英]SharePoint Web Services jax-ws namespace conflict

我正在尝试使用SharePoint Web服务来检索列表更改,但是jax-ws客户端生成的内容与SharePoint将接受的内容之间似乎存在命名空间冲突。 下面是jax-ws生成的xml。

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body>
    <GetListItemChanges xmlns="http://schemas.microsoft.com/sharepoint/soap/">
      <listName>Documents</listName>
      <viewFields>
        <FieldRef Name="Modified"/>
        <FieldRef Name="_CheckinComment"/>
        <FieldRef Name="Title"/>
        <FieldRef Name="Created"/>
      </viewFields>
      <since>1970-01-01T00:00:00</since>
      <contains/>
    </GetListItemChanges>
  </S:Body>
</S:Envelope>

我需要从GetListItemChanges中删除xmlns =“ http://schemas.microsoft.com/sharepoint/soap/”。 我尝试了以下内容(及其各种排列),但这些更改似乎被忽略了。 调试时会删除xmlns,但输出xml不会更改。

public class SharePointSoapHandler implements SOAPHandler<SOAPMessageContext> {
  ...
 @Override
  public boolean handleMessage(SOAPMessageContext p_soapMessageContext) {
    try {
      SOAPMessage l_soapMessage = p_soapMessageContext.getMessage();
      l_soapMessage.getSOAPBody().getFirstChild().getAttributes().removeNamedItem("xmlns");
      l_soapMessage.saveChanges();
      ByteArrayOutputStream l_outputStream = new ByteArrayOutputStream();
      l_soapMessage.writeTo(l_outputStream);
      m_logger.info(new String(l_outputStream.toByteArray()));
    } catch (Exception ex) {
      m_logger.error("Soap exception modifying xml for request", ex);
    }
    return true;
  }
}

我想念什么吗? 有没有更好的方法来完成此操作,或者我需要手工生成xml?

编辑:使用soap ui的有效soap请求。 jax-ws删除第二个前缀并移动xmlns属性。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.microsoft.com/sharepoint/soap/">
   <soapenv:Header/>
   <soapenv:Body>
      <soap:GetListItemChanges>
         <!--Optional:-->
         <soap:listName>Shared Documents</soap:listName>
         ...
         <soap:since>2012-02-15T00:00:00</soap:since>

      </soap:GetListItemChanges>
   </soapenv:Body>
</soapenv:Envelope>

请参阅更改使用JAXWS生成的默认XML名称空间前缀,以使用处理程序来拦截肥皂并根据需要进行修改; 这也是调试肥皂通过电线发送时的有用技术。

您还可以像下面这样在soap标头中设置名称空间声明:

SOAPMessage request = factory.createMessage();
SOAPEnvelope envelope = request.getSOAPPart().getEnvelope();
envelope.addNamespaceDeclaration("uri", "uri:foo.bar.com");
request.saveChanges();

然后使用以下名称空间前缀创建元素:

SOAPBody body = request.getSOAPBody();
SOAPElement ping = body.addChildElement("foo", "uri");

如果不先在标题中设置声明,则添加带有前缀的元素将失败。

以这种方式执行操作似乎可以避开将名称空间声明挂在主体节点上的方法,这打破了我的尝试。

这是我用来验证此工作的jUnit测试:

public void testPing() throws Exception {

String endpoint = "http://www.foo.bar/ws/someWebservice";
QName port = new QName(endpoint, "uri");
QName serviceName = new QName(endpoint, "someWebserviceMethod");

Service service = Service.create(serviceName);
service.setHandlerResolver(new MyHandlerResolver());
service.addPort(port, SOAPBinding.SOAP11HTTP_BINDING, endpoint);

Dispatch<SOAPMessage> dispatch = service.createDispatch(port, SOAPMessage.class, Service.Mode.MESSAGE);
MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
SOAPMessage request = factory.createMessage();

SOAPEnvelope envelope = request.getSOAPPart().getEnvelope();
envelope.addNamespaceDeclaration("uri", "uri:bar.foo");
request.saveChanges();

SOAPBody body = request.getSOAPBody();

SOAPElement element = body.addChildElement("someRequestElement", "uri");
SOAPElement child = ping.addChildElement("someRequestChild");

SOAPElement text_node = child.addChildElement("someTextNode");
messageType.addTextNode("test text");

request.saveChanges();

System.out.println();
request.writeTo(System.out);
System.out.println();

Object o = dispatch.invoke(request);

System.out.println("ret: " + o.toString());

assertNotNull( o );

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM