Skip to content

Commit

Permalink
feat: add MtRequestProcessor
Browse files Browse the repository at this point in the history
Signed-off-by: zhiheng123 <903292776@qq.com>
  • Loading branch information
zhiheng123 committed Sep 26, 2024
1 parent 2620521 commit ecd7535
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
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

View check run for this annotation

Codecov / codecov/patch

mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtConnectServer.java#L20

Added line #L20 was not covered by tests
}

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

View check run for this annotation

Codecov / codecov/patch

mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtConnectServer.java#L24-L26

Added lines #L24 - L26 were not covered by tests
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

View check run for this annotation

Codecov / codecov/patch

mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtHandlerImpl.java#L8

Added line #L8 was not covered by tests
}
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

View check run for this annotation

Codecov / codecov/patch

mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtRequestProcessor.java#L22

Added line #L22 was not covered by tests

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

View check run for this annotation

Codecov / codecov/patch

mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtRequestProcessor.java#L24-L25

Added lines #L24 - L25 were not covered by tests

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

View check run for this annotation

Codecov / codecov/patch

mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtRequestProcessor.java#L27-L29

Added lines #L27 - L29 were not covered by tests

@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

View check run for this annotation

Codecov / codecov/patch

mtconnect-server/src/main/java/io/github/protocol/mtconnect/server/MtRequestProcessor.java#L33

Added line #L33 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.github.protocol.mtconnect.server;

class MtConnectServerTest {
}

0 comments on commit ecd7535

Please sign in to comment.