【问题标题】:PropertyAccessException in Apache camel Spring Ws ConfigurationApache骆驼Spring Ws配置中的PropertyAccessException
【发布时间】:2016-03-15 08:26:22
【问题描述】:

我想将 Spring-ws 连接管理器配置为使用PoolingHttpClientConnectionManager。这是我的配置

骆驼上下文.xml

<camel-context>
    <route>
        <from uri="direct:sampleCall"/>
        <to uri="bean:sampleCommand"/>
        <to uri="spring-ws:http://{{sample.uri}}?timeout={{sample.timeout}}&amp;messageSender=#messageSender&amp;soapAction=urn:MidwareWebServiceIntf-MidwareWebService#sampleCommand"/>
        <to uri="bean:xmlProcessor"/>
        <to uri="bean:validateResponse"/>
    </route>

    <route>
        <from uri="direct:anotherSampleCall"/>
        <to uri="bean:anotherSampleCommand"/>
        <to uri="spring-ws:http://{{anotherSample.uri}}?timeout={{anotherSample.timeout}}&amp;messageSender=#messageSender&amp;soapAction=urn:MidwareWebServiceIntf-MidwareWebService#ExecuteCommand"/>
        <to uri="bean:trimResponse"/>
        <to uri="bean:xmlProcessorTrim"/>
        <to uri="bean:validateResponse"/>
    </route>



</camelContext>



<bean id="messageSender" class="org.springframework.ws.transport.http.HttpComponentsMessageSender">
    <property name="httpClient" ref="httpClient"/>
    <property name="readTimeout" value="30000"/>
    <property name="connectionTimeout" value="30000"/>
</bean>


<bean id="requestConfigBuilder" class="org.apache.http.client.config.RequestConfig"
      factory-method="custom">
    <property name="socketTimeout" value="30000" />
    <property name="connectTimeout" value="30000" />
</bean>

<bean id="requestConfig" factory-bean="requestConfigBuilder" factory-method="build" />

<bean id="poolingConnectionManager" class="org.apache.http.impl.conn.PoolingHttpClientConnectionManager">
    <property name="defaultMaxPerRoute" value="20"/>
    <property name="maxTotal" value="20"/>
</bean>

<bean id="httpClientBuilder" class="org.apache.http.impl.client.HttpClientBuilder"
      factory-method="create">
    <property name="defaultRequestConfig" ref="requestConfig" />
    <property name="connectionManager" ref="poolingConnectionManager"/>
</bean>



<bean id="httpClient" factory-bean="httpClientBuilder" factory-method="build" />

但是当我运行项目时,我得到以下异常

org.springframework.beans.factory.BeanCreationException: Error creating bean     with name 'messageSender' defined in class path resource [camel-context.xml]
: Error setting property values; nested exception is   org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (2) are:
PropertyAccessException 1:  org.springframework.beans.MethodInvocationException: Property 'readTimeout'  threw exception; nested exception is java.lang.Uns
upportedOperationException
PropertyAccessException 2:  org.springframework.beans.MethodInvocationException: Property 'connectionTimeout' threw exception; nested exception is java.la
ng.UnsupportedOperationException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1506)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4751)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5175)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:919)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1704)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested   PropertyAccessExceptions (2) are:
PropertyAccessException 1:    org.springframework.beans.MethodInvocationException: Property 'readTimeout'    threw exception; nested exception is java.lang.Uns
upportedOperationException
PropertyAccessException 2:  org.springframework.beans.MethodInvocationException:  Property 'connectionTimeout' threw exception; nested exception is java.la
ng.UnsupportedOperationException
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:121)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1502)
    ... 26 more
15-Mar-2016 11:28:47.846 SEVERE [localhost-startStop-1]   org.apache.catalina.core.StandardContext.startInternal Error listenerStart
15-Mar-2016 11:28:47.847 SEVERE [localhost-startStop-1]       org.apache.catalina.core.StandardContext.startInternal Context [/camel##2.0.0]   startup failed due
to previous errors

这与我一起使用的 API 版本不兼容有关吗?

【问题讨论】:

    标签: java spring apache-camel apache-httpclient-4.x spring-ws


    【解决方案1】:

    感谢@smarquis 提供了非常有帮助的答案,我终于可以正确配置 Spring-Ws 连接管理器了。这是正确的配置。不要忘记使用interceptedHttpClientBuilder 部分。如果没有它,您会遇到此异常:org.apache.http.ProtocolException: Content-Length header already present(有关更多信息,请参阅此thread

    骆驼上下文

    <camel-context>
        <route>
            <from uri="direct:sampleCall"/>
            <to uri="bean:sampleCommand"/>
            <to uri="spring-ws:http://{{sample.uri}}?messageSender=#messageSender&amp;soapAction=urn:MidwareWebServiceIntf-MidwareWebService#ExecuteCommand"/>
            <to uri="bean:trimResponse"/>
            <to uri="bean:xmlProcessorTrim"/>
            <to uri="bean:validateResponse"/>
        </route>
    
    </camelContext>
    
    <bean id="messageSender" class="org.springframework.ws.transport.http.HttpComponentsMessageSender">
        <constructor-arg index="0" type="org.apache.http.client.HttpClient" ref="httpClient"/>
    </bean>
    
    
    <bean id="requestConfigBuilder" class="org.apache.http.client.config.RequestConfig"
          factory-method="custom">
        <property name="socketTimeout" value="${bank.webservice.timeout}" />
        <property name="connectTimeout" value="${bank.webservice.timeout}" />
    </bean>
    
    <bean id="requestConfig" factory-bean="requestConfigBuilder" factory-method="build" />
    
    <bean id="poolingConnectionManager" class="org.apache.http.impl.conn.PoolingHttpClientConnectionManager">
        <property name="defaultMaxPerRoute" value="20"/>
        <property name="maxTotal" value="20"/>
    </bean>
    
    
    
    <bean id="interceptedHttpClientBuilder" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetObject" ref="httpClientBuilder" />
        <property name="targetMethod" value="addInterceptorFirst"> </property>
        <property name="arguments">
            <list>
                <bean class="org.springframework.ws.transport.http.HttpComponentsMessageSender.RemoveSoapHeadersInterceptor"/>
            </list>
        </property>
    </bean>
    
    
    <bean id="httpClientBuilder" class="org.apache.http.impl.client.HttpClientBuilder"
          factory-method="create">
        <property name="defaultRequestConfig" ref="requestConfig" />
        <property name="connectionManager" ref="poolingConnectionManager"/>
    </bean>
    
    
    
    <bean id="httpClient" factory-bean="interceptedHttpClientBuilder" factory-method="build" />
    

    【讨论】:

      【解决方案2】:

      是的,HttpClient.getParams() 已被弃用,现在抛出 UnsupportedOperationException。

      HttpComponentsMessageSender 的 setReadTimeout() 和 setConnectionTimeout() 方法仅在底层 HttpClient 上设置这些值。

      所以你必须依赖 requestConfigBuilder(就像你已经为 socketTimeout 所做的那样)来直接配置 HttpClient。

      【讨论】:

      • 谢谢。我从 bean 配置中删除了 readTimeoutconnectionTimeout。我还使用&lt;constructor-arg&gt; 调用HttpComponentMessageSender 中的构造函数,该构造函数提供HttpClient 参数。但问题也存在。换句话说,调用 setReadTimeout 。我找到那个东西。那是骆驼弹簧ws模块中的SpringWebserviceProducer。请参阅此类的第 121 行
      • 同时从你的路由中的 spring-ws "to" uri 中删除 timeout={{sample.timeout}}。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-30
      • 2020-10-16
      相关资源
      最近更新 更多