Example usage for org.apache.http.client ClientProtocolException getClass

List of usage examples for org.apache.http.client ClientProtocolException getClass

Introduction

In this page you can find the example usage for org.apache.http.client ClientProtocolException getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.batontouch.facebook.SessionStore.java

public static boolean save(Facebook session, Context context) {
    mcontext = context;/*www  . jav  a2 s.co  m*/
    Editor editor = context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
    editor.putString(TOKEN, session.getAccessToken());
    editor.putLong(EXPIRES, session.getAccessExpires());

    facebooktoken = session.getAccessToken();

    t = new Thread() {
        public void run() {

            try {
                authenticate(facebooktoken);
            } catch (ClientProtocolException e) {
                Log.e("my", e.getClass().getName() + e.getMessage() + "cl");
            } catch (IOException e) {
                Log.e("my", e.getClass().getName() + e.getMessage() + "io");
                e.printStackTrace();
            } catch (Exception e) {
                Log.e("my", e.getClass().getName() + e.getMessage() + "io");
            }
        }
    };
    t.start();
    return editor.commit();
}

From source file:com.batontouch.facebook.SessionStore.java

private static void FacebookServerLogin(String token) {
    Log.d("my", token);
    HashMap<String, String> sessionTokens = null;
    mPreferences = mcontext.getSharedPreferences("CurrentUser", mcontext.MODE_PRIVATE);

    DefaultHttpClient client = new DefaultHttpClient();
    HttpGet get = new HttpGet(Global.FacebookSendToken + token + "&regid=" + Global.gcm_regid);

    get.setHeader("Accept", "application/vnd.batontouch." + Global.version);

    String response = null;//www  .  j a  v a2  s  . c  o m
    try {
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        response = client.execute(get, responseHandler);
    } catch (ClientProtocolException e) {
        Log.e("my", e.getClass().getName() + e.getMessage() + " clpt");
    } catch (IOException e) {
        Log.e("my", e.getClass().getName() + e.getMessage() + " IO");
    } catch (Exception e) {
        Log.e("my", e.getClass().getName() + e.getMessage() + " exception");
    }

    ParsedLoginDataSet parsedLoginDataSet = new ParsedLoginDataSet();
    try {
        sessionTokens = parseToken(response);
    } catch (Exception e) {
        Log.e("my", e.getClass().getName() + e.getMessage() + "5");
    }
    parsedLoginDataSet.setExtractedString(sessionTokens.get("error"));
    if (parsedLoginDataSet.getExtractedString().equals("Success")) {
        GCMRegistrar.setRegisteredOnServer(mcontext, true);
        // Store the username and password in SharedPreferences after the
        // successful login
        SharedPreferences.Editor editor = mPreferences.edit();
        // editor.putString("UserName", email);
        // editor.putString("PassWord", password);
        editor.putString("AuthToken", sessionTokens.get("auth_token"));
        editor.commit();
        Message myMessage = new Message();
        myMessage.obj = "SUCCESS";
        handler.sendMessage(myMessage);
    } else {
        Log.e("my", "Login Error!");
    }
}

From source file:org.vuphone.assassins.android.http.HTTPPoster.java

public static void doGameAreaPost(double lat, double lon, float rad) {
    final HttpPost post = new HttpPost(VUphone.SERVER + PATH);
    post.addHeader("Content-Type", "application/x-www-form-urlencoded");

    StringBuffer params = new StringBuffer();
    params.append("type=gameAreaPost&lat=" + lat + "&lon=" + lon + "&radius=" + rad);

    Log.v(VUphone.tag, pre + "Created parameter string: " + params);
    post.setEntity(new ByteArrayEntity(params.toString().getBytes()));

    // Do it/*  w  ww. j  ava  2 s  .c  o  m*/
    Log.i(VUphone.tag, pre + "Executing post to " + VUphone.SERVER + PATH);

    HttpResponse resp = null;
    try {
        resp = c.execute(post);
        ByteArrayOutputStream bao = new ByteArrayOutputStream();
        resp.getEntity().writeTo(bao);
        Log.d(VUphone.tag, pre + "Response from server: " + new String(bao.toByteArray()));
    } catch (ClientProtocolException e) {
        Log.e(VUphone.tag, pre + "ClientProtocolException executing post: " + e.getMessage());
    } catch (IOException e) {
        Log.e(VUphone.tag, pre + "IOException writing to ByteArrayOutputStream: " + e.getMessage());
    } catch (Exception e) {
        Log.e(VUphone.tag, pre + "Other Exception of type:" + e.getClass());
        Log.e(VUphone.tag, pre + "The message is: " + e.getMessage());
    }
}

