class DerefMiddlewareHandler implements MiddlewareHandler {

    private static final Logger logger = LoggerFactory.getLogger(DerefMiddlewareHandler.class);
    private static final String CONFIG_NAME = "deref";
    private static final String MISSING_AUTH_TOKEN = "ERR10002";
    private static final String EMPTY_TOKEN_DEREFERENCE_RESPONSE = "ERR10044";
    private static final String TOKEN_DEREFERENCE_ERROR = "ERR10045";

    public static DerefConfig config =
            (DerefConfig)Config.getInstance().getJsonObjectConfig(CONFIG_NAME, DerefConfig.class);

    private volatile HttpHandler next;

    public DerefMiddlewareHandler() {
        if(logger.isInfoEnabled()) logger.info("DerefMiddlewareHandler is constructed.");
    }

    @Override
    public void handleRequest(final HttpServerExchange exchange) throws Exception {<FILL_FUNCTION_BODY>}

    @Override
    public HttpHandler getNext() {
        return next;
    }

    @Override
    public MiddlewareHandler setNext(final HttpHandler next) {
        Handlers.handlerNotNull(next);
        this.next = next;
        return this;
    }

    @Override
    public boolean isEnabled() {
        return config.isEnabled();
    }

    @Override
    public void register() {
        ModuleRegistry.registerModule(DerefConfig.CONFIG_NAME, DerefMiddlewareHandler.class.getName(), Config.getNoneDecryptedInstance().getJsonMapConfigNoCache(DerefConfig.CONFIG_NAME), null);
    }

    @Override
    public void reload() {
        config = (DerefConfig)Config.getInstance().getJsonObjectConfigNoCache(DerefConfig.CONFIG_NAME, DerefConfig.class);
        ModuleRegistry.registerModule(DerefConfig.CONFIG_NAME, DerefMiddlewareHandler.class.getName(), Config.getNoneDecryptedInstance().getJsonMapConfigNoCache(CONFIG_NAME), null);
        if(logger.isInfoEnabled()) logger.info("DerefMiddlewareHandler is reloaded.");
    }
}

        // check if the token is in the request Authorization header
        String token = exchange.getRequestHeaders().getFirst(Headers.AUTHORIZATION);
        if(token == null) {
            setExchangeStatus(exchange, MISSING_AUTH_TOKEN);
            return;
        } else {
            // ignore it and let it go if the token format is JWT
            if(token.indexOf('.') < 0) {
                // this is a by reference token
                DerefRequest request = new DerefRequest(token);
                String response = OauthHelper.derefToken(request);
                if(response == null || response.trim().length() == 0) {
                    setExchangeStatus(exchange, EMPTY_TOKEN_DEREFERENCE_RESPONSE, token);
                    return;
                }
                if(response.startsWith("{")) {
                    // an error status returned from OAuth 2.0 provider. We cannot assume that light-oauth2
                    // is used but still need to convert the error message to a status to wrap the error.
                    setExchangeStatus(exchange, TOKEN_DEREFERENCE_ERROR, response);
                    return;
                } else {
                    // now consider the response it jwt
                    exchange.getRequestHeaders().put(Headers.AUTHORIZATION, "Bearer " + response);
                }
            }
        }
        Handler.next(exchange, next);
    
<no_super_class>