SuperUserJwtTokenRequestHandler

Inheritance: java.lang.Object

public class SuperUserJwtTokenRequestHandler

JWT Token Request Handler with caching, local validation, and circuit breaker. Tokens are cached for up to 7 days with refresh 6 hours before expiration.

Constructors

ConstructorDescription
SuperUserJwtTokenRequestHandler()Public constructor.

Methods

MethodDescription
beforeSend(HttpURLConnection request, OutputStream streamToSend)Add authorization header before sending the request.
getCachedToken()Gets the currently cached token for testing purposes.
getTokenExpiration()Gets the token expiration as a Date for testing purposes.
getTokenExpirationMillis()Gets the token expiration time for testing purposes.
processResponse(HttpURLConnection response, String resultString, String errorString)Process the response, handling 401 Unauthorized by refreshing token.
processUrl(String url)Process the URL (ensures token is available).
resetForTesting()Resets all cached token state for testing purposes.

SuperUserJwtTokenRequestHandler()

public SuperUserJwtTokenRequestHandler()

Public constructor.

beforeSend(HttpURLConnection request, OutputStream streamToSend)

public void beforeSend(HttpURLConnection request, OutputStream streamToSend)

Add authorization header before sending the request.

Parameters:

ParameterTypeDescription
requestjava.net.HttpURLConnectionThe HTTP connection
streamToSendjava.io.OutputStreamThe output stream (unused)

getCachedToken()

public static String getCachedToken()

Gets the currently cached token for testing purposes.

Returns: java.lang.String - The cached JWT token or null

getTokenExpiration()

public static Date getTokenExpiration()

Gets the token expiration as a Date for testing purposes.

Returns: java.util.Date - The expiration Date or null if no token

getTokenExpirationMillis()

public static long getTokenExpirationMillis()

Gets the token expiration time for testing purposes.

Returns: long - The expiration time in milliseconds since epoch

processResponse(HttpURLConnection response, String resultString, String errorString)

public void processResponse(HttpURLConnection response, String resultString, String errorString)

Process the response, handling 401 Unauthorized by refreshing token.

Parameters:

ParameterTypeDescription
responsejava.net.HttpURLConnectionThe HTTP response
resultStringjava.lang.StringThe response body
errorStringjava.lang.StringThe error message if any

processUrl(String url)

public String processUrl(String url)

Process the URL (ensures token is available).

Parameters:

ParameterTypeDescription
urljava.lang.StringThe URL to process

Returns: java.lang.String - The URL unchanged

resetForTesting()

public static void resetForTesting()

Resets all cached token state for testing purposes.