io.undertow.attribute.ExchangeAttributes Java Examples
The following examples show how to use
io.undertow.attribute.ExchangeAttributes.
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: JsonLogFormatter.java From digdag with Apache License 2.0 | 6 votes |
public static ExchangeAttribute buildExchangeAttribute(String pattern, ClassLoader classLoader) { if (pattern.equals("json")) { pattern = DEFAULT_PATTERN; } String body = pattern.substring("json{".length(), pattern.length() - "}".length()); Map<String, ExchangeAttribute> map = new LinkedHashMap<>(); ExchangeAttributeParser parser = ExchangeAttributes.parser(classLoader); String[] kvs = body.split(" "); for (String kv : kvs) { String[] fragments = kv.split(":", 2); if (fragments.length != 2) { throw new IllegalArgumentException("JSON access log pattern includes an invalid fragment: " + kv); } String key = fragments[0]; String value = fragments[1]; map.put(key, parser.parse(value)); } return new JsonExchangeAttribute(map); }
Example #2
Source File: SetHeaderHandler.java From lams with GNU General Public License v2.0 | 5 votes |
public SetHeaderHandler(final String header, final String value) { if(value == null) { throw UndertowMessages.MESSAGES.argumentCannotBeNull("value"); } if(header == null) { throw UndertowMessages.MESSAGES.argumentCannotBeNull("header"); } this.next = ResponseCodeHandler.HANDLE_404; this.value = ExchangeAttributes.constant(value); this.header = new HttpString(header); }
Example #3
Source File: PathTemplatePredicate.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public Predicate build(final Map<String, Object> config) { ExchangeAttribute match = (ExchangeAttribute) config.get("match"); if (match == null) { match = ExchangeAttributes.relativePath(); } String value = (String) config.get("value"); return new PathTemplatePredicate(value, match); }
Example #4
Source File: Http2Server.java From quarkus-http with Apache License 2.0 | 5 votes |
public static void main(final String[] args) throws Exception { String version = System.getProperty("java.version"); System.out.println("Java version " + version); if(version.charAt(0) == '1' && Integer.parseInt(version.charAt(2) + "") < 8 ) { System.out.println("This example requires Java 1.8 or later"); System.out.println("The HTTP2 spec requires certain cyphers that are not present in older JVM's"); System.out.println("See section 9.2.2 of the HTTP2 specification for details"); System.exit(1); } String bindAddress = System.getProperty("bind.address", "localhost"); SSLContext sslContext = createSSLContext(loadKeyStore("server.keystore"), loadKeyStore("server.truststore")); Undertow server = Undertow.builder() .setServerOption(UndertowOptions.ENABLE_HTTP2, true) .addHttpListener(8080, bindAddress) .addHttpsListener(8443, bindAddress, sslContext) .setHandler(new SessionAttachmentHandler(new LearningPushHandler(100, -1, Handlers.header(predicate(secure(), resource(new PathResourceManager(Paths.get(System.getProperty("example.directory", System.getProperty("user.home"))), 100)) .setDirectoryListingEnabled(true), new HttpHandler() { @Override public void handleRequest(HttpServerExchange exchange) throws Exception { exchange.getResponseHeaders().add(Headers.LOCATION, "https://" + exchange.getHostName() + ":" + (exchange.getHostPort() + 363) + exchange.getRelativePath()); exchange.setStatusCode(StatusCodes.TEMPORARY_REDIRECT); } }), "x-undertow-transport", ExchangeAttributes.transportProtocol())), new InMemorySessionManager("test"), new SessionCookieConfig())).build(); server.start(); SSLContext clientSslContext = createSSLContext(loadKeyStore("client.keystore"), loadKeyStore("client.truststore")); LoadBalancingProxyClient proxy = new LoadBalancingProxyClient() .addHost(new URI("https://localhost:8443"), null, new UndertowXnioSsl(Xnio.getInstance(), OptionMap.EMPTY, clientSslContext), UndertowOptionMap.create(UndertowOptions.ENABLE_HTTP2, true)) .setConnectionsPerThread(20); Undertow reverseProxy = Undertow.builder() .setServerOption(UndertowOptions.ENABLE_HTTP2, true) .addHttpListener(8081, bindAddress) .addHttpsListener(8444, bindAddress, sslContext) .setHandler(ProxyHandler.builder().setProxyClient(proxy).setMaxRequestTime( 30000).build()) .build(); reverseProxy.start(); }
Example #5
Source File: FilePredicate.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public Predicate build(final Map<String, Object> config) { ExchangeAttribute value = (ExchangeAttribute) config.get("value"); Boolean requireContent = (Boolean)config.get("require-content"); if(value == null) { value = ExchangeAttributes.relativePath(); } return new FilePredicate(value, requireContent == null ? false : requireContent); }
Example #6
Source File: DirectoryPredicate.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public Predicate build(final Map<String, Object> config) { ExchangeAttribute value = (ExchangeAttribute) config.get("value"); if(value == null) { value = ExchangeAttributes.relativePath(); } return new DirectoryPredicate(value); }
Example #7
Source File: AccessLogHandler.java From lams with GNU General Public License v2.0 | 5 votes |
public AccessLogHandler(final HttpHandler next, final AccessLogReceiver accessLogReceiver, final String formatString, ClassLoader classLoader, Predicate predicate) { this.next = next; this.accessLogReceiver = accessLogReceiver; this.predicate = predicate; this.formatString = handleCommonNames(formatString); this.tokens = ExchangeAttributes.parser(classLoader, new SubstituteEmptyWrapper("-")).parse(this.formatString); }
Example #8
Source File: SetAttributeHandler.java From lams with GNU General Public License v2.0 | 5 votes |
public SetAttributeHandler(HttpHandler next, final String attribute, final String value) { this.next = next; ExchangeAttributeParser parser = ExchangeAttributes.parser(getClass().getClassLoader()); this.attribute = parser.parseSingleToken(attribute); this.value = parser.parse(value); this.preCommit = false; }
Example #9
Source File: SetAttributeHandler.java From lams with GNU General Public License v2.0 | 5 votes |
public SetAttributeHandler(HttpHandler next, final String attribute, final String value, final ClassLoader classLoader) { this.next = next; ExchangeAttributeParser parser = ExchangeAttributes.parser(classLoader); this.attribute = parser.parseSingleToken(attribute); this.value = parser.parse(value); this.preCommit = false; }
Example #10
Source File: SetAttributeHandler.java From lams with GNU General Public License v2.0 | 5 votes |
public SetAttributeHandler(HttpHandler next, final String attribute, final String value, boolean preCommit) { this.next = next; this.preCommit = preCommit; ExchangeAttributeParser parser = ExchangeAttributes.parser(getClass().getClassLoader()); this.attribute = parser.parseSingleToken(attribute); this.value = parser.parse(value); }
Example #11
Source File: SetAttributeHandler.java From lams with GNU General Public License v2.0 | 5 votes |
public SetAttributeHandler(HttpHandler next, final String attribute, final String value, final ClassLoader classLoader, boolean preCommit) { this.next = next; this.preCommit = preCommit; ExchangeAttributeParser parser = ExchangeAttributes.parser(classLoader); this.attribute = parser.parseSingleToken(attribute); this.value = parser.parse(value); }
Example #12
Source File: RegularExpressionPredicate.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public Predicate build(final Map<String, Object> config) { ExchangeAttribute value = (ExchangeAttribute) config.get("value"); if(value == null) { value = ExchangeAttributes.relativePath(); } Boolean fullMatch = (Boolean) config.get("full-match"); Boolean caseSensitive = (Boolean) config.get("case-sensitive"); String pattern = (String) config.get("pattern"); return new RegularExpressionPredicate(pattern, value, fullMatch == null ? false : fullMatch, caseSensitive == null ? true : caseSensitive); }
Example #13
Source File: SetHeaderHandler.java From lams with GNU General Public License v2.0 | 5 votes |
public SetHeaderHandler(final HttpHandler next, final String header, final String value) { if(value == null) { throw UndertowMessages.MESSAGES.argumentCannotBeNull("value"); } if(header == null) { throw UndertowMessages.MESSAGES.argumentCannotBeNull("header"); } if(next == null) { throw UndertowMessages.MESSAGES.argumentCannotBeNull("next"); } this.next = next; this.value = ExchangeAttributes.constant(value); this.header = new HttpString(header); }
Example #14
Source File: PredicatedHandlersParser.java From lams with GNU General Public License v2.0 | 5 votes |
public static List<PredicatedHandler> parse(final String contents, final ClassLoader classLoader) { Deque<Token> tokens = tokenize(contents); Node node = parse(contents, tokens); Map<String, PredicateBuilder> predicateBuilders = loadPredicateBuilders(classLoader); Map<String, HandlerBuilder> handlerBuilders = loadHandlerBuilders(classLoader); final ExchangeAttributeParser attributeParser = ExchangeAttributes.parser(classLoader); return handleNode(contents, node, predicateBuilders, handlerBuilders, attributeParser); }
Example #15
Source File: PredicatedHandlersParser.java From lams with GNU General Public License v2.0 | 5 votes |
public static Predicate parsePredicate(String string, ClassLoader classLoader) { Deque<Token> tokens = tokenize(string); Node node = parse(string, tokens); Map<String, PredicateBuilder> predicateBuilders = loadPredicateBuilders(classLoader); final ExchangeAttributeParser attributeParser = ExchangeAttributes.parser(classLoader); return handlePredicateNode(string, node, predicateBuilders, attributeParser); }
Example #16
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 #17
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 #18
Source File: DomainUtil.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
static ResourceHandlerDefinition createStaticContentHandler(ResourceManager resource, String context) { final io.undertow.server.handlers.resource.ResourceHandler handler = new io.undertow.server.handlers.resource.ResourceHandler(resource) .setCacheTime(60 * 60 * 24 * 31) .setAllowed(not(path("META-INF"))) .setResourceManager(resource) .setDirectoryListingEnabled(false) .setCachable(not(suffixes(NOCACHE_JS, APP_HTML, INDEX_HTML))); // avoid clickjacking attacks: console must not be included in (i)frames SetHeaderHandler frameHandler = new SetHeaderHandler(handler, "X-Frame-Options", "SAMEORIGIN"); // we also need to setup the default resource redirect PredicateHandler predicateHandler = new PredicateHandler(path("/"), new RedirectHandler(ExchangeAttributes.constant(context + DEFAULT_RESOURCE)), frameHandler); return new ResourceHandlerDefinition(context, DEFAULT_RESOURCE, predicateHandler); }
Example #19
Source File: ConsoleMode.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
static ResourceHandlerDefinition createConsoleHandler(String slot, String resource) throws ModuleLoadException { final ClassPathResourceManager cpresource = new ClassPathResourceManager(getClassLoader(Module.getCallerModuleLoader(), ERROR_MODULE, slot), ""); final io.undertow.server.handlers.resource.ResourceHandler handler = new io.undertow.server.handlers.resource.ResourceHandler(cpresource) .setAllowed(not(path("META-INF"))) .setResourceManager(cpresource) .setDirectoryListingEnabled(false) .setCachable(Predicates.<HttpServerExchange>falsePredicate()); //we also need to setup the default resource redirect PredicateHandler predicateHandler = new PredicateHandler(path("/"), new RedirectHandler(ExchangeAttributes.constant(CONTEXT + resource)), handler); return new ResourceHandlerDefinition(CONTEXT, resource, predicateHandler); }
Example #20
Source File: ErrorContextHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public static HttpHandler createErrorContext(final String slot) throws ModuleLoadException { final ClassPathResourceManager cpresource = new ClassPathResourceManager(getClassLoader(Module.getCallerModuleLoader(), ERROR_MODULE, slot), ""); final io.undertow.server.handlers.resource.ResourceHandler handler = new io.undertow.server.handlers.resource.ResourceHandler(cpresource) .setAllowed(not(path("META-INF"))) .setDirectoryListingEnabled(false) .setCachable(Predicates.<HttpServerExchange>falsePredicate()); //we also need to setup the default resource redirect return new PredicateHandler(path("/"), new RedirectHandler(ExchangeAttributes.constant(ERROR_CONTEXT + DEFAULT_RESOURCE)), handler); }
Example #21
Source File: SetAttributeHandler.java From quarkus-http with Apache License 2.0 | 5 votes |
public SetAttributeHandler(HttpHandler next, final String attribute, final String value, final ClassLoader classLoader) { this.next = next; ExchangeAttributeParser parser = ExchangeAttributes.parser(classLoader); this.attribute = parser.parseSingleToken(attribute); this.value = parser.parse(value); this.preCommit = false; }
Example #22
Source File: FilePredicate.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public Predicate build(final Map<String, Object> config) { ExchangeAttribute value = (ExchangeAttribute) config.get("value"); Boolean requireContent = (Boolean)config.get("require-content"); if(value == null) { value = ExchangeAttributes.relativePath(); } return new FilePredicate(value, requireContent == null ? false : requireContent); }
Example #23
Source File: DirectoryPredicate.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public Predicate build(final Map<String, Object> config) { ExchangeAttribute value = (ExchangeAttribute) config.get("value"); if(value == null) { value = ExchangeAttributes.relativePath(); } return new DirectoryPredicate(value); }
Example #24
Source File: PathTemplatePredicate.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public Predicate build(final Map<String, Object> config) { ExchangeAttribute match = (ExchangeAttribute) config.get("match"); if (match == null) { match = ExchangeAttributes.relativePath(); } String value = (String) config.get("value"); return new PathTemplatePredicate(value, match); }
Example #25
Source File: RegularExpressionPredicate.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public Predicate build(final Map<String, Object> config) { ExchangeAttribute value = (ExchangeAttribute) config.get("value"); if(value == null) { value = ExchangeAttributes.relativePath(); } Boolean fullMatch = (Boolean) config.get("full-match"); Boolean caseSensitive = (Boolean) config.get("case-sensitive"); String pattern = (String) config.get("pattern"); return new RegularExpressionPredicate(pattern, value, fullMatch == null ? false : fullMatch, caseSensitive == null ? true : caseSensitive); }
Example #26
Source File: AccessLogHandler.java From quarkus-http with Apache License 2.0 | 5 votes |
public AccessLogHandler(final HttpHandler next, final AccessLogReceiver accessLogReceiver, final String formatString, ClassLoader classLoader, Predicate predicate) { this.next = next; this.accessLogReceiver = accessLogReceiver; this.predicate = predicate; this.formatString = handleCommonNames(formatString); this.tokens = ExchangeAttributes.parser(classLoader, new SubstituteEmptyWrapper("-")).parse(this.formatString); }
Example #27
Source File: SetAttributeHandler.java From quarkus-http with Apache License 2.0 | 5 votes |
public SetAttributeHandler(HttpHandler next, final String attribute, final String value) { this.next = next; ExchangeAttributeParser parser = ExchangeAttributes.parser(getClass().getClassLoader()); this.attribute = parser.parseSingleToken(attribute); this.value = parser.parse(value); this.preCommit = false; }
Example #28
Source File: SetAttributeHandler.java From quarkus-http with Apache License 2.0 | 5 votes |
public SetAttributeHandler(HttpHandler next, final String attribute, final String value, boolean preCommit) { this.next = next; this.preCommit = preCommit; ExchangeAttributeParser parser = ExchangeAttributes.parser(getClass().getClassLoader()); this.attribute = parser.parseSingleToken(attribute); this.value = parser.parse(value); }
Example #29
Source File: SetAttributeHandler.java From quarkus-http with Apache License 2.0 | 5 votes |
public SetAttributeHandler(HttpHandler next, final String attribute, final String value, final ClassLoader classLoader, boolean preCommit) { this.next = next; this.preCommit = preCommit; ExchangeAttributeParser parser = ExchangeAttributes.parser(classLoader); this.attribute = parser.parseSingleToken(attribute); this.value = parser.parse(value); }
Example #30
Source File: SetHeaderHandler.java From quarkus-http with Apache License 2.0 | 5 votes |
public SetHeaderHandler(final String header, final String value) { if(value == null) { throw UndertowMessages.MESSAGES.argumentCannotBeNull("value"); } if(header == null) { throw UndertowMessages.MESSAGES.argumentCannotBeNull("header"); } this.next = ResponseCodeHandler.HANDLE_404; this.value = ExchangeAttributes.constant(value); this.header = header; }