通过apache GET进行HTTP操作当Rest请求URI太长时,Camel会失败

时间:2017-02-28 09:41:57

标签: java apache rest apache-camel cxf

我在我的项目中使用apache休息CXF和camel。有很多情况下,休息的请求URI的长度太长,并且在一定长度之后总是会因为HTTP操作失败而发生异常,如下所示 与

statusCode: 400 
        at org.apache.camel.component.http.HttpProducer.populateHttpOperationFailedException(HttpProducer.java:230) ~[camel-http-2.13.1.jar:2.13.1] 
        at org.apache.camel.component.http.HttpProducer.process(HttpProducer.java:156) ~[camel-http-2.13.1.jar:2.13.1] 
        at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) ~[camel-core-2.13.1.jar:2.13.1] 
        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:113) ~[camel-core-2.13.1.jar:2.13.1] 
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72) ~[camel-core-2.13.1.jar:2.13.1] 
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398) ~[camel-core-2.13.1.jar:2.13.1] 
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191) ~[camel-core-2.13.1.jar:2.13.1] 
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:118) ~[camel-core-2.13.1.jar:2.13.1] 
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:80) ~[camel-core-2.13.1.jar:2.13.1] 
        at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:111) ~[camel-core-2.13.1.jar:2.13.1] 
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72) ~[camel-core-2.13.1.jar:2.13.1] 
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398) ~[camel-core-2.13.1.jar:2.13.1] 
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191) ~[camel-core-2.13.1.jar:2.13.1]l 
        at org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:111) ~[camel-core-2.13.1.jar:2.13.1] 
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72) ~[camel-core-2.13.1.jar:2.13.1] 
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398) ~[camel-core-2.13.1.jar:2.13.1] 
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191) ~[camel-core-2.13.1.jar:2.13.1] 
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:118) ~[camel-core-2.13.1.jar:2.13.1] 
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:80) ~[camel-core-2.13.1.jar:2.13.1] 
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191) ~[camel-core-2.13.1.jar:2.13.1] 
        at org.apache.camel.component.seda.SedaConsumer.sendToConsumers(SedaConsumer.java:291) [camel-core-2.13.1.jar:2.13.1] 
        at org.apache.camel.component.seda.SedaConsumer.doRun(SedaConsumer.java:200) [camel-core-2.13.1.jar:2.13.1] 
        at org.apache.camel.component.seda.SedaConsumer.run(SedaConsumer.java:147) [camel-core-2.13.1.jar:2.13.1] 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_101] 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_101] 
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_101] 

所以有任何方法,我们可以在发送请求之前在头中显式传递length参数,或者用于设置请求URI的最大长度的任何其他配置。对于解决方法,我只是使用HttpConnection替换了camel调用,它工作正常,这意味着驼峰对请求的URI长度有一些限制。

我将请求放在link

骆驼代码:

.choice()
                .when(header(ReservationConstant.CALL_ENDECA_FOR_LAR_FACETS).isEqualTo(Boolean.TRUE))
                .setHeader(Exchange.HTTP_METHOD, constant(org.apache.camel.component.http4.HttpMethods.GET))
                .setHeader(Exchange.HTTP_PATH, constant(ReservationConstant.ENDECA_GUIDED_SEARCH_SERVICE))
                .setBody(simple(StringUtils.EMPTY))
                //.to("cxfrs:bean:endecaLocationKeyRSClient?throwExceptionOnFailure=false")
                .to("{{service.endeca.location.dimension.rest}}")
                //.process(endecaFacetProcessor)
                .bean(EndecaResponseBuilder.class, "getEndecaResponseForLARFacets")
                .end()

1 个答案:

答案 0 :(得分:0)

问题似乎不是因为URI太长,而是由于我删除该标头后,请求中的其中一个标头过大的事实