use of org.apache.http.entity.BasicHttpEntity in project robovm by robovm.
the class EntityDeserializer method doDeserialize.
protected BasicHttpEntity doDeserialize(final SessionInputBuffer inbuffer, final HttpMessage message) throws HttpException, IOException {
BasicHttpEntity entity = new BasicHttpEntity();
long len = this.lenStrategy.determineLength(message);
if (len == ContentLengthStrategy.CHUNKED) {
entity.setChunked(true);
entity.setContentLength(-1);
entity.setContent(new ChunkedInputStream(inbuffer));
} else if (len == ContentLengthStrategy.IDENTITY) {
entity.setChunked(false);
entity.setContentLength(-1);
entity.setContent(new IdentityInputStream(inbuffer));
} else {
entity.setChunked(false);
entity.setContentLength(len);
entity.setContent(new ContentLengthInputStream(inbuffer, len));
}
Header contentTypeHeader = message.getFirstHeader(HTTP.CONTENT_TYPE);
if (contentTypeHeader != null) {
entity.setContentType(contentTypeHeader);
}
Header contentEncodingHeader = message.getFirstHeader(HTTP.CONTENT_ENCODING);
if (contentEncodingHeader != null) {
entity.setContentEncoding(contentEncodingHeader);
}
return entity;
}
use of org.apache.http.entity.BasicHttpEntity in project robolectric by robolectric.
the class ShadowDefaultRequestDirector method interceptResponseContent.
private void interceptResponseContent(HttpResponse response) {
HttpEntity entity = response.getEntity();
if (entity instanceof HttpEntityWrapper) {
HttpEntityWrapper entityWrapper = (HttpEntityWrapper) entity;
try {
Field wrappedEntity = HttpEntityWrapper.class.getDeclaredField("wrappedEntity");
wrappedEntity.setAccessible(true);
entity = (HttpEntity) wrappedEntity.get(entityWrapper);
} catch (Exception e) {
// fail to record
}
}
if (entity instanceof BasicHttpEntity) {
BasicHttpEntity basicEntity = (BasicHttpEntity) entity;
try {
Field contentField = BasicHttpEntity.class.getDeclaredField("content");
contentField.setAccessible(true);
InputStream content = (InputStream) contentField.get(basicEntity);
byte[] buffer = Util.readBytes(content);
FakeHttp.getFakeHttpLayer().addHttpResponseContent(buffer);
contentField.set(basicEntity, new ByteArrayInputStream(buffer));
} catch (Exception e) {
// fail to record
}
}
}
use of org.apache.http.entity.BasicHttpEntity in project cloudstack by apache.
the class ClusterServiceServletHttpHandler method writeResponse.
private void writeResponse(HttpResponse response, int statusCode, String content) {
if (content == null) {
content = "";
}
response.setStatusCode(statusCode);
final BasicHttpEntity body = new BasicHttpEntity();
body.setContentType("text/html; charset=UTF-8");
final byte[] bodyData = content.getBytes();
body.setContent(new ByteArrayInputStream(bodyData));
body.setContentLength(bodyData.length);
response.setEntity(body);
}
use of org.apache.http.entity.BasicHttpEntity in project platform_external_apache-http by android.
the class EntityDeserializer method doDeserialize.
protected BasicHttpEntity doDeserialize(final SessionInputBuffer inbuffer, final HttpMessage message) throws HttpException, IOException {
BasicHttpEntity entity = new BasicHttpEntity();
long len = this.lenStrategy.determineLength(message);
if (len == ContentLengthStrategy.CHUNKED) {
entity.setChunked(true);
entity.setContentLength(-1);
entity.setContent(new ChunkedInputStream(inbuffer));
} else if (len == ContentLengthStrategy.IDENTITY) {
entity.setChunked(false);
entity.setContentLength(-1);
entity.setContent(new IdentityInputStream(inbuffer));
} else {
entity.setChunked(false);
entity.setContentLength(len);
entity.setContent(new ContentLengthInputStream(inbuffer, len));
}
Header contentTypeHeader = message.getFirstHeader(HTTP.CONTENT_TYPE);
if (contentTypeHeader != null) {
entity.setContentType(contentTypeHeader);
}
Header contentEncodingHeader = message.getFirstHeader(HTTP.CONTENT_ENCODING);
if (contentEncodingHeader != null) {
entity.setContentEncoding(contentEncodingHeader);
}
return entity;
}
use of org.apache.http.entity.BasicHttpEntity in project CodeUtils by boredream.
the class HttpUtils method entityFromConnection.
/**
* Initializes an {@link HttpEntity} from the given
* {@link HttpURLConnection}.
*
* @param connection
* @return an HttpEntity populated with data from <code>connection</code>.
*/
private static HttpEntity entityFromConnection(HttpURLConnection connection) {
BasicHttpEntity entity = new BasicHttpEntity();
InputStream inputStream;
try {
inputStream = connection.getInputStream();
} catch (IOException ioe) {
inputStream = connection.getErrorStream();
}
entity.setContent(inputStream);
entity.setContentLength(connection.getContentLength());
entity.setContentEncoding(connection.getContentEncoding());
entity.setContentType(connection.getContentType());
return entity;
}
Aggregations