从W3CEndpointReference获取服务URL

时间:2016-03-30 22:37:17

标签: java web-services soap jax-ws

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

<input>

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

还有其他办法让这个房产出来吗?一些util类或者可能将端点引用转换为BindingProvider或其他一些相关类?

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

1 个答案:

答案 0 :(得分: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;
}

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

相关问题