Home > Back-end >  Apache Camel rest -> ahc route giving missing scheme error
Apache Camel rest -> ahc route giving missing scheme error

Time:10-26

Somewhat new to camel here but having an issue with registering a route in my camel-quarkus project.

My route definition is as follows:

@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;
  }

}

Effecitvely I want this to transform a GET /customer into a POST localhost:8080/v1/customer

I try to do this GET call: http://localhost:8000/customer?phone=+35677777777

And in my logs I get this:

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=+35677777777 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=+35677777777 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=+35677777777 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=+35677777777 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=+35677777777 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=+35677777777 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=+35677777777 failed, error id: 48f1bc83-9ca7-4267-8aea-6b20b409025a-1: org.apache.camel.CamelExchangeException: Error creating URL. Exchange[]. Caused by: [java.lang.IllegalArgumentException - /customer?phone=+35677777777 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=+35677777777 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

I am most likely missing something small with regards to the path configuration but I looked at https://camel.apache.org/manual/latest/rest-dsl.html and https://camel.apache.org/components/latest/ahc-component.html and couldn't find anything obvious. Any help would be greatly appreciated in solving this

CodePudding user response:

The ahc component was using the input url as a target which was causing the issue

my solution was to add ?bridgeEndpoint=true to the path of the ahc call. This made it use my actual url instead.

  • Related