mirror of
https://github.com/nerzhul/ownCloud-SMS-App.git
synced 2026-08-20 21:03:08 +00:00
Import some sources from legacy HTTP Client to permit using self signed certificates like before
It's not the perfect solution but this works Rename HTTPRequestBuilder to OCHttpClient & make it child of HttpClient
This commit is contained in:
@@ -48,7 +48,7 @@ import java.io.IOException;
|
||||
|
||||
import fr.unix_experience.owncloud_sms.R;
|
||||
import fr.unix_experience.owncloud_sms.defines.DefaultPrefs;
|
||||
import fr.unix_experience.owncloud_sms.engine.HTTPRequestBuilder;
|
||||
import fr.unix_experience.owncloud_sms.engine.OCHttpClient;
|
||||
|
||||
/**
|
||||
* A login screen that offers login via email/password.
|
||||
@@ -241,7 +241,7 @@ public class LoginActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
_returnCode = 0;
|
||||
HTTPRequestBuilder http = new HTTPRequestBuilder(_serverURI, _login, _password);
|
||||
OCHttpClient http = new OCHttpClient(_serverURI, _login, _password);
|
||||
GetMethod testMethod = http.getVersion();
|
||||
try {
|
||||
_returnCode = http.execute(testMethod);
|
||||
|
||||
+17
-11
@@ -23,15 +23,19 @@ import android.util.Log;
|
||||
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.HttpMethod;
|
||||
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
|
||||
import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import org.apache.commons.httpclient.methods.PostMethod;
|
||||
import org.apache.commons.httpclient.methods.StringRequestEntity;
|
||||
import org.apache.commons.httpclient.protocol.Protocol;
|
||||
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class HTTPRequestBuilder {
|
||||
public class OCHttpClient extends HttpClient {
|
||||
|
||||
private static final String TAG = HTTPRequestBuilder.class.getCanonicalName();
|
||||
private static final String TAG = OCHttpClient.class.getCanonicalName();
|
||||
private final Uri _serverURI;
|
||||
private final String _username;
|
||||
private final String _password;
|
||||
@@ -48,47 +52,49 @@ public class HTTPRequestBuilder {
|
||||
private static final String OC_V2_GET_MESSAGES_PHONE ="/index.php/apps/ocsms/api/v2/messages/[PHONENUMBER]/[START]/[LIMIT]?format=json";
|
||||
private static final String OC_V2_GET_MESSAGES_SENDQUEUE = "/index.php/apps/ocsms/api/v2/messages/sendqueue?format=json";
|
||||
|
||||
public HTTPRequestBuilder(Uri serverURI, String accountName, String accountPassword) {
|
||||
public OCHttpClient(Uri serverURI, String accountName, String accountPassword) {
|
||||
super(new MultiThreadedHttpConnectionManager());
|
||||
Protocol easyhttps = new Protocol("https", (ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443);
|
||||
Protocol.registerProtocol("https", easyhttps);
|
||||
_serverURI = serverURI;
|
||||
_username = accountName;
|
||||
_password = accountPassword;
|
||||
}
|
||||
|
||||
private GetMethod get(String oc_call) {
|
||||
Log.i(HTTPRequestBuilder.TAG, "Create GET " + _serverURI + oc_call);
|
||||
Log.i(OCHttpClient.TAG, "Create GET " + _serverURI + oc_call);
|
||||
return new GetMethod(_serverURI.toString() + oc_call);
|
||||
}
|
||||
|
||||
GetMethod getAllSmsIds() {
|
||||
return get(HTTPRequestBuilder.OC_GET_ALL_SMS_IDS);
|
||||
return get(OCHttpClient.OC_GET_ALL_SMS_IDS);
|
||||
}
|
||||
|
||||
public GetMethod getVersion() {
|
||||
return get(HTTPRequestBuilder.OC_GET_VERSION);
|
||||
return get(OCHttpClient.OC_GET_VERSION);
|
||||
}
|
||||
|
||||
PostMethod pushSms(StringRequestEntity ent) {
|
||||
PostMethod post = new PostMethod(_serverURI.toString() + HTTPRequestBuilder.OC_PUSH_ROUTE);
|
||||
PostMethod post = new PostMethod(_serverURI.toString() + OCHttpClient.OC_PUSH_ROUTE);
|
||||
post.setRequestEntity(ent);
|
||||
return post;
|
||||
}
|
||||
|
||||
GetMethod getPhoneList() {
|
||||
return get(HTTPRequestBuilder.OC_V2_GET_PHONELIST);
|
||||
return get(OCHttpClient.OC_V2_GET_PHONELIST);
|
||||
}
|
||||
|
||||
GetMethod getMessages(Long start, Integer limit) {
|
||||
return get(HTTPRequestBuilder.OC_V2_GET_MESSAGES.
|
||||
return get(OCHttpClient.OC_V2_GET_MESSAGES.
|
||||
replace("[START]", start.toString()).replace("[LIMIT]", limit.toString()));
|
||||
}
|
||||
|
||||
public int execute(HttpMethod req) throws IOException {
|
||||
HttpClient http = new HttpClient();
|
||||
String basicAuth = "Basic " +
|
||||
Base64.encodeToString((_username + ":" + _password).getBytes(), Base64.NO_WRAP);
|
||||
//req.setFollowRedirects(true); // App is SIGKILLED by android when doing this... WTF
|
||||
req.setDoAuthentication(true);
|
||||
req.addRequestHeader("Authorization", basicAuth);
|
||||
return http.executeMethod(req);
|
||||
return executeMethod(req);
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public class OCSMSOwnCloudClient {
|
||||
}
|
||||
|
||||
Uri serverURI = Uri.parse(ocURI);
|
||||
_http = new HTTPRequestBuilder(serverURI, accountManager.getUserData(account, "ocLogin"),
|
||||
_http = new OCHttpClient(serverURI, accountManager.getUserData(account, "ocLogin"),
|
||||
accountManager.getPassword(account));
|
||||
_connectivityMonitor = new ConnectivityMonitor(_context);
|
||||
}
|
||||
@@ -369,7 +369,7 @@ public class OCSMSOwnCloudClient {
|
||||
|
||||
private static final int maximumHttpReqTries = 3;
|
||||
|
||||
private final HTTPRequestBuilder _http;
|
||||
private final OCHttpClient _http;
|
||||
private final Context _context;
|
||||
private final ConnectivityMonitor _connectivityMonitor;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user