diff --git a/gradle.properties b/gradle.properties index 5f60b48..67eb082 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,10 +23,10 @@ android.useAndroidX=true android.nonTransitiveRClass=true android.disableAutomaticComponentCreation=true -version.java-sdk-common = 7.0.8 -version.java-client-sdk = 7.0.7 -version.android-client-sdk = 7.0.8 -version.backendless-commons = 6.7.5.0 +version.java-sdk-common = 7.1.0 +version.java-client-sdk = 7.1.0 +version.android-client-sdk = 7.1.0 +version.backendless-commons = 6.7.5.1 version.weborbclient = 5.2.0.8 version.io-socket-client = 2.1.0 version.projectlombok = 1.18.24 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ae04661..e1bef7e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/java-client-sdk/src/main/java/com/backendless/Backendless.java b/java-client-sdk/src/main/java/com/backendless/Backendless.java index 7de9dd6..04138b5 100644 --- a/java-client-sdk/src/main/java/com/backendless/Backendless.java +++ b/java-client-sdk/src/main/java/com/backendless/Backendless.java @@ -108,7 +108,7 @@ public static void initApp( Object context, final String customDomain ) public static void initApp( String applicationId, String apiKey ) { - BackendlessInternal.initApp( applicationId, apiKey ); + BackendlessInternal.initApp( (Object) null, applicationId, apiKey ); } public static void initApp( Object context, final String applicationId, final String apiKey ) diff --git a/java-sdk-common/src/main/java/com/backendless/BackendlessInternal.java b/java-sdk-common/src/main/java/com/backendless/BackendlessInternal.java index d393c32..5467cf4 100644 --- a/java-sdk-common/src/main/java/com/backendless/BackendlessInternal.java +++ b/java-sdk-common/src/main/java/com/backendless/BackendlessInternal.java @@ -18,6 +18,7 @@ package com.backendless; + import com.backendless.exceptions.ExceptionMessage; import com.backendless.files.BackendlessFile; import com.backendless.files.BackendlessFileFactory; @@ -57,9 +58,12 @@ import weborb.writer.MessageWriter; import weborb.writer.amf.AmfV3Formatter; +import java.io.BufferedInputStream; import java.io.IOException; +import java.net.HttpURLConnection; import java.net.URI; import java.net.URISyntaxException; +import java.net.URL; import java.util.HashMap; import java.util.Map; @@ -143,7 +147,12 @@ public boolean isReferenceableType() private BackendlessInternal() { } - + + static boolean isInitialized() + { + return initialized; + } + /** * Initializes the Backendless API and all Backendless dependencies. This is the first step in using the client API. *
@@ -155,9 +164,17 @@ private BackendlessInternal() */ static void initApp( String applicationId, String apiKey ) { - initApp( BackendlessInjector.getInstance().getContextHandler().getAppContext(), applicationId, apiKey ); + setAppIdAndApiKey( applicationId, apiKey ); + initApp(); } - + + static void initApp( Object context, final String applicationId, final String apiKey ) + { + setAppIdAndApiKey(applicationId, apiKey); + BackendlessInjector.getInstance().getContextHandler().setContext(context); + initApp(); + } + /** * Initializes the Backendless API and all Backendless dependencies. This is the first step in using the client API. *
@@ -168,52 +185,62 @@ static void initApp( String applicationId, String apiKey )
*/
static void initApp( String customDomain )
{
- initApp( BackendlessInjector.getInstance().getContextHandler().getAppContext(), customDomain );
- }
-
- static boolean isInitialized()
- {
- return initialized;
+ initApp( (Object) null, customDomain );
}
-
+
static void initApp( Object context, final String customDomain )
{
if( customDomain == null || customDomain.trim().isEmpty() )
throw new IllegalArgumentException( "Custom domain cant be null or empty" );
-
- if( customDomain.startsWith( "http" ) )
- setUrl( customDomain );
- else
- setUrl( "http://" + customDomain );
-
- URI uri;
- try
- {
- uri = new URI( getUrl() );
+
+ final URI uri;
+ try {
+ uri = customDomain.startsWith("http") ? new URI(customDomain) : new URI("http://" + customDomain);
}
catch( URISyntaxException e )
{
- throw new RuntimeException( e );
+ throw new IllegalArgumentException( "Domain passed in wrong form.", e );
}
-
- prefs.setCustomDomain( uri.getHost() );
- BackendlessInjector.getInstance().getContextHandler().setContext( context );
+
+ StringBuilder response;
+ try {
+ URL apiInfoUrl = new URL( uri + "/api/info" );
+ HttpURLConnection urlConnection = (HttpURLConnection) apiInfoUrl.openConnection();
+ if ( urlConnection.getResponseCode() != 200 )
+ throw new IllegalStateException( "Server returned " + urlConnection.getResponseCode() + " " + urlConnection.getResponseMessage() );
+
+ response = new StringBuilder(10 * 1024);
+ int read;
+ byte[] fbuf = new byte[ 2048 ];
+ try ( BufferedInputStream bufInStream = new BufferedInputStream( urlConnection.getInputStream() )) {
+ while( (read = bufInStream.read( fbuf )) != -1 )
+ response.append( new String( fbuf, 0, read ) );
+ }
+ }
+ catch (IOException e) {
+ throw new IllegalStateException( "Cannot retrieve app info from Backendless server using domain '" + getUrl() + "'.", e );
+ }
+
+ Map