Search code examples
apache-camel

Handling JWT token renewal within Apache Camel


I've recently been working on setting up a project to use Azure and part of that involves requesting a token to access a REST API. I've been told that the token will expire in 30 minutes, but calling the API to get a new token isn't particularly expensive. I can do all this without any issue, but I'm curious if Camel has anything built in that can handle this for me without having to explicitly call to get a new token?


Solution

  • I don't know of anything built in, but you could have a timer route that runs every 25 minutes that requests a token and puts it in some kind of global state.

    from("timer:getAuthToken?period=1500000")
        .to("http:myKeyServer/getKey")
        .process(new MyKeyProcessor()) // store in global state, static, spring, etc.
    

    Then any route that needs the key can get it from global state and set it in a header or exchange property.