io.undertow.Undertow Java Examples
The following examples show how to use
io.undertow.Undertow.
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: WebConfigurerTest.java From e-commerce-microservice with Apache License 2.0 | 7 votes |
@Test public void testCustomizeServletContainer() { env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION); UndertowServletWebServerFactory container = new UndertowServletWebServerFactory(); webConfigurer.customize(container); assertThat(container.getMimeMappings().get("abs")).isEqualTo("audio/x-mpeg"); assertThat(container.getMimeMappings().get("html")).isEqualTo("text/html;charset=utf-8"); assertThat(container.getMimeMappings().get("json")).isEqualTo("text/html;charset=utf-8"); if (container.getDocumentRoot() != null) { assertThat(container.getDocumentRoot().getPath()).isEqualTo(FilenameUtils.separatorsToSystem("build/www")); } Builder builder = Undertow.builder(); container.getBuilderCustomizers().forEach(c -> c.customize(builder)); OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions"); assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isNull(); }
Example #2
Source File: AnnotatedWebSocketServer.java From wildfly-samples with MIT License | 7 votes |
public AnnotatedWebSocketServer() throws IOException { final Xnio xnio = Xnio.getInstance("nio", Undertow.class.getClassLoader()); final XnioWorker xnioWorker = xnio.createWorker(OptionMap.builder().getMap()); WebSocketDeploymentInfo websocket = new WebSocketDeploymentInfo() .addEndpoint(MyAnnotatedEndpoint.class) .setWorker(xnioWorker); DeploymentInfo deploymentInfo = deployment() .setClassLoader(MyAnnotatedEndpoint.class.getClassLoader()) .setContextPath("/myapp") .setDeploymentName("websockets") .addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, websocket); manager = defaultContainer().addDeployment(deploymentInfo); manager.deploy(); }
Example #3
Source File: DerefMiddlewareHandlerTest.java From light-4j with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() { if(server == null) { logger.info("starting server"); HttpHandler handler = getTestHandler(); DerefMiddlewareHandler derefHandler = new DerefMiddlewareHandler(); derefHandler.setNext(handler); handler = derefHandler; server = Undertow.builder() .addHttpListener(8887, "localhost") .setHandler(handler) .build(); server.start(); } if(oauth == null) { logger.info("starting oauth mock server"); oauth = Undertow.builder() .addHttpListener(6753, "localhost") .setHandler(getOAuthHandler()) .build(); oauth.start(); } }
Example #4
Source File: ServerBuilder.java From light-4j with Apache License 2.0 | 6 votes |
public Undertow build() { HttpHandler handler = HandlerBuilder.build(); SanitizerHandler sanitizerHandler = new SanitizerHandler(configName); sanitizerHandler.setNext(handler); handler = sanitizerHandler; BodyHandler bodyHandler = new BodyHandler(); bodyHandler.setNext(handler); handler = bodyHandler; instance = null; return Undertow.builder() .addHttpListener(8080, "localhost") .setHandler(handler) .build(); }
Example #5
Source File: HttpServerBenchmarks.java From brave with Apache License 2.0 | 6 votes |
protected int initServer() throws Exception { DeploymentInfo servletBuilder = Servlets.deployment() .setClassLoader(getClass().getClassLoader()) .setContextPath("/") .setDeploymentName("test.war"); init(servletBuilder); DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder); manager.deploy(); server = Undertow.builder() .addHttpListener(0, "127.0.0.1") .setHandler(manager.start()).build(); server.start(); return ((InetSocketAddress) server.getListenerInfo().get(0).getAddress()).getPort(); }
Example #6
Source File: JwtVerifyHandlerTest.java From light-rest-4j with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() { if(server == null) { logger.info("starting server"); HttpHandler handler = getTestHandler(); JwtVerifyHandler jwtVerifyHandler = new JwtVerifyHandler(); jwtVerifyHandler.setNext(handler); SwaggerHandler swaggerHandler = new SwaggerHandler(); swaggerHandler.setNext(jwtVerifyHandler); server = Undertow.builder() .addHttpListener(8080, "localhost") .setHandler(swaggerHandler) .build(); server.start(); } }
Example #7
Source File: HelloWorldServer.java From StubbornJava with MIT License | 6 votes |
public static void main(String[] args) { int port = 8080; /* * "localhost" will ONLY listen on local host. * If you want the server reachable from the outside you need to set "0.0.0.0" */ String host = "localhost"; /* * This web server has a single handler with no routing. * ALL urls are handled by the helloWorldHandler. */ Undertow server = Undertow.builder() // Add the helloWorldHandler as a method reference. .addHttpListener(port, host, HelloWorldServer::helloWorldHandler) .build(); logger.debug("starting on http://" + host + ":" + port); server.start(); }
Example #8
Source File: DefaultServer.java From quarkus-http with Apache License 2.0 | 6 votes |
/** * Start the SSL server using the default settings. * <p/> * The default settings initialise a server with a key for 'localhost' and a trust store containing the certificate of a * single client, the client authentication mode is set to 'REQUESTED' to optionally allow progression to CLIENT-CERT * authentication. */ public static void startSSLServer() throws IOException { getClientSSLContext(); sslUndertow = Undertow.builder() .setWorker(undertow.getWorker()) .setHandler(rootHandler) .addListener(new Undertow.ListenerBuilder().setType(Undertow.ListenerType.HTTPS) .setPort(getHostSSLPort(DEFAULT)) .setHost(getHostAddress()) .setKeyStore(SERVER_KEY_STORE) .setKeyStorePassword(STORE_PASSWORD) .setTrustStore(SERVER_TRUST_STORE) .setTrustStorePassword(STORE_PASSWORD)).build(); sslUndertow.start(); // startSSLServer(serverContext, OptionMap.create(Options.SSL_CLIENT_AUTH_MODE, SslClientAuthMode.REQUESTED, Options.SSL_ENABLED_PROTOCOLS, Sequence.of("TLSv1.2"))); }
Example #9
Source File: DefaultServer.java From quarkus-http with Apache License 2.0 | 6 votes |
private static void runInternal(final RunNotifier notifier) { if (openssl && OPENSSL_FAILURE != null) { throw new RuntimeException(OPENSSL_FAILURE); } if (first) { first = false; undertow = Undertow.builder() .setHandler(rootHandler) .addHttpListener(getHostPort(DEFAULT), getHostAddress(DEFAULT)) .build(); undertow.start(); notifier.addListener(new RunListener() { @Override public void testRunFinished(Result result) throws Exception { super.testRunFinished(result); undertow.stop(); clientGroup.shutdownGracefully(); } }); } }
Example #10
Source File: UndertowWebServer.java From oxygen with Apache License 2.0 | 6 votes |
@Override public void listen(int port) { this.port = port; this.contextPath = WebConfigKeys.SERVER_CONTEXT_PATH.getValue(); undertowConf = ConfigFactory.load(UndertowConf.class); DeploymentManager manager = deployment(); manager.deploy(); Undertow.Builder builder = Undertow.builder(); configServer(builder); try { undertow = builder.setHandler(configHttp(manager.start())).build(); } catch (ServletException e) { throw Exceptions.wrap(e); } undertow.start(); }
Example #11
Source File: SimpleServletServer.java From wildfly-samples with MIT License | 6 votes |
public SimpleServletServer() { DeploymentInfo deploymentInfo = deployment() .setClassLoader(SimpleServletServer.class.getClassLoader()) .setContextPath("/helloworld") .setDeploymentName("helloworld.war") .addServlets( Servlets.servlet("MyServlet", MyServlet.class) .addInitParam("message", "Hello World") .addMapping("/MyServlet"), Servlets.servlet("MyAnotherServlet", MyAnotherServlet.class) .addMapping("/MyAnotherServlet") ); DeploymentManager manager = defaultContainer().addDeployment(deploymentInfo); manager.deploy (); try { server = Undertow.builder() .addListener(8080, "localhost") .setHandler(manager.start()) .build(); } catch (ServletException ex) { Logger.getLogger(SimpleServletServer.class.getName()).log(Level.SEVERE, null, ex); } }
Example #12
Source File: IndexController.java From leafserver with Apache License 2.0 | 6 votes |
@PostConstruct public void init() { Undertow server = Undertow.builder() .addHttpListener(9999, "localhost").setHandler(new PathHandler() { { addExactPath("/id", exchange -> { Map<String, Deque<String>> pathParameters = exchange.getQueryParameters(); Result result = sequenceCore.nextValue(pathParameters.get("app").getFirst(), pathParameters.get("key").getFirst()); exchange.getResponseSender().send(JSON.toJSONString(result)); }); } }) .build(); server.start(); }
Example #13
Source File: ValidatorHandlerTest.java From light-rest-4j with Apache License 2.0 | 6 votes |
@Before public void setUp() { if(server == null) { logger.info("starting server"); HttpHandler handler = getPetStoreHandler(); ValidatorHandler validatorHandler = new ValidatorHandler(); validatorHandler.setNext(handler); handler = validatorHandler; BodyHandler bodyHandler = new BodyHandler(); bodyHandler.setNext(handler); handler = bodyHandler; SwaggerHandler swaggerHandler = new SwaggerHandler(); swaggerHandler.setNext(handler); handler = swaggerHandler; server = Undertow.builder() .addHttpListener(8080, "localhost") .setHandler(handler) .build(); server.start(); } }
Example #14
Source File: AbstractBaseHttpITest.java From hawkular-apm with Apache License 2.0 | 6 votes |
@BeforeClass public static void init() { server = Undertow.builder() .addHttpListener(8180, "localhost") .setHandler(path().addPrefixPath("sayHello", new HttpHandler() { @Override public void handleRequest(final HttpServerExchange exchange) throws Exception { if (!exchange.getRequestHeaders().contains("test-fault")) { if (!exchange.getRequestHeaders().contains("test-no-data")) { exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain"); exchange.getResponseSender().send(HELLO_WORLD); } } else { exchange.setResponseCode(401); } } })).build(); server.start(); }
Example #15
Source File: ResponseValidatorTest.java From light-rest-4j with Apache License 2.0 | 6 votes |
@Before public void setUp() { if(server == null) { logger.info("starting server"); TestValidateResponseHandler testValidateResponseHandler = new TestValidateResponseHandler(); HttpHandler handler = Handlers.routing() .add(Methods.GET, "/v1/todoItems", testValidateResponseHandler); ValidatorHandler validatorHandler = new ValidatorHandler(); validatorHandler.setNext(handler); handler = validatorHandler; BodyHandler bodyHandler = new BodyHandler(); bodyHandler.setNext(handler); handler = bodyHandler; OpenApiHandler openApiHandler = new OpenApiHandler(); openApiHandler.setNext(handler); handler = openApiHandler; server = Undertow.builder() .addHttpListener(8080, "localhost") .setHandler(handler) .build(); server.start(); } }
Example #16
Source File: Application.java From skywalking with Apache License 2.0 | 6 votes |
private static void undertow() { Undertow server = Undertow.builder().addHttpListener(8080, "0.0.0.0").setHandler(exchange -> { if (CASE_URL.equals(exchange.getRequestPath())) { exchange.dispatch(() -> { try { visit("http://localhost:8081/undertow-routing-scenario/case/undertow?send=httpHandler"); } catch (IOException e) { e.printStackTrace(); } }); } exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain"); exchange.getResponseSender().send("Success"); }).build(); Runtime.getRuntime().addShutdownHook(new Thread(server::stop)); server.start(); }
Example #17
Source File: Main.java From Jax-RS-Performance-Comparison with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { String host = "0.0.0.0"; int port = 8080; if (args.length > 0) { host = args[0]; } if (args.length > 1) { port = Integer.parseInt(args[1]); } Undertow.Builder builder = Undertow.builder().addHttpListener(port, host); server = new UndertowJaxrsServer().start(builder); server.deploy(MyApplication.class, "/"); // DeploymentInfo di = server.undertowDeployment(MyApplication.class); // di.setContextPath("/rest"); // di.setDeploymentName("rest"); // server.deploy(di); }
Example #18
Source File: UndertowApp.java From jweb-cms with GNU Affero General Public License v3.0 | 6 votes |
public void start() { super.configure(); container = new UndertowHttpContainer(this); container.getApplicationHandler().onStartup(container); UndertowOptions undertowOptions = options("undertow", UndertowOptions.class); this.undertow = Undertow.builder() .addHttpListener(undertowOptions.port, undertowOptions.host) .setServerOption(io.undertow.UndertowOptions.MAX_ENTITY_SIZE, undertowOptions.maxEntitySize) .setServerOption(io.undertow.UndertowOptions.MULTIPART_MAX_ENTITY_SIZE, undertowOptions.maxEntitySize) .setHandler(path() .addPrefixPath("/", new UndertowIOHandler(this, container))) .build(); logger.info("server started, host={}, port={}", undertowOptions.host, undertowOptions.port); Runtime.getRuntime().addShutdownHook(new Thread(this::stop)); this.undertow.start(); }
Example #19
Source File: UndertowUtil.java From StubbornJava with MIT License | 6 votes |
/** * This is currently intended to be used in unit tests but may * be appropriate in other situations as well. It's not worth building * out a test module at this time so it lives here. * * This helper will spin up the http handler on a random available port. * The full host and port will be passed to the hostConsumer and the server * will be shut down after the consumer completes. * * @param builder * @param handler * @param hostConusmer */ public static void useLocalServer(Undertow.Builder builder, HttpHandler handler, Consumer<String> hostConusmer) { Undertow undertow = null; try { // Starts server on a random open port undertow = builder.addHttpListener(0, "127.0.0.1", handler).build(); undertow.start(); ListenerInfo listenerInfo = undertow.getListenerInfo().get(0); InetSocketAddress addr = (InetSocketAddress) listenerInfo.getAddress(); String host = "http://localhost:" + addr.getPort(); hostConusmer.accept(host); } finally { if (undertow != null) { undertow.stop(); } } }
Example #20
Source File: WebConfigurerTest.java From e-commerce-microservice with Apache License 2.0 | 5 votes |
@Test public void testUndertowHttp2Enabled() { props.getHttp().setVersion(JHipsterProperties.Http.Version.V_2_0); UndertowServletWebServerFactory container = new UndertowServletWebServerFactory(); webConfigurer.customize(container); Builder builder = Undertow.builder(); container.getBuilderCustomizers().forEach(c -> c.customize(builder)); OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions"); assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isTrue(); }
Example #21
Source File: OpenApiHandlerTest.java From light-rest-4j with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUp() { if(server == null) { logger.info("starting server"); HttpHandler handler = getTestHandler(); OpenApiHandler openApiHandler = new OpenApiHandler(); openApiHandler.setNext(handler); handler = openApiHandler; server = Undertow.builder() .addHttpListener(8080, "localhost") .setHandler(handler) .build(); server.start(); } }
Example #22
Source File: WebConfigurerTest.java From tutorials with MIT License | 5 votes |
@Test public void testUndertowHttp2Enabled() { props.getHttp().setVersion(JHipsterProperties.Http.Version.V_2_0); UndertowServletWebServerFactory container = new UndertowServletWebServerFactory(); webConfigurer.customize(container); Builder builder = Undertow.builder(); container.getBuilderCustomizers().forEach(c -> c.customize(builder)); OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions"); assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isTrue(); }
Example #23
Source File: WebConfigurerTest.java From okta-jhipster-microservices-oauth-example with Apache License 2.0 | 5 votes |
@Test public void testUndertowHttp2Enabled() { props.getHttp().setVersion(JHipsterProperties.Http.Version.V_2_0); UndertowServletWebServerFactory container = new UndertowServletWebServerFactory(); webConfigurer.customize(container); Builder builder = Undertow.builder(); container.getBuilderCustomizers().forEach(c -> c.customize(builder)); OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions"); assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isTrue(); }
Example #24
Source File: SimpleServer.java From StubbornJava with MIT License | 5 votes |
public Undertow start() { Undertow undertow = undertowBuilder.build(); undertow.start(); /* * Undertow logs this on debug but we generally set 3rd party * default logger levels to info so we log it here. If it wasn't using the * io.undertow context we could turn on just that logger but no big deal. */ undertow.getListenerInfo() .stream() .forEach(listenerInfo -> logger.info(listenerInfo.toString())); return undertow; }
Example #25
Source File: WebConfigurerTest.java From okta-jhipster-microservices-oauth-example with Apache License 2.0 | 5 votes |
@Test public void testCustomizeServletContainer() { env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION); UndertowServletWebServerFactory container = new UndertowServletWebServerFactory(); webConfigurer.customize(container); assertThat(container.getMimeMappings().get("abs")).isEqualTo("audio/x-mpeg"); assertThat(container.getMimeMappings().get("html")).isEqualTo("text/html;charset=utf-8"); assertThat(container.getMimeMappings().get("json")).isEqualTo("text/html;charset=utf-8"); Builder builder = Undertow.builder(); container.getBuilderCustomizers().forEach(c -> c.customize(builder)); OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions"); assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isNull(); }
Example #26
Source File: AbstractMockApmServerBenchmark.java From apm-agent-java with Apache License 2.0 | 5 votes |
@Setup public void setUp(Blackhole blackhole) throws IOException { server = Undertow.builder() .addHttpListener(0, "127.0.0.1") .setHandler(new BlockingHandler(exchange -> { if (!exchange.getRequestPath().equals("/healthcheck")) { receivedPayloads++; exchange.startBlocking(); try (InputStream is = exchange.getInputStream()) { for (int n = 0; -1 != n; n = is.read(buffer)) { receivedBytes += n; } } System.getProperties().put("server.received.bytes", receivedBytes); System.getProperties().put("server.received.payloads", receivedPayloads); exchange.setStatusCode(200).endExchange(); } })).build(); server.start(); int port = ((InetSocketAddress) server.getListenerInfo().get(0).getAddress()).getPort(); tracer = new ElasticApmTracerBuilder() .configurationRegistry(ConfigurationRegistry.builder() .addConfigSource(new SimpleSource() .add(CoreConfiguration.SERVICE_NAME, "benchmark") .add(CoreConfiguration.INSTRUMENT, Boolean.toString(apmEnabled)) .add("active", Boolean.toString(apmEnabled)) .add("api_request_size", "10mb") .add("capture_headers", "false") // .add("profiling_inferred_spans", "true") // .add("profiling_interval", "10s") .add("classes_excluded_from_instrumentation", "java.*,com.sun.*,sun.*") .add("server_urls", "http://localhost:" + port)) .optionProviders(ServiceLoader.load(ConfigurationOptionProvider.class)) .build()) .buildAndStart(); ElasticApmAgent.initInstrumentation(tracer, ByteBuddyAgent.install()); }
Example #27
Source File: WhitelistHandlerTest.java From light-4j with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUp() { if (server == null) { logger.info("starting server"); HttpHandler handler = getTestHandler(); WhitelistHandler whitelistHandler = new WhitelistHandler(); whitelistHandler.setNext(handler); handler = whitelistHandler; server = Undertow.builder() .addHttpListener(8080, "localhost") .setHandler(handler) .build(); server.start(); } }
Example #28
Source File: KeycloakInstalled.java From keycloak with Apache License 2.0 | 5 votes |
public void start() { PathHandler pathHandler = Handlers.path().addExactPath("/", this); AllowedMethodsHandler allowedMethodsHandler = new AllowedMethodsHandler(pathHandler, Methods.GET); gracefulShutdownHandler = Handlers.gracefulShutdown(allowedMethodsHandler); server = Undertow.builder() .setIoThreads(1) .setWorkerThreads(1) .addHttpListener(0, "localhost") .setHandler(gracefulShutdownHandler) .build(); server.start(); }
Example #29
Source File: SpecDisplayHandlerTest.java From light-rest-4j with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUp() { if(server == null) { logger.info("starting server"); HttpHandler handler = getTestHandler(); server = Undertow.builder() .addHttpListener(8080, "localhost") .setHandler(handler) .build(); server.start(); } }
Example #30
Source File: WebConfigurerTest.java From cubeai with Apache License 2.0 | 5 votes |
@Test public void testCustomizeServletContainer() { env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION); UndertowEmbeddedServletContainerFactory container = new UndertowEmbeddedServletContainerFactory(); webConfigurer.customize(container); assertThat(container.getMimeMappings().get("abs")).isEqualTo("audio/x-mpeg"); assertThat(container.getMimeMappings().get("html")).isEqualTo("text/html;charset=utf-8"); assertThat(container.getMimeMappings().get("json")).isEqualTo("text/html;charset=utf-8"); Builder builder = Undertow.builder(); container.getBuilderCustomizers().forEach(c -> c.customize(builder)); OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions"); assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isNull(); }