diff --git a/privmx-endpoint-extra/src/main/java/com/simplito/java/privmx_endpoint_extra/lib/BasicPrivmxEndpoint.java b/privmx-endpoint-extra/src/main/java/com/simplito/java/privmx_endpoint_extra/lib/BasicPrivmxEndpoint.java index b1fa822..78e6eb0 100644 --- a/privmx-endpoint-extra/src/main/java/com/simplito/java/privmx_endpoint_extra/lib/BasicPrivmxEndpoint.java +++ b/privmx-endpoint-extra/src/main/java/com/simplito/java/privmx_endpoint_extra/lib/BasicPrivmxEndpoint.java @@ -55,7 +55,7 @@ public class BasicPrivmxEndpoint implements AutoCloseable { * * @param enableModule set of modules to initialize; should contain {@link Modules#THREAD } * to enable Thread module or {@link Modules#STORE } to enable Store module - * @param platformUrl Platform's Endpoint URL + * @param bridgeUrl Bridge's Endpoint URL * @param solutionId {@code SolutionId} of the current project * @param userPrivateKey user private key used to authorize; generated from: * {@link CryptoApi#generatePrivateKey} or @@ -68,9 +68,9 @@ public BasicPrivmxEndpoint( Set enableModule, String userPrivateKey, String solutionId, - String platformUrl + String bridgeUrl ) throws IllegalStateException, PrivmxException, NativeException { - connection = Connection.platformConnect(userPrivateKey, solutionId, platformUrl); + connection = Connection.connect(userPrivateKey, solutionId, bridgeUrl); storeApi = enableModule.contains(Modules.STORE) ? new StoreApi(connection) : null; threadApi = enableModule.contains(Modules.THREAD) ? new ThreadApi(connection) : null; inboxApi = enableModule.contains(Modules.INBOX) ? new InboxApi( diff --git a/privmx-endpoint-extra/src/main/java/com/simplito/java/privmx_endpoint_extra/lib/PrivmxEndpoint.java b/privmx-endpoint-extra/src/main/java/com/simplito/java/privmx_endpoint_extra/lib/PrivmxEndpoint.java index b9a1271..018ad6d 100644 --- a/privmx-endpoint-extra/src/main/java/com/simplito/java/privmx_endpoint_extra/lib/PrivmxEndpoint.java +++ b/privmx-endpoint-extra/src/main/java/com/simplito/java/privmx_endpoint_extra/lib/PrivmxEndpoint.java @@ -44,7 +44,7 @@ public class PrivmxEndpoint extends BasicPrivmxEndpoint implements AutoCloseable * * @param enableModule set of modules to initialize; should contain {@link Modules#THREAD } * to enable Thread module or {@link Modules#STORE } to enable Store module - * @param platformUrl Platform's Endpoint URL + * @param bridgeUrl Bridge's Endpoint URL * @param solutionId {@code SolutionId} of the current project * @param userPrivateKey user private key used to authorize; generated from: * {@link CryptoApi#generatePrivateKey} or @@ -57,9 +57,9 @@ public PrivmxEndpoint( Set enableModule, String userPrivateKey, String solutionId, - String platformUrl + String bridgeUrl ) throws IllegalStateException, PrivmxException, NativeException { - super(enableModule, userPrivateKey, solutionId, platformUrl); + super(enableModule, userPrivateKey, solutionId, bridgeUrl); } /** diff --git a/privmx-endpoint-extra/src/main/java/com/simplito/java/privmx_endpoint_extra/lib/PrivmxEndpointContainer.java b/privmx-endpoint-extra/src/main/java/com/simplito/java/privmx_endpoint_extra/lib/PrivmxEndpointContainer.java index 4873cf2..992dcea 100644 --- a/privmx-endpoint-extra/src/main/java/com/simplito/java/privmx_endpoint_extra/lib/PrivmxEndpointContainer.java +++ b/privmx-endpoint-extra/src/main/java/com/simplito/java/privmx_endpoint_extra/lib/PrivmxEndpointContainer.java @@ -114,7 +114,7 @@ public void setCertsPath(String certsPath) throws IllegalArgumentException, Priv * Creates a new connection. * * @param enableModule set of modules to initialize - * @param platformUrl Platform's Endpoint URL + * @param bridgeUrl Bridge's Endpoint URL * @param solutionId {@code SolutionId} of the current project * @param userPrivateKey user private key used to authorize; generated from: * {@link CryptoApi#generatePrivateKey} or @@ -128,14 +128,14 @@ public PrivmxEndpoint connect( Set enableModule, String userPrivateKey, String solutionId, - String platformUrl + String bridgeUrl ) throws IllegalStateException, PrivmxException, NativeException { if (!isInitialized) throw new IllegalStateException("Certs path is not set"); PrivmxEndpoint privmxEndpoint = new PrivmxEndpoint( enableModule, userPrivateKey, solutionId, - platformUrl + bridgeUrl ); synchronized (privmxEndpoints) { privmxEndpoints.put(privmxEndpoint.connection.getConnectionId(), privmxEndpoint); diff --git a/privmx-endpoint/src/main/cpp/modules/Connection.cpp b/privmx-endpoint/src/main/cpp/modules/Connection.cpp index 12b3a5d..88e242c 100644 --- a/privmx-endpoint/src/main/cpp/modules/Connection.cpp +++ b/privmx-endpoint/src/main/cpp/modules/Connection.cpp @@ -47,55 +47,6 @@ Java_com_simplito_java_privmx_1endpoint_modules_core_Connection_deinit(JNIEnv *e } } -extern "C" -JNIEXPORT jobject JNICALL -Java_com_simplito_java_privmx_1endpoint_modules_core_Connection_platformConnect( - JNIEnv *env, - jclass clazz, - jstring user_priv_key, - jstring solution_id, - jstring platform_url -) { - JniContextUtils ctx(env); - if (ctx.nullCheck(user_priv_key, "User Private Key") || - ctx.nullCheck(solution_id, "Solution ID") || - ctx.nullCheck(platform_url, "Platform URL")) { - return nullptr; - } - try { - jmethodID initMID = ctx->GetMethodID(clazz, "", "(Ljava/lang/Long;Ljava/lang/Long;)V"); - privmx::endpoint::core::Connection connection = privmx::endpoint::core::Connection::platformConnect( - ctx.jString2string(user_priv_key), - ctx.jString2string(solution_id), - ctx.jString2string(platform_url) - ); - privmx::endpoint::core::Connection *api = new privmx::endpoint::core::Connection(); - *api = connection; - jobject result = ctx->NewObject( - clazz, - initMID, - ctx.long2jLong((jlong) api), - ctx.long2jLong(api->getConnectionId()) - ); - return result; - } catch (const privmx::endpoint::core::Exception &e) { - env->Throw(ctx.coreException2jthrowable(e)); - } catch (const std::exception &e) { - env->ThrowNew( - env->FindClass( - "com/simplito/java/privmx_endpoint/model/exceptions/NativeException"), - e.what() - ); - } catch (...) { - env->ThrowNew( - env->FindClass( - "com/simplito/java/privmx_endpoint/model/exceptions/NativeException"), - "Unknown exception" - ); - } - return nullptr; -} - extern "C" JNIEXPORT jobject JNICALL Java_com_simplito_java_privmx_1endpoint_modules_core_Connection_listContexts( @@ -236,22 +187,72 @@ Java_com_simplito_java_privmx_1endpoint_modules_core_Connection_setCertsPath( extern "C" JNIEXPORT jobject JNICALL -Java_com_simplito_java_privmx_1endpoint_modules_core_Connection_platformConnectPublic( +Java_com_simplito_java_privmx_1endpoint_modules_core_Connection_connect( + JNIEnv *env, + jclass clazz, + jstring user_priv_key, + jstring solution_id, + jstring bridge_url +) { + JniContextUtils ctx(env); + if (ctx.nullCheck(user_priv_key, "User Private Key") || + ctx.nullCheck(solution_id, "Solution ID") || + ctx.nullCheck(bridge_url, "Bridge URL")) { + return nullptr; + } + try { + jmethodID initMID = ctx->GetMethodID(clazz, "", + "(Ljava/lang/Long;Ljava/lang/Long;)V"); + privmx::endpoint::core::Connection connection = privmx::endpoint::core::Connection::connect( + ctx.jString2string(user_priv_key), + ctx.jString2string(solution_id), + ctx.jString2string(bridge_url) + ); + privmx::endpoint::core::Connection *api = new privmx::endpoint::core::Connection(); + *api = connection; + jobject result = ctx->NewObject( + clazz, + initMID, + ctx.long2jLong((jlong) api), + ctx.long2jLong(api->getConnectionId()) + ); + return result; + } catch (const privmx::endpoint::core::Exception &e) { + env->Throw(ctx.coreException2jthrowable(e)); + } catch (const std::exception &e) { + env->ThrowNew( + env->FindClass( + "com/simplito/java/privmx_endpoint/model/exceptions/NativeException"), + e.what() + ); + } catch (...) { + env->ThrowNew( + env->FindClass( + "com/simplito/java/privmx_endpoint/model/exceptions/NativeException"), + "Unknown exception" + ); + } + return nullptr; +} +extern "C" +JNIEXPORT jobject JNICALL +Java_com_simplito_java_privmx_1endpoint_modules_core_Connection_connectPublic( JNIEnv *env, jclass clazz, jstring solution_id, - jstring platform_url + jstring bridge_url ) { JniContextUtils ctx(env); if (ctx.nullCheck(solution_id, "Solution ID") || - ctx.nullCheck(platform_url, "Platform URL")) { + ctx.nullCheck(bridge_url, "Bridge URL")) { return nullptr; } try { - jmethodID initMID = ctx->GetMethodID(clazz, "", "(Ljava/lang/Long;Ljava/lang/Long;)V"); - privmx::endpoint::core::Connection connection = privmx::endpoint::core::Connection::platformConnectPublic( + jmethodID initMID = ctx->GetMethodID(clazz, "", + "(Ljava/lang/Long;Ljava/lang/Long;)V"); + privmx::endpoint::core::Connection connection = privmx::endpoint::core::Connection::connectPublic( ctx.jString2string(solution_id), - ctx.jString2string(platform_url) + ctx.jString2string(bridge_url) ); privmx::endpoint::core::Connection *api = new privmx::endpoint::core::Connection(); *api = connection; diff --git a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/core/Connection.java b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/core/Connection.java index a6a094a..b1a7e9a 100644 --- a/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/core/Connection.java +++ b/privmx-endpoint/src/main/java/com/simplito/java/privmx_endpoint/modules/core/Connection.java @@ -48,7 +48,7 @@ private Connection(Long api, Long connectionId) { public static native void setCertsPath(String certsPath) throws PrivmxException, NativeException; /** - * Connects to the PrivMX Bridge server. + * Connects to PrivMX Bridge server. * * @param userPrivKey user's private key * @param solutionId ID of the Solution @@ -60,10 +60,28 @@ private Connection(Long api, Long connectionId) { * channel: - * payload: {@link Void} */ - public static native Connection platformConnect(String userPrivKey, String solutionId, String platformUrl) throws PrivmxException, NativeException; + @Deprecated + public static Connection platformConnect(String userPrivKey, String solutionId, String platformUrl) throws PrivmxException, NativeException{ + return connect(userPrivKey,solutionId,platformUrl); + } + + /** + * Connects to PrivMX Bridge server. + * + * @param userPrivKey user's private key + * @param solutionId ID of the Solution + * @param bridgeUrl Bridge's Endpoint URL + * @return Connection object + * @throws PrivmxException thrown when method encounters an exception. + * @throws NativeException thrown when method encounters an unknown exception. + * @event type: libConnected + * channel: - + * payload: {@link Void} + */ + public static native Connection connect(String userPrivKey, String solutionId, String bridgeUrl) throws PrivmxException, NativeException; /** - * Connects to the PrivMX Bridge server as a guest user. + * Connects to PrivMX Bridge server as a guest user. * * @param solutionId ID of the Solution * @param platformUrl Platform's Endpoint URL @@ -74,10 +92,27 @@ private Connection(Long api, Long connectionId) { * channel: - * payload: {@link Void} */ - public static native Connection platformConnectPublic(String solutionId, String platformUrl) throws PrivmxException, NativeException; + @Deprecated + public static Connection platformConnectPublic(String solutionId, String platformUrl) throws PrivmxException, NativeException{ + return connectPublic(solutionId,platformUrl); + } + + /** + * Connects to PrivMX Bridge server as a guest user. + * + * @param solutionId ID of the Solution + * @param bridgeUrl Bridge's Endpoint URL + * @return Connection object + * @throws PrivmxException thrown when method encounters an exception. + * @throws NativeException thrown when method encounters an unknown exception. + * @event type: libConnected + * channel: - + * payload: {@link Void} + */ + public static native Connection connectPublic(String solutionId, String bridgeUrl) throws PrivmxException, NativeException; /** - * Disconnects from the PrivMX Bridge server. + * Disconnects from PrivMX Bridge server. * * @throws IllegalStateException thrown when instance is not connected or closed. * @throws PrivmxException thrown when method encounters an exception. @@ -132,7 +167,7 @@ public Long getConnectionId() { /** - * If there is an active connnection then it + * If there is an active connection then it * disconnects from PrivMX Bridge and frees memory making this instance not reusable. */ @Override