Search in sources :

Example 1 with EventDispatcher

use of org.openecard.common.interfaces.EventDispatcher in project open-ecard by ecsec.

the class MessageDispatcher method deliver.

@Override
public Object deliver(Object req) throws DispatcherException, InvocationTargetException {
    EventDispatcher disp = environment.getEventDispatcher();
    // send API CALL STARTED event
    ConnectionHandleType handle = HandlerUtils.extractHandle(req);
    if (disp != null && req instanceof RequestType) {
        ApiCallEventObject startEvt = new ApiCallEventObject(handle, (RequestType) req);
        LOG.debug("Sending API_CALL_STARTED event.");
        disp.notify(EventType.API_CALL_STARTED, startEvt);
    }
    try {
        Class<?> reqClass = req.getClass();
        Service s = getService(reqClass);
        Object serviceImpl = getServiceImpl(s);
        LOG.debug("Delivering message of type: {}", req.getClass().getName());
        Object result = s.invoke(serviceImpl, req);
        // send API CALL FINISHED event
        if (disp != null && req instanceof RequestType && result instanceof ResponseType) {
            ApiCallEventObject finEvt = new ApiCallEventObject(handle, (RequestType) req);
            finEvt.setResponse((ResponseType) result);
            LOG.debug("Sending API_CALL_FINISHED event.");
            disp.notify(EventType.API_CALL_FINISHED, finEvt);
        }
        return result;
    } catch (IllegalAccessException | IllegalArgumentException ex) {
        throw new DispatcherException(ex);
    }
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) EventDispatcher(org.openecard.common.interfaces.EventDispatcher) ApiCallEventObject(org.openecard.common.event.ApiCallEventObject) DispatcherException(org.openecard.common.interfaces.DispatcherException) ApiCallEventObject(org.openecard.common.event.ApiCallEventObject) RequestType(iso.std.iso_iec._24727.tech.schema.RequestType) ResponseType(iso.std.iso_iec._24727.tech.schema.ResponseType)

Example 2 with EventDispatcher

use of org.openecard.common.interfaces.EventDispatcher in project open-ecard by ecsec.

the class TestClient method setup.

private void setup() throws Exception {
    // Set up client environment
    ClientEnv env = new ClientEnv();
    // Set up the IFD
    IFD ifd = new IFD();
    env.setIFD(ifd);
    // Set up Management
    TinyManagement management = new TinyManagement(env);
    env.setManagement(management);
    // Set up the Dispatcher
    MessageDispatcher dispatcher = new MessageDispatcher(env);
    env.setDispatcher(dispatcher);
    // Perform an EstablishContext to get a ContextHandle
    EstablishContext establishContext = new EstablishContext();
    EstablishContextResponse establishContextResponse = ifd.establishContext(establishContext);
    byte[] contextHandle = ifd.establishContext(establishContext).getContextHandle();
    final CardRecognitionImpl recognition = new CardRecognitionImpl(env);
    env.setRecognition(recognition);
    env.setCIFProvider(new CIFProvider() {

        @Override
        public CardInfoType getCardInfo(ConnectionHandleType type, String cardType) {
            return recognition.getCardInfo(cardType);
        }

        @Override
        public boolean needsRecognition(byte[] atr) {
            return true;
        }

        @Override
        public CardInfoType getCardInfo(String cardType) throws RuntimeException {
            return recognition.getCardInfo(cardType);
        }

        @Override
        public InputStream getCardImage(String cardType) {
            return recognition.getCardImage(cardType);
        }
    });
    // Set up EventManager
    EventDispatcher ed = new EventDispatcherImpl();
    env.setEventDispatcher(ed);
    // Set up SALStateCallback
    cardStates = new CardStateMap();
    SALStateCallback salCallback = new SALStateCallback(env, cardStates);
    ed.add(salCallback);
    // Set up SAL
    sal = new TinySAL(env, cardStates);
    env.setSAL(sal);
    // Set up GUI
    SwingUserConsent gui = new SwingUserConsent(new SwingDialogWrapper());
    sal.setGUI(gui);
    ifd.setGUI(gui);
    // Initialize the EventManager
    ed.start();
    AddonManager manager = new AddonManager(env, gui, cardStates, null);
    sal.setAddonManager(manager);
    HttpBinding binding = new HttpBinding(24727);
    binding.setAddonManager(manager);
    binding.start();
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) SALStateCallback(org.openecard.common.sal.state.SALStateCallback) TinySAL(org.openecard.sal.TinySAL) EventDispatcherImpl(org.openecard.common.event.EventDispatcherImpl) IFD(org.openecard.ifd.scio.IFD) InputStream(java.io.InputStream) CardRecognitionImpl(org.openecard.recognition.CardRecognitionImpl) EstablishContextResponse(iso.std.iso_iec._24727.tech.schema.EstablishContextResponse) ClientEnv(org.openecard.common.ClientEnv) CIFProvider(org.openecard.common.interfaces.CIFProvider) MessageDispatcher(org.openecard.transport.dispatcher.MessageDispatcher) SwingDialogWrapper(org.openecard.gui.swing.SwingDialogWrapper) CardInfoType(iso.std.iso_iec._24727.tech.schema.CardInfoType) EventDispatcher(org.openecard.common.interfaces.EventDispatcher) SwingUserConsent(org.openecard.gui.swing.SwingUserConsent) TinyManagement(org.openecard.management.TinyManagement) CardStateMap(org.openecard.common.sal.state.CardStateMap) EstablishContext(iso.std.iso_iec._24727.tech.schema.EstablishContext) AddonManager(org.openecard.addon.AddonManager)

