Getting Started
Initial Requirements
To start developing using PrivMX Endpoint Java you need a PrivMX Bridge instance.
To connect it to your environment, you need:
Bridge URL
- URL address of the instance of your PrivMX BridgeSolution ID
- ID of the Solution provided by PrivMX Bridge during its initialization processUser Private Key
- the private key from the user's public-private key pair
You also need to use your own application server to manage users (and their keys) and Contexts.
Installation
Our Java libraries contain all the necessary assets and helpers to get started with PrivMX Endpoint. Select which level is the best for you. Go to Java overview to see the descriptions of each library.
Java Dependencies
- Add
mavenCentral()
repository to yoursettings.gradle
:
dependencyResolutionManagement{
repositories{
mavenCentral()
}
}
- Add dependency to
build.gradle
:
dependencies {
def privmxLibVersion = "2.2.0" // privmx-endpoint-version
implementation("com.simplito.java:privmx-endpoint-extra:$privmxLibVersion")
//implementation("com.simplito.java:privmx-endpoint:$privmxLibVersion") #for base Java library
//implementation("com.simplito.java:privmx-endpoint-android:$privmxLibVersion") #for Android Java library
}
Shared Libraries
Java projects require you to install shared native libraries in a specified path and pass this path to java command as argument -Djava.library.path=
.
In Android, you just need to put the libraries in the src/main/jniLibs
directory.
Use our gradle plugin to download and unzip the shared libraries.
- Add
mavenCentral()
repository to yoursettings.gradle
:
pluginManagement {
repositories{
mavenCentral()
}
}
- Add and configure the plugin in
build.gradle
:
plugins {
id "com.simplito.privmx-endpoint-install-native" version "$pluginVersion"
}
privmxEndpointInstallJni{
version = $nativeLibVersion // this version should be the same as privmx-endpoint-java version
}
For more information about the plugin, go to its dedicated section.
Alternatively, download them from GitHub releases assets with the same version as your privmx-endpoint-java
library.
Initial Assumptions
The initial assumptions for all the code examples below are as follows:
/*
All the values below like BRIDGE_URL, SOLUTION_ID, CONTEXT_ID
should be replaced by the ones corresponding to your Bridge Server instance.
The private keys here are for demonstration purposes only.
Normally, they should be kept separately by each user and stored in a safe place,
or generated from a password (see the derivePrivateKey2() method in the Crypto API)
*/
String bridgeUrl = "YOUR_BRIDGE_URL";
String solutionId = "YOUR_SOLUTION_ID";
String contextId = "YOUR_CONTEXT_ID";
String user1Id = "USER_ID_1";
String user1PublicKey = "PUBLIC_KEY_1";
String user1PrivateKey = "PRIVATE_KEY_1";
String user2Id = "USER_ID_2";
String user2PublicKey = "PUBLIC_KEY_2";
Connecting to PrivMX Bridge
To use any of the library's elements, you must first connect to PrivMX Bridge. Use the API keys mentioned earlier:
String pathToCerts = "PATH_TO_CERTS"; // Path to .pem ssl certificate to connect with Privmx Bridge
Set<Modules> initModules = Set.of(
Modules.THREAD, // initializes ThreadApi to working with Threads
Modules.STORE, // initializes StoreApi to working with Stores
Modules.INBOX // initializes InboxApi to working with Inboxes
); // set of modules to activate in new connection
PrivmxEndpointContainer endpointContainer = new PrivmxEndpointContainer();
endpointContainer.setCertsPath(pathToCerts);
PrivmxEndpoint endpointSession = endpointContainer.connect(
initModules,
user1PrivateKey,
solutionId,
bridgeUrl
);
The active connection is kept by container
and can be accessed using container.getEndpoint(Long)
method.
endpointContainer.getEndpoint(endpointSession.connection.connectionId)
Disconnecting from PrivMX Bridge
endpointContainer.disconnect(endpointSession.connection.connectionId)
Closing PrivmxEndpointContainer
When you finish working with the container
, close it to end all connections, close the event loop, and release the resources being used.
You can also use a try-with-resources
block in Java or use
function in Kotlin.
container.close()
Next Steps
With everything ready to go, now it's time to start using all of the platform's capabilities.
Learn how to use: