Am I approaching this correctly? I'm using onException to catch the HttpOperationFailedException when I receive an http 401 error (although I haven't figured out how to catch a 401 specifically). When I see one of these, I want to make sure the token is fresh, so I regenerate one and set the header.
Here is a simplified example, cutting out what I know is working and using some hard coding.
onException(HttpOperationFailedException.class).maximumRedeliveries(1)
.setHeader("Authorization", constant("abcde"))
.log("Newly Set Header: ${headers.Authorization} ${body}");
from("jms:queue:Queue")
.unmarshal(receiptFormat)
.bean(ModelTranslator.class, "reqest")
.marshal(requestFormat)
.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
.setHeader("Accept", constant("application/json"))
.setHeader(Exchange.HTTP_METHOD, constant(org.apache.camel.component.http.HttpMethods.POST))
.setHeader("Authorization", constant("12345"))
.to("log:DEBUG?showBody=true&showHeaders=true")
.to("https://test.net/rest/api/email")
.to("log:DEBUG?showBody=true&showHeaders=true");
I intentionally set a bad token before the request to https://test.net/rest/api/email, which causes the error. I successfully catch it and set the good token. I can see that the good token is set with the .log(). And if I understand correctly, onException will re-try starting where it failed, which is the .to("https://test.net/rest/api/email"), correct?
But the call to https://test.net/rest/api/email fails with a 401 still... So I'm doing something wrong.