Example 3 with EventDispatcher

use of org.openecard.common.interfaces.EventDispatcher in project open-ecard by ecsec.

the class TestEventManager method test.

@Test(enabled = false)
public void test() throws InterruptedException, InitializationException {
    Environment env = new ClientEnv();
    MiddlewareSAL mwSAL = new MiddlewareSAL(env, null, mwConfig, cb);
    env.setSAL(mwSAL);
    EventDispatcher ed = new EventDispatcherImpl();
    env.setEventDispatcher(ed);
    mwSAL.initialize(new Initialize());
    ed.start();
    Thread.sleep(10000);
}
Also used : ClientEnv(org.openecard.common.ClientEnv) EventDispatcherImpl(org.openecard.common.event.EventDispatcherImpl) EventDispatcher(org.openecard.common.interfaces.EventDispatcher) Environment(org.openecard.common.interfaces.Environment) Initialize(iso.std.iso_iec._24727.tech.schema.Initialize) Test(org.testng.annotations.Test)

Aggregations

EventDispatcher (org.openecard.common.interfaces.EventDispatcher)3 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)2 ClientEnv (org.openecard.common.ClientEnv)2 EventDispatcherImpl (org.openecard.common.event.EventDispatcherImpl)2 CardInfoType (iso.std.iso_iec._24727.tech.schema.CardInfoType)1 EstablishContext (iso.std.iso_iec._24727.tech.schema.EstablishContext)1 EstablishContextResponse (iso.std.iso_iec._24727.tech.schema.EstablishContextResponse)1 Initialize (iso.std.iso_iec._24727.tech.schema.Initialize)1 RequestType (iso.std.iso_iec._24727.tech.schema.RequestType)1 ResponseType (iso.std.iso_iec._24727.tech.schema.ResponseType)1 InputStream (java.io.InputStream)1 AddonManager (org.openecard.addon.AddonManager)1 ApiCallEventObject (org.openecard.common.event.ApiCallEventObject)1 CIFProvider (org.openecard.common.interfaces.CIFProvider)1 DispatcherException (org.openecard.common.interfaces.DispatcherException)1 Environment (org.openecard.common.interfaces.Environment)1 CardStateMap (org.openecard.common.sal.state.CardStateMap)1 SALStateCallback (org.openecard.common.sal.state.SALStateCallback)1 SwingDialogWrapper (org.openecard.gui.swing.SwingDialogWrapper)1 SwingUserConsent (org.openecard.gui.swing.SwingUserConsent)1