use of org.apache.http.impl.client.DefaultHttpClient in project graphdb by neo4j-attic.
the class PingerTest method shouldRespondToHttpClientGet.
/**
* Test that the LocalTestServer actually works.
*
* @throws Exception
*/
@Test
public void shouldRespondToHttpClientGet() throws Exception {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(serverUrl + "/?id=storeId+v=kernelVersion");
System.out.println("HttpClient: http-get " + httpget.getURI());
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
int l;
byte[] tmp = new byte[2048];
while ((l = instream.read(tmp)) != -1) {
}
}
assertThat(response, notNullValue());
assertThat(response.getStatusLine().getStatusCode(), is(HttpStatus.SC_OK));
}
use of org.apache.http.impl.client.DefaultHttpClient in project pinpoint by naver.
the class HttpClientIT method test.
@Test
public void test() throws Exception {
HttpClient httpClient = new DefaultHttpClient();
try {
HttpPost post = new HttpPost("http://www.naver.com");
post.addHeader("Content-Type", "application/json;charset=UTF-8");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
httpClient.execute(post, responseHandler);
} catch (Exception ignored) {
} finally {
if (null != httpClient && null != httpClient.getConnectionManager()) {
httpClient.getConnectionManager().shutdown();
}
}
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
Class<?> connectorClass;
try {
connectorClass = Class.forName("org.apache.http.impl.conn.ManagedClientConnectionImpl");
} catch (ClassNotFoundException e) {
connectorClass = Class.forName("org.apache.http.impl.conn.AbstractPooledConnAdapter");
}
verifier.verifyTrace(event("HTTP_CLIENT_4_INTERNAL", AbstractHttpClient.class.getMethod("execute", HttpUriRequest.class, ResponseHandler.class)));
verifier.verifyTrace(event("HTTP_CLIENT_4_INTERNAL", connectorClass.getMethod("open", HttpRoute.class, HttpContext.class, HttpParams.class), annotation("http.internal.display", "www.naver.com")));
verifier.verifyTrace(event("HTTP_CLIENT_4", HttpRequestExecutor.class.getMethod("execute", HttpRequest.class, HttpClientConnection.class, HttpContext.class), null, null, "www.naver.com", annotation("http.url", "/"), annotation("http.status.code", 200), annotation("http.io", anyAnnotationValue())));
verifier.verifyTraceCount(0);
}
use of org.apache.http.impl.client.DefaultHttpClient in project custom-cert-https by nelenkov.
the class MainActivity method createHttpClient.
private HttpClient createHttpClient(SocketFactory socketFactory) {
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET);
HttpConnectionParams.setConnectionTimeout(params, TIMEOUT);
ConnPerRoute connPerRoute = new ConnPerRouteBean(MAX_CONN_PER_ROUTE);
ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute);
ConnManagerParams.setMaxTotalConnections(params, MAX_CONNECTIONS);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
SocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
if (socketFactory != null) {
sslSocketFactory = socketFactory;
}
schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
return new DefaultHttpClient(cm, params);
}
use of org.apache.http.impl.client.DefaultHttpClient in project neo4j by neo4j.
the class DisableWADLIT method should404OnAnyUriEndinginWADL.
@Test
public void should404OnAnyUriEndinginWADL() throws Exception {
URI nodeUri = new URI("http://localhost:7474/db/data/application.wadl");
HttpClient httpclient = new DefaultHttpClient();
try {
HttpGet httpget = new HttpGet(nodeUri);
httpget.setHeader("Accept", "*/*");
HttpResponse response = httpclient.execute(httpget);
assertEquals(404, response.getStatusLine().getStatusCode());
} finally {
httpclient.getConnectionManager().shutdown();
}
}
use of org.apache.http.impl.client.DefaultHttpClient in project neo4j by neo4j.
the class ConfigureBaseUriIT method shouldForwardHttpAndFirstHost.
@Test
public void shouldForwardHttpAndFirstHost() throws Exception {
URI rootUri = functionalTestHelper.baseUri();
HttpClient httpclient = new DefaultHttpClient();
try {
HttpGet httpget = new HttpGet(rootUri);
httpget.setHeader("Accept", "application/json");
httpget.setHeader("X-Forwarded-Host", "foobar.com, bazbar.com");
httpget.setHeader("X-Forwarded-Proto", "http");
HttpResponse response = httpclient.execute(httpget);
String length = response.getHeaders("CONTENT-LENGTH")[0].getValue();
byte[] data = new byte[Integer.valueOf(length)];
response.getEntity().getContent().read(data);
String responseEntityBody = new String(data);
assertTrue(responseEntityBody.contains("http://foobar.com"));
assertFalse(responseEntityBody.contains("http://localhost"));
} finally {
httpclient.getConnectionManager().shutdown();
}
}
Aggregations