Search in sources :

Example 1 with Terminate

use of iso.std.iso_iec._24727.tech.schema.Terminate in project open-ecard by ecsec.

the class IFD method releaseContext.

@Override
public synchronized ReleaseContextResponse releaseContext(ReleaseContext parameters) {
    ReleaseContextResponse response;
    if (ByteUtils.compare(ctxHandle, parameters.getContextHandle())) {
        if (numClients.decrementAndGet() == 0) {
            // last client detaches
            env.removeIFDCtx(ctxHandle);
            ctxHandle = null;
            numClients = null;
            // terminate thread pool
            // wait for threads to die and block new requests
            threadPool.shutdownNow();
            // just assume it worked ... and don't wait
            threadPool = null;
            asyncWaitThreads = null;
        }
        evManager.terminate();
        response = WSHelper.makeResponse(ReleaseContextResponse.class, WSHelper.makeResultOK());
        return response;
    } else {
        String msg = "Invalid context handle specified.";
        Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_CONTEXT_HANDLE, msg);
        response = WSHelper.makeResponse(ReleaseContextResponse.class, r);
        return response;
    }
}
Also used : ReleaseContextResponse(iso.std.iso_iec._24727.tech.schema.ReleaseContextResponse) Result(oasis.names.tc.dss._1_0.core.schema.Result)

Example 2 with Terminate

use of iso.std.iso_iec._24727.tech.schema.Terminate 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 3 with Terminate

use of iso.std.iso_iec._24727.tech.schema.Terminate in project open-ecard by ecsec.

the class RichClient method teardown.

public void teardown() {
    try {
        if (eventDispatcher != null) {
            eventDispatcher.terminate();
        }
        // TODO: shutdown addon manager and related components?
        if (manager != null) {
            manager.shutdown();
        }
        // shutdown control modules
        if (httpBinding != null) {
            httpBinding.stop();
        }
        // shutdown SAL
        if (sal != null) {
            Terminate terminate = new Terminate();
            sal.terminate(terminate);
        }
        // shutdown IFD
        if (ifd != null && contextHandle != null) {
            ReleaseContext releaseContext = new ReleaseContext();
            releaseContext.setContextHandle(contextHandle);
            ifd.releaseContext(releaseContext);
        }
    } catch (Exception ex) {
        LOG.error("Failed to stop Richclient.", ex);
    }
    System.exit(0);
}
Also used : ReleaseContext(iso.std.iso_iec._24727.tech.schema.ReleaseContext) Terminate(iso.std.iso_iec._24727.tech.schema.Terminate) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) Win32Exception(com.sun.jna.platform.win32.Win32Exception) BindException(java.net.BindException) HttpException(org.openecard.apache.http.HttpException) IOException(java.io.IOException) JoranException(ch.qos.logback.core.joran.spi.JoranException)

Example 4 with Terminate

use of iso.std.iso_iec._24727.tech.schema.Terminate 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)

Example 5 with Terminate

use of iso.std.iso_iec._24727.tech.schema.Terminate in project open-ecard by ecsec.

the class TinySALTest method testTerminate.

/**
 * Test of terminate method, of class TinySAL.
 */
@Test(enabled = TESTS_ENABLED)
public void testTerminate() {
    System.out.println("terminate");
    Terminate parameters = new Terminate();
    TerminateResponse result = instance.terminate(parameters);
    assertEquals(ECardConstants.Major.ERROR, result.getResult().getResultMajor());
}
Also used : TerminateResponse(iso.std.iso_iec._24727.tech.schema.TerminateResponse) Terminate(iso.std.iso_iec._24727.tech.schema.Terminate) Test(org.testng.annotations.Test)

Aggregations

Terminate (iso.std.iso_iec._24727.tech.schema.Terminate)4 TerminateResponse (iso.std.iso_iec._24727.tech.schema.TerminateResponse)3 ReleaseContext (iso.std.iso_iec._24727.tech.schema.ReleaseContext)2 IOException (java.io.IOException)2 WSHelper (org.openecard.common.WSHelper)2 SpecializedSAL (org.openecard.common.sal.SpecializedSAL)2 SAL (org.openecard.ws.SAL)2 JoranException (ch.qos.logback.core.joran.spi.JoranException)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Win32Exception (com.sun.jna.platform.win32.Win32Exception)1 CardApplicationDisconnect (iso.std.iso_iec._24727.tech.schema.CardApplicationDisconnect)1 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)1 InitializeResponse (iso.std.iso_iec._24727.tech.schema.InitializeResponse)1 ReleaseContextResponse (iso.std.iso_iec._24727.tech.schema.ReleaseContextResponse)1 BindException (java.net.BindException)1 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)1 LinkedList (java.util.LinkedList)1 Result (oasis.names.tc.dss._1_0.core.schema.Result)1 ChipGatewayDataError (org.openecard.addons.cg.ex.ChipGatewayDataError)1 HttpException (org.openecard.apache.http.HttpException)1