Use reload PCSC code in fault tolerant init code
@@ -89,9 +89,9 @@ public class PCSCFactory implements org.openecard.common.ifd.scio.TerminalFactor
new Thread(() -> {
while (initLock.isDone()) {
try {
- loadPCSC();
+ reloadPCSCInt();
initLock.complete(null);
- } catch (NoSuchAlgorithmException exInner) {
+ } catch (Exception exInner) {
if (isNoServiceException(exInner)) {
try {
Thread.sleep(5000);
@@ -202,6 +202,32 @@ public class PCSCFactory implements org.openecard.common.ifd.scio.TerminalFactor
void reloadPCSC() {
try {
+ reloadPCSCInt();
+ } catch (NoSuchAlgorithmException ex) {
+ // if it worked once it will work again
+ String msg = "PCSC changed it's algorithm. There is something really wrong.";
+ LOG.error(msg, ex);
+ throw new RuntimeException("PCSC changed it's algorithm. There is something really wrong.");
+ } catch (ClassNotFoundException | IllegalAccessException | NoSuchFieldException | NoSuchMethodException |
+ SecurityException ex) {
+ LOG.error("Failed to perform reflection magic to reload TerminalFactory.", ex);
+ } catch (InvocationTargetException ex) {
+ if (isNoServiceException(ex)) {
+ // silent drop after giving the system some time to recover for themselves
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException ignore) {
+ Thread.currentThread().interrupt();
+ }
+ return;
+ }
+
+ LOG.error("Error while invoking PCSC restart functionality.");
+ }
+ }
+
+ private void reloadPCSCInt() throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException,
+ NoSuchMethodException, InvocationTargetException, NoSuchAlgorithmException {
// code taken from http://stackoverflow.com/questions/16921785/
Class pcscterminal = Class.forName("sun.security.smartcardio.PCSCTerminals");
Field contextId = pcscterminal.getDeclaredField("contextId");
@@ -229,27 +255,6 @@ public class PCSCFactory implements org.openecard.common.ifd.scio.TerminalFactor
clearMap.invoke(fieldTerminals.get(terminals));
}
- } catch (NoSuchAlgorithmException ex) {
- // if it worked once it will work again
- String msg = "PCSC changed it's algorithm. There is something really wrong.";
- LOG.error(msg, ex);
- throw new RuntimeException("PCSC changed it's algorithm. There is something really wrong.");
- } catch (ClassNotFoundException | IllegalAccessException | NoSuchFieldException | NoSuchMethodException |
- SecurityException ex) {
- LOG.error("Failed to perform reflection magic to reload TerminalFactory.", ex);
- } catch (InvocationTargetException ex) {
- if (isNoServiceException(ex)) {
- // silent drop after giving the system some time to recover for themselves
- try {
- Thread.sleep(5000);
- } catch (InterruptedException ignore) {
- Thread.currentThread().interrupt();
- }
- return;
- }
-
- LOG.error("Error while invoking PCSC restart functionality.");
- }
}
private boolean isNoServiceException(Exception mainException) {