From source file:org.vuphone.assassins.android.http.HTTPPoster.java

public static void doLandMineRemove(LandMine lm) {

    final HttpPost post = new HttpPost(VUphone.SERVER + PATH);
    post.addHeader("Content-Type", "application/x-www-form-urlencoded");

    StringBuffer params = new StringBuffer();
    params.append("type=landMineRemove&lat=" + lm.getLatitude() + "&lon=" + lm.getLongitude());

    Log.v(VUphone.tag, pre + "Created parameter string: " + params);
    post.setEntity(new ByteArrayEntity(params.toString().getBytes()));

    // Do it/*w ww.j a  v a  2s .  c o  m*/
    Log.i(VUphone.tag, pre + "Executing post to " + VUphone.SERVER + PATH);

    HttpResponse resp = null;
    try {
        resp = c.execute(post);
        ByteArrayOutputStream bao = new ByteArrayOutputStream();
        resp.getEntity().writeTo(bao);
        Log.d(VUphone.tag, pre + "Response from server: " + new String(bao.toByteArray()));
    } catch (ClientProtocolException e) {
        Log.e(VUphone.tag, pre + "ClientProtocolException executing post: " + e.getMessage());
    } catch (IOException e) {
        Log.e(VUphone.tag, pre + "IOException writing to ByteArrayOutputStream: " + e.getMessage());
    } catch (Exception e) {
        Log.e(VUphone.tag, pre + "Other Exception of type:" + e.getClass());
        Log.e(VUphone.tag, pre + "The message is: " + e.getMessage());
    }
}

From source file:org.vuphone.assassins.android.http.HTTPPoster.java

public static void doLandMinePost(LandMine lm) {

    final HttpPost post = new HttpPost(VUphone.SERVER + PATH);
    post.addHeader("Content-Type", "application/x-www-form-urlencoded");

    StringBuffer params = new StringBuffer();
    params.append("type=landMinePost&lat=" + lm.getLatitude() + "&lon=" + lm.getLongitude() + "&radius="
            + lm.getRadius());/* w  w w. j av  a 2  s  .c o  m*/

    Log.v(VUphone.tag, pre + "Created parameter string: " + params);
    post.setEntity(new ByteArrayEntity(params.toString().getBytes()));

    // Do it
    Log.i(VUphone.tag, pre + "Executing post to " + VUphone.SERVER + PATH);

    HttpResponse resp = null;
    try {
        resp = c.execute(post);
        ByteArrayOutputStream bao = new ByteArrayOutputStream();
        resp.getEntity().writeTo(bao);
        Log.d(VUphone.tag, pre + "Response from server: " + new String(bao.toByteArray()));
    } catch (ClientProtocolException e) {
        Log.e(VUphone.tag, pre + "ClientProtocolException executing post: " + e.getMessage());
    } catch (IOException e) {
        Log.e(VUphone.tag, pre + "IOException writing to ByteArrayOutputStream: " + e.getMessage());
    } catch (Exception e) {
        Log.e(VUphone.tag, pre + "Other Exception of type:" + e.getClass());
        Log.e(VUphone.tag, pre + "The message is: " + e.getMessage());
    }
}

From source file:es.warp.killthedj.spotify.SpotifyHTTPGet.java

public String get(String query) throws SpotifyQueryNetworkException {
    String url = SPOTIFY_URL + query;
    Log.d("SpotifyHTTPGet", "URL: " + url);
    StringBuilder builder = new StringBuilder();
    HttpClient client = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(url);
    try {/*from   w w  w .j a v  a  2s .  c o  m*/
        HttpResponse response = client.execute(httpGet);
        if (response.getStatusLine().getStatusCode() != 200) {
            Log.e("SpotifyHTTPGet", "URL: " + url);
            Log.e("SpotifyHTTPGet", response.getStatusLine().toString());
            throw new SpotifyQueryNetworkException("Didn't get 200 OK");
        }
        BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        String line;
        while ((line = reader.readLine()) != null) {
            builder.append(line);
        }
        return builder.toString();
    } catch (ClientProtocolException e) {
        Log.e("SpotifyHTTPGet", e.getClass().getSimpleName() + ": " + e.getMessage());
        throw new SpotifyQueryNetworkException(e);
    } catch (IOException e) {
        Log.e("SpotifyHTTPGet", e.getClass().getSimpleName() + ": " + e.getMessage());
        throw new SpotifyQueryNetworkException(e);
    }
}

