简体   繁体   English

从 W3CEndpointReference 获取服务 URL

[英]Getting the service URL from W3CEndpointReference

I'm implementing a web service, however the standard defines that I receive W3CEndpointReference as a part of the request.我正在实现一个 Web 服务,但是标准定义我接收 W3CEndpointReference 作为请求的一部分。 In the xml it looks somewhat like the following:在 xml 中,它看起来有点像以下内容:

<b:ConsumerReference>
      <add:Address>http://localhost:8088/NotificationConsumer?wsdl</add:Address>
      <!--Optional:-->
      <add:ReferenceParameters/>
      <!--Optional:-->
      <add:Metadata/>
</b:ConsumerReference>

The thing is I need to get to the address part, but W3CEndpointReference for some reason does not have a public address field accessor.问题是我需要访问地址部分,但 W3CEndpointReference 由于某种原因没有公共地址字段访问器。 The only working solution I got so far, which I hate, is calling .toString() on the W3CEndpointReference and getting the address using a regex.到目前为止,我唯一讨厌的可行解决方案是在 W3CEndpointReference 上调用 .toString() 并使用正则表达式获取地址。

Is there any other way to get this property out?有没有其他方法可以把这个属性拿出来? Some util class or maybe casting the endpoint reference to the BindingProvider or some other related class?一些 util 类或者可能将端点引用转换为 BindingProvider 或一些其他相关类?

I would appreciate any ideas.我将不胜感激任何想法。 Thanks in advance提前致谢

Solution found in Apache CXF implementation:在 Apache CXF 实现中找到的解决方案:

public String getWSAAddress(W3CEndpointReference ref) {
    Element element = DOMUtils.createDocument().createElement("elem");
    ref.writeTo(new DOMResult(element));
    NodeList nl = element.getElementsByTagNameNS("http://www.w3.org/2005/08/addressing", "Address");
    if (nl != null && nl.getLength() > 0) {
        Element e = (Element) nl.item(0);
        return DOMUtils.getContent(e).trim();
    }
    return null;
}

Maybe not the prettiest, but certainly better than extracting the address with regex.也许不是最漂亮的,但肯定比用正则表达式提取地址要好。

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

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