add ExceptionFilter

This commit is contained in:
Looly
2023-09-28 18:54:23 +08:00
parent 0c3f91bad3
commit 53419903c1
5 changed files with 139 additions and 9 deletions

View File

@@ -0,0 +1,28 @@
/*
* Copyright (c) 2023. looly(loolly@aliyun.com)
* Hutool is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* https://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
package org.dromara.hutool.http;
import org.dromara.hutool.core.lang.Console;
import org.dromara.hutool.http.client.Request;
import org.dromara.hutool.http.client.engine.jdk.JdkClientEngine;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
public class Issue444Test {
@Test
@Disabled
void getTest() {
final String s = Request.of("http://localhost:8888").send(new JdkClientEngine()).bodyStr();
Console.log(s);
}
}

View File

@@ -0,0 +1,29 @@
/*
* Copyright (c) 2023 looly(loolly@aliyun.com)
* Hutool is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* https://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
package org.dromara.hutool.http.server;
import org.dromara.hutool.http.HttpUtil;
import org.dromara.hutool.http.server.filter.DefaultExceptionFilter;
import java.io.IOException;
public class ExceptionServerTest {
public static void main(final String[] args) {
HttpUtil.createServer(8888)
.addFilter(new DefaultExceptionFilter())
.addAction("/", (req, res) -> {
throw new IOException("Test Exception");
})
.start();
}
}