diff --git a/app/src/main/java/org/transdroid/daemon/adapters/aria2c/Aria2Adapter.java b/app/src/main/java/org/transdroid/daemon/adapters/aria2c/Aria2Adapter.java
index a96018ab..49e8dd4b 100644
--- a/app/src/main/java/org/transdroid/daemon/adapters/aria2c/Aria2Adapter.java
+++ b/app/src/main/java/org/transdroid/daemon/adapters/aria2c/Aria2Adapter.java
@@ -19,9 +19,7 @@ package org.transdroid.daemon.adapters.aria2c;
import android.net.Uri;
import android.text.TextUtils;
-
import net.iharder.Base64;
-
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
@@ -86,6 +84,14 @@ public class Aria2Adapter implements IDaemonAdapter {
this.settings = settings;
}
+ private synchronized void initialise() throws DaemonException {
+ if (httpclient == null) {
+ httpclient = HttpHelper.createStandardHttpClient(settings, !TextUtils.isEmpty(settings.getUsername()));
+ httpclient.addRequestInterceptor(HttpHelper.gzipRequestInterceptor);
+ httpclient.addResponseInterceptor(HttpHelper.gzipResponseInterceptor);
+ }
+ }
+
@Override
public DaemonTaskResult executeTask(Log log, DaemonTask task) {
@@ -282,13 +288,8 @@ public class Aria2Adapter implements IDaemonAdapter {
private synchronized String makeRawRequest(Log log, String data) throws DaemonException {
try {
-
// Initialise the HTTP client
- if (httpclient == null) {
- httpclient = HttpHelper.createStandardHttpClient(settings, !TextUtils.isEmpty(settings.getUsername()));
- httpclient.addRequestInterceptor(HttpHelper.gzipRequestInterceptor);
- httpclient.addResponseInterceptor(HttpHelper.gzipResponseInterceptor);
- }
+ initialise();
// Set POST URL and data
String url =
diff --git a/app/src/main/java/org/transdroid/daemon/adapters/bitComet/BitCometAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/bitComet/BitCometAdapter.java
index b19da394..3371f6b4 100644
--- a/app/src/main/java/org/transdroid/daemon/adapters/bitComet/BitCometAdapter.java
+++ b/app/src/main/java/org/transdroid/daemon/adapters/bitComet/BitCometAdapter.java
@@ -19,7 +19,6 @@ package org.transdroid.daemon.adapters.bitComet;
import com.android.internal.http.multipart.MultipartEntity;
import com.android.internal.http.multipart.Part;
-
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
@@ -253,8 +252,10 @@ public class BitCometAdapter implements IDaemonAdapter {
*
* @throws DaemonException On conflicting or missing settings
*/
- private void initialise() throws DaemonException {
- httpclient = HttpHelper.createStandardHttpClient(settings, true);
+ private synchronized void initialise() throws DaemonException {
+ if(httpclient == null) {
+ httpclient = HttpHelper.createStandardHttpClient(settings, true);
+ }
}
/**
@@ -271,9 +272,7 @@ public class BitCometAdapter implements IDaemonAdapter {
try {
// Initialize the HTTP client
- if (httpclient == null) {
- initialise();
- }
+ initialise();
// Add the parameters to the query string
boolean first = true;
diff --git a/app/src/main/java/org/transdroid/daemon/adapters/bitflu/BitfluAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/bitflu/BitfluAdapter.java
index 7b43c1bd..3dd4f916 100644
--- a/app/src/main/java/org/transdroid/daemon/adapters/bitflu/BitfluAdapter.java
+++ b/app/src/main/java/org/transdroid/daemon/adapters/bitflu/BitfluAdapter.java
@@ -140,9 +140,7 @@ public class BitfluAdapter implements IDaemonAdapter {
try {
// Initialise the HTTP client
- if (httpclient == null) {
- initialise();
- }
+ initialise();
// TLog.d(LOG_NAME, "Request to: "+ buildWebUIUrl() + addToUrl);
@@ -268,9 +266,10 @@ public class BitfluAdapter implements IDaemonAdapter {
*
* @throws DaemonException On conflicting or missing settings
*/
- private void initialise() throws DaemonException {
-
- httpclient = HttpHelper.createStandardHttpClient(settings, true);
+ private synchronized void initialise() throws DaemonException {
+ if(httpclient == null) {
+ httpclient = HttpHelper.createStandardHttpClient(settings, true);
+ }
}
/**
diff --git a/app/src/main/java/org/transdroid/daemon/adapters/buffaloNas/BuffaloNasAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/buffaloNas/BuffaloNasAdapter.java
index a591ff71..4808ce9d 100644
--- a/app/src/main/java/org/transdroid/daemon/adapters/buffaloNas/BuffaloNasAdapter.java
+++ b/app/src/main/java/org/transdroid/daemon/adapters/buffaloNas/BuffaloNasAdapter.java
@@ -20,7 +20,6 @@ package org.transdroid.daemon.adapters.buffaloNas;
import com.android.internal.http.multipart.FilePart;
import com.android.internal.http.multipart.MultipartEntity;
import com.android.internal.http.multipart.Part;
-
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
@@ -174,9 +173,7 @@ public class BuffaloNasAdapter implements IDaemonAdapter {
try {
// Initialise the HTTP client
- if (httpclient == null) {
- initialise();
- }
+ initialise();
// Add the parameters to the query string
boolean first = true;
@@ -251,9 +248,10 @@ public class BuffaloNasAdapter implements IDaemonAdapter {
*
* @throws DaemonException On conflicting or missing settings
*/
- private void initialise() throws DaemonException {
-
- httpclient = HttpHelper.createStandardHttpClient(settings, true);
+ private synchronized void initialise() throws DaemonException {
+ if(httpclient == null) {
+ httpclient = HttpHelper.createStandardHttpClient(settings, true);
+ }
}
diff --git a/app/src/main/java/org/transdroid/daemon/adapters/dLinkRouterBT/DLinkRouterBTAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/dLinkRouterBT/DLinkRouterBTAdapter.java
index 8049aa08..a13ed17e 100644
--- a/app/src/main/java/org/transdroid/daemon/adapters/dLinkRouterBT/DLinkRouterBTAdapter.java
+++ b/app/src/main/java/org/transdroid/daemon/adapters/dLinkRouterBT/DLinkRouterBTAdapter.java
@@ -20,7 +20,6 @@ package org.transdroid.daemon.adapters.dLinkRouterBT;
import com.android.internal.http.multipart.FilePart;
import com.android.internal.http.multipart.MultipartEntity;
import com.android.internal.http.multipart.Part;
-
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
@@ -234,9 +233,7 @@ public class DLinkRouterBTAdapter implements IDaemonAdapter {
try {
// Initialise the HTTP client
- if (httpclient == null) {
- initialise();
- }
+ initialise();
// Setup request using POST stream with URL and data
HttpPost httppost = new HttpPost(buildWebUIUrl() + requestUrl);
@@ -304,8 +301,10 @@ public class DLinkRouterBTAdapter implements IDaemonAdapter {
*
* @throws DaemonException On conflicting or missing settings
*/
- private void initialise() throws DaemonException {
- httpclient = HttpHelper.createStandardHttpClient(settings, true);
+ private synchronized void initialise() throws DaemonException {
+ if(httpclient == null) {
+ httpclient = HttpHelper.createStandardHttpClient(settings, true);
+ }
}
/**
diff --git a/app/src/main/java/org/transdroid/daemon/adapters/deluge/DelugeAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/deluge/DelugeAdapter.java
index d32bc984..42fdd5b2 100644
--- a/app/src/main/java/org/transdroid/daemon/adapters/deluge/DelugeAdapter.java
+++ b/app/src/main/java/org/transdroid/daemon/adapters/deluge/DelugeAdapter.java
@@ -20,7 +20,6 @@ package org.transdroid.daemon.adapters.deluge;
import com.android.internal.http.multipart.FilePart;
import com.android.internal.http.multipart.MultipartEntity;
import com.android.internal.http.multipart.Part;
-
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
@@ -163,9 +162,7 @@ public class DelugeAdapter implements IDaemonAdapter {
log.d(LOG_NAME, "Uploading a file to the Deluge daemon: " + url);
// Initialise the HTTP client
- if (httpclient == null) {
- initialise();
- }
+ initialise();
// Setup client using POST
HttpPost httppost = new HttpPost(url);
@@ -437,9 +434,7 @@ public class DelugeAdapter implements IDaemonAdapter {
// We still need to retrieve the version number from the server
// Do this by getting the web interface main html page and trying to parse the version number
// Format is something like '
Deluge: Web UI 1.3.6'
- if (httpclient == null) {
- initialise();
- }
+ initialise();
try {
HttpResponse response = httpclient.execute(new HttpGet(buildWebUIUrl() + "/"));
String main = HttpHelper.convertStreamToString(response.getEntity().getContent());
@@ -478,9 +473,7 @@ public class DelugeAdapter implements IDaemonAdapter {
try {
// Initialise the HTTP client
- if (httpclient == null) {
- initialise();
- }
+ initialise();
// Login first?
if (sessionCookie == null) {
@@ -582,11 +575,11 @@ public class DelugeAdapter implements IDaemonAdapter {
* @throws DaemonException On missing settings
*/
private void initialise() throws DaemonException {
-
- httpclient = HttpHelper.createStandardHttpClient(settings, settings.getUsername() != null && !settings.getUsername().equals(""));
- httpclient.addRequestInterceptor(HttpHelper.gzipRequestInterceptor);
- httpclient.addResponseInterceptor(HttpHelper.gzipResponseInterceptor);
-
+ if(httpclient == null) {
+ httpclient = HttpHelper.createStandardHttpClient(settings, settings.getUsername() != null && !settings.getUsername().equals(""));
+ httpclient.addRequestInterceptor(HttpHelper.gzipRequestInterceptor);
+ httpclient.addResponseInterceptor(HttpHelper.gzipResponseInterceptor);
+ }
}
/**
diff --git a/app/src/main/java/org/transdroid/daemon/adapters/kTorrent/KTorrentAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/kTorrent/KTorrentAdapter.java
index 05ea604f..6e2ccbd9 100644
--- a/app/src/main/java/org/transdroid/daemon/adapters/kTorrent/KTorrentAdapter.java
+++ b/app/src/main/java/org/transdroid/daemon/adapters/kTorrent/KTorrentAdapter.java
@@ -20,7 +20,6 @@ package org.transdroid.daemon.adapters.kTorrent;
import com.android.internal.http.multipart.FilePart;
import com.android.internal.http.multipart.MultipartEntity;
import com.android.internal.http.multipart.Part;
-
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.ProtocolException;
@@ -464,12 +463,10 @@ public class KTorrentAdapter implements IDaemonAdapter {
*
* @throws DaemonException Thrown on settings error
*/
- private void initialise() throws DaemonException {
-
- if (httpclient != null) {
- httpclient = null;
+ private synchronized void initialise() throws DaemonException {
+ if (httpclient == null) {
+ httpclient = HttpHelper.createStandardHttpClient(settings, false);
}
- httpclient = HttpHelper.createStandardHttpClient(settings, false);
}
/**
diff --git a/app/src/main/java/org/transdroid/daemon/adapters/qBittorrent/QBittorrentAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/qBittorrent/QBittorrentAdapter.java
index 9d7602d9..51e030d7 100644
--- a/app/src/main/java/org/transdroid/daemon/adapters/qBittorrent/QBittorrentAdapter.java
+++ b/app/src/main/java/org/transdroid/daemon/adapters/qBittorrent/QBittorrentAdapter.java
@@ -20,7 +20,6 @@ package org.transdroid.daemon.adapters.qBittorrent;
import com.android.internal.http.multipart.FilePart;
import com.android.internal.http.multipart.MultipartEntity;
import com.android.internal.http.multipart.Part;
-
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
@@ -587,7 +586,7 @@ public class QBittorrentAdapter implements IDaemonAdapter {
*
* @throws DaemonException On conflicting or missing settings
*/
- private void initialise() throws DaemonException {
+ private synchronized void initialise() throws DaemonException {
if (httpclient == null) {
httpclient = HttpHelper.createStandardHttpClient(settings, true);
}
diff --git a/app/src/main/java/org/transdroid/daemon/adapters/rTorrent/RTorrentAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/rTorrent/RTorrentAdapter.java
index 512c43c4..5205367f 100644
--- a/app/src/main/java/org/transdroid/daemon/adapters/rTorrent/RTorrentAdapter.java
+++ b/app/src/main/java/org/transdroid/daemon/adapters/rTorrent/RTorrentAdapter.java
@@ -18,7 +18,9 @@
package org.transdroid.daemon.adapters.rTorrent;
import android.text.TextUtils;
-
+import de.timroes.axmlrpc.XMLRPCClient;
+import de.timroes.axmlrpc.XMLRPCClient.UnauthorizdException;
+import de.timroes.axmlrpc.XMLRPCException;
import org.transdroid.core.gui.log.Log;
import org.transdroid.daemon.Daemon;
import org.transdroid.daemon.DaemonException;
@@ -66,10 +68,6 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import de.timroes.axmlrpc.XMLRPCClient;
-import de.timroes.axmlrpc.XMLRPCClient.UnauthorizdException;
-import de.timroes.axmlrpc.XMLRPCException;
-
/**
* An adapter that allows for easy access to rTorrent torrent data. Communication is handled via the XML-RPC protocol as
* implemented by the aXMLRPC library.
@@ -328,9 +326,7 @@ public class RTorrentAdapter implements IDaemonAdapter {
throws DaemonException, MalformedURLException {
// Initialise the HTTP client
- if (rpcclient == null) {
- initialise();
- }
+ initialise();
StringBuilder paramsBuilder = new StringBuilder();
for (Object arg : arguments) {
@@ -365,14 +361,13 @@ public class RTorrentAdapter implements IDaemonAdapter {
* Instantiates a XML-RPC client with proper credentials.
*
* @throws DaemonException On conflicting settings (i.e. user authentication but no password or username provided)
- * @throws MalformedURLException Thrown when the URL could not be properly constructed
*/
- private void initialise() throws DaemonException, MalformedURLException {
-
- int flags = XMLRPCClient.FLAGS_8BYTE_INT;
- this.rpcclient = new XMLRPCClient(HttpHelper.createStandardHttpClient(settings, true),
- settings.getAddress(), buildWebUIUrl(), flags);
-
+ private synchronized void initialise() throws DaemonException {
+ if(rpcclient == null) {
+ int flags = XMLRPCClient.FLAGS_8BYTE_INT;
+ this.rpcclient = new XMLRPCClient(HttpHelper.createStandardHttpClient(settings, true),
+ settings.getAddress(), buildWebUIUrl(), flags);
+ }
}
/**
diff --git a/app/src/main/java/org/transdroid/daemon/adapters/synology/SynologyAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/synology/SynologyAdapter.java
index 504c15ab..9655d69e 100644
--- a/app/src/main/java/org/transdroid/daemon/adapters/synology/SynologyAdapter.java
+++ b/app/src/main/java/org/transdroid/daemon/adapters/synology/SynologyAdapter.java
@@ -20,7 +20,6 @@ package org.transdroid.daemon.adapters.synology;
import com.android.internal.http.multipart.FilePart;
import com.android.internal.http.multipart.MultipartEntity;
import com.android.internal.http.multipart.Part;
-
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
@@ -84,10 +83,17 @@ public class SynologyAdapter implements IDaemonAdapter {
this.settings = settings;
}
+ private synchronized void initialise() throws DaemonException {
+ if (httpClient == null) {
+ httpClient = HttpHelper.createStandardHttpClient(settings, true);
+ }
+ }
+
@Override
public DaemonTaskResult executeTask(Log log, DaemonTask task) {
String tid;
try {
+ initialise();
switch (task.getMethod()) {
case Retrieve:
return new RetrieveTaskSuccessResult((RetrieveTask) task, tasksList(log), null);
@@ -425,13 +431,6 @@ public class SynologyAdapter implements IDaemonAdapter {
return new SynoRequest(path, api, version).post(sid, params);
}
- private DefaultHttpClient getHttpClient() throws DaemonException {
- if (httpClient == null) {
- httpClient = HttpHelper.createStandardHttpClient(settings, true);
- }
- return httpClient;
- }
-
private static class SynoResponse {
private final HttpResponse response;
@@ -502,7 +501,7 @@ public class SynologyAdapter implements IDaemonAdapter {
public SynoResponse get(String params) throws DaemonException {
try {
- return new SynoResponse(getHttpClient().execute(new HttpGet(buildURL(params))));
+ return new SynoResponse(httpClient.execute(new HttpGet(buildURL(params))));
} catch (IOException e) {
throw new DaemonException(ExceptionType.ConnectionError, e.toString());
}
@@ -523,7 +522,7 @@ public class SynologyAdapter implements IDaemonAdapter {
System.arraycopy(params, 0, allParams, baseParams.length, params.length);
request.setEntity(new MultipartEntity(allParams));
- return new SynoResponse(getHttpClient().execute(request));
+ return new SynoResponse(httpClient.execute(request));
} catch (IOException e) {
throw new DaemonException(ExceptionType.ConnectionError, e.toString());
}
diff --git a/app/src/main/java/org/transdroid/daemon/adapters/tTorrent/TTorrentAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/tTorrent/TTorrentAdapter.java
index 1c573a77..4ab2bc77 100644
--- a/app/src/main/java/org/transdroid/daemon/adapters/tTorrent/TTorrentAdapter.java
+++ b/app/src/main/java/org/transdroid/daemon/adapters/tTorrent/TTorrentAdapter.java
@@ -20,7 +20,6 @@ package org.transdroid.daemon.adapters.tTorrent;
import com.android.internal.http.multipart.FilePart;
import com.android.internal.http.multipart.MultipartEntity;
import com.android.internal.http.multipart.Part;
-
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
@@ -233,9 +232,7 @@ public class TTorrentAdapter implements IDaemonAdapter {
try {
// Initialise the HTTP client
- if (httpclient == null) {
- initialise();
- }
+ initialise();
// Execute
HttpResponse response = httpclient.execute(httppost);
@@ -267,8 +264,10 @@ public class TTorrentAdapter implements IDaemonAdapter {
*
* @throws DaemonException On conflicting or missing settings
*/
- private void initialise() throws DaemonException {
- httpclient = HttpHelper.createStandardHttpClient(settings, true);
+ private synchronized void initialise() throws DaemonException {
+ if(httpclient == null) {
+ httpclient = HttpHelper.createStandardHttpClient(settings, true);
+ }
}
/**
diff --git a/app/src/main/java/org/transdroid/daemon/adapters/tfb4rt/Tfb4rtAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/tfb4rt/Tfb4rtAdapter.java
index 02c9ed79..f1326e82 100644
--- a/app/src/main/java/org/transdroid/daemon/adapters/tfb4rt/Tfb4rtAdapter.java
+++ b/app/src/main/java/org/transdroid/daemon/adapters/tfb4rt/Tfb4rtAdapter.java
@@ -20,7 +20,6 @@ package org.transdroid.daemon.adapters.tfb4rt;
import com.android.internal.http.multipart.FilePart;
import com.android.internal.http.multipart.MultipartEntity;
import com.android.internal.http.multipart.Part;
-
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
@@ -176,9 +175,7 @@ public class Tfb4rtAdapter implements IDaemonAdapter {
try {
// Initialise the HTTP client
- if (httpclient == null) {
- initialise();
- }
+ initialise();
// Make request
HttpGet httpget = new HttpGet(buildWebUIUrl(RPC_URL_STATS));
@@ -205,9 +202,7 @@ public class Tfb4rtAdapter implements IDaemonAdapter {
try {
// Initialise the HTTP client
- if (httpclient == null) {
- initialise();
- }
+ initialise();
// Make request
HttpGet httpget = new HttpGet(buildWebUIUrl(RPC_URL_DISPATCH + action + RPC_URL_DISPATCH2 + RPC_URL_AID
@@ -239,9 +234,7 @@ public class Tfb4rtAdapter implements IDaemonAdapter {
try {
// Initialise the HTTP client
- if (httpclient == null) {
- initialise();
- }
+ initialise();
// Make request
HttpPost httppost = new HttpPost(buildWebUIUrl(RPC_URL_DISPATCH + action + RPC_URL_DISPATCH2 + RPC_URL_AID));
@@ -276,8 +269,10 @@ public class Tfb4rtAdapter implements IDaemonAdapter {
*
* @throws DaemonException On conflicting or missing settings
*/
- private void initialise() throws DaemonException {
- httpclient = HttpHelper.createStandardHttpClient(settings, true);
+ private synchronized void initialise() throws DaemonException {
+ if(httpclient == null) {
+ httpclient = HttpHelper.createStandardHttpClient(settings, true);
+ }
}
/**
diff --git a/app/src/main/java/org/transdroid/daemon/adapters/transmission/TransmissionAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/transmission/TransmissionAdapter.java
index b03ef3d7..ca630802 100644
--- a/app/src/main/java/org/transdroid/daemon/adapters/transmission/TransmissionAdapter.java
+++ b/app/src/main/java/org/transdroid/daemon/adapters/transmission/TransmissionAdapter.java
@@ -19,7 +19,6 @@ package org.transdroid.daemon.adapters.transmission;
import net.iharder.Base64;
import net.iharder.Base64.InputStream;
-
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
@@ -403,9 +402,7 @@ public class TransmissionAdapter implements IDaemonAdapter {
try {
// Initialise the HTTP client
- if (httpclient == null) {
- initialise();
- }
+ initialise();
final String sessionHeader = "X-Transmission-Session-Id";
// Setup request using POST stream with URL and data
@@ -477,8 +474,10 @@ public class TransmissionAdapter implements IDaemonAdapter {
*
* @throws DaemonException On conflicting or missing settings
*/
- private void initialise() throws DaemonException {
- httpclient = HttpHelper.createStandardHttpClient(settings, true);
+ private synchronized void initialise() throws DaemonException {
+ if(httpclient == null) {
+ httpclient = HttpHelper.createStandardHttpClient(settings, true);
+ }
}
/**
diff --git a/app/src/main/java/org/transdroid/daemon/adapters/uTorrent/UTorrentAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/uTorrent/UTorrentAdapter.java
index 2d9e203d..e2c24237 100644
--- a/app/src/main/java/org/transdroid/daemon/adapters/uTorrent/UTorrentAdapter.java
+++ b/app/src/main/java/org/transdroid/daemon/adapters/uTorrent/UTorrentAdapter.java
@@ -20,12 +20,9 @@ package org.transdroid.daemon.adapters.uTorrent;
import com.android.internal.http.multipart.FilePart;
import com.android.internal.http.multipart.MultipartEntity;
import com.android.internal.http.multipart.Part;
-
import org.apache.http.HttpResponse;
-import org.apache.http.client.CookieStore;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
-import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
@@ -117,12 +114,10 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier {
private static final int RPC_FILESIZE_IDX = 1;
private static final int RPC_FILEDOWNLOADED_IDX = 2;
private static final int RPC_FILEPRIORITY_IDX = 3;
- private static String authtoken;
+ private String authtoken;
private static ArrayList remoteRssChannels = new ArrayList<>();
private DaemonSettings settings;
private DefaultHttpClient httpclient;
- private static CookieStore cookieStore;
-
/**
* Initialises an adapter that provides operations to the uTorrent web daemon
@@ -368,11 +363,8 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier {
try {
// Initialise the HTTP client
- if (httpclient == null) {
- initialise();
- }
-
- ensureToken();
+ initialise();
+ ensureToken(retried > 0);
// Make request
HttpGet httpget = new HttpGet(buildWebUIUrl() + "?token=" + authtoken + addToUrl);
@@ -383,7 +375,6 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier {
String result = HttpHelper.convertStreamToString(instream);
if ((result.equals("") || result.trim().equals("invalid request"))) {
// Auth token was invalidated; retry at max 3 times
- authtoken = null; // So that ensureToken() will request a new token on the next try
if (retried < 2) {
return makeUtorrentRequest(log, addToUrl, ++retried);
}
@@ -407,10 +398,10 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier {
}
- private synchronized void ensureToken() throws IOException, DaemonException {
+ private synchronized void ensureToken(boolean forceReload) throws IOException, DaemonException {
- // Make sure we have a valid token
- if (authtoken == null) {
+ // Make sure we have a valid token or we're regenerating it
+ if (authtoken == null || forceReload) {
// Make a request to /gui/token.html
// See https://github.com/bittorrent/webui/wiki/TokenSystem
@@ -437,11 +428,8 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier {
public JSONObject uploadTorrentFile(String file) throws DaemonException, IOException, JSONException {
// Initialise the HTTP client
- if (httpclient == null) {
- initialise();
- }
-
- ensureToken();
+ initialise();
+ ensureToken(false);
// Build and make request
HttpPost httppost = new HttpPost(buildWebUIUrl() + "?token=" + authtoken + "&action=add-file");
@@ -464,13 +452,10 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier {
*
* @throws DaemonException On conflicting or missing settings
*/
- private void initialise() throws DaemonException {
- if (this.cookieStore == null) {
- this.cookieStore = new BasicCookieStore();
+ private synchronized void initialise() throws DaemonException {
+ if(httpclient == null) {
+ httpclient = HttpHelper.createStandardHttpClient(settings, true);
}
-
- this.httpclient = HttpHelper.createStandardHttpClient(settings, true);
- this.httpclient.setCookieStore(this.cookieStore);
}
/**
diff --git a/app/src/main/java/org/transdroid/daemon/adapters/vuze/VuzeAdapter.java b/app/src/main/java/org/transdroid/daemon/adapters/vuze/VuzeAdapter.java
index 561afdb4..9207aa07 100644
--- a/app/src/main/java/org/transdroid/daemon/adapters/vuze/VuzeAdapter.java
+++ b/app/src/main/java/org/transdroid/daemon/adapters/vuze/VuzeAdapter.java
@@ -226,9 +226,7 @@ public class VuzeAdapter implements IDaemonAdapter {
// TODO: It would be nicer to now split each of these steps into separate makeVuzeCalls when there are multiple logical steps such as stopping a torrent before removing it
// Initialise the HTTP client
- if (rpcclient == null) {
- initialise();
- }
+ initialise();
if (settings.getAddress() == null || settings.getAddress().equals("")) {
throw new DaemonException(DaemonException.ExceptionType.AuthenticationFailure, "No host name specified.");
}
@@ -329,10 +327,10 @@ public class VuzeAdapter implements IDaemonAdapter {
*
* @throws DaemonException On conflicting settings (i.e. user authentication but no password or username provided)
*/
- private void initialise() throws DaemonException {
-
- this.rpcclient = new VuzeXmlOverHttpClient(settings, buildWebUIUrl());
-
+ private synchronized void initialise() throws DaemonException {
+ if(rpcclient == null) {
+ rpcclient = new VuzeXmlOverHttpClient(settings, buildWebUIUrl());
+ }
}
/**