I have a little Java app that retrieves a list of documents (XML response) using a digital signature PCKS#11. The webpage is paginated and after the first page the JAR crashes with no error or message. The JAR works perfectly on another PC with same windows, same JDK 17, same digital signature. The PC with the problem is a laptop with fresh Windows 10 Pro x64, Ryzen 5 7530U and 16GB of RAM so I doubt performance is an issue. Why can’t I see any message or error? I’ve tried every log, try/catch (Exception, Throwable). I have try/catch in main method where I start de WebSocket Server and still nothing no message…
public class Main {
public static void main(String[] args) {
try {
String host = "localhost";
int port = 8002;
WebSocketServer server = new WebsocketServer(new InetSocketAddress(host, port));
server.run();
} catch (Throwable e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}
public String loadAll(MessageModel msg, String alias) {
try {
KeyStore ks = KeyStore.getInstance("Windows-MY");
System.out.println("1");
ks.load(null, null);
System.out.println("2");
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
System.out.println("3");
kmf.init(ks, null);
System.out.println("4");
X509ExtendedKeyManager km = getX509ExtendedKeyManager(kmf, alias);
System.out.println("5");
SSLContext sc = SSLContext.getInstance("TLS");
System.out.println("6");
sc.init(new X509ExtendedKeyManager[] {km}, null, null);
System.out.println("7");
String url = "https://forexe.mfinante.gov.ro/ForexeSNM/messages/loadAll.do?nomCategoryCode=" + msg.forexe_category + "&start=" + msg.start + "&limit=20";
System.out.println("8");
Document doc = Jsoup.connect(url).timeout(120000).sslSocketFactory(sc.getSocketFactory()).get();
System.out.println("9");
String body = doc.body().text();
System.out.println("10");
if (body.contains(""success":true")) {
return new StringBuilder(body).insert(body.length() - 1, ", "certificate_alias": "" + alias + """).toString();
} else if (triesLoadAll < 10) {
triesLoadAll = triesLoadAll + 1;
return loadAll(msg, alias);
} else {
return "{ "errorB": "" + Base64.getEncoder().encodeToString(body.getBytes(StandardCharsets.UTF_8)) + "" }";
}
} catch (Throwable e) {
System.out.println(e.getMessage());
e.printStackTrace();
if (triesLoadAll < 10) {
triesLoadAll = triesLoadAll + 1;
return loadAll(msg, alias);
} else {
return "{ "errorB": "" + Base64.getEncoder().encodeToString(ExceptionUtils.getStackTrace(e).getBytes(StandardCharsets.UTF_8)) + "" }";
}
}
}
private static X509ExtendedKeyManager getX509ExtendedKeyManager(KeyManagerFactory kmf, String alias) {
try {
final X509ExtendedKeyManager origKm = (X509ExtendedKeyManager) kmf.getKeyManagers()[0];
return new X509ExtendedKeyManager() {
@Override
public String[] getClientAliases(String s, Principal[] principals) {
return origKm.getClientAliases(s, principals);
}
@Override
public String chooseClientAlias(String[] strings, Principal[] principals, Socket socket) {
return alias;
}
@Override
public String[] getServerAliases(String s, Principal[] principals) {
return origKm.getServerAliases(s, principals);
}
@Override
public String chooseServerAlias(String s, Principal[] principals, Socket socket) {
return origKm.chooseServerAlias(s, principals, socket);
}
@Override
public X509Certificate[] getCertificateChain(String s) {
return origKm.getCertificateChain(s);
}
@Override
public PrivateKey getPrivateKey(String s) {
return origKm.getPrivateKey(s);
}
};
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
The log from the console is this.
C:ExtensieContaYCS>java -jar -Xms2048m ExtensieContaYCS.jar
1
2
3
4
5
6
7
8
9
10
1
1
1
C:ExtensieContaYCS>
First page is ok but after that it opens 3 more sockets and the JAR crashes…
The Server is used from Javascript to send and receive data but I dont’ think this is relevant.
How can I get an error message or a core dump or something? It’s the 3rd day with no progress.