Search in sources :

Example 41 with BufferedHttpEntity

use of org.apache.http.entity.BufferedHttpEntity in project ThinkAndroid by white-cat.

the class AsyncHttpResponseHandler method sendResponseMessage.

protected void sendResponseMessage(HttpResponse response) {
    StatusLine status = response.getStatusLine();
    String responseBody = null;
    try {
        HttpEntity entity = null;
        HttpEntity temp = response.getEntity();
        if (temp != null) {
            entity = new BufferedHttpEntity(temp);
            responseBody = EntityUtils.toString(entity, "UTF-8");
        }
    } catch (IOException e) {
        sendFailureMessage(e, (String) null);
    }
    if (status.getStatusCode() >= 300) {
        sendFailureMessage(new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()), responseBody);
    } else {
        sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), responseBody);
    }
}
Also used : StatusLine(org.apache.http.StatusLine) HttpEntity(org.apache.http.HttpEntity) BufferedHttpEntity(org.apache.http.entity.BufferedHttpEntity) BufferedHttpEntity(org.apache.http.entity.BufferedHttpEntity) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException)

Example 42 with BufferedHttpEntity

use of org.apache.http.entity.BufferedHttpEntity in project RoboZombie by sahan.

the class RequestParamEndpointTest method testBufferedHttpEntity.

/**
 * <p>Test for a {@link Request} with a <b>buffered</b> entity.</p>
 *
 * @since 1.3.0
 */
@Test
public final void testBufferedHttpEntity() throws ParseException, IOException {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String subpath = "/bufferedhttpentity";
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    InputStream inputStream = classLoader.getResourceAsStream("LICENSE.txt");
    InputStream parallelInputStream = classLoader.getResourceAsStream("LICENSE.txt");
    BasicHttpEntity bhe = new BasicHttpEntity();
    bhe.setContent(parallelInputStream);
    stubFor(put(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200)));
    requestEndpoint.bufferedHttpEntity(inputStream);
    verify(putRequestedFor(urlEqualTo(subpath)).withRequestBody(equalTo(EntityUtils.toString(new BufferedHttpEntity(bhe)))));
}
Also used : BufferedHttpEntity(org.apache.http.entity.BufferedHttpEntity) InputStream(java.io.InputStream) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) Test(org.junit.Test)

Example 43 with BufferedHttpEntity

use of org.apache.http.entity.BufferedHttpEntity in project FastDev4Android by jiangqqlmj.

the class IoUtils method getBitmapData.

/**
 * 获取Image图片信息
 *
 * @return bitmap
 */
public static Bitmap getBitmapData(String imgUrl) {
    Bitmap bmp = null;
    Log.d(TAG_LISTLOGIC, "get imgage:" + imgUrl);
    InputStream inpStream = null;
    try {
        HttpGet http = new HttpGet(imgUrl);
        HttpClient client = new DefaultHttpClient();
        HttpResponse response = (HttpResponse) client.execute(http);
        HttpEntity httpEntity = response.getEntity();
        BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(httpEntity);
        // 获取数据流
        inpStream = bufferedHttpEntity.getContent();
        bmp = BitmapFactory.decodeStream(inpStream);
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        if (inpStream != null) {
            try {
                inpStream.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
    return bmp;
}
Also used : Bitmap(android.graphics.Bitmap) HttpEntity(org.apache.http.HttpEntity) BufferedHttpEntity(org.apache.http.entity.BufferedHttpEntity) BufferedHttpEntity(org.apache.http.entity.BufferedHttpEntity) DataInputStream(java.io.DataInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) ClientProtocolException(org.apache.http.client.ClientProtocolException) URISyntaxException(java.net.URISyntaxException) SocketException(java.net.SocketException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

BufferedHttpEntity (org.apache.http.entity.BufferedHttpEntity)43 HttpEntity (org.apache.http.HttpEntity)31 IOException (java.io.IOException)21 HttpResponse (org.apache.http.HttpResponse)16 HttpGet (org.apache.http.client.methods.HttpGet)11 Header (org.apache.http.Header)9 InputStream (java.io.InputStream)8 HttpClient (org.apache.http.client.HttpClient)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 HttpException (org.apache.http.HttpException)6 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)6 File (java.io.File)5 FileOutputStream (java.io.FileOutputStream)5 URISyntaxException (java.net.URISyntaxException)5 HttpHost (org.apache.http.HttpHost)4 HttpRequest (org.apache.http.HttpRequest)4 StatusLine (org.apache.http.StatusLine)4 AuthenticationException (org.apache.http.auth.AuthenticationException)4 CredentialsProvider (org.apache.http.client.CredentialsProvider)4