web-services - 贾克斯WS : Externalize Http Conduit name Attribute

标签 web-services soap apache-camel jax-ws webservices-client

我有需要通过 http 调用的 SOAP Web 服务的 WSDL 文件。使用 cxf wsdl2java 插件我创建了 stub 方法。

我已经使用 jaxws 创建了 web 服务客户端。 Web 服务启用了基本身份验证。我正在尝试配置 http 管道

 my application.properties
 --------------------------
 webservices.http.auth.username=username
 webservices.http.auth.password=password
 fold.webservices.http.auth.authtype=Basic
 webservices.http.conduit.property.name=https://fixed_deposits-test.co.in/fold-webservices/services.*
 fold.updateservice.soap.address=https://fixed_deposits-test.co.in/fold-webservices/services/UpdateService
 ----------------------------     

My Spring Context...


 <?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"
        xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
        xmlns:sec="http://cxf.apache.org/configuration/security"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                    http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
                    http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd
                    http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

   <bean id="properties" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
      <property name="locations">
        <util:list>
            <value>file:${config.dir}/application.properties</value>
        </util:list>
      </property>
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
   </bean>

   <jaxws:client id="updateServiceClient" serviceClass="com.fold.facade.v1.UpdateService" address="${fold.updateservice.soap.address}" >
      <jaxws:inInterceptors>
        <bean id="loggingInInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor" >
            <property name="prettyLogging" value="true" />
        </bean>
      </jaxws:inInterceptors>
      <jaxws:outInterceptors>
        <bean id="loggingOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor" >
            <property name="prettyLogging" value="true" />
        </bean>
      </jaxws:outInterceptors>
   </jaxws:client>

  <http-conf:conduit name="***?????????***">
    <http-conf:authorization>
        <sec:UserName>${fold.webservices.http.auth.username}</sec:UserName>
        <sec:Password>${fold.webservices.http.auth.password}</sec:Password>
        <sec:AuthorizationType>${fold.webservices.http.auth.authtype}</sec:AuthorizationType>
    </http-conf:authorization>
</http-conf:conduit>

我在网上做了很多搜索,以确定 的有效值是多少?名称属性..

根据 CXF 文档,它应该是......
{WSDL_endpoint_target_namespace}PortName.http-conduit

我的 WSDL 文件有..
...
targetNamespace="http://facade.fold.com/" and
...
<wsdl:port binding="tns:UpdateServiceImplServiceSoapBinding"
        name="UpdateServiceImplPort">
        <soap:address
            location="https://fixed_deposits-test.co.in/fold-webservices/services/UpdateService" />
    </wsdl:port>

所以我尝试了这些..
<http-conf:conduit name="{http://facade.fold.com/}UpdateServiceImplPort.http_conduit">
or
<http-conf:conduit name="*UpdateServiceImplPort.http_conduit">
or
<http-conf:conduit name="{http://facade.fold.com/}*.http_conduit">

但是它们都不起作用,因为我得到 401 未经授权的异常..

org.apache.cxf.transport.http.HTTPException:与 https://fixed_deposits-test.co.in/fold-webservices/services/UpdateService 通信时的 HTTP 响应“401:未经授权”

THERE ARE COUPLE OF WAYS I GOT IT TO WORK


a) <http-conf:conduit name="*.http_conduit">

但我真的不想这样做...
b) <http-conf:conduit name="https://fixed_deposits-test.co.in/fold-webservices/services/UpdateService">

这是对 SOAP 服务 URL 进行硬编码...我不想要,因为我正在寻找外部化 URL,因为我的 SOAP URL 对于不同的环境是不同的......(dev/test/prod 等)

下面是我在外部化方面的最佳尝试,但它因 401 Unauthorized Exception 而失败...

在我的 spring 上下文中,所有其他实例中的属性都被替换了,但 http-conf:conduit 没有名称属性 :(
<http-conf:conduit name="${webservices.http.conduit.property.name}">

作为一种解决方法,我目前正在使用有效的正则表达式方法..
<http-conf:conduit name="*.*/fold-webservices/services/UpdateService">

But i really want to figure out if it possible to externalize it and read from properties file. And i want to do it the Spring configuration way. Please help me !!!

最佳答案

JBoss Fuse 6.1 (Camel CXF 2.12.0) 也有同样的问题。
您可以通过启用 DEBUG 日志级别并查看您的日志来查看 http-conf:conduit 名称设置的内容,应该有一个日志行,例如:

DEBUG 10:40:41,437 [Camel (cnpms-as-mnp-ctx) thread #0 - JmsConsumer[cnpms-queue]] org.apache.cxf.transport.http.HTTPConduit.setTlsClientParameters(HTTPConduit.java:901) - Conduit '{http://acme.com/manageporting/v1}ManageportingPortPort.http-conduit' has been (re)configured for plain http.

因此,在这种情况下,您可以将名称设置为:
<http-conf:conduit name="{http://acme.com/manageporting/v1}ManageportingPortPort.http-conduit"

但是 Web 服务(WS)接口(interface)类被定义为:
@WebService(targetNamespace = "http://acme.com/manageporting/v1", name = "ManageportingPort")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface ManageportingPort {

从 WSDL 生成:
<wsdl:portType name="ManageportingPort">

请注意,按照 CXF documentation您会期望端口名称组件是“ManageportingPort”而不是“ManageportingPortPort”,即附加了“Port”。
但是查看 org.apache.cxf.jaxws.support.JaxWsImplementorInfo.getEndpointName() 中的 portQName 是如何解析的,如果端口名称未在 WS 接口(interface)类中设置,并且名称不为 null 或空白,则会设置端口名称为 portName = name + "Port"否则将其设置为 portName = implementorClass.getSimpleName() + "Port" .

关于web-services - 贾克斯WS : Externalize Http Conduit name Attribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31072830/

相关文章:

web-services - 为什么将 SOAP 用于 Web 服务?

java - Camel Rest DSL 响应编码

java - 异常 : defaultEndpoint must be specified. 对于 Camel AWS SES for direct:start

java - 如何在 Camel 路由上模拟 Kafka Consumer 端点?

soap - 在wsdl文件中是否可以要求参数的最小和最大字符串长度?

.net - 使用 Android 调用 .NET Webservice

java - 在 spring 托管 bean 的构造函数中初始化 Jersey 客户端

.net - 记录 .net SOAP Web 服务的请求/响应

xml - WCF 契约(Contract)第一个 : No methods are exposed

android - 何时使用 Soapobject 和 SoapPrimitive