简体   繁体   English

如何在soap中忽略TargetNamespace

[英]How to ignore TargetNamespace in soap

I have a Soap service generated by a wsdl file, that expects a certain TargetNamespace我有一个由 wsdl 文件生成的 Soap 服务,它需要某个 TargetNamespace

@WebResult(name = "getResponse", targetNamespace = "http://targetNameSpace1.com", partName = "result")

but we have multiple clients calling this api and each one uses a diferente TargetNamespace:但是我们有多个客户端调用这个 api,每个客户端都使用不同的 TargetNamespace:

Client one:客户一:

<soap:Envelope
    xmlns:loc="http://targetNameSpace1.com">
    <soap:Header>
        <ns3:RequestSOAPHeader>
           ...
        </ns3:RequestSOAPHeader>
    </soap:Header>
    <soap:Body>
        <loc:getResponse>
            <loc:value>url/</loc:value>
        </loc:getResponse>
    </soap:Body>
</soap:Envelope>

Client two:客户二:

<soap:Envelope
    xmlns:loc="http://targetNameSpace2.com">
    <soap:Header>
        <ns3:RequestSOAPHeader>
           ...
        </ns3:RequestSOAPHeader>
    </soap:Header>
    <soap:Body>
        <loc:getResponse>
            <loc:value>url/</loc:value>
        </loc:getResponse>
    </soap:Body>
</soap:Envelope>

This is the error i get:这是我得到的错误:

<soap:Envelope>
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Client</faultcode>
         <faultstring>Message part {http://targetNameSpace2.com}getResponse was not recognized.  (Does it exist in service WSDL?)</faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

and i can only make it work with one at a time changing the targetNameSpace tag in the webResult, but my ultimate goal is to ignore this tag, because i dont know witch namespace will each client use.并且我一次只能使用一个更改 webResult 中的 targetNameSpace 标记,但我的最终目标是忽略此标记,因为我不知道每个客户端都会使用女巫命名空间。

At the moment i am trying to use an interceptor that extends this AbstractSoapInterceptor and i get a SoapMessage object i can acess it before the request is made, but i can't seem to change the request, not sure if its the best aproach.目前我正在尝试使用一个扩展这个AbstractSoapInterceptor的拦截器,我得到一个 SoapMessage 对象,我可以在发出请求之前访问它,但我似乎无法更改请求,不确定它是否是最好的方法。

Does anyone have a solution for this?有没有人对此有解决方案?

Thanks!谢谢!

The wsdl and the (embedded) xsd are the contracts that you specify. wsdl 和(嵌入式)xsd 是您指定的契约。 Server and client need to follow that contract.服务器和客户端需要遵守该合同。 Changing the contract single sided will result into invalid messages.单方面更改合约将导致无效消息。 Instead of looking for a solution to accept invalid messages you should update the clients so they obey the contracts.与其寻找接受无效消息的解决方案,不如更新客户端,使其遵守合同。

I ended up following this article https://www.javatips.net/blog/cxf-interceptor-example ,我最终关注了这篇文章https://www.javatips.net/blog/cxf-interceptor-example

I intercept every request, and replace this:我拦截每个请求,并替换它:

xmlns:loc="http://targetNameSpace2.com"

with the url that i want, i used regex to replace whats inside the loc tag使用我想要的网址,我使用正则表达式替换 loc 标签内的内容

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

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