mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
0ead90d433
commit
ce4d309841
@ -27,6 +27,16 @@ import org.dromara.hutool.core.lang.Assert;
|
||||
*/
|
||||
public class RouteHttpHandler implements HttpHandler {
|
||||
|
||||
/**
|
||||
* 创建路由处理器
|
||||
*
|
||||
* @param defaultHandler 默认处理器
|
||||
* @return {@code RouteHttpHandler}
|
||||
*/
|
||||
public static RouteHttpHandler of(final HttpHandler defaultHandler) {
|
||||
return new RouteHttpHandler(defaultHandler);
|
||||
}
|
||||
|
||||
private final PathTrie pathTrie;
|
||||
private final HttpHandler defaultHandler;
|
||||
|
||||
|
@ -21,12 +21,13 @@ import org.dromara.hutool.core.lang.Console;
|
||||
import org.dromara.hutool.core.net.ssl.SSLContextUtil;
|
||||
import org.dromara.hutool.crypto.KeyStoreUtil;
|
||||
import org.dromara.hutool.http.server.ServerConfig;
|
||||
import org.dromara.hutool.http.server.handler.RouteHttpHandler;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.security.KeyStore;
|
||||
|
||||
public class UndertowTest {
|
||||
public static void main(String[] args) {
|
||||
public static void main(final String[] args) {
|
||||
final char[] pwd = "123456".toCharArray();
|
||||
final KeyStore keyStore = KeyStoreUtil.readJKSKeyStore(FileUtil.file("d:/test/keystore.jks"), pwd);
|
||||
// 初始化SSLContext
|
||||
@ -34,10 +35,16 @@ public class UndertowTest {
|
||||
|
||||
final ServerEngine engine = ServerEngineFactory.createEngine("undertow");
|
||||
engine.init(ServerConfig.of().setSslContext(sslContext));
|
||||
engine.setHandler((request, response) -> {
|
||||
|
||||
// 自定义路由策略
|
||||
engine.setHandler(RouteHttpHandler.of((request, response) -> {
|
||||
Console.log(request.getPath());
|
||||
response.write("Hutool Undertow response test");
|
||||
});
|
||||
}).route("/test", (request, response) -> {
|
||||
Console.log(request.getPath());
|
||||
response.write("test path");
|
||||
}));
|
||||
|
||||
engine.start();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user