Camel服务呼叫出现400错误

camsedfj  于 12个月前  发布在  Apache
关注(0)|答案(1)|浏览(159)

我正在使用Camel serviceCall调用我的Eureka VIP。主机和端口按预期解析。但响应为400并抛出错误。我的serviceCall看起来像下面的内容:

from("direct:servicecall")
    .setBody().constant(null)
    .setHeader(Exchange.HTTP_METHOD, constant(HttpMethods.GET))
    .serviceCall().name("eureka_vip_name")
    .expression()
    .simple("http4:${header.CamelServiceCallServiceHost}:${header.CamelServiceCallServicePort}"
        + "service call path and parameters")
    .end()

字符集
添加错误日志:
org. apache. camel. http. common. HttpOperationFailedException:HTTP操作调用http://172.31.20.241:8080/失败,状态代码:<------url path and parameteres------>400 at org.apache.camel.component.http4.HttpProducer.populateHttpOperationFailedException(HttpProducer.java:312)~[camel-http4 - 2.20.1.jar!/:2.20.1] at org.apache.camel.component.http4.HttpProducer.process(HttpProducer.java:207)~[camel-http4 - 2.20.1.jar!/:2.20.1] at org. apache. camel. util. AsyncProcessorConverterHelper $ProcessorToAsyncProcessorBridge. process(AsyncProcessorConverterHelper.java:61)~[camel-core-2.20.1.jar!/:2.20.1] at org.apache.camel.processor.SendDynamicProcessor$1.doInAsyncProducer(SendDynamicProcessor.java:132)~[camel-core-2.20.1.jar!/:2.20.1] at org. apache. camel. impl. ProducerCache. doInAsyncProducer(ProducerCache.java:445)~[camel-core-2.20.1.jar!/:2.20.1] at org. apache. camel. processor. SendDynamicProcessor. process(SendDynamicProcessor.java:127)~[camel-core-2.20.1.jar!/:2.20.1] at org. apache. camel. impl. cloud. DefaultServiceCallProcessor. execute(DefaultServiceCallProcessor.java:184)~[camel-core-2.20.1.jar!/:2.20.1] at org.apache.camel.impl.cloud.DefaultServiceCallProcessor.judda$process$0(DefaultServiceCallProcessor.java:164)~[camel-core-2.20.1.jar!/:2.20.1]在org.apache.camel.spring.cloud.CamelSpringCloudServiceLoadBalancer.juda$process$0(CamelSpringCloudServiceLoadBalancer.java:66)~[camel-spring-cloud-2.20.1.jar!/:2.20.1] at org. springframework. cloud. networks. ribbon. RibbonLoadBalancerClient. execute(RibbonLoadBalancerClient.java:98)~[spring-cloud-netflix-core-1.3.4.RELEASE.jar!/:1.3.4.RELEASE] at org. springframework. cloud. netflix.ribbon. RibbonLoadBalancerClient. execute(RibbonLoadBalancerClient.java:80)~[spring-cloud-netflix-core-1.3.4.RELEASE.jar!/:1.3.4.RELEASE] at org. apache. camel. spring. cloud. CamelSpringCloudServiceLoadBalancer. process(CamelSpringCloudServiceLoadBalancer.java:66)~[camel-spring-cloud-2.20.1.jar!/:2.20.1] at org. apache. camel. impl. cloud. DefaultServiceCallProcessor. process(DefaultServiceCallProcessor.java:164)~[camel-core-2.20.1.jar!/:2.20.1] at org. apache. camel. management. InstrumentationProcessor. process(InstrumentationProcessor.java:[camel-core-2.20.1.jar!/:2.20.1]在org. apache. camel. processor. RediveryErrorHandler $www.example.com(RediveryErrorHandler.java:203)~[camel-core-2.20.1.jar!/:2.20.1] at org. apache. camel. processor. RediveryErrorHandler.java:171)~[camel-core-2.20.1.jar!/:2.20.1] at www.example.com(FutureTask.java:266)~[?:1.8.0_161]在java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:1.8.0)~[?:1.8.0_161]在java. util. concurrent. ScheduledThreadPoolExecutor $ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)~[?:1.8.0_161]在java. util. concurrent. ThreadPoolExecutor. runWorker(ThreadPoolExecutor.java:AsyncRedeliveryTask.call:1.8.0_161]在java. util. concurrent. ThreadPoolExecutor $www.example.com(ThreadPoolExecutor.java:624)[?:1.8.0_161]在www.example.com(Thread.java:748)[?:1.8.0_161]
我试着从postMan(Chrome扩展)中点击相同的URL:当从postMan中点击时,我使用ec2示例DNS名称作为主机,它给了我预期的响应,即200 OK,预期的正文作为结果。

h6my8fg2

h6my8fg21#

试图回答这个问题的事件,如果它是写在很久以前。
我遇到了同样的问题,我注意到这是由于一些额外的头部,设置在父/以前的路由
例如,如果您在父路由中设置了一个过长或不同格式的报头(即byte[]),则此报头也会发送到http请求,并产生Http 400错误代码。
在执行http请求之前,我已经通过使用**.removeHeaders(“*”)**删除所有头部来解决:

from("direct:myHttpRoute")
        .removeHeaders("*", "PrefixToKeepSomeHeaders*") // clean headers         
        .setHeader(Exchange.HTTP_METHOD, constant("GET"))
        .setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
        .setBody().constant(null) // clean body
        .to("https://mypath.com")
        .log("Response: ${body}");

字符集
我希望这对别人有用!

相关问题