ContentResponseHandler to extend AbstractResponseHandler
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1643670 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
35cf0a6a1c
commit
602d9f9fc9
|
@ -29,12 +29,8 @@ package org.apache.http.client.fluent;
|
|||
import java.io.IOException;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.HttpResponseException;
|
||||
import org.apache.http.client.ResponseHandler;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.impl.client.AbstractResponseHandler;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
/**
|
||||
|
@ -46,23 +42,13 @@ import org.apache.http.util.EntityUtils;
|
|||
*
|
||||
* @since 4.4
|
||||
*/
|
||||
public class ContentResponseHandler implements ResponseHandler<Content> {
|
||||
public class ContentResponseHandler extends AbstractResponseHandler<Content> {
|
||||
|
||||
@Override
|
||||
public Content handleResponse(
|
||||
final HttpResponse response) throws ClientProtocolException, IOException {
|
||||
final StatusLine statusLine = response.getStatusLine();
|
||||
final HttpEntity entity = response.getEntity();
|
||||
if (statusLine.getStatusCode() >= 300) {
|
||||
throw new HttpResponseException(statusLine.getStatusCode(),
|
||||
statusLine.getReasonPhrase());
|
||||
}
|
||||
if (entity != null) {
|
||||
return new Content(
|
||||
EntityUtils.toByteArray(entity),
|
||||
ContentType.getOrDefault(entity));
|
||||
}
|
||||
return Content.NO_CONTENT;
|
||||
public Content handleEntity(final HttpEntity entity) throws IOException {
|
||||
return entity != null ?
|
||||
new Content(EntityUtils.toByteArray(entity), ContentType.getOrDefault(entity)) :
|
||||
Content.NO_CONTENT;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue