Http token request
This commit is contained in:
@@ -65,28 +65,10 @@ public class Main {
|
|||||||
|
|
||||||
server.start();
|
server.start();
|
||||||
|
|
||||||
requestACQ(ctx);
|
|
||||||
|
|
||||||
Logger.displayInfo("Server started on port " + HTTP_SERVER_PORT);
|
Logger.displayInfo("Server started on port " + HTTP_SERVER_PORT);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,19 @@ import com.sun.net.httpserver.HttpExchange;
|
|||||||
import common.common.src.html.HtmlManager;
|
import common.common.src.html.HtmlManager;
|
||||||
import common.common.src.json.JsonManager;
|
import common.common.src.json.JsonManager;
|
||||||
import common.common.src.logger.Logger;
|
import common.common.src.logger.Logger;
|
||||||
|
import common.common.src.socket.SocketManager;
|
||||||
import common.common.src.json.JsonManager;
|
import common.common.src.json.JsonManager;
|
||||||
import httpServer.httpServer.src.annotations.AllowedVerb;
|
import httpServer.httpServer.src.annotations.AllowedVerb;
|
||||||
import httpServer.httpServer.src.annotations.OnlyAuthorizedClients;
|
import httpServer.httpServer.src.annotations.OnlyAuthorizedClients;
|
||||||
import httpServer.httpServer.src.authorization.AuthorizedClients;
|
import httpServer.httpServer.src.authorization.AuthorizedClients;
|
||||||
import httpServer.httpServer.src.authorization.Client;
|
import httpServer.httpServer.src.authorization.Client;
|
||||||
|
|
||||||
|
import static common.common.src.ports.Ports.*;
|
||||||
|
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
|
import javax.net.ssl.SSLSocket;
|
||||||
|
import javax.net.ssl.SSLSocketFactory;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -56,17 +62,30 @@ public class RequestHandler implements IRequestHandler {
|
|||||||
|
|
||||||
Map<String, Object> map = Map.of("token", token);
|
Map<String, Object> map = Map.of("token", token);
|
||||||
String jsonString = JsonManager.serialize(map);
|
String jsonString = JsonManager.serialize(map);
|
||||||
|
String response = "";
|
||||||
// Send request to ACQ
|
// Send request to ACQ
|
||||||
|
|
||||||
|
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
|
||||||
// Wait ACQ ACK or NAK
|
response = SocketManager.readResponse(socket);
|
||||||
|
Logger.displayReceived(response);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
// Return result
|
// Return result
|
||||||
|
|
||||||
|
if(response == "ACK"){
|
||||||
|
// if ACK
|
||||||
|
}else{
|
||||||
|
// else NAK
|
||||||
|
}
|
||||||
|
|
||||||
} catch(Exception e){
|
} catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user