forked from janbodnar/Java-Advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUndertowAccessLog.java
More file actions
43 lines (33 loc) · 1.43 KB
/
UndertowAccessLog.java
File metadata and controls
43 lines (33 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.zetcode;
import io.undertow.Undertow;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.server.handlers.accesslog.AccessLogHandler;
import io.undertow.server.handlers.accesslog.DefaultAccessLogReceiver;
import io.undertow.util.Headers;
import java.nio.file.Paths;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
class MyHandler implements HttpHandler {
@Override
public void handleRequest(HttpServerExchange exchange) {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
exchange.getResponseSender().send("Hello there");
}
}
public class UndertowAccessLog {
public static void main(String[] args) {
final ExecutorService executor = Executors.newSingleThreadExecutor();
DefaultAccessLogReceiver.Builder builder = DefaultAccessLogReceiver.builder().setLogWriteExecutor(executor)
.setOutputDirectory(Paths.get("C:/Users/Jano/tmp/"))
.setLogBaseName("access-log.")
.setLogNameSuffix("log")
.setRotate(true);
Undertow server = Undertow.builder()
.addHttpListener(8080, "0.0.0.0")
.setHandler(new AccessLogHandler(new MyHandler(), builder.build(),
"combined", UndertowAccessLog.class.getClassLoader()))
.build();
server.start();
}
}