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

Dev api link interaction #153

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
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
Expand Up @@ -12,14 +12,14 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jembi.jempi.AppConfig;
import org.jembi.jempi.shared.models.ApiModels;
import org.jembi.jempi.shared.models.GlobalConstants;
import org.jembi.jempi.shared.models.LinkInteractionSyncBody;
import org.jembi.jempi.shared.models.LinkInteractionToGidSyncBody;
import org.jembi.jempi.shared.utils.AppUtils;

import java.util.Locale;
import java.util.concurrent.CompletionStage;

import static org.jembi.jempi.shared.utils.AppUtils.OBJECT_MAPPER;

public final class HttpServer extends AllDirectives {

private static final Logger LOGGER = LogManager.getLogger(HttpServer.class);
Expand All @@ -42,7 +42,7 @@ void open(
LOGGER.info("Server online at http://{}:{}", "0.0.0.0", AppConfig.CONTROLLER_HTTP_PORT);
}

private CompletionStage<HttpResponse> postLinkInteraction(final LinkInteractionSyncBody body) throws JsonProcessingException {
private CompletionStage<HttpResponse> postLinkInteraction(final ApiModels.LinkInteractionSyncBody body) throws JsonProcessingException {
final HttpRequest request;
request = HttpRequest
.create(String.format(Locale.ROOT,
Expand All @@ -51,20 +51,20 @@ private CompletionStage<HttpResponse> postLinkInteraction(final LinkInteractionS
AppConfig.LINKER_HTTP_PORT,
GlobalConstants.SEGMENT_PROXY_POST_LINK_INTERACTION))
.withMethod(HttpMethods.POST)
.withEntity(ContentTypes.APPLICATION_JSON, AppUtils.OBJECT_MAPPER.writeValueAsBytes(body));
.withEntity(ContentTypes.APPLICATION_JSON, OBJECT_MAPPER.writeValueAsBytes(body));
final var stage = http.singleRequest(request);
return stage.thenApply(response -> response);
}

private CompletionStage<HttpResponse> postLinkInteractionToGid(final LinkInteractionToGidSyncBody body) throws JsonProcessingException {
private CompletionStage<HttpResponse> postLinkInteractionToGid(final ApiModels.LinkInteractionToGidSyncBody body) throws JsonProcessingException {
final var request = HttpRequest
.create(String.format(Locale.ROOT,
"http://%s:%d/JeMPI/%s",
AppConfig.LINKER_IP,
AppConfig.LINKER_HTTP_PORT,
GlobalConstants.SEGMENT_PROXY_POST_LINK_INTERACTION_TO_GID))
.withMethod(HttpMethods.POST)
.withEntity(ContentTypes.APPLICATION_JSON, AppUtils.OBJECT_MAPPER.writeValueAsBytes(body));
.withEntity(ContentTypes.APPLICATION_JSON, OBJECT_MAPPER.writeValueAsBytes(body));
final var stage = http.singleRequest(request);
return stage.thenApply(response -> response);
}
Expand All @@ -78,7 +78,7 @@ private CompletionStage<HttpResponse> getMU() {
}

private Route routeLinkInteraction() {
return entity(Jackson.unmarshaller(LinkInteractionSyncBody.class),
return entity(Jackson.unmarshaller(ApiModels.LinkInteractionSyncBody.class),
obj -> {
try {
LOGGER.debug("{}", obj);
Expand All @@ -94,17 +94,17 @@ private Route routeLinkInteraction() {
}

private Route routeLinkInteractionToGid() {
return entity(Jackson.unmarshaller(LinkInteractionToGidSyncBody.class),
return entity(Jackson.unmarshaller(ApiModels.LinkInteractionToGidSyncBody.class),
obj -> {
try {
return onComplete(postLinkInteractionToGid(obj),
response -> response.isSuccess()
? complete(response.get())
: complete(StatusCodes.IM_A_TEAPOT));
: complete(ApiModels.getHttpErrorResponse(StatusCodes.IM_A_TEAPOT)));
} catch (JsonProcessingException e) {
LOGGER.error(e.getLocalizedMessage(), e);
return complete(StatusCodes.IM_A_TEAPOT);
}
return complete(ApiModels.getHttpErrorResponse(StatusCodes.IM_A_TEAPOT));
});
}

Expand Down
4 changes: 2 additions & 2 deletions JeMPI_Apps/JeMPI_LibAPI/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
<source>21</source>
<target>21</target>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>
Expand Down
Loading