java - 获取 CXF 端点的 URL

标签 java web-services cxf

情况

我正在使用 Apache CXF 2.6.2 将 Web 服务部署到 Tomcat 服务器。我正在使用 CXFServlet 和以下基于 Spring 的配置导出服务:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xsi:schemaLocation="
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
         http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
    <import resource="classpath:META-INF/cxf/cxf.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

    <jaxws:endpoint id="test_endpoint"
                    implementor="org.xyz.TestImpl"
                    address="/test"/>

    <bean id="testBean" class="org.xyz.TestBean">
        <property name="endpoint" ref="test_endpoint" />
    </bean>
</beans>

在我的示例部署中,CXFServlet 使用相对路径/service,例如,由 TestImpl 类实现的 Web 服务可作为 http://domain.com/tomcat-context/services/test 使用。 TestBean 类有一个端点 setter ,它由 Spring 设置。

目标

我想使用端点字段确定类 TestBean 中端点 test_endpoint 提供的地址 (URL)。结果应该是“http://domain.com/tomcat-context/services/test”。

我尝试过的

log.info("Endpoint set to " + endpoint);
log.info("Address: " + endpoint.getAddress());
org.apache.cxf.jaxws.EndpointImpl ep = (org.apache.cxf.jaxws.EndpointImpl) endpoint;
log.info("Other Address: " + ep.getBindingUri());
log.info("Props: " + ep.getProperties());

但结果只是

Address: /Sachbearbeiter
Other Address: null
Props: {}

如何获得完整的 URL?有没有不自己搭建的方法?

最佳答案

您是否尝试查看 CXF 消息以查看它是否在其中一个属性中?我将 Camel 与 CXF 一起使用,并像这样获取实际的 CXF 消息:

Message cxfMessage = exchange.getIn().getHeader(CxfConstants.CAMEL_CXF_MESSAGE, Message.class);

您应该能够像这样在普通 CXF 中获取 CXF 消息:

PhaseInterceptorChain.getCurrentMessage()

请参阅此网址:Is there a way to access the CXF message exchange from a JAX-RS REST Resource within CXF?

从那里,您可以获得如下属性:

org.apache.cxf.request.url=someDomain/myURL

关于java - 获取 CXF 端点的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12695722/

相关文章:

java - 什么都没有输入时,如何在edittext中将默认值设置为0?

java - 如何检查哪些复选框已选中,哪些未选中?

java - 需要网络服务方面的帮助

java - FTPing 文件而不引用物理目录

Java 将图像加载到类 - 最有效的做法?

Java:查找可导航集的上一个和下一个值

web-services - 将记录从 Netsuite 发送到外部系统的最佳方式?

java - 使用 cxf 客户端发送 BASIC 身份验证凭据

cxf - 如何使用蓝图配置 CXF JAX-WS 服务器

web-services - CXF JAXB JAXBEncoderDecoder 解码错误 : unexpected element when having qualified elements