对camel来说有点陌生,但是在我的camel-quarkus项目中注册一条路线有问题。
我的路线定义如下:
@ApplicationScoped
@Slf4j
public class Routes extends RouteBuilder {
@Override
public void configure() throws Exception {
restConfiguration()
.bindingMode(RestBindingMode.json)
.enableCORS(false);
rest().get("customer")
.route()
.id("GetCustomerRoute")
.messageHistory()
.log(LoggingLevel.INFO, "Got a request on GET:customer")
.validate(a -> validateJwt(a))
.transform().body((in, head) -> in)
.setHeader(Exchange.HTTP_METHOD, constant("POST"))
.toD("ahc:http://localhost:8080/v1/customer")
.endRest();
});
}
public boolean validateJwt(Exchange a) {
return true;
}
}
实际上,我希望将GET /customer
转换为POST localhost:8080/v1/customer
我尝试执行以下GET调用:http://localhost:8000/customer?phone=%2B35677777777
在我的日志里我看到了这个:
2021-10-22 13:05:05,011 INFO [GetCustomerRoute] (vert.x-worker-thread-0) Got a request on GET:customer
2021-10-22 13:05:05,282 ERROR [org.apa.cam.pro.err.DefaultErrorHandler] (vert.x-worker-thread-0) Failed delivery for (MessageId: AF59F252EE8DCC0-0000000000000000 on ExchangeId: AF59F252EE8DCC0-0000000000000000). Exhausted after delivery attempt: 1 caught: org.apache.camel.CamelExchangeException: Error creating URL. Exchange[]. Caused by: [java.lang.IllegalArgumentException - /customer?phone=%2B35677777777 could not be parsed into a proper Uri, missing scheme]
Message History
---------------------------------------------------------------------------------------------------------------------------------------
RouteId ProcessorId Processor Elapsed (ms)
[GetCustomerRoute ] [GetCustomerRoute ] [from[platform-http:///customer?httpMethodRestrict=GET] ] [ 278]
[GetCustomerRoute ] [log1 ] [log ] [ 1]
[GetCustomerRoute ] [validate1 ] [validate[{my.project.user.Routes$$Lambda$1196/0x000000080129] [ 0]
[GetCustomerRoute ] [transform1 ] [transform[org.apache.camel.builder.ExpressionClause@781ce812] ] [ 0]
[GetCustomerRoute ] [setHeader1 ] [setHeader[CamelHttpMethod] ] [ 1]
[GetCustomerRoute ] [toD1 ] [ahc:http://localhost:8080/v1/customer ] [ 0]
Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
: org.apache.camel.CamelExchangeException: Error creating URL. Exchange[]. Caused by: [java.lang.IllegalArgumentException - /customer?phone=%2B35677777777 could not be parsed into a proper Uri, missing scheme]
at org.apache.camel.component.ahc.DefaultAhcBinding.prepareRequest(DefaultAhcBinding.java:82)
at org.apache.camel.component.ahc.AhcProducer.process(AhcProducer.java:76)
at org.apache.camel.processor.SendDynamicProcessor.lambda$process$0(SendDynamicProcessor.java:197)
at org.apache.camel.support.cache.DefaultProducerCache.doInAsyncProducer(DefaultProducerCache.java:318)
at org.apache.camel.processor.SendDynamicProcessor.process(SendDynamicProcessor.java:182)
at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.run(RedeliveryErrorHandler.java:463)
at org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:179)
at org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:64)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:184)
at org.apache.camel.impl.engine.CamelInternalProcessor.process(CamelInternalProcessor.java:398)
at org.apache.camel.component.platform.http.vertx.VertxPlatformHttpConsumer.lambda$handleRequest$2(VertxPlatformHttpConsumer.java:184)
at io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:159)
at io.vertx.core.impl.AbstractContext.dispatch(AbstractContext.java:100)
at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$1(ContextImpl.java:157)
at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:831)
Caused by: java.lang.IllegalArgumentException: /customer?phone=%2B35677777777 could not be parsed into a proper Uri, missing scheme
at org.asynchttpclient.uri.Uri.create(Uri.java:70)
at org.asynchttpclient.uri.Uri.create(Uri.java:62)
at org.asynchttpclient.RequestBuilderBase.setUrl(RequestBuilderBase.java:147)
at org.apache.camel.component.ahc.DefaultAhcBinding.prepareRequest(DefaultAhcBinding.java:80)
... 20 more
2021-10-22 13:05:05,283 WARN [org.apa.cam.com.pla.htt.ver.VertxPlatformHttpConsumer] (vert.x-eventloop-thread-15) Failed handling platform-http endpoint /customer. Caused by: [org.apache.camel.CamelExchangeException - Error creating URL. Exchange[]. Caused by: [java.lang.IllegalArgumentException - /customer?phone=%2B35677777777 could not be parsed into a proper Uri, missing scheme]]: org.apache.camel.CamelExchangeException: Error creating URL. Exchange[]. Caused by: [java.lang.IllegalArgumentException - /customer?phone=%2B35677777777 could not be parsed into a proper Uri, missing scheme]
at org.apache.camel.component.ahc.DefaultAhcBinding.prepareRequest(DefaultAhcBinding.java:82)
at org.apache.camel.component.ahc.AhcProducer.process(AhcProducer.java:76)
at org.apache.camel.processor.SendDynamicProcessor.lambda$process$0(SendDynamicProcessor.java:197)
at org.apache.camel.support.cache.DefaultProducerCache.doInAsyncProducer(DefaultProducerCache.java:318)
at org.apache.camel.processor.SendDynamicProcessor.process(SendDynamicProcessor.java:182)
at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.run(RedeliveryErrorHandler.java:463)
at org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:179)
at org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:64)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:184)
at org.apache.camel.impl.engine.CamelInternalProcessor.process(CamelInternalProcessor.java:398)
at org.apache.camel.component.platform.http.vertx.VertxPlatformHttpConsumer.lambda$handleRequest$2(VertxPlatformHttpConsumer.java:184)
at io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:159)
at io.vertx.core.impl.AbstractContext.dispatch(AbstractContext.java:100)
at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$1(ContextImpl.java:157)
at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:831)
Caused by: java.lang.IllegalArgumentException: /customer?phone=%2B35677777777 could not be parsed into a proper Uri, missing scheme
at org.asynchttpclient.uri.Uri.create(Uri.java:70)
at org.asynchttpclient.uri.Uri.create(Uri.java:62)
at org.asynchttpclient.RequestBuilderBase.setUrl(RequestBuilderBase.java:147)
at org.apache.camel.component.ahc.DefaultAhcBinding.prepareRequest(DefaultAhcBinding.java:80)
... 20 more
2021-10-22 13:05:05,287 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (vert.x-eventloop-thread-15) HTTP Request to /customer?phone=%2B35677777777 failed, error id: 48f1bc83-9ca7-4267-8aea-6b20b409025a-1: org.apache.camel.CamelExchangeException: Error creating URL. Exchange[]. Caused by: [java.lang.IllegalArgumentException - /customer?phone=%2B35677777777 could not be parsed into a proper Uri, missing scheme]
at org.apache.camel.component.ahc.DefaultAhcBinding.prepareRequest(DefaultAhcBinding.java:82)
at org.apache.camel.component.ahc.AhcProducer.process(AhcProducer.java:76)
at org.apache.camel.processor.SendDynamicProcessor.lambda$process$0(SendDynamicProcessor.java:197)
at org.apache.camel.support.cache.DefaultProducerCache.doInAsyncProducer(DefaultProducerCache.java:318)
at org.apache.camel.processor.SendDynamicProcessor.process(SendDynamicProcessor.java:182)
at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.run(RedeliveryErrorHandler.java:463)
at org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:179)
at org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:64)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:184)
at org.apache.camel.impl.engine.CamelInternalProcessor.process(CamelInternalProcessor.java:398)
at org.apache.camel.component.platform.http.vertx.VertxPlatformHttpConsumer.lambda$handleRequest$2(VertxPlatformHttpConsumer.java:184)
at io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:159)
at io.vertx.core.impl.AbstractContext.dispatch(AbstractContext.java:100)
at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$1(ContextImpl.java:157)
at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:831)
Caused by: java.lang.IllegalArgumentException: /customer?phone=%2B35677777777 could not be parsed into a proper Uri, missing scheme
at org.asynchttpclient.uri.Uri.create(Uri.java:70)
at org.asynchttpclient.uri.Uri.create(Uri.java:62)
at org.asynchttpclient.RequestBuilderBase.setUrl(RequestBuilderBase.java:147)
at org.apache.camel.component.ahc.DefaultAhcBinding.prepareRequest(DefaultAhcBinding.java:80)
... 20 more
我很可能遗漏了一些关于路径配置的小问题,但是我查看了https://camel.apache.org/manual/latest/rest-dsl.html和https://camel.apache.org/components/latest/ahc-component.html,没有发现任何明显的问题。如果能帮助解决这个问题,我将不胜感激
1条答案
按热度按时间qkf9rpyu1#
ahc组件使用输入URL作为目标,这导致了此问题
我的解决方案是将
?bridgeEndpoint=true
添加到ahc调用的路径中,这样它就使用了我的实际url。