Skip to content

SSL TLS Configuration

Christian Appl edited this page Mar 10, 2023 · 23 revisions

To establish a secured HTTPS connection to your webPDF server, you can add a "TLSContext" to your session´s SessionContext. The usage is identical for REST and SOAP - hence only a REST usage example shall be provided:

Be aware: TLS is the official successor of SSL, the webPDF wsclient library only supports the protocol versions:

  • TLSv1, TLSv1.1, TLSv1.2, TLSv1.3
// When setting "allowSelfSigned" to true, using self-signed certificates is acceptable to secure the connection.
boolean allowSelfSigned = true;
// Select the TLS protocol used for the connection.
TLSProtocol tlsProtocol = TLSProtocol.TLSV1_3;
// A truststore (keystore) contains a selection of certificates, that are deemed trustworthy by the client. 
// The client shall deny accessing targets, that don´t use one of the hereby defined certificates.
File keystore = new File("./someKeystoreFile");
// Accessing a keystore might require a password.
String keystorePassword = "keystorePassword";

// The TLSContext provides a set of overloaded constructors, that allow to specify whether a keystore is used,
// whether self signed certificates are accepted etc.
TLSContext tlsContext = new TLSContext(tlsProtocol, allowSelfSigned, keystore, keystorePassword);

// The SessionContext allows to set advanced options via chainable setters.
// Make sure, that the provided port (in this example port 8443) actually has been set up as a secure HTTPS port for
// your webPDF server.
SessionContext sessionContext = new SessionContext(WebServiceProtocol.REST, new URL("https://localhost:8443/webPDF"))
      .setTlsContext(tlsContext);

// Next create the Session via the "SessionFactory".
// Also be aware: If no "AuthProvider" is selected in the "createInstance" Method, this will default to
// the "AnonymousAuthProvider".
try (RestSession<RestDocument> session = SessionFactory.createInstance(sessionContext) {
   // Do something.
} catch (ResultException ex) {
   // Handle exceptions as you see fit.
}

Clone this wiki locally