I’m new here and have a problem.
First of all, I’ll describe the environment.
My ex-colleague integrated the JXBrowser version 7.37.0 into our software (= Java based)
in order to establish a connection to a document management system (DMS) via a link.
The DMS is operated on the customer’s intranet.
The users log into the DMS with their Windows user.
The DMS has installed so-called “WEB clients” and certificates on the clients.
These WEB clients start Outlook on the client in order to send the documents by email.
Only the message appears that the browser should be reloaded.
The DMS has switched from http to https.
The problem that now occurs is that the WEB clients no longer work and therefore Outlook cannot be started.
I would be very happy and grateful if someone could give me a tip on my issue.
Here is the source code of my test program:
package demon;
import com.teamdev.jxbrowser.browser.Browser;
import com.teamdev.jxbrowser.engine.Engine;
import com.teamdev.jxbrowser.engine.EngineOptions;
import com.teamdev.jxbrowser.engine.event.EngineClosed;
import com.teamdev.jxbrowser.engine.event.EngineCrashed;
import com.teamdev.jxbrowser.view.swing.BrowserView;
import com.teamdev.jxbrowser.net.callback.AuthenticateCallback;
import com.teamdev.jxbrowser.net.callback.VerifyCertificateCallback;
import com.teamdev.jxbrowser.net.callback.VerifyCertificateCallback.Response;
import com.teamdev.jxbrowser.net.tls.CertVerificationError;
import com.teamdev.jxbrowser.net.tls.Certificate;
import com.teamdev.jxbrowser.browser.callback.CertificateErrorCallback;
import com.teamdev.jxbrowser.browser.callback.OpenExternalAppCallback;
import com.teamdev.jxbrowser.browser.callback.SelectClientCertificateCallback;
import static com.teamdev.jxbrowser.engine.RenderingMode.HARDWARE_ACCELERATED;
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.Properties;
public class JxBrowserApp {
public static void main(String[] args) {
// Load settings from App.config
Properties props = new Properties();
try (FileInputStream fis = new FileInputStream(Paths.get("config", "App.config").toString())) {
props.load(fis);
} catch (IOException e) {
System.err.println("Error loading App.config: " + e.getMessage());
System.exit(0);
}
String dateDir = Paths.get(System.getProperty("user.dir"), "directory").toString();
File dir = new File(dateDir);
if (!(dir.exists() && dir.isDirectory())) {
try {
Files.createDirectories(Paths.get(dateDir));
} catch (IOException e) {
e.printStackTrace();
}
} else {
deleteDirectory(dateDir);
}
String userDataDir = Paths.get(dateDir, "user").toString() + System.getProperty("file.separator");
String chromiumDir = Paths.get(dateDir, "chromium").toString() + System.getProperty("file.separator");
String crashDumpDir = Paths.get(dateDir, "CrashReports").toString() + System.getProperty("file.separator");
dir = new File(userDataDir);
if (!(dir.exists() && dir.isDirectory())) {
try {
Files.createDirectories(Paths.get(userDataDir));
} catch (IOException e) {
e.printStackTrace();
}
}
dir = new File(chromiumDir);
if (!(dir.exists() && dir.isDirectory())) {
try {
Files.createDirectories(Paths.get(chromiumDir));
} catch (IOException e) {
e.printStackTrace();
}
}
dir = new File(crashDumpDir);
if (!(dir.exists() && dir.isDirectory())) {
try {
Files.createDirectories(Paths.get(crashDumpDir));
} catch (IOException e) {
e.printStackTrace();
}
}
System.setProperty("jxbrowser.crash.dump.dir", crashDumpDir);
String url = "https://dmssrv";
boolean devTools = (props.getProperty("devTools", "false").toLowerCase().equals("true") ? true : false);
String authenticateUsername = props.getProperty("authenticateUsername", "");
String authenticatePassword = props.getProperty("authenticatePassword", "");
// Initialize Chromium.
EngineOptions options = null;
options = EngineOptions.newBuilder(HARDWARE_ACCELERATED)
.treatInsecureOriginAsSecure("https://dmsrv")
.userDataDir(Paths.get(userDataDir))
.chromiumDir(Paths.get(chromiumDir))
.build();
Engine engine = Engine.newInstance(options);
engine.network().httpAuthPreferences().serverWhitelist("dmssrv");
engine.network().httpAuthPreferences().delegateWhitelist("dmssrv");
engine.on(EngineClosed.class, event -> {
System.out.println("CLOSE ENGINEn");
});
engine.on(EngineCrashed.class, event -> {
System.out.println("CRASHED ENGINE: ExitCode = " + event.exitCode() + "n");
});
// Create a Browser instance.
Browser browser = engine.newBrowser();
// Allows JavaScript code on the web pages loaded in the browser to
// access clipboard.
browser.settings().allowJavaScriptAccessClipboard();
// Allows JavaScript code on the web pages loaded in the browser to
// read/write cookies in the cookies storage using the document.cookie
// property.
browser.settings().allowJavaScriptAccessCookies();
// Allows running an insecure content in the browser.
browser.settings().allowRunningInsecureContent();
// Enables the local storage in the browser.
browser.settings().enableLocalStorage();
// Enables all plugins on the web pages loaded in the browser.
browser.settings().enablePlugins();
// Enables JavaScript on the web pages loaded in the browser.
browser.settings().enableJavaScript();
browser.set(OpenExternalAppCallback.class, (param, tell) -> {
System.out.println("ExternalApp.title: " + param.title());
System.out.println("ExternalApp.message: " + param.message());
tell.open();
});
engine.network().set(AuthenticateCallback.class, (param, tell) -> {
System.out.println("AuthenticateCallback.browser: " + param.browser());
System.out.println("AuthenticateCallback.hostPort: " + param.hostPort());
System.out.println("AuthenticateCallback.isProxy: " + param.isProxy());
System.out.println("AuthenticateCallback.url: " + param.url());
System.out.println("AuthenticateCallback.scheme: " + param.scheme());
if (authenticateUsername.toLowerCase().equals("none") &&
authenticatePassword.toLowerCase().equals("none")) {
} else if (authenticateUsername.equals("") && authenticatePassword.equals("")) {
tell.authenticate("<username>", "<password>");
} else {
tell.authenticate(authenticateUsername, authenticatePassword);
}
});
browser.set(SelectClientCertificateCallback.class, (params, tell) -> {
String host = params.hostPort().toString();
System.out.println("useSystemCertificateStore for " + host + "...");
// The list of the installed and available client certificates.
java.util.List<Certificate> certificates = params.certificates();
certificates.forEach(e -> {
System.out.println("useSystemCertificateStore:n" + e);
});
// Select the all client certificate in the list of available
// client certificates.
tell.select(certificates.size());
});
browser.settings().disallowJavaScriptAccessCookies();
// Load the required web page.
//browser.navigation().loadUrlAndWait(url);
browser.navigation().loadUrl(url);
if (devTools) {
System.out.println("devTools: eingestelltn");
browser.devTools().show();
} else {
System.out.println("devTools: nicht eingestelltn");
}
engine.network().set(VerifyCertificateCallback.class, params -> {
String host = params.host().value();
System.out.println("VerifyCertificateCallback: Verifying certificate for " + host);
System.out.println("VerifyCertificateCallback.certificate = " + params.certificate());
System.out.println("VerifyCertificateCallback.host = " + params.host());
System.out.println("VerifyCertificateCallback.intermediateCertificates = " + params.intermediateCertificates());
// SSL Certificate to verify.
Certificate certificates = params.certificate();
// The results of the verification performed by default verifier.
java.util.List<Certificate> certs = params.intermediateCertificates();
for (Certificate cert : certs) {
System.out.println("IntermediateCertificates: " + cert);
}
// The results of the verification performed by default verifier.
java.util.List<CertVerificationError> errors = params.verificationErrors();
for (CertVerificationError error : errors) {
System.out.println("VerifyCertificateCallback (Error): " + host);
System.out.println("Status = " + error.status());
System.out.println("Short Description = " + error.shortDescription());
System.out.println("Detailed Description = " + error.detailedDescription());
}
return Response.valid();
});
browser.set(CertificateErrorCallback.class, (params, tell) -> {
System.out.println("CertificateErrorCallback.url = " + params.url());
System.out.println("CertificateErrorCallback.error = " + params.error());
System.out.println("CertificateErrorCallback.isMainFrame = " + params.isMainFrame());
System.out.println("CertificateErrorCallback.certificate = " + params.certificate());
tell.allow();
});
SwingUtilities.invokeLater(() -> {
JFrame frame = new JFrame("JxBrowser AWT/Swing");
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// Shutdown Chromium and release allocated resources.
engine.close();
System.exit(0);
}
});
// Create and embed Swing BrowserView component to display web content.
frame.add(BrowserView.newInstance(browser), BorderLayout.CENTER);
frame.setSize(1280, 800);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setUndecorated(false);
frame.setVisible(true);
});
}
public static void deleteDirectory(String directoryPath) {
Path path = Paths.get(directoryPath);
try {
Files.walk(path)
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.forEach(File::delete);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
After researching on the Internet, I found a few things and implemented them in a test program so that I and the customer can test them beforehand.
I have implemented the following methods:
- VerifyCertificateCallback
- CertificateErrorCallback
- disallowJavaScriptAccessCookies
- SelectClientCertificateCallback
- AuthenticateCallback
- OpenExternalAppCallback
- enablePlugins
- enableJavaScript
- enableLocalStorage
- allowRunningInsecureContent
- allowJavaScriptAccessCookies
- allowJavaScriptAccessClipboard
When testing, we noticed that the VerifyCertificateCallback is always executed and the DMS server certificate cannot be verified.
Chris is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.