From ecd75350557294b9bb12cdbcdc24f9382179f04b Mon Sep 17 00:00:00 2001 From: zhiheng123 <903292776@qq.com> Date: Sun, 22 Sep 2024 17:20:10 +0800 Subject: [PATCH] feat: add MtRequestProcessor Signed-off-by: zhiheng123 <903292776@qq.com> --- .../mtconnect/server/MtConnectServer.java | 8 +++++ .../protocol/mtconnect/server/MtHandler.java | 6 ++++ .../mtconnect/server/MtHandlerImpl.java | 9 +++++ .../mtconnect/server/MtRequestProcessor.java | 35 +++++++++++++++++++ .../mtconnect/server/MtConnectServerTest.java | 4 +++ 5 files changed, 62 insertions(+) create mode 100644 mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtHandler.java create mode 100644 mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtHandlerImpl.java create mode 100644 mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtRequestProcessor.java create mode 100644 mtconnect-server/src/test/java/io/github/protocol/mtconnect/server/MtConnectServerTest.java diff --git a/mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtConnectServer.java b/mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtConnectServer.java index 7f0d000..af9f0fe 100644 --- a/mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtConnectServer.java +++ b/mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtConnectServer.java @@ -1,8 +1,10 @@ package io.github.protocol.mtconnect.server; +import io.github.shoothzj.http.facade.core.HttpMethod; import io.github.shoothzj.http.facade.server.HttpServer; import io.github.shoothzj.http.facade.server.HttpServerFactory; +import java.util.HashMap; import java.util.concurrent.CompletableFuture; public class MtConnectServer { @@ -10,12 +12,18 @@ public class MtConnectServer { private final HttpServer httpServer; + private final MtRequestProcessor mtRequestProcessor; + public MtConnectServer(MtConnectServerConfiguration configuration) { this.config = configuration; this.httpServer = HttpServerFactory.createHttpServer(config.httpConfig()); + this.mtRequestProcessor = new MtRequestProcessor(configuration); } public CompletableFuture start() { + mtRequestProcessor.getHandlerMap().entrySet().forEach(entry -> { + httpServer.addRoute(entry.getKey(), HttpMethod.GET, mtRequestProcessor); + }); return httpServer.start(); } } diff --git a/mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtHandler.java b/mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtHandler.java new file mode 100644 index 0000000..4f27921 --- /dev/null +++ b/mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtHandler.java @@ -0,0 +1,6 @@ +package io.github.protocol.mtconnect.server; + +import io.github.shoothzj.http.facade.server.RequestHandler; + +public interface MtHandler { +} diff --git a/mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtHandlerImpl.java b/mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtHandlerImpl.java new file mode 100644 index 0000000..01e2bf2 --- /dev/null +++ b/mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtHandlerImpl.java @@ -0,0 +1,9 @@ +package io.github.protocol.mtconnect.server; + +import io.github.shoothzj.http.facade.core.HttpRequest; +import io.github.shoothzj.http.facade.core.HttpResponse; + +import java.util.concurrent.CompletableFuture; + +public class MtHandlerImpl implements MtHandler { +} diff --git a/mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtRequestProcessor.java b/mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtRequestProcessor.java new file mode 100644 index 0000000..bedecdf --- /dev/null +++ b/mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtRequestProcessor.java @@ -0,0 +1,35 @@ +package io.github.protocol.mtconnect.server; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; +import io.github.shoothzj.http.facade.core.HttpRequest; +import io.github.shoothzj.http.facade.core.HttpResponse; +import io.github.shoothzj.http.facade.server.RequestHandler; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.CompletableFuture; + +@Getter +@Setter +public class MtRequestProcessor implements RequestHandler { + private MtConnectServerConfiguration serverCfg; + + private Map handlerMap = new HashMap<>(); + + public MtRequestProcessor(MtConnectServerConfiguration serverCfg) { + this.serverCfg = serverCfg; + + handlerMap.put("/asset", new MtHandlerImpl()); + handlerMap.put("/current", new MtHandlerImpl()); + } + + @Override + public CompletableFuture handle(HttpRequest request) { + return null; + } +} diff --git a/mtconnect-server/src/test/java/io/github/protocol/mtconnect/server/MtConnectServerTest.java b/mtconnect-server/src/test/java/io/github/protocol/mtconnect/server/MtConnectServerTest.java new file mode 100644 index 0000000..e876d35 --- /dev/null +++ b/mtconnect-server/src/test/java/io/github/protocol/mtconnect/server/MtConnectServerTest.java @@ -0,0 +1,4 @@ +package io.github.protocol.mtconnect.server; + +class MtConnectServerTest { +}