use of org.apache.http.impl.client.BasicResponseHandler in project cw-andtutorials by commonsguy.
the class Patchy method updateStatus.
private void updateStatus() {
try {
String s = status.getText().toString();
HttpPost post = new HttpPost("https://identi.ca/api/statuses/update.json");
post.addHeader("Authorization", "Basic " + getCredentials());
List<NameValuePair> form = new ArrayList<NameValuePair>();
form.add(new BasicNameValuePair("status", s));
post.setEntity(new UrlEncodedFormEntity(form, HTTP.UTF_8));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = client.execute(post, responseHandler);
JSONObject response = new JSONObject(responseBody);
} catch (Throwable t) {
Log.e("Patchy", "Exception in updateStatus()", t);
goBlooey(t);
}
}
use of org.apache.http.impl.client.BasicResponseHandler in project musiccabinet by hakko.
the class AbstractWSGetClient method invokeSingleCall.
/*
* Make a single call to a Last.fm web service, and return a packaged result.
*/
private WSResponse invokeSingleCall(List<NameValuePair> params) throws ApplicationException {
if (throttleService != null) {
throttleService.awaitAllowance();
}
WSResponse wsResponse;
HttpClient httpClient = getHttpClient();
try {
HttpGet httpGet = new HttpGet(getURI(params));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpClient.execute(httpGet, responseHandler);
wsResponse = new WSResponse(responseBody);
} catch (HttpResponseException e) {
wsResponse = new WSResponse(isHttpRecoverable(e.getStatusCode()), e.getStatusCode(), e.getMessage());
} catch (IOException e) {
LOG.warn("Could not fetch data from Last.fm!", e);
wsResponse = new WSResponse(true, -1, "Call failed due to " + e.getMessage());
}
return wsResponse;
}
use of org.apache.http.impl.client.BasicResponseHandler in project android-sms-relay by nyaruka.
the class RelayService method sendAlert.
/**
* Sends an alert to our server with the passed in subject. The body will contain
* configuration attributes and debugging information.
*
* TODO: Would be nice to echo these out to SMS if the client is configured
* with an alert phone number.
*
* @param subject The subject of the alert to send to the server
*/
public static boolean sendAlert(Context context, String subject, String body) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String hostname = prefs.getString("router_hostname", null);
Log.d(TAG, "__SENDING ALERT: " + subject);
if (hostname != null && subject != null) {
// send the alert off
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter("http.connection-manager.timeout", new Integer(60000));
client.getParams().setParameter("http.connection.timeout", new Integer(60000));
client.getParams().setParameter("http.socket.timeout", new Integer(60000));
StringBuilder conf = new StringBuilder();
conf.append("SMS Relay Version: " + AndroidRelay.getVersionNumber(context));
conf.append("\n");
conf.append("\nHostname: " + prefs.getString("router_hostname", null));
String backend = prefs.getString("router_backend", null);
conf.append("\nBackend:" + backend);
conf.append("\nPassword:" + prefs.getString("router_password", null));
conf.append("\n");
conf.append("\nProcess Incoming:" + prefs.getBoolean("process_incoming", false));
conf.append("\nProcess Outgoing:" + prefs.getBoolean("process_outgoing", false));
conf.append("\nInterval:" + prefs.getString("update_interval", "null"));
TextMessageHelper helper = AndroidRelay.getHelper(context);
int total = helper.getAllMessages().size();
int unsynced = helper.withStatus(context, TextMessage.INCOMING, TextMessage.RECEIVED).size();
conf.append("\n");
conf.append("\nTotal Messages:" + total);
conf.append("\nUnsynced:" + unsynced);
List<TextMessage> erroredOut = helper.withStatus(context, TextMessage.OUTGOING, TextMessage.ERRORED);
conf.append("\n\nErrored Out: " + erroredOut.size());
for (TextMessage msg : erroredOut) {
conf.append("\n" + msg.number + ": " + msg.text);
}
List<TextMessage> erroredIn = helper.withStatus(context, TextMessage.INCOMING, TextMessage.ERRORED);
conf.append("\n\nErrored In: " + erroredIn.size());
for (TextMessage msg : erroredIn) {
conf.append("\n" + msg.number + ": " + msg.text);
}
conf.append("\n\nLog:\n\n");
// prepend our configuration to our body
body = conf.toString() + body;
try {
HttpPost post = new HttpPost("http://" + hostname + "/router/alert");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("password", "" + prefs.getString("router_password", null)));
nameValuePairs.add(new BasicNameValuePair("subject", "[" + backend + "] " + subject));
nameValuePairs.add(new BasicNameValuePair("body", body));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Log.e(MainActivity.TAG, "Sending log to: " + post.getURI().toURL().toString());
ResponseHandler<String> responseHandler = new BasicResponseHandler();
client.execute(post, responseHandler);
return true;
} catch (Throwable t) {
Log.e(MainActivity.TAG, "Sending of alert failed", t);
return false;
}
}
return false;
}
use of org.apache.http.impl.client.BasicResponseHandler in project android-sms-relay by nyaruka.
the class RelayService method fetchURL.
public String fetchURL(String url) throws ClientProtocolException, IOException {
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter("http.connection-manager.timeout", new Integer(25000));
client.getParams().setParameter("http.connection.timeout", new Integer(25000));
client.getParams().setParameter("http.socket.timeout", new Integer(25000));
HttpGet httpget = new HttpGet(url);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String content = client.execute(httpget, responseHandler);
return content;
}
use of org.apache.http.impl.client.BasicResponseHandler in project qi4j-sdk by Qi4j.
the class ServletTest method test.
// END SNIPPET: usage
@Test
public void test() throws Exception {
int port = FreePortFinder.findFreePortOnLoopback(9001);
Server server = new Server(port);
try {
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
context.addEventListener(new FooServletContextListener());
context.addServlet(FooServlet.class, "/*");
server.setHandler(context);
server.start();
HttpClient client = new DefaultHttpClient();
String result = client.execute(new HttpGet("http://127.0.0.1:" + port + "/"), new BasicResponseHandler());
Assert.assertEquals(APP_NAME, result.trim());
} finally {
server.stop();
}
}
Aggregations