-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
Signed-off-by: zhiheng123 <903292776@qq.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
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 { | ||
private final MtConnectServerConfiguration config; | ||
|
||
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); | ||
Check warning on line 20 in mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtConnectServer.java Codecov / codecov/patchmtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtConnectServer.java#L20
|
||
} | ||
|
||
public CompletableFuture<Void> start() { | ||
mtRequestProcessor.getHandlerMap().entrySet().forEach(entry -> { | ||
httpServer.addRoute(entry.getKey(), HttpMethod.GET, mtRequestProcessor); | ||
}); | ||
Check warning on line 26 in mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtConnectServer.java Codecov / codecov/patchmtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtConnectServer.java#L24-L26
|
||
return httpServer.start(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package io.github.protocol.mtconnect.server; | ||
|
||
import io.github.shoothzj.http.facade.server.RequestHandler; | ||
|
||
public interface MtHandler { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
Check warning on line 8 in mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtHandlerImpl.java Codecov / codecov/patchmtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtHandlerImpl.java#L8
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, MtHandler> handlerMap = new HashMap<>(); | ||
Check warning on line 22 in mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtRequestProcessor.java Codecov / codecov/patchmtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtRequestProcessor.java#L22
|
||
|
||
public MtRequestProcessor(MtConnectServerConfiguration serverCfg) { | ||
this.serverCfg = serverCfg; | ||
Check warning on line 25 in mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtRequestProcessor.java Codecov / codecov/patchmtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtRequestProcessor.java#L24-L25
|
||
|
||
handlerMap.put("/asset", new MtHandlerImpl()); | ||
handlerMap.put("/current", new MtHandlerImpl()); | ||
} | ||
Check warning on line 29 in mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtRequestProcessor.java Codecov / codecov/patchmtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtRequestProcessor.java#L27-L29
|
||
|
||
@Override | ||
public CompletableFuture<HttpResponse> handle(HttpRequest request) { | ||
return null; | ||
Check warning on line 33 in mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtRequestProcessor.java Codecov / codecov/patchmtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtRequestProcessor.java#L33
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package io.github.protocol.mtconnect.server; | ||
|
||
class MtConnectServerTest { | ||
} |