From source file:org.prx.prp.utility.HttpHelper.java

private synchronized String execute(final HttpRequestBase method) {
    String response = null;/* w  ww .  j  a v a2s  .  co m*/
    try {
        response = HttpHelper.client.execute(method, this.responseHandler);
    } catch (ClientProtocolException e) {
        response = HttpHelper.HTTP_RESPONSE_ERROR + " - " + e.getClass().getSimpleName() + " " + e.getMessage();
    } catch (IOException e) {
        response = HttpHelper.HTTP_RESPONSE_ERROR + " - " + e.getClass().getSimpleName() + " " + e.getMessage();
    }
    return response;
}

From source file:org.tomahawk.tomahawk_android.utils.TomahawkExceptionReporter.java

/**
 * Pull information from the given {@link CrashReportData} and send it via HTTP to
 * oops.tomahawk-player.org or sends it as a TEXT intent, if IS_SILENT is true
 *//*from  ww w. j  a  va  2 s  .  c o  m*/
@Override
public void send(CrashReportData data) throws ReportSenderException {
    StringBuilder body = new StringBuilder();

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    nameValuePairs.add(new BasicNameValuePair("Version", data.getProperty(ReportField.APP_VERSION_NAME)));

    nameValuePairs.add(new BasicNameValuePair("BuildID", data.getProperty(ReportField.BUILD)));
    nameValuePairs.add(new BasicNameValuePair("ProductName", "tomahawk-android"));
    nameValuePairs.add(new BasicNameValuePair("Vendor", "Tomahawk"));
    nameValuePairs.add(new BasicNameValuePair("timestamp", data.getProperty(ReportField.USER_CRASH_DATE)));

    for (NameValuePair pair : nameValuePairs) {
        body.append("--thkboundary\r\n");
        body.append("Content-Disposition: form-data; name=\"");
        body.append(pair.getName()).append("\"\r\n\r\n").append(pair.getValue()).append("\r\n");
    }

    body.append("--thkboundary\r\n");
    body.append("Content-Disposition: form-data; name=\"upload_file_minidump\"; filename=\"")
            .append(data.getProperty(ReportField.REPORT_ID)).append("\"\r\n");
    body.append("Content-Type: application/octet-stream\r\n\r\n");

    body.append("============== Tomahawk Exception Report ==============\r\n\r\n");
    body.append("Report ID: ").append(data.getProperty(ReportField.REPORT_ID)).append("\r\n");
    body.append("App Start Date: ").append(data.getProperty(ReportField.USER_APP_START_DATE)).append("\r\n");
    body.append("Crash Date: ").append(data.getProperty(ReportField.USER_CRASH_DATE)).append("\r\n\r\n");

    body.append("--------- Phone Details  ----------\r\n");
    body.append("Phone Model: ").append(data.getProperty(ReportField.PHONE_MODEL)).append("\r\n");
    body.append("Brand: ").append(data.getProperty(ReportField.BRAND)).append("\r\n");
    body.append("Product: ").append(data.getProperty(ReportField.PRODUCT)).append("\r\n");
    body.append("Display: ").append(data.getProperty(ReportField.DISPLAY)).append("\r\n");
    body.append("-----------------------------------\r\n\r\n");

    body.append("----------- Stack Trace -----------\r\n");
    body.append(data.getProperty(ReportField.STACK_TRACE)).append("\r\n");
    body.append("-----------------------------------\r\n\r\n");

    body.append("------- Operating System  ---------\r\n");
    body.append("App Version Name: ").append(data.getProperty(ReportField.APP_VERSION_NAME)).append("\r\n");
    body.append("Total Mem Size: ").append(data.getProperty(ReportField.TOTAL_MEM_SIZE)).append("\r\n");
    body.append("Available Mem Size: ").append(data.getProperty(ReportField.AVAILABLE_MEM_SIZE)).append("\r\n");
    body.append("Dumpsys Meminfo: ").append(data.getProperty(ReportField.DUMPSYS_MEMINFO)).append("\r\n");
    body.append("-----------------------------------\r\n\r\n");

    body.append("-------------- Misc ---------------\r\n");
    body.append("Package Name: ").append(data.getProperty(ReportField.PACKAGE_NAME)).append("\r\n");
    body.append("File Path: ").append(data.getProperty(ReportField.FILE_PATH)).append("\r\n");

    body.append("Android Version: ").append(data.getProperty(ReportField.ANDROID_VERSION)).append("\r\n");
    body.append("Build: ").append(data.getProperty(ReportField.BUILD)).append("\r\n");
    body.append("Initial Configuration:  ").append(data.getProperty(ReportField.INITIAL_CONFIGURATION))
            .append("\r\n");
    body.append("Crash Configuration: ").append(data.getProperty(ReportField.CRASH_CONFIGURATION))
            .append("\r\n");
    body.append("Settings Secure: ").append(data.getProperty(ReportField.SETTINGS_SECURE)).append("\r\n");
    body.append("User Email: ").append(data.getProperty(ReportField.USER_EMAIL)).append("\r\n");
    body.append("User Comment: ").append(data.getProperty(ReportField.USER_COMMENT)).append("\r\n");
    body.append("-----------------------------------\r\n\r\n");

    body.append("---------------- Logs -------------\r\n");
    body.append("Logcat: ").append(data.getProperty(ReportField.LOGCAT)).append("\r\n\r\n");
    body.append("Events Log: ").append(data.getProperty(ReportField.EVENTSLOG)).append("\r\n\r\n");
    body.append("Radio Log: ").append(data.getProperty(ReportField.RADIOLOG)).append("\r\n");
    body.append("-----------------------------------\r\n\r\n");

    body.append("=======================================================\r\n\r\n");
    body.append("--thkboundary\r\n");
    body.append(
            "Content-Disposition: form-data; name=\"upload_file_tomahawklog\"; filename=\"Tomahawk.log\"\r\n");
    body.append("Content-Type: text/plain\r\n\r\n");
    body.append(data.getProperty(ReportField.LOGCAT));
    body.append("\r\n--thkboundary--\r\n");

    if ("true".equals(data.getProperty(ReportField.IS_SILENT))) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        body.insert(0, "Please tell us why you're sending us this log:\n\n\n\n\n");
        intent.putExtra(Intent.EXTRA_TEXT, body.toString());
        intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "support@tomahawk-player.org" });
        intent.putExtra(Intent.EXTRA_SUBJECT, "Tomahawk Android Log");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        TomahawkApp.getContext().startActivity(intent);
    } else {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://oops.tomahawk-player.org/addreport.php");
        httppost.setHeader("Content-type", "multipart/form-data; boundary=thkboundary");
        try {
            httppost.setEntity(new StringEntity(body.toString()));
            httpclient.execute(httppost);
        } catch (ClientProtocolException e) {
            Log.e(TAG, "send: " + e.getClass() + ": " + e.getLocalizedMessage());
        } catch (IOException e) {
            Log.e(TAG, "send: " + e.getClass() + ": " + e.getLocalizedMessage());
        }
    }
}

