Search in sources :

Example 1 with ListTokensResponseType

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);
}
Also used : WSHelper(org.openecard.common.WSHelper) ListTokensResponseType(org.openecard.ws.chipgateway.ListTokensResponseType) UnsupportedAlgorithmException(org.openecard.crypto.common.UnsupportedAlgorithmException) ThreadTerminateException(org.openecard.common.ThreadTerminateException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with ListTokensResponseType

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.");
}
Also used : ListTokensResponseType(org.openecard.ws.chipgateway.ListTokensResponseType) TokenInfoType(org.openecard.ws.chipgateway.TokenInfoType) BigInteger(java.math.BigInteger) Date(java.util.Date) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

TimeoutException (java.util.concurrent.TimeoutException)2 ListTokensResponseType (org.openecard.ws.chipgateway.ListTokensResponseType)2 BigInteger (java.math.BigInteger)1 Date (java.util.Date)1 ThreadTerminateException (org.openecard.common.ThreadTerminateException)1 WSHelper (org.openecard.common.WSHelper)1 UnsupportedAlgorithmException (org.openecard.crypto.common.UnsupportedAlgorithmException)1 TokenInfoType (org.openecard.ws.chipgateway.TokenInfoType)1