【发布时间】:2023-03-26 09:10:02
【问题描述】:
我正在使用 CXF 开发网络服务。我使用 HTTP 绑定,因此根据http://www.w3.org/TR/wsdl#_soap:operation soapaction 对于这种类型的传输是强制性的。
问题是我想为测试和生产服务器部署相同的应用程序。我想在不重新构建应用程序或保留外部 WSDL 文件的情况下执行此操作,这将在维护列表中增加一件事。
location 我也遇到了同样的问题,但解决起来很简单。我在端点配置中使用 publishedEndpointUrl 来设置正确的值。该值是在应用程序初始化期间从外部属性文件中检索的,我将其放在类路径 tomcat/common/classes 上。
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:soap="http://cxf.apache.org/bindings/soap" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:ws.properties</value>
</list>
</property>
</bean>
<jaxws:endpoint xmlns:tns="http://example.org/ds" id="ds" implementor="org.example.Ds" wsdlLocation="wsdl/ds.wsdl" endpointName="tns:dsSOAP" serviceName="tns:Ds" address="/dsSOAP" publishedEndpointUrl="${publishedEndpointUrl}">
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
</jaxws:endpoint>
</beans>
我想为soapaction 实现相同的功能。此属性的值不应是相对 URI。所以对于测试它应该是:
<soap:operation soapAction="https://test.example.org/dsSOAP/operation1" />
用于生产
<soap:operation soapAction="https://example.org/dsSOAP/operation1" />
知道如何实现吗?
【问题讨论】:
-
您的测试和生产服务为什么需要不同的soapActions?如果两个服务使用相同的 WSDL,您可以定义一次soapAction 并使用相同的soap 动作进行测试和生产。
-
@YogeshChawla 如果由于文档原因我没有错,属性
soapAcion需要使用绝对网址。因此我不能放一个相对的dsSOAP/operation1。对于测试和生产具有相同的值,我最终可能会导致客户端开始调用生产服务器而不是测试服务器。 -
嗨 Aleksander,它应该是一个完整的非相对 URI,但不需要描述被调用的实际物理地址。您可以在两个平台上使用:“example.org/dsSOAP/operation1”。否则,您将需要每个平台唯一的 WSDL。
-
我不想为每个环境使用不同的 WSDL。这就是为什么我一直在寻找一种方法来制作
soapAction变量。我知道这个属性不是端点位置,但是在测试环境中使用生产 URI 让我感到不舒服。对我来说没有区别。然而,据我所知,soapAction被用于路由。因此对其他人来说可能很重要。 -
为了路由您的消息,我会看看 WS-Addressing:w3.org/Submission/ws-addressing 但是您可能正在处理使用 SoapAction 进行路由的现有实现。
标签: web-services soap action cxf operation