How to add an trailing slash to the camel http component of camel

Viewed 15

Im am trying to call a rest post service from my Camel route. The rest service is deployed at https://csp-verteileauftrag-camunda-v1-csp-ims-dev-az.apcn.osp4-preprod.hel.kko.ch/api/v1/verteileauftrag/. Calling the Service from a Rest Client like VS Code works if there is a trailing slash (after verteileauftrag).

In my camel route I have configured the following:

restConfiguration().host("https://csp-verteileauftrag-camunda-v1-csp-ims-dev-az.apcn.osp4-preprod.hel.kko.ch/api/v1").component("http").bindingMode(RestBindingMode.json);

and in then later using the config: .to("rest:post:verteileauftrag?outType=ch.helsana.csp.verteileauftrag.rest.model.apiadapter.ResponseType")

If I execute the code, I get a 404 HTTP Error from the Backend as the URL used is
https://csp-verteileauftrag-camunda-v1-csp-ims-dev-az.apcn.osp4-preprod.hel.kko.ch/api/v1/verteileauftrag. So without a trailing slash. I have tried to add it like .to("rest:post:verteileauftrag/?outType=ch.helsana.csp.verteileauftrag.rest.model.apiadapter.ResponseType")

but no success. Do you have any idea how to tell the http component in the rest configuration how to add the trailing slash? Thank you very much. Using redhat fuse 7_10_2.

Regards Michel

1 Answers

Apache camel REST-DLS is not for calling external Rest services. Its for making Rest services with Apache Camel using one of the web-servers like jetty, undertow or netty.

If you want to call external rest service you can just use http-component

Example:

from("direct:requrestDataFromAPI")
    .routeId("requrestDataFromAPI")
    .to("http://localhost:3001/api/test?throwExceptionOnFailure=false")
    .filter(header(Exchange.HTTP_RESPONSE_CODE).isGreaterThanOrEqualTo(300))
        .log(LoggingLevel.ERROR, "Failed to request data from API.\n" 
            + " ResponseBody: ${body}\nResponseCode ${headers.CamelHttpResponseCode}")
        .stop()
    .end()
    .log("Succefully requested data from API: ${body}")
;
Related