aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/eu/siacs/conversations/services/UpdaterWebService.java')
-rw-r--r--src/main/java/eu/siacs/conversations/services/UpdaterWebService.java91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java b/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java
new file mode 100644
index 000000000..1001562dc
--- /dev/null
+++ b/src/main/java/eu/siacs/conversations/services/UpdaterWebService.java
@@ -0,0 +1,91 @@
+package eu.siacs.conversations.services;
+
+import android.app.IntentService;
+import android.content.Intent;
+import android.util.Log;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.StatusLine;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.conn.params.ConnManagerParams;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import eu.siacs.conversations.ui.UpdaterActivity.MyWebReceiver;
+
+public class UpdaterWebService extends IntentService{
+ private static final String LOG_TAG = "MyWebService";
+ public static final String REQUEST_STRING = "myRequest";
+ public static final String RESPONSE_STRING = "myResponse";
+ public static final String RESPONSE_MESSAGE = "myResponseMessage";
+
+ private String URL = null;
+ private static final int REGISTRATION_TIMEOUT = 3 * 1000;
+ private static final int WAIT_TIMEOUT = 30 * 1000;
+
+ public UpdaterWebService() {
+ super("UpdaterWebService");
+ }
+
+ @Override
+ protected void onHandleIntent(Intent intent) {
+
+ String requestString = intent.getStringExtra(REQUEST_STRING);
+ Log.v(LOG_TAG, requestString);
+ String responseMessage = "";
+
+ try {
+
+ URL = requestString;
+ HttpClient httpclient = new DefaultHttpClient();
+ HttpParams params = httpclient.getParams();
+
+ HttpConnectionParams.setConnectionTimeout(params, REGISTRATION_TIMEOUT);
+ HttpConnectionParams.setSoTimeout(params, WAIT_TIMEOUT);
+ ConnManagerParams.setTimeout(params, WAIT_TIMEOUT);
+
+ HttpGet httpGet = new HttpGet(URL);
+ HttpResponse response = httpclient.execute(httpGet);
+
+ StatusLine statusLine = response.getStatusLine();
+ if(statusLine.getStatusCode() == HttpStatus.SC_OK){
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ response.getEntity().writeTo(out);
+ out.close();
+ responseMessage = out.toString();
+ }
+
+ else{
+ Log.w("HTTP1:",statusLine.getReasonPhrase());
+ response.getEntity().getContent().close();
+ throw new IOException(statusLine.getReasonPhrase());
+ }
+
+ } catch (ClientProtocolException e) {
+ Log.w("HTTP2:",e );
+ responseMessage = e.getMessage();
+ } catch (IOException e) {
+ Log.w("HTTP3:",e );
+ responseMessage = e.getMessage();
+ }catch (Exception e) {
+ Log.w("HTTP4:",e );
+ responseMessage = e.getMessage();
+ }
+
+
+ Intent broadcastIntent = new Intent();
+ broadcastIntent.setAction(MyWebReceiver.PROCESS_RESPONSE);
+ broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
+ broadcastIntent.putExtra(RESPONSE_MESSAGE, responseMessage);
+ sendBroadcast(broadcastIntent);
+
+ }
+
+} \ No newline at end of file