I am trying to fetch token from a REST end point. This token I need to use to call other APIs for the resources. I am using apache camel to fetch the token after calling the API. However I am getting an error which I am not able to comprehend. I have only REST endpoint as "https://mytokenurl/token" to fetch the token.
from("timer://scheduler?period=30s")
.log("get access token")
.to("direct:authService");
from("direct:authService").tracing()
.setHeader(Exchange.HTTP_PATH)
.simple("https://mytokenurl/token") //Which url to give here?
.setHeader("CamelHttpMethod")
.simple("POST")
.setHeader("Content-Type")
.simple("application/x-www-form-urlencoded")
.setHeader("Cache-Control")
.simple("no-cache")
.setBody()
.constant("grant_type=client_credentials&scope=${scope}&client_id=${clientID}&client_secret=${clientSecret}")
.to("https://mytokenurl/token") //Error is getting generated here
.convertBodyTo(String.class)
.log("response from API: " + body())
.choice()
.when().simple("${header.CamelHttpResponseCode} == 200")
.unmarshal().json(JsonLibrary.Jackson,AccessResponseToken.class)
.setHeader("jwt").simple("${body.access_token}").log("token received")
.to("direct:toother")
.otherwise()
.log("Not Authenticated!!!");
The error generated as below -
org.apache.camel.FailedToCreateRouteException: Failed to create route route2 at: >>> To[https://myurltoken/token] <<< in route: Route(route2)[From[direct:authService] -> [SetHeader[CamelHt... because of No endpoint could be found for: https:/myurltoken/token, please check your classpath contains the needed Camel component jar.
at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:240) ~[camel-core-reifier-3.18.1.jar:3.18.1]
Please let me know how to avoid this error?