Fixed Index method, Comm back to back

This commit is contained in:
Cédric
2025-12-08 11:40:44 +01:00
parent 54c16c24b7
commit 9cdbcc3734
5 changed files with 19 additions and 13 deletions

View File

@@ -85,17 +85,20 @@
let token = document.getElementById("token-input").value; let token = document.getElementById("token-input").value;
await fetch("/payement", { let dataToken = {
token: token
};
await fetch("/payment", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json" "Content-Type": "application/json"
//"Authorization" : "username:password"
}, },
body: JSON.stringify(token) body: JSON.stringify(dataToken)
}) })
.then(response => { .then(response => {
if (response.ok) { if (response.ok) {
//Logique à executer si serveur répond avec 200 HTTP
} else { } else {
throw new Error("Payment request failed") throw new Error("Payment request failed")
} }

View File

@@ -52,7 +52,7 @@ public class Main {
// contact ACS // contact ACS
SSLSocketFactory factory = ctx.getSocketFactory(); SSLSocketFactory factory = ctx.getSocketFactory();
SSLSocket socketACS = (SSLSocket) factory.createSocket(Main.HOST, AUTH_PORT); SSLSocket socketACS = (SSLSocket) factory.createSocket(Main.HOST, ACS_SERVER_PORT);
socketACS.startHandshake(); socketACS.startHandshake();
String request = response; String request = response;

View File

@@ -24,7 +24,7 @@ public class Main {
private static final String KEY_STORE_PWD = "hepl_keystore"; private static final String KEY_STORE_PWD = "hepl_keystore";
private static final String TRUST_STORE_PATH = "assets/certs/httpServer/httpServer.truststore.p12"; private static final String TRUST_STORE_PATH = "assets/certs/httpServer/httpServer.truststore.p12";
private static final String TRUST_STORE_PWD = "hepl_keystore"; private static final String TRUST_STORE_PWD = "hepl_truststore";
public static void main(String[] args) { public static void main(String[] args) {
@@ -33,9 +33,10 @@ public class Main {
KeyFactory loader = new KeyFactory(); KeyFactory loader = new KeyFactory();
KeyManagerFactory kmf = loader.loadKeyStore(KEY_STORE_PATH, KEY_STORE_PWD); KeyManagerFactory kmf = loader.loadKeyStore(KEY_STORE_PATH, KEY_STORE_PWD);
TrustManagerFactory tmf = loader.loadTrustStore(TRUST_STORE_PATH, TRUST_STORE_PWD);
SSLContext ctx = SSLContext.getInstance("TLS"); SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(kmf.getKeyManagers(), null, null); ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
server.setHttpsConfigurator(new HttpsConfigurator(ctx) { server.setHttpsConfigurator(new HttpsConfigurator(ctx) {
@Override @Override

View File

@@ -42,7 +42,6 @@ public class RequestHandler implements IRequestHandler {
} }
@AllowedVerb(name = "POST") @AllowedVerb(name = "POST")
//@OnlyAuthorizedClients
public void handlePayment(HttpExchange exchange) { public void handlePayment(HttpExchange exchange) {
Logger.displayReceived("/payment request"); Logger.displayReceived("/payment request");
try{ try{
@@ -80,12 +79,13 @@ public class RequestHandler implements IRequestHandler {
} }
// Return result // Return result
if(response == "ACK"){ response = response.trim();
// if ACK
}else{
// else NAK
}
if ("ACK".equalsIgnoreCase(response)) {
// success
} else {
// failure
}
} catch(Exception e){ } catch(Exception e){
e.printStackTrace(); e.printStackTrace();
} }

View File

@@ -53,6 +53,8 @@ public class RequestInterceptor implements InvocationHandler {
if (!method.isAnnotationPresent(AllowedVerb.class)) return; if (!method.isAnnotationPresent(AllowedVerb.class)) return;
String allowedVerb = method.getAnnotation(AllowedVerb.class).name(); String allowedVerb = method.getAnnotation(AllowedVerb.class).name();
Logger.displayReceived(receivedVerb);
Logger.displayReceived(allowedVerb);
if(!allowedVerb.equalsIgnoreCase(receivedVerb)){ if(!allowedVerb.equalsIgnoreCase(receivedVerb)){
throw new NoSuchVerbException("HTTP verb not allowed"); throw new NoSuchVerbException("HTTP verb not allowed");
} }