Fixed Index method, Comm back to back
This commit is contained in:
@@ -85,17 +85,20 @@
|
||||
|
||||
let token = document.getElementById("token-input").value;
|
||||
|
||||
await fetch("/payement", {
|
||||
let dataToken = {
|
||||
token: token
|
||||
};
|
||||
|
||||
await fetch("/payment", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
//"Authorization" : "username:password"
|
||||
},
|
||||
body: JSON.stringify(token)
|
||||
body: JSON.stringify(dataToken)
|
||||
})
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
//Logique à executer si serveur répond avec 200 HTTP
|
||||
|
||||
} else {
|
||||
throw new Error("Payment request failed")
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class Main {
|
||||
// contact ACS
|
||||
|
||||
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();
|
||||
|
||||
String request = response;
|
||||
|
||||
@@ -24,7 +24,7 @@ public class Main {
|
||||
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_PWD = "hepl_keystore";
|
||||
private static final String TRUST_STORE_PWD = "hepl_truststore";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -33,9 +33,10 @@ public class Main {
|
||||
|
||||
KeyFactory loader = new KeyFactory();
|
||||
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");
|
||||
ctx.init(kmf.getKeyManagers(), null, null);
|
||||
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
|
||||
|
||||
server.setHttpsConfigurator(new HttpsConfigurator(ctx) {
|
||||
@Override
|
||||
|
||||
@@ -42,7 +42,6 @@ public class RequestHandler implements IRequestHandler {
|
||||
}
|
||||
|
||||
@AllowedVerb(name = "POST")
|
||||
//@OnlyAuthorizedClients
|
||||
public void handlePayment(HttpExchange exchange) {
|
||||
Logger.displayReceived("/payment request");
|
||||
try{
|
||||
@@ -80,12 +79,13 @@ public class RequestHandler implements IRequestHandler {
|
||||
}
|
||||
// Return result
|
||||
|
||||
if(response == "ACK"){
|
||||
// if ACK
|
||||
}else{
|
||||
// else NAK
|
||||
}
|
||||
response = response.trim();
|
||||
|
||||
if ("ACK".equalsIgnoreCase(response)) {
|
||||
// success
|
||||
} else {
|
||||
// failure
|
||||
}
|
||||
} catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -53,6 +53,8 @@ public class RequestInterceptor implements InvocationHandler {
|
||||
if (!method.isAnnotationPresent(AllowedVerb.class)) return;
|
||||
|
||||
String allowedVerb = method.getAnnotation(AllowedVerb.class).name();
|
||||
Logger.displayReceived(receivedVerb);
|
||||
Logger.displayReceived(allowedVerb);
|
||||
if(!allowedVerb.equalsIgnoreCase(receivedVerb)){
|
||||
throw new NoSuchVerbException("HTTP verb not allowed");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user