use of io.undertow.server.handlers.AllowedMethodsHandler in project adeptj-runtime by AdeptJ.
the class Server method rootHandler.
/**
* Chaining of Undertow {@link HttpHandler} instances as follows.
* <p>
* 1. GracefulShutdownHandler
* 2. RequestLimitingHandler
* 3. AllowedMethodsHandler
* 4. PredicateHandler which resolves to either RedirectHandler or SetHeadersHandler
* 5. RequestBufferingHandler if request buffering is enabled, wrapped in SetHeadersHandler
* 5. And Finally ServletInitialHandler
*
* @param servletInitialHandler the {@link io.undertow.servlet.handlers.ServletInitialHandler}
* @return GracefulShutdownHandler as the root handler
*/
private GracefulShutdownHandler rootHandler(HttpHandler servletInitialHandler) {
Config cfg = Objects.requireNonNull(this.cfgReference.get());
Map<HttpString, String> headers = new HashMap<>();
headers.put(HttpString.tryFromString(HEADER_SERVER), cfg.getString(KEY_HEADER_SERVER));
if (Environment.isDev()) {
headers.put(HttpString.tryFromString(HEADER_X_POWERED_BY), Version.getFullVersionString());
}
HttpHandler headersHandler = Boolean.getBoolean(SYS_PROP_ENABLE_REQ_BUFF) ? new SetHeadersHandler(new RequestBufferingHandler(servletInitialHandler, Integer.getInteger(SYS_PROP_REQ_BUFF_MAX_BUFFERS, cfg.getInt(KEY_REQ_BUFF_MAX_BUFFERS))), headers) : new SetHeadersHandler(servletInitialHandler, headers);
return Handlers.gracefulShutdown(new RequestLimitingHandler(Integer.getInteger(SYS_PROP_MAX_CONCUR_REQ, cfg.getInt(KEY_MAX_CONCURRENT_REQS)), new AllowedMethodsHandler(Handlers.predicate(exchange -> CONTEXT_PATH.equals(exchange.getRequestURI()), Handlers.redirect(TOOLS_DASHBOARD_URI), headersHandler), this.allowedMethods(cfg))));
}
use of io.undertow.server.handlers.AllowedMethodsHandler in project undertow by undertow-io.
the class PredicatedHandlersParserTestCase method testParsedHandler3.
@Test
public void testParsedHandler3() {
String value = "allowed-methods(GET)";
List<PredicatedHandler> ret = PredicatedHandlersParser.parse(value, getClass().getClassLoader());
Assert.assertEquals(1, ret.size());
AllowedMethodsHandler handler = (AllowedMethodsHandler) ret.get(0).getHandler().wrap(ResponseCodeHandler.HANDLE_200);
Assert.assertEquals(new HashSet<>(Arrays.asList(HttpString.tryFromString("GET"))), handler.getAllowedMethods());
value = "allowed-methods(methods=GET)";
ret = PredicatedHandlersParser.parse(value, getClass().getClassLoader());
Assert.assertEquals(1, ret.size());
handler = (AllowedMethodsHandler) ret.get(0).getHandler().wrap(ResponseCodeHandler.HANDLE_200);
Assert.assertEquals(new HashSet<>(Arrays.asList(HttpString.tryFromString("GET"))), handler.getAllowedMethods());
value = "allowed-methods(methods={GET})";
ret = PredicatedHandlersParser.parse(value, getClass().getClassLoader());
Assert.assertEquals(1, ret.size());
handler = (AllowedMethodsHandler) ret.get(0).getHandler().wrap(ResponseCodeHandler.HANDLE_200);
Assert.assertEquals(new HashSet<>(Arrays.asList(HttpString.tryFromString("GET"))), handler.getAllowedMethods());
value = "allowed-methods({GET})";
ret = PredicatedHandlersParser.parse(value, getClass().getClassLoader());
Assert.assertEquals(1, ret.size());
handler = (AllowedMethodsHandler) ret.get(0).getHandler().wrap(ResponseCodeHandler.HANDLE_200);
Assert.assertEquals(new HashSet<>(Arrays.asList(HttpString.tryFromString("GET"))), handler.getAllowedMethods());
value = "allowed-methods({GET, POST})";
ret = PredicatedHandlersParser.parse(value, getClass().getClassLoader());
Assert.assertEquals(1, ret.size());
handler = (AllowedMethodsHandler) ret.get(0).getHandler().wrap(ResponseCodeHandler.HANDLE_200);
Assert.assertEquals(new HashSet<>(Arrays.asList(HttpString.tryFromString("GET"), HttpString.tryFromString("POST"))), handler.getAllowedMethods());
value = "allowed-methods(methods={GET, POST})";
ret = PredicatedHandlersParser.parse(value, getClass().getClassLoader());
Assert.assertEquals(1, ret.size());
handler = (AllowedMethodsHandler) ret.get(0).getHandler().wrap(ResponseCodeHandler.HANDLE_200);
Assert.assertEquals(new HashSet<>(Arrays.asList(HttpString.tryFromString("GET"), HttpString.tryFromString("POST"))), handler.getAllowedMethods());
value = "allowed-methods(GET, POST)";
ret = PredicatedHandlersParser.parse(value, getClass().getClassLoader());
Assert.assertEquals(1, ret.size());
handler = (AllowedMethodsHandler) ret.get(0).getHandler().wrap(ResponseCodeHandler.HANDLE_200);
Assert.assertEquals(new HashSet<>(Arrays.asList(HttpString.tryFromString("GET"), HttpString.tryFromString("POST"))), handler.getAllowedMethods());
}
Aggregations