use of org.apache.http.message.BasicStatusLine 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.BasicStatusLine in project android-uploader by nightscout.
the class RestV1UploaderTest method setUpExecuteCaptor.
public void setUpExecuteCaptor(int status) throws IOException {
captor = ArgumentCaptor.forClass(HttpUriRequest.class);
HttpResponse response = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("mock", 1, 2), status, ""));
response.setEntity(new StringEntity(""));
when(mockHttpClient.execute(captor.capture())).thenReturn(response);
}
use of org.apache.http.message.BasicStatusLine in project LiveSDK-for-Android by liveservices.
the class UploadRequestTest method testSendPathQueryParameterToHttpPut.
/**
* WinLive 633441: Make sure the query parameters on path get sent to
* the HTTP PUT part of the upload.
*/
public void testSendPathQueryParameterToHttpPut() throws Throwable {
JSONObject jsonResponseBody = new JSONObject();
jsonResponseBody.put(JsonKeys.UPLOAD_LOCATION, "http://test.com/location");
InputStream responseStream = new ByteArrayInputStream(jsonResponseBody.toString().getBytes());
MockHttpEntity responseEntity = new MockHttpEntity(responseStream);
BasicStatusLine ok = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "");
final MockHttpResponse uploadLocationResponse = new MockHttpResponse(responseEntity, ok);
HttpClient client = new HttpClient() {
/** the first request to the client is the upload location request. */
boolean uploadLocationRequest = true;
@Override
public HttpResponse execute(HttpUriRequest request) throws IOException, ClientProtocolException {
if (uploadLocationRequest) {
uploadLocationRequest = false;
return uploadLocationResponse;
}
// This is really the only part we care about in this test.
// That the 2nd request's uri has foo=bar in the query string.
URI uri = request.getURI();
assertEquals("foo=bar&overwrite=choosenewname", uri.getQuery());
// just return the previous reponse.
return uploadLocationResponse;
}
@Override
public HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException, ClientProtocolException {
throw new UnsupportedOperationException();
}
@Override
public HttpResponse execute(HttpHost target, HttpRequest request) throws IOException, ClientProtocolException {
throw new UnsupportedOperationException();
}
@Override
public <T> T execute(HttpUriRequest arg0, ResponseHandler<? extends T> arg1) throws IOException, ClientProtocolException {
throw new UnsupportedOperationException();
}
@Override
public HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context) throws IOException, ClientProtocolException {
throw new UnsupportedOperationException();
}
@Override
public <T> T execute(HttpUriRequest arg0, ResponseHandler<? extends T> arg1, HttpContext arg2) throws IOException, ClientProtocolException {
throw new UnsupportedOperationException();
}
@Override
public <T> T execute(HttpHost arg0, HttpRequest arg1, ResponseHandler<? extends T> arg2) throws IOException, ClientProtocolException {
throw new UnsupportedOperationException();
}
@Override
public <T> T execute(HttpHost arg0, HttpRequest arg1, ResponseHandler<? extends T> arg2, HttpContext arg3) throws IOException, ClientProtocolException {
throw new UnsupportedOperationException();
}
@Override
public ClientConnectionManager getConnectionManager() {
throw new UnsupportedOperationException();
}
@Override
public HttpParams getParams() {
throw new UnsupportedOperationException();
}
};
LiveConnectSession session = TestUtils.newMockLiveConnectSession();
HttpEntity entity = new MockHttpEntity();
String path = Paths.ME_SKYDRIVE + "?foo=bar";
String filename = "filename";
UploadRequest uploadRequest = new UploadRequest(session, client, path, entity, filename, OverwriteOption.Rename);
uploadRequest.execute();
}
use of org.apache.http.message.BasicStatusLine in project LiveSDK-for-Android by liveservices.
the class ApiTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
// Set up the MockClient
this.mockEntity = new MockHttpEntity();
StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
this.mockResponse = new MockHttpResponse(this.mockEntity, statusLine);
this.mockClient = new MockHttpClient(this.mockResponse);
this.loadLiveLibraryHeaderChecker();
this.exceptionQueue = new LinkedBlockingQueue<LiveOperationException>();
this.liveConnectClient = TestUtils.newLiveConnectClient(this.mockClient);
}
use of org.apache.http.message.BasicStatusLine in project LiveSDK-for-Android by liveservices.
the class UploadTest method loadValidResponseBody.
@Override
protected void loadValidResponseBody() throws Exception {
JSONObject jsonResponseBody = new JSONObject();
jsonResponseBody.put(JsonKeys.ID, FILE_ID);
jsonResponseBody.put(JsonKeys.SOURCE, SOURCE);
InputStream responseStream = new ByteArrayInputStream(jsonResponseBody.toString().getBytes());
MockHttpEntity responseEntity = new MockHttpEntity(responseStream);
StatusLine created = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_CREATED, "");
MockHttpResponse response = new MockHttpResponse(responseEntity, created);
this.mockClient.addHttpResponse(response);
}
Aggregations