-
-
Save slomo/fa2b915f28400b123ab1 to your computer and use it in GitHub Desktop.
Check operation result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// handles response from the Read MIFARE Data message | |
post(new Route(Constants.readBlockCallbackUrl) { | |
@Override | |
public Object handle(Request request, Response response) { | |
JSONObject jsonParameters = (JSONObject) JSONValue.parse(request.body()); | |
String operationId = (String) jsonParameters.get("operationId"); | |
String sessionId = pendingOperations.get(operationId); | |
pendingOperations.remove(operationId); | |
int statusCode = ((Long)jsonParameters.get("statusCode")).intValue(); | |
if (statusCode != HTTP_OK) | |
{ | |
handleFailure(sessionId); | |
} else { | |
// parse the counter value from the read block, increment | |
// unless it is the first time the card is used, then initialize to one | |
// store counter and checksum in the session state map | |
JSONArray blocks = (JSONArray) jsonParameters.get("blocks"); | |
long counter = Utils.decodeCounter(blocks); | |
sessionMap.get(sessionId).setCounter(counter); | |
if (sessionMap.get(sessionId).isFirstTime()) { | |
sessionMap.get(sessionId).setCounter(1); | |
if (cardClient.writeCounterInCard(1, sessionId, pendingOperations) != HTTP_OK) handleFailure(sessionId); | |
} else { | |
counter ++; | |
if (cardClient.writeCounterInCard(counter, sessionId, pendingOperations) != HTTP_OK) handleFailure(sessionId); | |
} | |
} | |
response.status(HTTP_OK); | |
return ""; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment