Skip to content

Commit

Permalink
Updated generateShortLinkSync and test
Browse files Browse the repository at this point in the history
  • Loading branch information
nsingh-branch committed Jul 18, 2023
1 parent 86fca0e commit e291670
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void run() {
@Test
public void test00GetShortUrlSyncFailure() {
String url = new BranchShortLinkBuilder(getTestContext()).getShortUrl();
Assert.assertNull(url);
Assert.assertNotNull(url);
}

@Test
Expand Down
40 changes: 16 additions & 24 deletions Branch-SDK/src/main/java/io/branch/referral/Branch.java
Original file line number Diff line number Diff line change
Expand Up @@ -1662,35 +1662,27 @@ public void cancelShareLinkDialog(boolean animateClose) {
// PRIVATE FUNCTIONS

private String generateShortLinkSync(ServerRequestCreateUrl req) {
if (trackingController.isTrackingDisabled()) {
return req.getLongUrl();
ServerResponse response = null;
try {
int timeOut = prefHelper_.getTimeout() + 2000; // Time out is set to slightly more than link creation time to prevent any edge case
response = new GetShortLinkTask().execute(req).get(timeOut, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException ignore) {
}
String url = null;
if (req.isDefaultToLongUrl()) {
url = req.getLongUrl();
}
if (initState_ == SESSION_STATE.INITIALISED) {
ServerResponse response = null;
if (response != null && response.getStatusCode() == HttpURLConnection.HTTP_OK) {
try {
int timeOut = prefHelper_.getTimeout() + 2000; // Time out is set to slightly more than link creation time to prevent any edge case
response = new GetShortLinkTask().execute(req).get(timeOut, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException ignore) {
}
String url = null;
if (req.isDefaultToLongUrl()) {
url = req.getLongUrl();
}
if (response != null && response.getStatusCode() == HttpURLConnection.HTTP_OK) {
try {
url = response.getObject().getString("url");
if (req.getLinkPost() != null) {
linkCache_.put(req.getLinkPost(), url);
}
} catch (JSONException e) {
e.printStackTrace();
url = response.getObject().getString("url");
if (req.getLinkPost() != null) {
linkCache_.put(req.getLinkPost(), url);
}
} catch (JSONException e) {
e.printStackTrace();
}
return url;
} else {
PrefHelper.Debug("Warning: User session has not been initialized");
}
return null;
return url;
}

private JSONObject convertParamsStringToDictionary(String paramString) {
Expand Down

0 comments on commit e291670

Please sign in to comment.