use of org.apache.http.client.methods.HttpGet in project custom-cert-https by nelenkov.
the class MainActivity method httpClientConnect.
private void httpClientConnect() {
new GetHtmlTask() {
@Override
protected String doInBackground(Void... arg0) {
try {
boolean useClientAuth = useClientAuthCb.isChecked();
SSLContext sslContext = createSslContext(useClientAuth);
MySSLSocketFactory socketFactory = new MySSLSocketFactory(sslContext, new BrowserCompatHostnameVerifier());
HttpClient client = createHttpClient(socketFactory);
HttpGet get = new HttpGet(useClientAuth ? CLIENT_AUTH_URL : SERVER_AUTH_URL);
HttpResponse response = client.execute(get);
if (response.getStatusLine().getStatusCode() != 200) {
return "Error: " + response.getStatusLine();
} else {
return EntityUtils.toString(response.getEntity());
}
} catch (Exception e) {
Log.d(TAG, "Error: " + e.getMessage(), e);
error = e;
return null;
}
}
}.execute();
}
use of org.apache.http.client.methods.HttpGet 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.client.methods.HttpGet 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();
}
}
use of org.apache.http.client.methods.HttpGet in project neo4j by neo4j.
the class ConfigureBaseUriIT method shouldForwardHttpAndHost.
@Test
public void shouldForwardHttpAndHost() 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");
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();
}
}
use of org.apache.http.client.methods.HttpGet in project neo4j by neo4j.
the class ConfigureBaseUriIT method shouldUseRequestUriWhenNoXForwardHeadersPresent.
@Test
public void shouldUseRequestUriWhenNoXForwardHeadersPresent() throws Exception {
URI rootUri = functionalTestHelper.baseUri();
HttpClient httpclient = new DefaultHttpClient();
try {
HttpGet httpget = new HttpGet(rootUri);
httpget.setHeader("Accept", "application/json");
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);
assertFalse(responseEntityBody.contains("https://foobar.com"));
assertFalse(responseEntityBody.contains(":0"));
assertTrue(responseEntityBody.contains("http://localhost"));
} finally {
httpclient.getConnectionManager().shutdown();
}
}
Aggregations