use of org.apache.http.impl.client.BasicResponseHandler in project musicbrainz-android by jdamcd.
the class MusicBrainzWebClient method autenticateCredentials.
@Override
public boolean autenticateCredentials() throws IOException {
HttpGet authenticationTest = new HttpGet(QueryBuilder.authenticationCheck());
authenticationTest.setHeader("Accept", "application/xml");
try {
httpClient.execute(authenticationTest, new BasicResponseHandler());
} catch (HttpResponseException e) {
return false;
}
return true;
}
use of org.apache.http.impl.client.BasicResponseHandler in project Klyph by jonathangerbaud.
the class HttpRequest2 method send.
public String send() {
client = AndroidHttpClient.newInstance("Android");
HttpPost request = new HttpPost(url);
if (params != null) {
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
for (Map.Entry<String, String> entry : params.entrySet()) {
postParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
try {
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(postParams);
entity.setContentEncoding(HTTP.UTF_8);
request.setEntity(entity);
} catch (UnsupportedEncodingException e) {
Log.e("", "UnsupportedEncodingException: " + e);
}
}
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = "";
try {
response = client.execute(request, responseHandler);
} catch (ClientProtocolException e) {
Log.e("HttpRequest2", e.toString());
} catch (IOException e) {
Log.e("HttpRequest2", e.toString());
}
if (LOG_RESPONSE == true)
Log.i("HttpRequest2", response);
if (HTML_TRANSFORM == true)
response = Html.fromHtml(response).toString();
close();
return response;
}
use of org.apache.http.impl.client.BasicResponseHandler 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.BasicResponseHandler in project robolectric by robolectric.
the class ShadowDefaultRequestDirectorTest method shouldSupportBasicResponseHandlerHandleResponse.
@Test
public void shouldSupportBasicResponseHandlerHandleResponse() throws Exception {
FakeHttp.addPendingHttpResponse(200, "OK", new BasicHeader("Content-Type", "text/plain"));
DefaultHttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(new HttpGet("http://www.nowhere.org"));
assertThat(((HttpUriRequest) FakeHttp.getSentHttpRequest(0)).getURI()).isEqualTo(URI.create("http://www.nowhere.org"));
Assert.assertNotNull(response);
String responseStr = new BasicResponseHandler().handleResponse(response);
Assert.assertEquals("OK", responseStr);
}
use of org.apache.http.impl.client.BasicResponseHandler in project apn-proxy by apn-proxy.
the class TestProxyWithHttpClient method test.
private void test(String uri, int exceptCode, String exceptHeaderName, String exceptHeaderValue) {
ConnectionConfig connectionConfig = ConnectionConfig.custom().setCharset(Consts.UTF_8).build();
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(2000);
cm.setDefaultMaxPerRoute(40);
cm.setDefaultConnectionConfig(connectionConfig);
CloseableHttpClient httpClient = HttpClients.custom().setUserAgent("Mozilla/5.0 xx-dev-web-common httpclient/4.x").setConnectionManager(cm).disableContentCompression().disableCookieManagement().build();
HttpHost proxy = new HttpHost("127.0.0.1", ApnProxyConfig.getConfig().getPort());
RequestConfig config = RequestConfig.custom().setProxy(proxy).setExpectContinueEnabled(true).setConnectionRequestTimeout(5000).setConnectTimeout(10000).setSocketTimeout(10000).setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
HttpGet request = new HttpGet(uri);
request.setConfig(config);
try {
CloseableHttpResponse httpResponse = httpClient.execute(request);
Assert.assertEquals(exceptCode, httpResponse.getStatusLine().getStatusCode());
if (StringUtils.isNotBlank(exceptHeaderName) && StringUtils.isNotBlank(exceptHeaderValue)) {
Assert.assertEquals(exceptHeaderValue, httpResponse.getFirstHeader(exceptHeaderName).getValue());
}
ResponseHandler<String> responseHandler = new BasicResponseHandler();
responseHandler.handleResponse(httpResponse);
httpResponse.close();
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
Aggregations