Fixed Index method, Comm back to back
This commit is contained in:
@@ -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")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user