获取java.net.SocketException:在Apache骆驼路由中进行http4调用期间重置连接

时间:2018-11-27 11:18:42

标签: http apache-camel

我正在从目标服务器获取以下异常。我正在将骆驼的http组件迁移到http4组件。

2018-11-27 01:17:34,156 | ERROR | ernal.req.queue] | DefaultErrorHandler              | 81 - org.apache.camel.camel-core - 2.16.3 | Failed delivery for (MessageId: ID:ip-172-16-11-197-60068-1543219848548-41:1:1:1:1 on ExchangeId: ID-ip-172-16-11-197-36927-1543219848013-31-14). Exhausted after delivery attempt: 1 caught: java.net.SocketException: Connection reset

HTTP4请求标头(不起作用)-

POST /GenieWebService/documentgenerator.asmx HTTP/1.1  
Connection: Keep-Alive  
Content-Length: 28955  
Content-Type: text/xml; charset=utf-8  
Accept-Encoding: gzip,deflate  
Authorization: Basic ZXNidXNlcjpwYXNzd29yZA==  
Host: xmz.ab.a.aaa(This is not actual ip)  
User-Agent: Apache-HttpClient/4.5.1 (Java/1.7.0_79)   
breadcrumbId: ID-ip-abc-ad-ac-abc-36927-15432193242455-7-90    
EXTR_SERVICE_URL: http://abs.ab.a.abc/GenieWebService/documentgenerator.xmzx  
X-Forwarded-For: 111.93.62.106, 165.225.106.106  
X-Forwarded-Port: 80  
X-Forwarded-Proto: http 

HTTP请求标头(工作流程)

POST /GenieWebService/documentgenerator.asmx HTTP/1.1  
Content-Length: 66831  
Content-Type: text/xml;charset=utf-8  
Authorization: Basic ZXNidXNlcjpwYXNzd29yZA==  
Cookie: ASP.NET_SessionId=lairgud4nkaledjpuzarfqj0  
Host: abc.ab.a.abc
User-Agent: Jakarta Commons-HttpClient/3.1    
breadcrumbId: ID-ip-abc-ab-a-abc-34162-1542796372800-25-80  
EXTR_SERVICE_URL: http://abs.ab.a.abc/GenieWebService/documentgenerator.asmx   
X-Forwarded-For: 112.196.86.34, 165.225.106.89  
X-Forwarded-Port: 80  
X-Forwarded-Proto: http

根据我的理解,似乎是cookie标头。在http4请求标头中,当它位于http标头中时,我看不到cookie标头。 有人可以在这里帮助您解决什么问题吗,如果它与Cookie标头有关,那么我如何添加Cookie。我正在使用spring dsl和apache-camel 2.16.3版本。

2 个答案:

答案 0 :(得分:0)

您可以通过指定http4:// foo?httpClient.soTimeout = 100在客户端上设置100ms超时。发生超时时,它可能会引发一个异常,您可以像这样处理:

onException(IOException.class).to("direct:timeouts");

from("direct:start")
.setHeader(Exchange.HTTP_QUERY,simple("format=json&count=${in.headers.count}"))
.to("http4://www.host.com/someapi?httpClient.soTimeout=100")
.unmarshal().json(JsonLibrary.JACKSON,MyResponseType.class)
.to("bean:SomeBean?method=echo");

from("direct:timeouts").to("...");

答案 1 :(得分:0)

我已经使用httpClient.socketTimeout = 180000而不使用bridgeEndpoint选项,所以骆驼将使用我在标头中设置的http url。以下是我的路线。

<route> 
    <from uri="{{document-service.esb.new.document.internal.req.queue.name}}"/>     
    <convertBodyTo type="javax.xml.transform.dom.DOMSource" charset="utf-8"/>    
    <process ref="document-serviceHttpUrlResolver"/>      
    <removeHeaders pattern="CamelHttp*"/>    
    <removeHeaders pattern="JMS*"/>    
    <setHeader headerName="SOAPAction">    
        <xpath resultType="java.lang.String">function:properties('document-service.esb.new_genie.document.service.soap.action')</xpath>  
    </setHeader>                
    <setHeader headerName="CamelHttpUri">
        <xpath resultType="java.lang.String">in:header('EXTR_SERVICE_URL')</xpath>
    </setHeader>
    <!--CamelHttpUri value will be - http://xyz.xy.x.bcd/WebGenie/DocumentGenerator.svc-->              
    <setHeader headerName="Content-Type">
        <xpath resultType="java.lang.String">function:properties('http.content.type.value')</xpath>
    </setHeader>                                                            
    <process ref="document-serviceSoapWrapper"/>
    <log message="*** A request message sent to New Genie service: ${body}" loggingLevel="INFO" logName="document-service"/>                
    <to uri="http4://abc.ab.a.abc/GenieWebService/documentgenerator.asmx?httpClient.socketTimeout=180000"/>         
    <convertBodyTo type="javax.xml.transform.dom.DOMSource" charset="utf-8"/>               
    <to uri="{{document-service.esb.new.document.internal.resp.queue.name}}{{document-service.esb.internal.queue.parameters}}" pattern="InOnly"/>
</route>