use of org.apache.http.entity.BasicHttpEntity in project k-9 by k9mail.
the class WebDavFolderTest method folder_can_fetch_sensible_body_data_and_notifies_listener.
@Test
public void folder_can_fetch_sensible_body_data_and_notifies_listener() throws MessagingException, IOException, URISyntaxException {
setupStoreForMessageFetching();
List<WebDavMessage> messages = setup25MessagesToFetch();
when(mockHttpClient.executeOverride(any(HttpUriRequest.class), any(HttpContext.class))).thenAnswer(new Answer<HttpResponse>() {
@Override
public HttpResponse answer(InvocationOnMock invocation) throws Throwable {
HttpResponse httpResponse = mock(HttpResponse.class);
StatusLine statusLine = mock(StatusLine.class);
when(httpResponse.getStatusLine()).thenReturn(statusLine);
when(statusLine.getStatusCode()).thenReturn(200);
BasicHttpEntity httpEntity = new BasicHttpEntity();
String body = "";
httpEntity.setContent(new ByteArrayInputStream(body.getBytes("UTF-8")));
when(httpResponse.getEntity()).thenReturn(httpEntity);
return httpResponse;
}
});
FetchProfile profile = new FetchProfile();
profile.add(FetchProfile.Item.BODY_SANE);
folder.fetch(messages, profile, listener);
verify(listener, times(25)).messageStarted(any(String.class), anyInt(), eq(25));
verify(listener, times(25)).messageFinished(any(WebDavMessage.class), anyInt(), eq(25));
}
use of org.apache.http.entity.BasicHttpEntity 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)))));
}
use of org.apache.http.entity.BasicHttpEntity in project XobotOS by xamarin.
the class AndroidHttpClientConnection method receiveResponseEntity.
/**
* Return the next response entity.
* @param headers contains values for parsing entity
* @see HttpClientConnection#receiveResponseEntity(HttpResponse response)
*/
public HttpEntity receiveResponseEntity(final Headers headers) {
assertOpen();
BasicHttpEntity entity = new BasicHttpEntity();
long len = determineLength(headers);
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));
}
String contentTypeHeader = headers.getContentType();
if (contentTypeHeader != null) {
entity.setContentType(contentTypeHeader);
}
String contentEncodingHeader = headers.getContentEncoding();
if (contentEncodingHeader != null) {
entity.setContentEncoding(contentEncodingHeader);
}
return entity;
}
use of org.apache.http.entity.BasicHttpEntity in project XobotOS by xamarin.
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 saga-android by AnandChowdhary.
the class HurlStack method entityFromConnection.
/**
* Initializes an {@link org.apache.http.HttpEntity} from the given {@link java.net.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