use of org.apache.http.HttpResponse in project opennms by OpenNMS.
the class JUnitHttpServerTest method testBasicAuthSuccess.
@Test
@JUnitHttpServer(port = 9162, basicAuth = true, webapps = { @Webapp(context = "/testContext", path = "src/test/resources/test-webapp") })
public void testBasicAuthSuccess() throws Exception {
final HttpUriRequest method = new HttpGet("http://localhost:9162/testContext/monkey");
m_clientWrapper.addBasicCredentials("admin", "istrator");
final HttpResponse response = m_clientWrapper.execute(method);
final String responseString = EntityUtils.toString(response.getEntity());
LOG.debug("got response:\n{}", responseString);
assertEquals(200, response.getStatusLine().getStatusCode());
assertTrue(responseString.contains("You are reading this from a servlet!"));
}
use of org.apache.http.HttpResponse in project opennms by OpenNMS.
the class NCSNorthbounderIT method testTestServlet.
@Test
@JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/fmpm", path = "src/test/resources/test-webapp") })
public void testTestServlet() throws Exception {
TestServlet.reset();
CloseableHttpClient client = HttpClientBuilder.create().build();
try {
HttpEntity entity = new StringEntity(xml);
HttpPost method = new HttpPost("http://localhost:10342/fmpm/restful/NotificationMessageRelay");
method.setEntity(entity);
HttpResponse response = client.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
assertEquals(xml, TestServlet.getPosted());
} finally {
IOUtils.closeQuietly(client);
}
}
use of org.apache.http.HttpResponse in project android_frameworks_base by DirtyUnicorns.
the class AbstractProxyTest method testParamPreferredOverSystemProperty.
private void testParamPreferredOverSystemProperty(ProxyConfig proxyConfig) throws Exception {
server.enqueue(new MockResponse().setBody("Via request parameter proxy!"));
server.play();
System.setProperty("http.proxyHost", "proxy.foo");
System.setProperty("http.proxyPort", "8080");
HttpClient client = newHttpClient();
HttpGet request = new HttpGet("http://origin.foo/bar");
proxyConfig.configure(server, client, request);
HttpResponse response = client.execute(request);
assertEquals("Via request parameter proxy!", contentToString(response));
RecordedRequest recordedRequest = server.takeRequest();
assertEquals("GET http://origin.foo/bar HTTP/1.1", recordedRequest.getRequestLine());
}
use of org.apache.http.HttpResponse in project android_frameworks_base by DirtyUnicorns.
the class CookiesTest method testCookiesWithNonMatchingCase.
/**
* Test that cookies aren't case-sensitive with respect to hostname.
* http://b/3167208
*/
public void testCookiesWithNonMatchingCase() throws Exception {
// use a proxy so we can manipulate the origin server's host name
server = new MockWebServer();
server.enqueue(new MockResponse().addHeader("Set-Cookie: a=first; Domain=my.t-mobile.com").addHeader("Set-Cookie: b=second; Domain=.T-mobile.com").addHeader("Set-Cookie: c=third; Domain=.t-mobile.com").setBody("This response sets some cookies."));
server.enqueue(new MockResponse().setBody("This response gets those cookies back."));
server.play();
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost("localhost", server.getPort()));
HttpResponse getCookies = client.execute(new HttpGet("http://my.t-mobile.com/"));
getCookies.getEntity().consumeContent();
server.takeRequest();
HttpResponse sendCookies = client.execute(new HttpGet("http://my.t-mobile.com/"));
sendCookies.getEntity().consumeContent();
RecordedRequest sendCookiesRequest = server.takeRequest();
assertContains(sendCookiesRequest.getHeaders(), "Cookie: a=first; b=second; c=third");
}
use of org.apache.http.HttpResponse in project android_frameworks_base by ParanoidAndroid.
the class BandwidthTestUtil method postFileToServer.
/**
* Post a given file for a given device and timestamp to the server.
* @param server {@link String} url of test server
* @param deviceId {@link String} device id that is uploading
* @param timestamp {@link String} timestamp
* @param file {@link File} to upload
* @return true if it succeeded
*/
public static boolean postFileToServer(String server, String deviceId, String timestamp, File file) {
try {
Log.d(LOG_TAG, "Uploading begining");
HttpClient httpClient = new DefaultHttpClient();
String uri = server;
if (!uri.endsWith("/")) {
uri += "/";
}
uri += "upload";
Log.d(LOG_TAG, "Upload url:" + uri);
HttpPost postRequest = new HttpPost(uri);
Part[] parts = { new StringPart("device_id", deviceId), new StringPart("timestamp", timestamp), new FilePart("file", file) };
MultipartEntity reqEntity = new MultipartEntity(parts, postRequest.getParams());
postRequest.setEntity(reqEntity);
HttpResponse res = httpClient.execute(postRequest);
res.getEntity().getContent().close();
} catch (IOException e) {
Log.e(LOG_TAG, "Could not upload file with error: " + e);
return false;
}
return true;
}
Aggregations