io.undertow.server.session.SessionAttachmentHandler Java Examples
The following examples show how to use
io.undertow.server.session.SessionAttachmentHandler.
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: 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 #2
Source File: FormAuthTestCase.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override protected void setRootHandler(HttpHandler current) { final PredicateHandler handler = new PredicateHandler(Predicates.path("/login"), new HttpHandler() { @Override public void handleRequest(HttpServerExchange exchange) throws Exception { exchange.writeAsync("Login Page"); } }, current); super.setRootHandler(new SessionAttachmentHandler(handler, new InMemorySessionManager("test"), new SessionCookieConfig())); }
Example #3
Source File: URLRewritingSessionTestCase.java From quarkus-http with Apache License 2.0 | 5 votes |
@BeforeClass public static void setup() { final PathParameterSessionConfig sessionConfig = new PathParameterSessionConfig(); final SessionAttachmentHandler handler = new SessionAttachmentHandler(new InMemorySessionManager(""), sessionConfig); handler.setNext(new HttpHandler() { @Override public void handleRequest(final HttpServerExchange exchange) throws Exception { final SessionManager manager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY); Session session = manager.getSession(exchange, sessionConfig); if (session == null) { session = manager.createSession(exchange, sessionConfig); session.setAttribute(COUNT, 0); } else { Assert.assertEquals("/notamatchingpath;jsessionid=" + session.getId(), exchange.getRequestURI()); } Integer count = (Integer) session.getAttribute(COUNT); exchange.addResponseHeader(COUNT, count.toString()); session.setAttribute(COUNT, ++count); for (Map.Entry<String, Deque<String>> qp : exchange.getQueryParameters().entrySet()) { exchange.addResponseHeader(qp.getKey(), qp.getValue().getFirst()); } if (exchange.getQueryString().isEmpty()) { exchange.writeAsync(sessionConfig.rewriteUrl(DefaultServer.getDefaultServerURL() + "/notamatchingpath", session.getId())); } else { exchange.writeAsync(sessionConfig.rewriteUrl(DefaultServer.getDefaultServerURL() + "/notamatchingpath?" + exchange.getQueryString(), session.getId())); } } }); DefaultServer.setRootHandler(handler); }