【问题标题】:Getting the service URL from W3CEndpointReference从 W3CEndpointReference 获取服务 URL
【发布时间】:2016-03-30 22:37:16
【问题描述】:

我正在实现一个 Web 服务,但是标准定义我接收 W3CEndpointReference 作为请求的一部分。在 xml 中,它看起来有点像以下:

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

问题是我需要访问地址部分,但 W3CEndpointReference 出于某种原因没有公共地址字段访问器。 到目前为止,我讨厌的唯一可行的解​​决方案是在 W3CEndpointReference 上调用 .toString() 并使用正则表达式获取地址。

还有其他方法可以取出这个属性吗?一些 util 类,或者可能将端点引用转换为 BindingProvider 或其他相关类?

我会很感激任何想法。提前致谢

【问题讨论】:

    标签: java web-services soap jax-ws


    【解决方案1】:

    在 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;
    }
    

    也许不是最漂亮的,但肯定比用正则表达式提取地址要好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-08
      • 2015-11-26
      • 2019-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-23
      • 2010-11-20
      相关资源
      最近更新 更多