use of org.apache.http.client.methods.HttpGet in project android_frameworks_base by ParanoidAndroid.
the class CookiesTest method testCookiesAreNotLogged.
/**
* Test that we don't log potentially sensitive cookie values.
* http://b/3095990
*/
public void testCookiesAreNotLogged() throws IOException, URISyntaxException {
// enqueue an HTTP response with a cookie that will be rejected
server.enqueue(new MockResponse().addHeader("Set-Cookie: password=secret; Domain=fake.domain"));
server.play();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Logger logger = Logger.getLogger("org.apache.http");
StreamHandler handler = new StreamHandler(out, new SimpleFormatter());
logger.addHandler(handler);
try {
HttpClient client = new DefaultHttpClient();
client.execute(new HttpGet(server.getUrl("/").toURI()));
handler.close();
String log = out.toString("UTF-8");
assertTrue(log, log.contains("password"));
assertTrue(log, log.contains("fake.domain"));
assertFalse(log, log.contains("secret"));
} finally {
logger.removeHandler(handler);
}
}
use of org.apache.http.client.methods.HttpGet in project android_frameworks_base by ParanoidAndroid.
the class DefaultHttpClientTest method testServerClosesOutput.
private void testServerClosesOutput(SocketPolicy socketPolicy) throws Exception {
server.enqueue(new MockResponse().setBody("This connection won't pool properly").setSocketPolicy(socketPolicy));
server.enqueue(new MockResponse().setBody("This comes after a busted connection"));
server.play();
DefaultHttpClient client = new DefaultHttpClient();
HttpResponse a = client.execute(new HttpGet(server.getUrl("/a").toURI()));
assertEquals("This connection won't pool properly", contentToString(a));
assertEquals(0, server.takeRequest().getSequenceNumber());
HttpResponse b = client.execute(new HttpGet(server.getUrl("/b").toURI()));
assertEquals("This comes after a busted connection", contentToString(b));
// sequence number 0 means the HTTP socket connection was not reused
assertEquals(0, server.takeRequest().getSequenceNumber());
}
use of org.apache.http.client.methods.HttpGet in project android_frameworks_base by ParanoidAndroid.
the class DefaultHttpClientTest method authenticateDigestAlgorithm.
private void authenticateDigestAlgorithm(String algorithm) throws Exception {
String challenge = "Digest realm=\"protected area\", " + "nonce=\"dcd98b7102dd2f0e8b11d0f600bfb0c093\", " + "algorithm=" + algorithm;
DigestScheme digestScheme = new DigestScheme();
digestScheme.processChallenge(new BasicHeader("WWW-Authenticate", challenge));
HttpGet get = new HttpGet();
digestScheme.authenticate(new UsernamePasswordCredentials("username", "password"), get);
}
use of org.apache.http.client.methods.HttpGet in project android_frameworks_base by ParanoidAndroid.
the class FsUtils method getLayoutTestsDirContents.
public static List<String> getLayoutTestsDirContents(String dirRelativePath, boolean recurse, boolean mode) {
String modeString = (mode ? "folders" : "files");
URL url = null;
try {
url = new URL(SCRIPT_URL + "?path=" + dirRelativePath + "&recurse=" + recurse + "&mode=" + modeString);
} catch (MalformedURLException e) {
Log.e(LOG_TAG, "path=" + dirRelativePath + " recurse=" + recurse + " mode=" + modeString, e);
return new LinkedList<String>();
}
HttpGet httpRequest = new HttpGet(url.toString());
ResponseHandler<LinkedList<String>> handler = new ResponseHandler<LinkedList<String>>() {
@Override
public LinkedList<String> handleResponse(HttpResponse response) throws IOException {
LinkedList<String> lines = new LinkedList<String>();
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
return lines;
}
HttpEntity entity = response.getEntity();
if (entity == null) {
return lines;
}
BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
String line;
try {
while ((line = reader.readLine()) != null) {
lines.add(line);
}
} finally {
if (reader != null) {
reader.close();
}
}
return lines;
}
};
try {
return getHttpClient().execute(httpRequest, handler);
} catch (IOException e) {
Log.e(LOG_TAG, "getLayoutTestsDirContents(): HTTP GET failed for URL " + url);
return null;
}
}
use of org.apache.http.client.methods.HttpGet in project qi4j-sdk by Qi4j.
the class JettyServiceTest method testInstantiation.
@Test
public final void testInstantiation() throws Throwable {
Iterable<ServiceReference<JettyService>> services = module.findServices(JettyService.class);
assertNotNull(services);
Iterator<ServiceReference<JettyService>> iterator = services.iterator();
assertTrue(iterator.hasNext());
ServiceReference<JettyService> serviceRef = iterator.next();
assertNotNull(serviceRef);
JettyService jettyService = serviceRef.get();
assertNotNull(jettyService);
String output = defaultHttpClient.execute(new HttpGet("http://127.0.0.1:8041/helloWorld"), stringResponseHandler);
assertEquals("Hello World", output);
}
Aggregations