I want to use Apache Camel to call a rest webservice which takes a bearer token as authorization. I am getting 401 unauthorized access if I use the below code--
@Component
public class LoadFileRouteBuilder extends RouteBuilder{
@Override
public void configure() throws Exception {
from("timer:mytimer?repeatCount=1")
.log("Scheduled job!")
.to("direct:httpRoute");
from("direct:httpRoute")
.log("Http Route started")
.setHeader(Exchange.HTTP_METHOD).constant(HttpMethod.GET)
.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
.setHeader("Authorization").simple("Bearer "+ myToken)
.to("https://my-rest-ws-url")
.log("Response : ${body}");
}
}
I have also tried using process method to set the authorization token exchange.getIn().setHeader("Authorization", "Bearer "+myToken); didn't work either.
Is it the correct way to send bearer token ?