JaxWS:外部化Http Conduit名称属性

问题描述 投票:2回答:3

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

我使用jax ws创建了webservice客户端。 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
 ----------------------------     

我的春天语境......

 <?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>

我已经做了很多在线搜索,以便知道name属性的有效值。

根据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:Unauthorized'

我有很多方法可以工作

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 name属性不是:(

<http-conf:conduit name="${webservices.http.conduit.property.name}">

作为一种解决方法,我目前使用的正则表达式方法有效..

<http-conf:conduit name="*.*/fold-webservices/services/UpdateService">

但我真的想弄清楚是否有可能将其外化并从属性文件中读取。我想做Spring配置方式。请帮我 !!!

web-services soap apache-camel jax-ws webservices-client
3个回答
2
投票

我有同样的问题...

在我的情况下,以下2个更改有助于:

1)将“端口”后缀添加到端口名称,尽管它没有在wsdl中定义

e.g wsdl: 
<wsdl:port name="XXXSoap">

将在管道定义中为“XXXSoapPort”

2)删除目标命名空间名称末尾的“\”

==>因此尝试

<http-conf:conduit name="{http://facade.fold.com}UpdateServiceImplPort.http_conduit">
or 
<http-conf:conduit name="{http://facade.fold.com}UpdateServiceImplPortPort.http_conduit">

1
投票

我们遇到了与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)接口类定义为:

@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”,即附加“端口”。但是,在org.apache.cxf.jaxws.support.JaxWsImplementorInfo.getEndpointName()中查看如何解析portQName,如果未在WS接口类中设置端口名称,并且名称不为null或为空,则会设置端口名称为portName = name + "Port",否则将其设置为portName = implementorClass.getSimpleName() + "Port"


0
投票

我遇到了同样的挑战,发现没有现成的解决方案。 Spring似乎没有解决bean名称中的占位符(很有意义)。但是,除非cxf允许使用其他属性进行管道匹配,否则这是一种有效的情况。

有几种方法可以解决这个问题:

  1. 以编程方式定义管道bean(丢失整齐的xml声明)
  2. 找到一种方法来解析包含占位符的bean名称

我更喜欢选项1,这是我很满意的实现。请注意,PropertyPlaceholderResolver是我们自己的实用程序,它使用相同的定义的解析程序bean。

public class NameWithPlaceholderBeanFactoryPostProcessor implements BeanFactoryPostProcessor
{
    @Override
    public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException
    {
        if (!(beanFactory instanceof DefaultListableBeanFactory))
            return;

        DefaultListableBeanFactory bf = (DefaultListableBeanFactory) beanFactory;

        String[] names = bf.getBeanDefinitionNames();
        for (String name : names)
        {
            if (name.indexOf('$') < 0)
                continue;

            BeanDefinition bd = bf.getBeanDefinition(name);
            bf.removeBeanDefinition(name);
            bf.registerBeanDefinition(PropertyPlaceholderResolver.resolvePlaceHolders(name), bd);
        }
    }
}

最后一步是将其定义为一个spring bean。

© www.soinside.com 2019 - 2024. All rights reserved.