diff --git a/service-forest/src/test/java/com/lanyuanxiaoyao/service/forest/TestClient.java b/service-forest/src/test/java/com/lanyuanxiaoyao/service/forest/TestClient.java new file mode 100644 index 0000000..d99bee1 --- /dev/null +++ b/service-forest/src/test/java/com/lanyuanxiaoyao/service/forest/TestClient.java @@ -0,0 +1,24 @@ +package com.lanyuanxiaoyao.service.forest; + +import com.dtflys.forest.Forest; +import com.dtflys.forest.annotation.Get; + +/** + * @author lanyuanxiaoyao + * @date 2024-01-24 + */ +public class TestClient { + public static void main(String[] args) { + TestService testService = Forest.client(TestService.class); + System.out.println(testService.success()); + System.out.println(testService.error()); + } + + public interface TestService { + @Get("http://localhost:8000/success") + String success(); + + @Get("http://localhost:8000/error") + String error(); + } +} diff --git a/service-forest/src/test/java/com/lanyuanxiaoyao/service/forest/TestServer.java b/service-forest/src/test/java/com/lanyuanxiaoyao/service/forest/TestServer.java new file mode 100644 index 0000000..6fca7a3 --- /dev/null +++ b/service-forest/src/test/java/com/lanyuanxiaoyao/service/forest/TestServer.java @@ -0,0 +1,41 @@ +package com.lanyuanxiaoyao.service.forest; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpServer; +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetSocketAddress; + +/** + * @author lanyuanxiaoyao + * @date 2024-01-24 + */ +public class TestServer { + public static void main(String[] args) throws IOException { + HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0); + server.createContext("/success", new SuccessHandler()); + server.createContext("/error", new ErrorHandler()); + server.start(); + } + + public static class SuccessHandler implements HttpHandler { + @Override + public void handle(HttpExchange exchange) throws IOException { + exchange.sendResponseHeaders(200, 0); + OutputStream body = exchange.getResponseBody(); + body.write("Success".getBytes()); + body.close(); + } + } + + public static class ErrorHandler implements HttpHandler { + @Override + public void handle(HttpExchange exchange) throws IOException { + exchange.sendResponseHeaders(500, 0); + OutputStream body = exchange.getResponseBody(); + body.write("Error".getBytes()); + body.close(); + } + } +}