diff options
| author | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-10-12 10:07:07 +0200 |
|---|---|---|
| committer | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-10-12 10:07:07 +0200 |
| commit | 0ab73e47af2bba3fb2ff6a4bf08ada4a3309bf3e (patch) | |
| tree | 05e2b9ebd60e5c8175f086e1de73657032d9c2fc /java/Main.java | |
| parent | 3363ab2da764825558c859f4419ff99528ed2274 (diff) | |
| download | lambda-nantes-0ab73e47af2bba3fb2ff6a4bf08ada4a3309bf3e.tar.gz | |
Add java evaluator
Diffstat (limited to 'java/Main.java')
| -rw-r--r-- | java/Main.java | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/java/Main.java b/java/Main.java new file mode 100644 index 0000000..76cb839 --- /dev/null +++ b/java/Main.java @@ -0,0 +1,49 @@ +package org.lambdanantes.lcgoji; + +import lombok.extern.slf4j.Slf4j; +import org.apache.http.client.fluent.Request; +import org.apache.http.client.fluent.Response; +import org.apache.http.entity.StringEntity; + +import static spark.Spark.*; + +@Slf4j +public class Main { + + public static final String TEAM_NAME = "LCGOJI"; + public static final int SELF_PORT = 8888; + public static final String SELF_URL = "http://127.0.0.1:" + SELF_PORT; + public static final String TESTER_URL = "http://127.0.0.1:8080"; + + public static void main(String[] args) throws Exception { + port(SELF_PORT); + + before((request, response) -> log.info("Requête entrante : " + request.requestMethod() + " " + request.pathInfo() + ", query params : " + request.queryString())); + + // API pour l'évaluation de λ-term + // Le body est une S-expression sous sa forme textuelle + post("/eval", (request, response) -> { + String body = request.body(); + log.info("Demande d'évaluation de l'expression : " + body); + + // TODO Parser, contruire l'AST, l'évaluer + String result = body; // Renvoie la s-expression à l'identique pour le moment + + log.info("Réponse envoyée : " + body); + + return result.getBytes(); + }); + + init(); + + // Enregistrement de notre API auprès du tester d'API + String jsonBody = "{\"url\":\"" + SELF_URL + "/eval\", \"name\": \"" + TEAM_NAME + "\"}"; + Response response = Request.Post(TESTER_URL + "/register") + .addHeader("Content-type", "application/json") + .body(new StringEntity(jsonBody)) + .execute(); + + log.info("Résultat de l'enregistrement : "+response.returnContent().toString()); + } + +}
\ No newline at end of file |
