Apache Camel rest -> ahc 路由给出丢失的方案错误

Apache Camel rest -> ahc route giving missing scheme error

这里对 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$$Lambda96/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[=11=](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(VertxPlatformHttpConsumer.java:184)
    at io.vertx.core.impl.ContextImpl.lambda$null[=11=](ContextImpl.java:159)
    at io.vertx.core.impl.AbstractContext.dispatch(AbstractContext.java:100)
    at io.vertx.core.impl.ContextImpl.lambda$executeBlocking(ContextImpl.java:157)
    at org.jboss.threads.ContextHandler.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[=11=](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(VertxPlatformHttpConsumer.java:184)
    at io.vertx.core.impl.ContextImpl.lambda$null[=11=](ContextImpl.java:159)
    at io.vertx.core.impl.AbstractContext.dispatch(AbstractContext.java:100)
    at io.vertx.core.impl.ContextImpl.lambda$executeBlocking(ContextImpl.java:157)
    at org.jboss.threads.ContextHandler.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[=11=](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(VertxPlatformHttpConsumer.java:184)
    at io.vertx.core.impl.ContextImpl.lambda$null[=11=](ContextImpl.java:159)
    at io.vertx.core.impl.AbstractContext.dispatch(AbstractContext.java:100)
    at io.vertx.core.impl.ContextImpl.lambda$executeBlocking(ContextImpl.java:157)
    at org.jboss.threads.ContextHandler.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 and https://camel.apache.org/components/latest/ahc-component.html 并没有找到任何明显的东西。解决此问题的任何帮助将不胜感激

ahc 组件使用输入 url 作为导致问题的目标

我的解决方案是将 ?bridgeEndpoint=true 添加到 ahc 调用的路径中。这使得它使用我的实际 url 代替。