From source file:at.fhooe.mcm.webdav.WebDavInterface.java

/**
 * executes a http post request//  ww  w .  j a  va2s  . c  o m
 * 
 * also adds the user/password to the request params
 * 
 * @param values
 * @return
 */
private RestResponse doRequest(List<NameValuePair> values) {
    HttpClient httpclient = new DefaultHttpClient();

    // Prepare a request object
    HttpPost post = new HttpPost(url);

    // Execute the request
    String data = "";
    int returnCode = -1;
    try {
        values.add(new BasicNameValuePair("user", user));
        values.add(new BasicNameValuePair("pw", pw));

        HttpEntity entity = new UrlEncodedFormEntity(values);
        post.setEntity(entity);
        HttpResponse response = httpclient.execute(post);
        // Examine the response status

        returnCode = response.getStatusLine().getStatusCode();
        data = convertStreamToString(response.getEntity().getContent());

        return new RestResponse(returnCode, data);

    } catch (ClientProtocolException e) {
        e.printStackTrace();
        data = e.getClass().getName() + " " + e.getMessage();
    } catch (IOException e) {
        e.printStackTrace();
        data = e.getClass().getName() + " " + e.getMessage();
    }

    return new RestResponse(-1, data);
}

From source file:uk.co.uwcs.choob.modules.HttpModule.java

private synchronized String execute(final HttpRequestBase method) {
    String response = null;/*from w  ww.  j ava  2s  . co  m*/
    // execute method returns?!? (rather than async) - do it here sync, and
    // wrap async elsewhere
    try {
        response = HttpModule.client.execute(method, responseHandler);
    } catch (ClientProtocolException e) {
        response = HttpModule.HTTP_RESPONSE_ERROR + " - " + e.getClass().getSimpleName() + " " + e.getMessage();
        // e.printStackTrace();
    } catch (IOException e) {
        response = HttpModule.HTTP_RESPONSE_ERROR + " - " + e.getClass().getSimpleName() + " " + e.getMessage();
        // e.printStackTrace();
    }
    return response;
}