Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add MtRequestProcessor #4

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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;

Expand All @@ -10,12 +11,18 @@

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 19 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#L19

Added line #L19 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 25 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#L23-L25

Added lines #L23 - L25 were not covered by tests
return httpServer.start();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.github.protocol.mtconnect.server;


public interface MtHandler {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.github.protocol.mtconnect.server;



public class MtHandlerImpl implements MtHandler {

Check warning on line 5 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#L5

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

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.Getter;
import lombok.Setter;

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 18 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#L18

Added line #L18 was not covered by tests

public MtRequestProcessor(MtConnectServerConfiguration serverCfg) {
this.serverCfg = serverCfg;

Check warning on line 21 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#L20-L21

Added lines #L20 - L21 were not covered by tests

handlerMap.put("/asset", new MtHandlerImpl());
handlerMap.put("/current", new MtHandlerImpl());
}

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#L23-L25

Added lines #L23 - L25 were not covered by tests

@Override
public CompletableFuture<HttpResponse> handle(HttpRequest request) {
return null;

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#L29

Added line #L29 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 {
}