Search in sources :

Example 1 with SAL

use of org.openecard.ws.SAL in project open-ecard by ecsec.

the class SelectorSAL method initialize.

@Override
public InitializeResponse initialize(Initialize init) {
    InitializeResponse response = WSHelper.makeResponse(InitializeResponse.class, WSHelper.makeResultOK());
    // only initialize one time
    if (initializedSals.isEmpty()) {
        LinkedList<SAL> sals = new LinkedList<>();
        sals.add(main);
        sals.addAll(special);
        for (SAL next : sals) {
            try {
                InitializeResponse res = next.initialize(init);
                WSHelper.checkResult(res);
                if (!WSHelper.resultsInWarn(res)) {
                    if (next instanceof SpecializedSAL) {
                        initializedSpecializedSals.add((SpecializedSAL) next);
                    } else {
                        initializedSals.add(next);
                    }
                }
            } catch (WSHelper.WSException ex) {
                String msg = "One of the SAL instances failed to initialize:\n" + ex.getMessage();
                terminate(new Terminate());
                response.setResult(WSHelper.makeResultError(ECardConstants.Minor.Disp.COMM_ERROR, msg));
                return response;
            }
        }
    }
    return response;
}
Also used : WSHelper(org.openecard.common.WSHelper) InitializeResponse(iso.std.iso_iec._24727.tech.schema.InitializeResponse) Terminate(iso.std.iso_iec._24727.tech.schema.Terminate) LinkedList(java.util.LinkedList) SAL(org.openecard.ws.SAL) SpecializedSAL(org.openecard.common.sal.SpecializedSAL) SpecializedSAL(org.openecard.common.sal.SpecializedSAL)

Example 2 with SAL

use of org.openecard.ws.SAL in project open-ecard by ecsec.

the class SelectorSAL method terminate.

@Override
public TerminateResponse terminate(Terminate terminate) {
    TerminateResponse response = WSHelper.makeResponse(TerminateResponse.class, WSHelper.makeResultOK());
    // only terminate if initialized
    if (!initializedSals.isEmpty()) {
        boolean errorHit = false;
        for (SAL next : initializedSals) {
            try {
                TerminateResponse res = next.terminate(terminate);
                WSHelper.checkResult(res);
            } catch (WSHelper.WSException ex) {
                // in case of an error, take the error code from the first SAL
                if (!errorHit) {
                    response.setResult(ex.getResult());
                }
            }
        }
        initializedSals.clear();
    }
    return response;
}
Also used : WSHelper(org.openecard.common.WSHelper) TerminateResponse(iso.std.iso_iec._24727.tech.schema.TerminateResponse) SAL(org.openecard.ws.SAL) SpecializedSAL(org.openecard.common.sal.SpecializedSAL)

Aggregations

WSHelper (org.openecard.common.WSHelper)2 SpecializedSAL (org.openecard.common.sal.SpecializedSAL)2 SAL (org.openecard.ws.SAL)2 InitializeResponse (iso.std.iso_iec._24727.tech.schema.InitializeResponse)1 Terminate (iso.std.iso_iec._24727.tech.schema.Terminate)1 TerminateResponse (iso.std.iso_iec._24727.tech.schema.TerminateResponse)1 LinkedList (java.util.LinkedList)1