From ba67cc05ca15e6cd6cdc61ed038e33c66c52a19b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= Date: Sun, 7 Dec 2025 21:00:10 +0100 Subject: [PATCH] Http token request --- .../java/httpServer/httpServer/src/Main.java | 18 ----------- .../src/handlers/RequestHandler.java | 31 +++++++++++++++---- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/main/java/httpServer/httpServer/src/Main.java b/src/main/java/httpServer/httpServer/src/Main.java index 58941b8..68d15d5 100644 --- a/src/main/java/httpServer/httpServer/src/Main.java +++ b/src/main/java/httpServer/httpServer/src/Main.java @@ -65,28 +65,10 @@ public class Main { server.start(); - requestACQ(ctx); - Logger.displayInfo("Server started on port " + HTTP_SERVER_PORT); } catch (Exception e) { throw new RuntimeException(e); } } - public static void requestACQ(SSLContext ctx) { - SSLSocketFactory factory = ctx.getSocketFactory(); - try (SSLSocket socket = (SSLSocket) factory.createSocket("127.0.0.1", ACQ_SERVER_PORT)) { - socket.startHandshake(); - - String message = "Hello ACQ"; - SocketManager.send(socket, message); - Logger.displaySent(message); - - String response = SocketManager.readResponse(socket); - Logger.displayReceived(response); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } diff --git a/src/main/java/httpServer/httpServer/src/handlers/RequestHandler.java b/src/main/java/httpServer/httpServer/src/handlers/RequestHandler.java index 866bfb5..09fa75e 100644 --- a/src/main/java/httpServer/httpServer/src/handlers/RequestHandler.java +++ b/src/main/java/httpServer/httpServer/src/handlers/RequestHandler.java @@ -6,13 +6,19 @@ import com.sun.net.httpserver.HttpExchange; import common.common.src.html.HtmlManager; import common.common.src.json.JsonManager; import common.common.src.logger.Logger; +import common.common.src.socket.SocketManager; import common.common.src.json.JsonManager; import httpServer.httpServer.src.annotations.AllowedVerb; import httpServer.httpServer.src.annotations.OnlyAuthorizedClients; import httpServer.httpServer.src.authorization.AuthorizedClients; import httpServer.httpServer.src.authorization.Client; +import static common.common.src.ports.Ports.*; + import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocket; +import javax.net.ssl.SSLSocketFactory; + import java.io.*; import java.nio.charset.StandardCharsets; import java.util.Map; @@ -56,17 +62,30 @@ public class RequestHandler implements IRequestHandler { Map map = Map.of("token", token); String jsonString = JsonManager.serialize(map); - + String response = ""; // Send request to ACQ - - - - // Wait ACQ ACK or NAK - + SSLSocketFactory factory = sslCtx.getSocketFactory(); + try (SSLSocket socket = (SSLSocket) factory.createSocket("127.0.0.1", ACQ_SERVER_PORT)) { + socket.startHandshake(); + SocketManager.send(socket, jsonString); + Logger.displaySent(jsonString); + + // Wait ACQ ACK or NAK + response = SocketManager.readResponse(socket); + Logger.displayReceived(response); + } catch (Exception e) { + throw new RuntimeException(e); + } // Return result + if(response == "ACK"){ + // if ACK + }else{ + // else NAK + } + } catch(Exception e){ e.printStackTrace(); }