io.undertow.server.HandlerWrapper Java Examples
The following examples show how to use
io.undertow.server.HandlerWrapper.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AccessControlListHandler.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public HandlerWrapper build(Map<String, Object> config) { String[] acl = (String[]) config.get("acl"); Boolean defaultAllow = (Boolean) config.get("default-allow"); ExchangeAttribute attribute = (ExchangeAttribute) config.get("attribute"); List<AclMatch> peerMatches = new ArrayList<>(); for(String rule :acl) { String[] parts = rule.split(" "); if(parts.length != 2) { throw UndertowMessages.MESSAGES.invalidAclRule(rule); } if(parts[1].trim().equals("allow")) { peerMatches.add(new AclMatch(false, parts[0].trim())); } else if(parts[1].trim().equals("deny")) { peerMatches.add(new AclMatch(true, parts[0].trim())); } else { throw UndertowMessages.MESSAGES.invalidAclRule(rule); } } return new Wrapper(peerMatches, defaultAllow == null ? false : defaultAllow, attribute); }
Example #2
Source File: IPAddressAccessControlHandler.java From quarkus-http with Apache License 2.0 | 6 votes |
@Override public HandlerWrapper build(Map<String, Object> config) { String[] acl = (String[]) config.get("acl"); Boolean defaultAllow = (Boolean) config.get("default-allow"); Integer failureStatus = (Integer) config.get("failure-status"); List<Holder> peerMatches = new ArrayList<>(); for(String rule :acl) { String[] parts = rule.split(" "); if(parts.length != 2) { throw UndertowMessages.MESSAGES.invalidAclRule(rule); } if(parts[1].trim().equals("allow")) { peerMatches.add(new Holder(parts[0].trim(), false)); } else if(parts[1].trim().equals("deny")) { peerMatches.add(new Holder(parts[0].trim(), true)); } else { throw UndertowMessages.MESSAGES.invalidAclRule(rule); } } return new Wrapper(peerMatches, defaultAllow == null ? false : defaultAllow, failureStatus == null ? StatusCodes.FORBIDDEN : failureStatus); }
Example #3
Source File: UndertowHandlersConfServletExtension.java From quarkus with Apache License 2.0 | 6 votes |
@Override public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try (InputStream handlers = classLoader.getResourceAsStream(META_INF_UNDERTOW_HANDLERS_CONF)) { if (handlers != null) { // From Stuart Douglas: Ideally these would be parsed at deployment time and passed into a recorder, // however they are likely not bytecode serialisable. Even though this approach // does not 100% align with the Quarkus ethos I think it is ok in this case as // the gains would be marginal compared to the cost of attempting to make // every predicate bytecode serialisable. List<PredicatedHandler> handlerList = PredicatedHandlersParser.parse(handlers, classLoader); if (!handlerList.isEmpty()) { deploymentInfo.addOuterHandlerChainWrapper(new RewriteCorrectingHandlerWrappers.PostWrapper()); deploymentInfo.addOuterHandlerChainWrapper(new HandlerWrapper() { @Override public HttpHandler wrap(HttpHandler handler) { return Handlers.predicates(handlerList, handler); } }); deploymentInfo.addOuterHandlerChainWrapper(new RewriteCorrectingHandlerWrappers.PreWrapper()); } } } catch (IOException e) { throw new UncheckedIOException(e); } }
Example #4
Source File: IPAddressAccessControlHandler.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public HandlerWrapper build(Map<String, Object> config) { String[] acl = (String[]) config.get("acl"); Boolean defaultAllow = (Boolean) config.get("default-allow"); Integer failureStatus = (Integer) config.get("failure-status"); List<Holder> peerMatches = new ArrayList<>(); for(String rule :acl) { String[] parts = rule.split(" "); if(parts.length != 2) { throw UndertowMessages.MESSAGES.invalidAclRule(rule); } if(parts[1].trim().equals("allow")) { peerMatches.add(new Holder(parts[0].trim(), false)); } else if(parts[1].trim().equals("deny")) { peerMatches.add(new Holder(parts[0].trim(), true)); } else { throw UndertowMessages.MESSAGES.invalidAclRule(rule); } } return new Wrapper(peerMatches, defaultAllow == null ? false : defaultAllow, failureStatus == null ? StatusCodes.FORBIDDEN : failureStatus); }
Example #5
Source File: SetHeaderHandler.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public HandlerWrapper build(final Map<String, Object> config) { final ExchangeAttribute value = (ExchangeAttribute) config.get("value"); final String header = (String) config.get("header"); return new HandlerWrapper() { @Override public HttpHandler wrap(HttpHandler handler) { return new SetHeaderHandler(handler, header, value); } }; }
Example #6
Source File: PredicatedHandlersParser.java From quarkus-http with Apache License 2.0 | 5 votes |
private static HandlerWrapper handlePredicatedAction(String contents, Node node, Map<String, PredicateBuilder> predicateBuilders, Map<String, HandlerBuilder> handlerBuilders, ExchangeAttributeParser parser) { if(node instanceof ExpressionNode) { return handleHandlerNode(contents, (ExpressionNode) node, handlerBuilders, parser); } else if(node instanceof BlockNode) { List<PredicatedHandler> handlers = handleBlockNode(contents, (BlockNode) node, predicateBuilders, handlerBuilders, parser); return new PredicatesHandler.Wrapper(handlers, false); } else { throw error(contents, node.getToken().getPosition(), "unexpected token " + node.getToken()); } }
Example #7
Source File: RewriteHandlerBuilder.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public HandlerWrapper build(final Map<String, Object> config) { final ExchangeAttribute value = (ExchangeAttribute) config.get("value"); return new HandlerWrapper() { @Override public HttpHandler wrap(HttpHandler handler) { return new SetAttributeHandler(handler, ExchangeAttributes.relativePath(), value); } }; }
Example #8
Source File: PredicatedHandlersParser.java From lams with GNU General Public License v2.0 | 5 votes |
public static HandlerWrapper parseHandler(String string, ClassLoader classLoader) { Deque<Token> tokens = tokenize(string); Node node = parse(string, tokens); Map<String, HandlerBuilder> handlerBuilders = loadHandlerBuilders(classLoader); final ExchangeAttributeParser attributeParser = ExchangeAttributes.parser(classLoader); return handleHandlerNode(string, (ExpressionNode)node, handlerBuilders, attributeParser); }
Example #9
Source File: StoredResponseHandler.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public HandlerWrapper build(Map<String, Object> config) { return new HandlerWrapper() { @Override public HttpHandler wrap(HttpHandler handler) { return new StoredResponseHandler(handler); } }; }
Example #10
Source File: DeploymentManagerImpl.java From quarkus-http with Apache License 2.0 | 5 votes |
private static HttpHandler wrapHandlers(final HttpHandler wrapee, final List<HandlerWrapper> wrappers) { HttpHandler current = wrapee; for (HandlerWrapper wrapper : wrappers) { current = wrapper.wrap(current); } return current; }
Example #11
Source File: ServletPathMatches.java From quarkus-http with Apache License 2.0 | 5 votes |
private static HttpHandler wrapHandlers(final HttpHandler wrapee, final List<HandlerWrapper> wrappers) { HttpHandler current = wrapee; for (HandlerWrapper wrapper : wrappers) { current = wrapper.wrap(current); } return current; }
Example #12
Source File: SetAttributeHandler.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public HandlerWrapper build(final Map<String, Object> config) { final ExchangeAttribute value = (ExchangeAttribute) config.get("value"); final ExchangeAttribute attribute = (ExchangeAttribute) config.get("attribute"); final Boolean preCommit = (Boolean) config.get("pre-commit"); return new HandlerWrapper() { @Override public HttpHandler wrap(HttpHandler handler) { return new SetAttributeHandler(handler, attribute, value, preCommit == null ? false : preCommit); } }; }
Example #13
Source File: EncodingHandler.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public HandlerWrapper build(Map<String, Object> config) { return new HandlerWrapper() { @Override public HttpHandler wrap(HttpHandler handler) { return new EncodingHandler(handler, new ContentEncodingRepository() .addEncodingHandler("gzip", new GzipEncodingProvider(), 100) .addEncodingHandler("deflate", new DeflateEncodingProvider(), 10)); } }; }
Example #14
Source File: DeploymentManagerImpl.java From lams with GNU General Public License v2.0 | 5 votes |
private static HttpHandler wrapHandlers(final HttpHandler wrapee, final List<HandlerWrapper> wrappers) { HttpHandler current = wrapee; for (HandlerWrapper wrapper : wrappers) { current = wrapper.wrap(current); } return current; }
Example #15
Source File: PredicatedHandlersParser.java From quarkus-http with Apache License 2.0 | 5 votes |
public static HandlerWrapper parseHandler(String string, ClassLoader classLoader) { Deque<Token> tokens = tokenize(string); Node node = parse(string, tokens); Map<String, HandlerBuilder> handlerBuilders = loadHandlerBuilders(classLoader); final ExchangeAttributeParser attributeParser = ExchangeAttributes.parser(classLoader); return handleHandlerNode(string, (ExpressionNode)node, handlerBuilders, attributeParser); }
Example #16
Source File: PredicatedHandlersParser.java From lams with GNU General Public License v2.0 | 5 votes |
private static List<PredicatedHandler> handleNode(String contents, Node node, Map<String, PredicateBuilder> predicateBuilders, Map<String, HandlerBuilder> handlerBuilders, ExchangeAttributeParser attributeParser) { if(node instanceof BlockNode) { return handleBlockNode(contents, (BlockNode) node, predicateBuilders, handlerBuilders, attributeParser); } else if(node instanceof ExpressionNode) { HandlerWrapper handler = handleHandlerNode(contents, (ExpressionNode) node, handlerBuilders, attributeParser); return Collections.singletonList(new PredicatedHandler(Predicates.truePredicate(), handler)); } else if(node instanceof PredicateOperatorNode) { return Collections.singletonList(handlePredicateOperatorNode(contents, (PredicateOperatorNode)node, predicateBuilders, handlerBuilders, attributeParser)); } else { throw error(contents, node.getToken().getPosition(), "unexpected token " + node.getToken()); } }
Example #17
Source File: PredicatedHandlersParser.java From quarkus-http with Apache License 2.0 | 5 votes |
private static PredicatedHandler handlePredicateOperatorNode(String contents, PredicateOperatorNode node, Map<String, PredicateBuilder> predicateBuilders, Map<String, HandlerBuilder> handlerBuilders, ExchangeAttributeParser parser) { Predicate predicate = handlePredicateNode(contents, node.getLeft(), predicateBuilders, parser); HandlerWrapper ret = handlePredicatedAction(contents, node.getRight(), predicateBuilders, handlerBuilders, parser); HandlerWrapper elseBranch = null; if(node.getElseBranch() != null) { elseBranch = handlePredicatedAction(contents, node.getElseBranch(), predicateBuilders, handlerBuilders, parser); } return new PredicatedHandler(predicate, ret, elseBranch); }
Example #18
Source File: BypassServletTestCase.java From quarkus-http with Apache License 2.0 | 5 votes |
@BeforeClass public static void setup() throws ServletException { final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); DeploymentInfo builder = new DeploymentInfo() .setClassLoader(SimpleServletTestCase.class.getClassLoader()) .setContextPath("/servletContext") .setClassIntrospecter(TestClassIntrospector.INSTANCE) .setDeploymentName("servletContext.war") .addServlet( new ServletInfo("servlet", MessageServlet.class) .addMapping("/") .addInitParam(MessageServlet.MESSAGE, "This is a servlet") ) .addListener(new ListenerInfo(TestListener.class)) .addInitialHandlerChainWrapper(new HandlerWrapper() { @Override public HttpHandler wrap(final HttpHandler handler) { return new HttpHandler() { @Override public void handleRequest(final HttpServerExchange exchange) throws Exception { if (exchange.getRelativePath().equals("/async")) { exchange.writeAsync("This is not a servlet"); } else { handler.handleRequest(exchange); } } }; } }); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
Example #19
Source File: StuckThreadDetectionHandler.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public HandlerWrapper build(Map<String, Object> config) { Integer threshhold = (Integer) config.get("threshhold"); if(threshhold == null) { return new Wrapper(); } else { return new Wrapper(threshhold); } }
Example #20
Source File: JDBCLogHandler.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public HandlerWrapper build(Map<String, Object> config) { String datasourceName = (String) config.get("datasource"); try { DataSource ds = (DataSource) new InitialContext().lookup((String) config.get("datasource")); String format = (String) config.get("format"); return new Wrapper(format, ds, (String) config.get("tableName"), (String) config.get("remoteHostField"), (String) config.get("userField"), (String) config.get("timestampField"), (String) config.get("virtualHostField"), (String) config.get("methodField"), (String) config.get("queryField"), (String) config.get("statusField"), (String) config.get("bytesField"), (String) config.get("refererField"), (String) config.get("userAgentField")); } catch (NamingException ex) { throw UndertowMessages.MESSAGES.datasourceNotFound(datasourceName); } }
Example #21
Source File: PredicatedHandlersParser.java From quarkus-http with Apache License 2.0 | 5 votes |
private static HandlerWrapper handleHandlerNode(String contents, ExpressionNode node, Map<String, HandlerBuilder> handlerBuilders, ExchangeAttributeParser parser) { Token token = node.getToken(); HandlerBuilder builder = handlerBuilders.get(token.getToken()); if (builder == null) { throw error(contents, token.getPosition(), "no handler named " + token.getToken() + " known handlers are " + handlerBuilders.keySet()); } Map<String, Object> parameters = new HashMap<>(); for(Map.Entry<String, Node> val : node.getValues().entrySet()) { String name = val.getKey(); if(name == null) { if(builder.defaultParameter() == null) { throw error(contents, token.getPosition(), "default parameter not supported"); } name = builder.defaultParameter(); } Class<?> type = builder.parameters().get(name); if(type == null) { throw error(contents, val.getValue().getToken().getPosition(), "unknown parameter " + name); } if(val.getValue() instanceof ValueNode) { parameters.put(name, coerceToType(contents, val.getValue().getToken(), type, parser)); } else if(val.getValue() instanceof ArrayNode) { parameters.put(name, readArrayType(contents, name, (ArrayNode)val.getValue(), parser, type)); } else { throw error(contents, val.getValue().getToken().getPosition(), "unexpected node " + val.getValue()); } } return builder.build(parameters); }
Example #22
Source File: LearningPushHandler.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public HandlerWrapper build(Map<String, Object> config) { final int maxAge = config.containsKey("max-age") ? (Integer)config.get("max-age") : DEFAULT_MAX_CACHE_AGE; final int maxEntries = config.containsKey("max-entries") ? (Integer)config.get("max-entries") : DEFAULT_MAX_CACHE_ENTRIES; return new HandlerWrapper() { @Override public HttpHandler wrap(HttpHandler handler) { return new LearningPushHandler(maxEntries, maxAge, handler); } }; }
Example #23
Source File: StoredResponseHandler.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public HandlerWrapper build(Map<String, Object> config) { return new HandlerWrapper() { @Override public HttpHandler wrap(HttpHandler handler) { return new StoredResponseHandler(handler); } }; }
Example #24
Source File: ResponseCodeHandlerBuilder.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public HandlerWrapper build(final Map<String, Object> config) { final Integer value = (Integer) config.get("value"); return new HandlerWrapper() { @Override public HttpHandler wrap(HttpHandler handler) { return new ResponseCodeHandler(value); } }; }
Example #25
Source File: PredicatedHandlersParser.java From lams with GNU General Public License v2.0 | 5 votes |
private static HandlerWrapper handlePredicatedAction(String contents, Node node, Map<String, PredicateBuilder> predicateBuilders, Map<String, HandlerBuilder> handlerBuilders, ExchangeAttributeParser parser) { if(node instanceof ExpressionNode) { return handleHandlerNode(contents, (ExpressionNode) node, handlerBuilders, parser); } else if(node instanceof BlockNode) { List<PredicatedHandler> handlers = handleBlockNode(contents, (BlockNode) node, predicateBuilders, handlerBuilders, parser); return new PredicatesHandler.Wrapper(handlers, false); } else { throw error(contents, node.getToken().getPosition(), "unexpected token " + node.getToken()); } }
Example #26
Source File: RewriteHandlerBuilder.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public HandlerWrapper build(final Map<String, Object> config) { final ExchangeAttribute value = (ExchangeAttribute) config.get("value"); return new HandlerWrapper() { @Override public HttpHandler wrap(HttpHandler handler) { return new SetAttributeHandler(handler, ExchangeAttributes.relativePath(), value); } }; }
Example #27
Source File: SetHeaderHandler.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public HandlerWrapper build(final Map<String, Object> config) { final ExchangeAttribute value = (ExchangeAttribute) config.get("value"); final String header = (String) config.get("header"); return new HandlerWrapper() { @Override public HttpHandler wrap(HttpHandler handler) { return new SetHeaderHandler(handler, header, value); } }; }
Example #28
Source File: ProxyHandlerBuilder.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public HandlerWrapper build(Map<String, Object> config) { String[] hosts = (String[]) config.get("hosts"); List<URI> uris = new ArrayList<>(); for (String host : hosts) { try { uris.add(new URI(host)); } catch (URISyntaxException e) { throw new RuntimeException(e); } } Boolean rewriteHostHeader = (Boolean) config.get("rewrite-host-header"); return new Wrapper(uris, rewriteHostHeader); }
Example #29
Source File: SecureCookieHandler.java From quarkus-http with Apache License 2.0 | 4 votes |
@Override public HandlerWrapper build(Map<String, Object> config) { return WRAPPER; }
Example #30
Source File: HandlerParser.java From quarkus-http with Apache License 2.0 | 4 votes |
public static HandlerWrapper parse(String string, final ClassLoader classLoader) { return PredicatedHandlersParser.parseHandler(string, classLoader); }