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);
}
}
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();
}
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);
}
Aggregations