use of io.undertow.Undertow in project undertow by undertow-io.
the class HelloWorldServer method main.
public static void main(final String[] args) {
Undertow server = Undertow.builder().addHttpListener(8080, "localhost").setHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
exchange.getResponseSender().send("Hello World");
}
}).build();
server.start();
}
use of io.undertow.Undertow in project undertow by undertow-io.
the class JSRWebSocketServer method main.
public static void main(final String[] args) {
PathHandler path = Handlers.path();
Undertow server = Undertow.builder().addHttpListener(8080, "localhost").setHandler(path).build();
server.start();
final ServletContainer container = ServletContainer.Factory.newInstance();
DeploymentInfo builder = new DeploymentInfo().setClassLoader(JSRWebSocketServer.class.getClassLoader()).setContextPath("/").addWelcomePage("index.html").setResourceManager(new ClassPathResourceManager(JSRWebSocketServer.class.getClassLoader(), JSRWebSocketServer.class.getPackage())).addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo().setBuffers(new DefaultByteBufferPool(true, 100)).addEndpoint(JsrChatWebSocketEndpoint.class)).setDeploymentName("chat.war");
DeploymentManager manager = container.addDeployment(builder);
manager.deploy();
try {
path.addPrefixPath("/", manager.start());
} catch (ServletException e) {
throw new RuntimeException(e);
}
}
use of io.undertow.Undertow in project undertow by undertow-io.
the class ModClusterProxyServer method main.
public static void main(final String[] args) throws IOException {
final XnioWorker worker = Xnio.getInstance().createWorker(OptionMap.EMPTY);
final Undertow server;
final ModCluster modCluster = ModCluster.builder(worker).build();
try {
if (chost == null) {
// We are going to guess it.
chost = java.net.InetAddress.getLocalHost().getHostName();
System.out.println("Using: " + chost + ":" + cport);
}
modCluster.start();
// Create the proxy and mgmt handler
final HttpHandler proxy = modCluster.createProxyHandler();
final MCMPConfig config = MCMPConfig.webBuilder().setManagementHost(chost).setManagementPort(cport).enableAdvertise().getParent().build();
final HttpHandler mcmp = config.create(modCluster, proxy);
server = Undertow.builder().addHttpListener(cport, chost).addHttpListener(pport, phost).setHandler(mcmp).build();
server.start();
// Start advertising the mcmp handler
modCluster.advertise(config);
} catch (Exception e) {
e.printStackTrace();
}
}
use of io.undertow.Undertow in project undertow by undertow-io.
the class SimpleBenchmarkState method before.
@Setup
public final void before() {
Undertow.Builder builder = Undertow.builder().setIoThreads(4).setWorkerThreads(64).setServerOption(UndertowOptions.SHUTDOWN_TIMEOUT, 10000).setSocketOption(Options.SSL_CLIENT_AUTH_MODE, SslClientAuthMode.NOT_REQUESTED).setHandler(Handlers.routing().get("/blocking", new BlockingHandler(new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
String value = exchange.getQueryParameters().get("size").getFirst();
int bytes = Integer.parseInt(value);
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/octet-stream").put(Headers.CONTENT_LENGTH, value);
OutputStream out = exchange.getOutputStream();
for (int i = 0; i < bytes; i++) {
out.write(1);
}
}
})).post("/blocking", new BlockingHandler(new HttpHandler() {
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
InputStream stream = exchange.getInputStream();
long length = BenchmarkUtils.length(stream);
String stringValue = Long.toString(length);
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain").put(Headers.CONTENT_LENGTH, stringValue.length());
exchange.getResponseSender().send(stringValue);
}
})));
switch(listenerType) {
case HTTP:
builder.addHttpListener(PORT, "0.0.0.0");
break;
case HTTPS:
builder.addHttpsListener(PORT, "0.0.0.0", TLSUtils.newServerContext());
break;
default:
throw new IllegalStateException("Unknown protocol: " + listenerType);
}
undertow = builder.build();
undertow.start();
client = HttpClients.custom().disableConnectionState().disableAutomaticRetries().setSSLContext(TLSUtils.newClientContext()).setMaxConnPerRoute(100).setMaxConnTotal(100).build();
baseUri = (listenerType == ListenerType.HTTP ? "http" : "https") + "://localhost:" + PORT;
}
use of io.undertow.Undertow in project undertow by undertow-io.
the class FileHandlerTestCase method main.
/*
Starts simple file server, it is useful for testing directory browsing
*/
public static void main(String[] args) throws URISyntaxException {
Path rootPath = Paths.get(FileHandlerTestCase.class.getResource("page.html").toURI()).getParent().getParent();
HttpHandler root = new CanonicalPathHandler().setNext(new PathHandler().addPrefixPath("/path", new ResourceHandler(new PathResourceManager(rootPath, 1)).setDirectoryListingEnabled(true)));
Undertow undertow = Undertow.builder().addHttpListener(8888, "localhost").setHandler(root).build();
undertow.start();
}
Aggregations