Search in sources :

Example 11 with BasicStatusLine

use of org.apache.http.message.BasicStatusLine in project android-volley by mcxiaoke.

the class MockHttpClient method execute.

// This is the only one we actually use.
@Override
public HttpResponse execute(HttpUriRequest request, HttpContext context) {
    requestExecuted = request;
    StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), mStatusCode, "");
    HttpResponse response = new BasicHttpResponse(statusLine);
    response.setEntity(mResponseEntity);
    return response;
}
Also used : BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) 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 12 with BasicStatusLine

use of org.apache.http.message.BasicStatusLine in project android-uploader by nightscout.

the class AbstractRestUploaderTest method setUpExecuteCaptor.

public void setUpExecuteCaptor(int status) throws IOException {
    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 : 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 13 with BasicStatusLine

use of org.apache.http.message.BasicStatusLine in project android-uploader by nightscout.

the class RestLegacyUploaderTest 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 14 with BasicStatusLine

use of org.apache.http.message.BasicStatusLine in project robovm by robovm.

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 15 with BasicStatusLine

use of org.apache.http.message.BasicStatusLine in project LiveSDK-for-Android by liveservices.

the class ApiTest method loadPathInvalidResponse.

/**
     * Loads an invalid path response into the HttpClient.
     *
     * @param requestPath
     * @throws Exception
     */
protected void loadPathInvalidResponse(String requestPath) throws Exception {
    JSONObject error = new JSONObject();
    error.put(JsonKeys.CODE, ErrorCodes.REQUEST_URL_INVALID);
    String message = String.format(ErrorMessages.URL_NOT_VALID, requestPath.toLowerCase());
    error.put(JsonKeys.MESSAGE, message);
    JSONObject response = new JSONObject();
    response.put(JsonKeys.ERROR, error);
    byte[] bytes = response.toString().getBytes();
    this.mockResponse.addHeader(HTTP.CONTENT_LEN, Long.toString(bytes.length));
    this.mockEntity.setInputStream(new ByteArrayInputStream(bytes));
    StatusLine status = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_BAD_REQUEST, "Bad Request");
    this.mockResponse.setStatusLine(status);
    this.mockClient.setHttpResponse(this.mockResponse);
}
Also used : BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) JSONObject(org.json.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) BasicStatusLine(org.apache.http.message.BasicStatusLine)

Aggregations

BasicStatusLine (org.apache.http.message.BasicStatusLine)60 ProtocolVersion (org.apache.http.ProtocolVersion)46 StatusLine (org.apache.http.StatusLine)44 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)37 Header (org.apache.http.Header)17 BasicHeader (org.apache.http.message.BasicHeader)17 Test (org.junit.Test)17 URL (java.net.URL)16 HttpResponse (org.apache.http.HttpResponse)16 HttpURLConnection (java.net.HttpURLConnection)15 List (java.util.List)15 HashMap (java.util.HashMap)12 ByteArrayInputStream (java.io.ByteArrayInputStream)10 IOException (java.io.IOException)9 HttpEntity (org.apache.http.HttpEntity)9 StringEntity (org.apache.http.entity.StringEntity)9 HttpHost (org.apache.http.HttpHost)6 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)5 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)5 MockHttpEntity (com.microsoft.live.mock.MockHttpEntity)4