com.networknt.router.middleware.GatewayTokenHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gateway Show documentation
Show all versions of gateway Show documentation
This module will admin handler for re-load config values from config server runtime.
package com.networknt.router.middleware;
import com.networknt.config.Config;
import com.networknt.handler.Handler;
import com.networknt.httpstring.HttpStringConstants;
import com.networknt.router.GatewayConfig;
import com.networknt.url.HttpURL;
import com.networknt.utility.Constants;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.HeaderValues;
public class GatewayTokenHandler extends TokenHandler{
public static GatewayConfig gatewayConfig = (GatewayConfig)Config.getInstance().getJsonObjectConfig(GatewayConfig.CONFIG_NAME, GatewayConfig.class);
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
if (Constants.HEADER.equalsIgnoreCase(gatewayConfig.getEgressIngressIndicator())) {
HeaderValues serviceIdHeader = exchange.getRequestHeaders().get(HttpStringConstants.SERVICE_ID);
String serviceId = serviceIdHeader != null ? serviceIdHeader.peekFirst() : null;
String serviceUrl = exchange.getRequestHeaders().getFirst(HttpStringConstants.SERVICE_URL);
if (serviceId != null || serviceUrl!=null) {
super.handleRequest(exchange);
} else {
Handler.next(exchange, next);
}
} else if (Constants.PROTOCOL.equalsIgnoreCase(gatewayConfig.getEgressIngressIndicator()) && HttpURL.PROTOCOL_HTTP.equalsIgnoreCase(exchange.getRequestScheme())){
super.handleRequest(exchange);
} else {
Handler.next(exchange, next);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy