use of org.apache.http.message.BasicHttpResponse in project k-9 by k9mail.
the class WebDavStoreTest method createOkSearchResponse.
//TODO: Replace XML with actual XML from an Exchange server
private BasicHttpResponse createOkSearchResponse() throws UnsupportedEncodingException {
BasicHttpResponse okSearchResponse = createOkResponse();
HttpEntity searchResponseEntity = new StringEntity("" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + " <D:multistatus xmlns:D=\"DAV:\"\n" + " xmlns:R=\"http://example.org/propschema\">\n" + " <D:response>" + " <D:propstat>\n" + " <uid>Inbox</uid>" + " <href>http://example.org/Exchange/user/Inbox</href>\n" + " </D:propstat></D:response>\n" + " <D:response>" + " <D:propstat>\n" + " <uid>Drafts</uid>" + " <href>http://example.org/Exchange/user/Drafts</href>\n" + " </D:propstat></D:response>\n" + " <D:response>" + " <D:propstat>\n" + " <uid>Folder2</uid>" + " <href>http://example.org/Exchange/user/Folder2</href>\n" + " </D:propstat></D:response>\n" + " </D:multistatus>");
okSearchResponse.setEntity(searchResponseEntity);
return okSearchResponse;
}
use of org.apache.http.message.BasicHttpResponse in project k-9 by k9mail.
the class WebDavStoreTest method createOkPropfindResponse.
//TODO: Replace XML with actual XML from an Exchange server
private BasicHttpResponse createOkPropfindResponse() throws UnsupportedEncodingException {
BasicHttpResponse okPropfindResponse = createOkResponse();
HttpEntity propfindResponseEntity = new StringEntity("" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<D:multistatus xmlns:D=\"DAV:\" xmlns:e=\"urn:schemas:httpmail:\">\n" + " <D:response><e:inbox>http://example.org/Exchange/user/Inbox</e:inbox></D:response>\n" + "</D:multistatus>");
okPropfindResponse.setEntity(propfindResponseEntity);
return okPropfindResponse;
}
use of org.apache.http.message.BasicHttpResponse in project SimplifyReader by chentao0707.
the class OkHttpStack method performRequest.
@Override
public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError {
OkHttpClient client = mClient.clone();
int timeoutMs = request.getTimeoutMs();
client.setConnectTimeout(timeoutMs, TimeUnit.MILLISECONDS);
client.setReadTimeout(timeoutMs, TimeUnit.MILLISECONDS);
client.setWriteTimeout(timeoutMs, TimeUnit.MILLISECONDS);
com.squareup.okhttp.Request.Builder okHttpRequestBuilder = new com.squareup.okhttp.Request.Builder();
okHttpRequestBuilder.url(request.getUrl());
Map<String, String> headers = request.getHeaders();
for (final String name : headers.keySet()) {
okHttpRequestBuilder.addHeader(name, headers.get(name));
}
for (final String name : additionalHeaders.keySet()) {
okHttpRequestBuilder.addHeader(name, additionalHeaders.get(name));
}
setConnectionParametersForRequest(okHttpRequestBuilder, request);
com.squareup.okhttp.Request okHttpRequest = okHttpRequestBuilder.build();
Call okHttpCall = client.newCall(okHttpRequest);
Response okHttpResponse = okHttpCall.execute();
StatusLine responseStatus = new BasicStatusLine(parseProtocol(okHttpResponse.protocol()), okHttpResponse.code(), okHttpResponse.message());
BasicHttpResponse response = new BasicHttpResponse(responseStatus);
response.setEntity(entityFromOkHttpResponse(okHttpResponse));
Headers responseHeaders = okHttpResponse.headers();
for (int i = 0, len = responseHeaders.size(); i < len; i++) {
final String name = responseHeaders.name(i), value = responseHeaders.value(i);
if (name != null) {
response.addHeader(new BasicHeader(name, value));
}
}
return response;
}
use of org.apache.http.message.BasicHttpResponse in project iosched by google.
the class BasicNetworkTest method testHeadersAndPostParams.
public void testHeadersAndPostParams() throws Exception {
MockHttpStack mockHttpStack = new MockHttpStack();
BasicHttpResponse fakeResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), 200, "OK");
fakeResponse.setEntity(new StringEntity("foobar"));
mockHttpStack.setResponseToReturn(fakeResponse);
BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
Request<String> request = new Request<String>(Request.Method.GET, "http://foo", null) {
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
return null;
}
@Override
protected void deliverResponse(String response) {
}
@Override
public Map<String, String> getHeaders() {
Map<String, String> result = new HashMap<String, String>();
result.put("requestheader", "foo");
return result;
}
@Override
public Map<String, String> getParams() {
Map<String, String> result = new HashMap<String, String>();
result.put("requestpost", "foo");
return result;
}
};
httpNetwork.performRequest(request);
assertEquals("foo", mockHttpStack.getLastHeaders().get("requestheader"));
assertEquals("requestpost=foo&", new String(mockHttpStack.getLastPostBody()));
}
use of org.apache.http.message.BasicHttpResponse in project voldemort by voldemort.
the class VoldemortIOUtilsTest method testCloseQuietlyNullEntity.
@Test
public void testCloseQuietlyNullEntity() {
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpURLConnection.HTTP_OK, "");
response.setEntity(null);
VoldemortIOUtils.closeQuietly(response);
}
Aggregations