List of usage examples for org.apache.http.client ClientProtocolException getMessage
public String getMessage()
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/* ww w . j a va 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 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/*from w w w. j a v a 2s . c om*/ 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());/*from w w w. java 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:net.ccghe.utils.Server.java
public static JSONObject Send(PostDataPairs pairs) { HttpClient client = new DefaultHttpClient(); try {//from ww w . ja v a2 s . c o m HttpPost post = new HttpPost(serverURL); post.setEntity(new UrlEncodedFormEntity(pairs.get())); HttpResponse response = client.execute(post); HttpEntity entity = response.getEntity(); InputStream stream = entity.getContent(); String jsonResponse = convertStreamToString(stream); stream.close(); if (entity != null) { entity.consumeContent(); } JSONObject jObject = new JSONObject(jsonResponse); return jObject; } catch (ClientProtocolException e) { Log.e("EMOCHA", "ClientProtocolException ERR. " + e.getMessage()); } catch (UnknownHostException e) { Log.e("EMOCHA", "UnknownHostException ERR. " + e.getMessage()); } catch (IOException e) { Log.e("EMOCHA", "IOException ERR. " + e.getMessage()); } catch (Exception e) { Log.e("EMOCHA", "Exception ERR. " + e.getMessage()); } return null; }
From source file:com.batontouch.facebook.SessionStore.java
public static boolean save(Facebook session, Context context) { mcontext = context;/* w w w.j a va2s.com*/ 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:eu.citadel.converter.io.index.CitadelIndexUtil.java
/** * Upload a file to citadel index// w w w.j a va2 s . com * @param config Upload configuration * @param uploadFile File to be uploaded * @throws ConverterException */ public static void uploadToCitadelIndex(CitadelIndexConfig config, File uploadFile) throws ConverterException { String jsonResponse; try { jsonResponse = uploadFile(config.getSaveFileUrl(), uploadFile, config.getCharset(), USER_AGENT); Gson gson = new GsonBuilder().create(); IndexSaveFileResponse rs = gson.fromJson(jsonResponse, IndexSaveFileResponse.class); if (!rs.isOk()) { log.error("Invalid response from server: " + rs.getResponse() + ", " + rs.getMessage() + "."); throw new ConverterException( "Invalid response from server: " + rs.getResponse() + ", " + rs.getMessage() + "."); } jsonResponse = saveToIndex(config, rs.getStoredfileName()); IndexSaveToIndexResponse ri = gson.fromJson(jsonResponse, IndexSaveToIndexResponse.class); if (!ri.isOk()) { log.error("Invalid response from server: " + ri.getResponse() + ", " + ri.getMessage() + "."); throw new ConverterException( "Invalid response from server: " + ri.getResponse() + ", " + ri.getMessage() + "."); } } catch (ClientProtocolException e) { log.error(e.getMessage()); throw new ConverterException(e.getMessage()); } catch (IOException e) { log.error(e.getMessage()); throw new ConverterException(e.getMessage()); } ; }
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 + "®id=" + Global.gcm_regid); get.setHeader("Accept", "application/vnd.batontouch." + Global.version); String response = null;/*from ww w . j av 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:com.project.utilities.Utilities.java
/** * Sends post request to sepcified URL/*from w ww .j a va 2 s . co m*/ * @param valuePairs * @param postUrl * @return */ public static String postRequest(final List<BasicNameValuePair> valuePairs, final String postUrl) { String responseStr = null; StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); HttpClient httpclient = new DefaultHttpClient(); Log.e("POST_REQUEST", "ACTION LOGIN"); HttpPost httppost = new HttpPost(postUrl); try { // Add your data List<NameValuePair> postFields = new ArrayList<NameValuePair>(2); for (BasicNameValuePair nameValuePair : valuePairs) { postFields.add(nameValuePair); } httppost.setEntity(new UrlEncodedFormEntity(postFields)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); responseStr = EntityUtils.toString(response.getEntity()); Log.e("POST_REQUEST", "RESPONSE_CODE: " + response.getStatusLine().getStatusCode() + ""); } catch (ClientProtocolException e) { Log.e("ClientProtocolException", e.getMessage().toString()); } catch (IOException e) { Log.e("IOException", e.getMessage().toString()); } return responseStr; }
From source file:com.project.utilities.Utilities.java
/** * Sends get request to sepcified URL.//from w ww . j ava 2s . c o m * @param getUri * @return */ public static String getRequest(final String getUrl) { String responseStr = null; StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); HttpClient httpclient = new DefaultHttpClient(); Log.e("GET_REQUEST", "ACTION REQUEST"); try { // Execute HTTP Post Request HttpGet request = new HttpGet(); request.setURI(new URI(getUrl)); HttpResponse response = httpclient.execute(request); response.getStatusLine().getStatusCode(); BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer sb = new StringBuffer(""); String l = ""; String nl = System.getProperty("line.separator"); while ((l = in.readLine()) != null) { sb.append(l + nl); } in.close(); responseStr = sb.toString(); Log.e("POST_REQUEST", "RESPONSE_STR: " + responseStr); Log.e("POST_REQUEST", "RESPONSE_CODE: " + response.getStatusLine().getStatusCode() + ""); } catch (ClientProtocolException e) { Log.e("ClientProtocolException", e.getMessage().toString()); } catch (IOException e) { Log.e("IOException", e.getMessage().toString()); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } return responseStr; }
From source file:org.ubicompforall.cityexplorer.buildingblock.BusTimeStep.java
public static String connect(String url) { String result = ""; HttpClient httpclient = new DefaultHttpClient(); // Prepare a request object HttpGet httpget = new HttpGet(url); // Execute the request HttpResponse response;/*from w w w. ja v a2 s. c o m*/ try { response = httpclient.execute(httpget); // Examine the response status debug(2, response.getStatusLine().toString()); // Get hold of the response entity HttpEntity entity = response.getEntity(); // If the response does not enclose an entity, there is no need // to worry about connection release if (entity != null) { // A Simple JSON Response Read InputStream instream = entity.getContent(); result = convertStreamToString(instream); // now you have the string representation of the HTML request instream.close(); } } catch (ClientProtocolException e) { debug(-1, e.getCause() + " " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { debug(-1, e.getCause() + " " + e.getMessage()); } return result; }