使用HttpCllient的Spring集成代理设置

时间:2015-09-21 21:38:17

标签: http proxy spring-integration

我正在使用Spring集成4.1.2(ws和core)尝试在传输上使用HTTPClient(apache)。

我认为在阅读和配置messageSendermessageFactory之后,Spring将使用在XML上配置的设置(应用程序上下文),但配置无法按预期工作。

我的xml配置HttpClient如下:

   <bean id="requestConfigBuilder" class="org.apache.http.client.config.RequestConfig" factory-method="custom">
            <property name="socketTimeout" value="${saog.connection.timeout}" /> 
            <property name="connectTimeout" value="${saog.connection.timeout}" /> 
        </bean>

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

<bean id="httpHostProxy" class="org.apache.http.HttpHost">
        <constructor-arg index="0" value="10.1.6.91" ></constructor-arg>
        <constructor-arg  index="1" value="80"></constructor-arg>
    </bean>

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

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

    <bean id="httpComponentsClientHttpRequestFactory" class="org.springframework.http.client.HttpComponentsClientHttpRequestFactory">
        <constructor-arg ref="httpClient"/>
    </bean>     

    <bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
    </bean>

    <bean id="defaultMessageSender" class="org.springframework.ws.transport.http.HttpComponentsMessageSender">
        <constructor-arg ref="httpClient"/>
    </bean>

    <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
        <constructor-arg ref="messageFactory"/>
        <property name="messageSender" ref="defaultMessageSender" />
    </bean>

从这里使用ws:outbound-gateway我遇到了一些配置问题:

我使用以下参数作为配置进行了服务:

    <ws:outbound-gateway
        uri="${server.address}/${endpoint}"
        interceptor="anintercerptor"
        message-factory="messageFactory"  message-sender="defaultMessageSender">
        <ws:request-handler-advice-chain>
                <ref bean="retryAdvice" />
        </ws:request-handler-advice-chain>          
    </ws:outbound-gateway>  

但是当我调试代理时没有设置代理(但超时是超时并且超时是在同一个bean配置中)。并且ApplicationServer抛出异常,令我惊讶的是,transport(http)是JavaNative传输。

错误示例如下:

java.io.IOException:
                        java.net.ConnectException: Connection timed out: connect
         at java.net.PlainSocketImpl.socketConnect(Native Method)
         at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:412)
         at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:271)
         at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:258)
         at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:376)
         at java.net.Socket.connect(Socket.java:546)
         at java.net.Socket.connect(Socket.java:495)
         at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
         at sun.net.www.http.HttpClient.openServer(HttpClient.java:437)
         at sun.net.www.http.HttpClient.openServer(HttpClient.java:551)
         at com.ibm.net.ssl.www2.protocol.https.c.<init>(c.java:143)
         at com.ibm.net.ssl.www2.protocol.https.c.a(c.java:67)
         at com.ibm.net.ssl.www2.protocol.https.d.getNewHttpClient(d.java:55)
         at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:935)
         at com.ibm.net.ssl.www2.protocol.https.d.connect(d.java:10)
         at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1043)
         at com.ibm.net.ssl.www2.protocol.https.b.getOutputStream(b.java:62)
         at org.springframework.ws.transport.http.HttpUrlConnection.getRequestOutputStream(HttpUrlConnection.java:85)
         at org.springframework.ws.transport.AbstractSenderConnection$RequestTransportOutputStream.createOutputStream(AbstractSenderConnection.java:106)
         at org.springframework.ws.transport.TransportOutputStream.getOutputStream(TransportOutputStream.java:41)
         at org.springframework.ws.transport.TransportOutputStream.write(TransportOutputStream.java:64)
         at com.ibm.ws.webservices.utils.LowFlushFilter.write(LowFlushFilter.java:70)
         at sun.nio.cs.StreamEncoder$CharsetSE.writeBytes(StreamEncoder.java:355)
         at sun.nio.cs.StreamEncoder$CharsetSE.implFlushBuffer(StreamEncoder.java:425)
         at sun.nio.cs.StreamEncoder$CharsetSE.implFlush(StreamEncoder.java:429)
         at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:175)
         at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:274)
         at com.ibm.ws.webservices.utils.BufferedWriter.flush(BufferedWriter.java:318)
         at com.ibm.ws.webservices.engine.SOAPPart.writeTo(SOAPPart.java:841)
         at com.ibm.ws.webservices.engine.Message.writeTo(Message.java:669)
         at org.springframework.ws.soap.saaj.SaajSoapMessage.writeTo(SaajSoapMessage.java:275)
         at org.springframework.ws.transport.AbstractWebServiceConnection.send(AbstractWebServiceConnection.java:46)
         at org.springframework.ws.client.core.WebServiceTemplate.sendRequest(WebServiceTemplate.java:654)
         at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:603)
         at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)
         at org.springframework.integration.ws.SimpleWebServiceOutboundGateway.doHandle(SimpleWebServiceOutboundGateway.java:93)
         at org.springframework.integration.ws.AbstractWebServiceOutboundGateway.handleRequestMessage(AbstractWebServiceOutboundGateway.java:188)
         at org.springframework.integration.handler.AbstractReplyProducingMessageHandler$AdvisedRequestHandler.handleRequestMessa

并提示如何使用SpringIntegration上的HttpClient来解决代理配置设置?

的问候。

何塞卡洛斯卡诺瓦。

0 个答案:

没有答案