从 W3CEndpointReference 获取服务 URL

Getting the service URL from W3CEndpointReference

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

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

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

有没有其他办法把这个 属性 弄出来?一些 util class 或者可能将端点引用转换为 BindingProvider 或其他一些相关的 class?

如果有任何想法,我将不胜感激。提前致谢

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

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