Search in sources :

Example 56 with BasicHttpResponse

use of org.apache.http.message.BasicHttpResponse in project okhttp by square.

the class OkApacheClient method transformResponse.

private static HttpResponse transformResponse(Response response) {
    int code = response.code();
    String message = response.message();
    BasicHttpResponse httpResponse = new BasicHttpResponse(HTTP_1_1, code, message);
    ResponseBody body = response.body();
    InputStreamEntity entity = new InputStreamEntity(body.byteStream(), body.contentLength());
    httpResponse.setEntity(entity);
    Headers headers = response.headers();
    for (int i = 0, size = headers.size(); i < size; i++) {
        String name = headers.name(i);
        String value = headers.value(i);
        httpResponse.addHeader(name, value);
        if ("Content-Type".equalsIgnoreCase(name)) {
            entity.setContentType(value);
        } else if ("Content-Encoding".equalsIgnoreCase(name)) {
            entity.setContentEncoding(value);
        }
    }
    return httpResponse;
}
Also used : BasicHttpResponse(org.apache.http.message.BasicHttpResponse) Headers(okhttp3.Headers) ResponseBody(okhttp3.ResponseBody) InputStreamEntity(org.apache.http.entity.InputStreamEntity)

Example 57 with BasicHttpResponse

use of org.apache.http.message.BasicHttpResponse 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);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) StringEntity(org.apache.http.entity.StringEntity) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine)

Example 58 with BasicHttpResponse

use of org.apache.http.message.BasicHttpResponse in project OpenRefine by OpenRefine.

the class AppEngineClientConnection method receiveResponseHeader.

public HttpResponse receiveResponseHeader() {
    URLFetchService ufs = URLFetchServiceFactory.getURLFetchService();
    try {
        _appengine_hresponse = ufs.fetch(_appengine_hrequest);
    } catch (java.io.IOException e) {
        throw new RuntimeException(e);
    }
    org.apache.http.HttpResponse apache_response = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 0), _appengine_hresponse.getResponseCode(), null);
    for (HTTPHeader h : _appengine_hresponse.getHeaders()) {
        apache_response.addHeader(h.getName(), h.getValue());
    }
    return apache_response;
}
Also used : BasicHttpResponse(org.apache.http.message.BasicHttpResponse) URLFetchService(com.google.appengine.api.urlfetch.URLFetchService) HttpResponse(org.apache.http.HttpResponse) ProtocolVersion(org.apache.http.ProtocolVersion) HTTPHeader(com.google.appengine.api.urlfetch.HTTPHeader)

Example 59 with BasicHttpResponse

use of org.apache.http.message.BasicHttpResponse in project XobotOS by xamarin.

the class DefaultHttpResponseFactory method newHttpResponse.

// non-javadoc, see interface HttpResponseFactory
public HttpResponse newHttpResponse(final ProtocolVersion ver, final int status, HttpContext context) {
    if (ver == null) {
        throw new IllegalArgumentException("HTTP version may not be null");
    }
    final Locale loc = determineLocale(context);
    final String reason = reasonCatalog.getReason(status, loc);
    StatusLine statusline = new BasicStatusLine(ver, status, reason);
    return new BasicHttpResponse(statusline, reasonCatalog, loc);
}
Also used : Locale(java.util.Locale) BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) BasicStatusLine(org.apache.http.message.BasicStatusLine)

Example 60 with BasicHttpResponse

use of org.apache.http.message.BasicHttpResponse in project TaEmCasa by Dionen.

the class BasicNetworkTest method forbidden.

@Test
public void forbidden() throws Exception {
    MockHttpStack mockHttpStack = new MockHttpStack();
    BasicHttpResponse fakeResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), 403, "Forbidden");
    mockHttpStack.setResponseToReturn(fakeResponse);
    BasicNetwork httpNetwork = new BasicNetwork(mockHttpStack);
    Request<String> request = buildRequest();
    request.setRetryPolicy(mMockRetryPolicy);
    doThrow(new VolleyError()).when(mMockRetryPolicy).retry(any(VolleyError.class));
    try {
        httpNetwork.performRequest(request);
    } catch (VolleyError e) {
    // expected
    }
    // should retry in case it's an auth failure.
    verify(mMockRetryPolicy).retry(any(AuthFailureError.class));
}
Also used : VolleyError(com.android.volley.VolleyError) MockHttpStack(com.android.volley.mock.MockHttpStack) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) AuthFailureError(com.android.volley.AuthFailureError) ProtocolVersion(org.apache.http.ProtocolVersion) Test(org.junit.Test)

Aggregations

BasicHttpResponse (org.apache.http.message.BasicHttpResponse)72 ProtocolVersion (org.apache.http.ProtocolVersion)51 BasicStatusLine (org.apache.http.message.BasicStatusLine)47 StatusLine (org.apache.http.StatusLine)41 HttpResponse (org.apache.http.HttpResponse)33 StringEntity (org.apache.http.entity.StringEntity)25 Header (org.apache.http.Header)24 List (java.util.List)23 IOException (java.io.IOException)20 HttpHost (org.apache.http.HttpHost)19 URL (java.net.URL)16 BasicHeader (org.apache.http.message.BasicHeader)16 HttpURLConnection (java.net.HttpURLConnection)15 HashMap (java.util.HashMap)15 HttpEntity (org.apache.http.HttpEntity)14 MainResponse (org.elasticsearch.action.main.MainResponse)14 ElasticsearchException (org.elasticsearch.ElasticsearchException)12 RequestLine (org.apache.http.RequestLine)11 BasicRequestLine (org.apache.http.message.BasicRequestLine)11 RestStatus (org.elasticsearch.rest.RestStatus)11