use of javax.smartcardio.TerminalFactory in project jdk8u_jdk by JetBrains.
the class Utils method getTerminal.
static CardTerminal getTerminal(String[] args, String provider) throws Exception {
setLibrary(args);
try {
TerminalFactory factory = (provider == null) ? TerminalFactory.getInstance("PC/SC", null) : TerminalFactory.getInstance("PC/SC", null, provider);
System.out.println(factory);
List<CardTerminal> terminals = factory.terminals().list();
System.out.println("Terminals: " + terminals);
if (terminals.isEmpty()) {
return null;
}
CardTerminal terminal = terminals.get(0);
if (terminal.isCardPresent() == false) {
System.out.println("*** Insert card");
if (terminal.waitForCardPresent(20 * 1000) == false) {
throw new Exception("no card available");
}
}
System.out.println("card present: " + terminal.isCardPresent());
return terminal;
} catch (NoSuchAlgorithmException e) {
Throwable cause = e.getCause();
if (cause != null && cause.getMessage().startsWith("PC/SC not available")) {
return null;
}
throw e;
}
}
use of javax.smartcardio.TerminalFactory in project jdk8u_jdk by JetBrains.
the class TestDirect method main.
public static void main(String[] args) throws Exception {
TerminalFactory terminalFactory = TerminalFactory.getDefault();
List<CardTerminal> cardTerminals = terminalFactory.terminals().list();
if (cardTerminals.isEmpty()) {
System.out.println("Skipping the test: " + "no card terminals available");
return;
}
System.out.println("Terminals: " + cardTerminals);
CardTerminal cardTerminal = cardTerminals.get(0);
Card card = cardTerminal.connect("DIRECT");
card.disconnect(true);
System.out.println("OK.");
}
use of javax.smartcardio.TerminalFactory in project jdk8u_jdk by JetBrains.
the class Utils method getTerminalFactory.
static TerminalFactory getTerminalFactory(String provName) throws Exception {
try {
TerminalFactory factory = (provName == null) ? TerminalFactory.getInstance("PC/SC", null) : TerminalFactory.getInstance("PC/SC", null, provName);
System.out.println(factory);
return factory;
} catch (NoSuchAlgorithmException e) {
Throwable cause = e.getCause();
if (cause != null && cause.getMessage().startsWith("PC/SC not available")) {
return null;
}
throw e;
}
}
use of javax.smartcardio.TerminalFactory in project jdk8u_jdk by JetBrains.
the class TestDefault method main.
public static void main(String[] args) throws Exception {
TerminalFactory factory = TerminalFactory.getDefault();
System.out.println("Type: " + factory.getType());
List<CardTerminal> terminals = factory.terminals().list();
if (terminals.isEmpty()) {
System.out.println("Skipping the test: " + "no card terminals available");
return;
}
System.out.println("Terminals: " + terminals);
System.out.println("OK.");
}
use of javax.smartcardio.TerminalFactory in project jdk8u_jdk by JetBrains.
the class TestMultiplePresent method main.
public static void main(String[] args) throws Exception {
Utils.setLibrary(args);
TerminalFactory factory = Utils.getTerminalFactory(null);
if (factory == null) {
System.out.println("Skipping the test: " + "no card terminals available");
return;
}
System.out.println(factory);
CardTerminals terminals = factory.terminals();
List<CardTerminal> list = terminals.list();
System.out.println("Terminals: " + list);
boolean multipleReaders = true;
if (list.size() < 2) {
if (list.isEmpty()) {
System.out.println("Skipping the test: " + "no card terminals available");
return;
}
System.out.println("Only one reader present, using simplified test");
multipleReaders = false;
}
while (true) {
boolean present = false;
for (CardTerminal terminal : list) {
present |= terminal.isCardPresent();
}
if (present == false) {
break;
}
System.out.println("*** Remove all cards!");
Thread.sleep(1000);
}
System.out.println("OK");
List<CardTerminal> result;
result = terminals.list(CARD_PRESENT);
if (result.size() != 0) {
throw new Exception("List not empty: " + result);
}
if (terminals.waitForChange(1000)) {
throw new Exception("no timeout");
}
if (terminals.waitForChange(1000)) {
throw new Exception("no timeout");
}
result = terminals.list(CARD_PRESENT);
if (result.size() != 0) {
throw new Exception("List not empty: " + result);
}
System.out.println("*** Insert card!");
terminals.waitForChange();
result = terminals.list(CARD_INSERTION);
System.out.println(result);
if (result.size() != 1) {
throw new Exception("no card present");
}
CardTerminal t1 = result.get(0);
result = terminals.list(CARD_INSERTION);
System.out.println(result);
if ((result.size() != 1) || (result.get(0) != t1)) {
throw new Exception("no card present");
}
if (terminals.list(CARD_REMOVAL).size() != 0) {
throw new Exception("List not empty: " + result);
}
if (terminals.list(CARD_REMOVAL).size() != 0) {
throw new Exception("List not empty: " + result);
}
if (terminals.waitForChange(1000)) {
throw new Exception("no timeout");
}
if (terminals.list(CARD_REMOVAL).size() != 0) {
throw new Exception("List not empty: " + result);
}
if (multipleReaders) {
System.out.println("*** Insert card into other reader!");
terminals.waitForChange();
result = terminals.list(CARD_INSERTION);
System.out.println(result);
if (result.size() != 1) {
throw new Exception("no card present");
}
CardTerminal t2 = result.get(0);
if (t1.getName().equals(t2.getName())) {
throw new Exception("same terminal");
}
System.out.println("*** Remove card from 2nd reader!");
terminals.waitForChange();
if (terminals.list(CARD_INSERTION).size() != 0) {
throw new Exception("List not empty: " + result);
}
result = terminals.list(CARD_REMOVAL);
if ((result.size() != 1) || (result.get(0) != t2)) {
throw new Exception("no or wrong terminal");
}
}
System.out.println("*** Remove card from 1st reader!");
terminals.waitForChange();
if (terminals.list(CARD_INSERTION).size() != 0) {
throw new Exception("List not empty: " + result);
}
result = terminals.list(CARD_REMOVAL);
if ((result.size() != 1) || (result.get(0) != t1)) {
throw new Exception("no or wrong terminal");
}
System.out.println("OK.");
}
Aggregations