use of org.openecard.ws.chipgateway.ListTokensResponseType in project open-ecard by ecsec.
the class ChipGateway method processTokensRequest.
private CommandType processTokensRequest(ListTokensRequestType tokensReq) throws ConnectionError, JsonProcessingException, InvalidRedirectUrlException, ChipGatewayDataError {
// check if we have been interrupted
checkProcessCancelled();
ListTokensResponseType tokensResp = new ListTokensResponseType();
tokensResp.setSessionIdentifier(sessionId);
try {
tokensResp = waitForTokens(tokensReq);
} catch (UnsupportedAlgorithmException ex) {
LOG.error("Unsupported algorithm used.", ex);
tokensResp.setResult(ChipGatewayStatusCodes.INCORRECT_PARAMETER);
} catch (WSHelper.WSException ex) {
LOG.error("Unknown error.", ex);
tokensResp.setResult(ChipGatewayStatusCodes.OTHER);
} catch (ThreadTerminateException | InterruptedException ex) {
LOG.info("Chipgateway process interrupted.", ex);
tokensResp.setResult(ChipGatewayStatusCodes.STOPPED);
} catch (TimeoutException ex) {
LOG.info("Waiting for new tokens timed out.", ex);
tokensResp.setResult(ChipGatewayStatusCodes.TIMEOUT);
}
return sendMessageInterruptableAndCheckTermination(getResource(listTokensUrl), tokensResp);
}
use of org.openecard.ws.chipgateway.ListTokensResponseType in project open-ecard by ecsec.
the class ChipGateway method waitForTokens.
private ListTokensResponseType waitForTokens(ListTokensRequestType tokensReq) throws UnsupportedAlgorithmException, WSHelper.WSException, InterruptedException, TimeoutException {
BigInteger waitSecondsBig = tokensReq.getMaxWaitSeconds();
long waitMillis = getWaitMillis(waitSecondsBig);
Date startTime = new Date();
ListTokens helper = new ListTokens(tokensReq.getTokenInfo(), addonCtx);
do {
// build list of matching tokens
List<TokenInfoType> matchedTokens = helper.findTokens();
// save handles of connected cards
connectedSlots.addAll(helper.getConnectedSlots());
// return if tokens have been found or no specific set of tokens has been requested
if (!matchedTokens.isEmpty() || tokensReq.getTokenInfo().isEmpty()) {
ListTokensResponseType tokensResp = new ListTokensResponseType();
tokensResp.setSessionIdentifier(sessionId);
tokensResp.setResult(ChipGatewayStatusCodes.OK);
tokensResp.getTokenInfo().addAll(matchedTokens);
return tokensResp;
}
// TODO: use real wait mechanism on the SAL implementation
Thread.sleep(1000);
} while ((new Date().getTime() - startTime.getTime()) < waitMillis);
throw new TimeoutException("Waiting for ListTokens timed out.");
}
Aggregations