Android BasicHttpResponse - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android BasicHttpResponse class.

This code example shows how to use the following methods:addHeader
        Assert.assertTrue(conn.contentDecoder instanceof IdentityDecoder);
    } 
 
    @Test 
    public void testPrepareLengthDelimitedDecoder() throws Exception { 
        final BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        response.addHeader(HTTP.CONTENT_LEN, "10");
        response.addHeader(HTTP.CONTENT_TYPE, "stuff");
        response.addHeader(HTTP.CONTENT_ENCODING, "identity");
        Mockito.when(session.channel()).thenReturn(channel);
 
        final HttpEntity entity = conn.prepareDecoder(response);
        Assert.assertNotNull(entity);
        Assert.assertEquals(10, entity.getContentLength());
        Assert.assertFalse(entity.isChunked());
        Assert.assertNotNull(entity.getContentType());
        Assert.assertEquals("stuff", entity.getContentType().getValue());
        Assert.assertNotNull(entity.getContentEncoding());
        Assert.assertEquals("identity", entity.getContentEncoding().getValue());
        Assert.assertTrue(conn.contentDecoder instanceof LengthDelimitedDecoder);
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setEntity
    @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;
    } 
 
 
    // Unimplemented methods ahoy 
 
    @Override 
    public HttpResponse execute(HttpUriRequest request) {
        throw new UnsupportedOperationException();
    } 
 
    @Override 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:equals, setEntity
     */ 
    @Test 
    public void testHandleSuccess(){ 
        String successJSON = "{\"ok\" : true, \"operation_id\" : \"OpID\", " +
                "\"schedule_ids\" : [\"ScheduleID\"]}"; 
        HttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine(
                new ProtocolVersion("HTTP",1,1), 200, "OK"));
        InputStreamEntity inputStreamEntity = new InputStreamEntity(
                new ByteArrayInputStream(successJSON.getBytes()),
                successJSON.getBytes().length);
        httpResponse.setEntity(inputStreamEntity);
        ScheduleAPIResponseHandler handler = new ScheduleAPIResponseHandler();
 
        try { 
            APIClientResponse<APIScheduleResponse> response =
                    handler.handleResponse(httpResponse);
            assertTrue("Operation ID incorrect", 
                       response.getApiResponse().getOperationId().equals("OpID"));
            assertTrue("HttpResponse is incorrect", 
                       httpResponse.equals(httpResponse));

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getStatusLine
                handlerResolver);
        final HttpCoreContext context = HttpCoreContext.create();
        final HttpServerConnection conn = Mockito.mock(HttpServerConnection.class);
        final HttpRequest request = new BasicHttpRequest("GET", "/");
        Mockito.when(conn.receiveRequestHeader()).thenReturn(request);
        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        Mockito.when(responseFactory.newHttpResponse(HttpVersion.HTTP_1_1, 200, context)).thenReturn(response);
        Mockito.when(connReuseStrategy.keepAlive(response, context)).thenReturn(Boolean.FALSE);
 
        httpservice.handleRequest(conn, context);
 
        Assert.assertEquals(HttpStatus.SC_NOT_IMPLEMENTED, response.getStatusLine().getStatusCode());
 
        Assert.assertSame(conn, context.getConnection());
        Assert.assertSame(request, context.getRequest());
        Assert.assertSame(response, context.getResponse());
 
        Mockito.verify(httprocessor).process(request, context);
        Mockito.verify(httprocessor).process(response, context);
        Mockito.verify(conn).sendResponseHeader(response);

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
        return getInstrumentation().getContext();
    } 
 
    public PersitingActorTestCase<T> given(InputStream in) {
        httpResponse = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("http", 1, 1),
                200, "OK")); 
        InputStreamEntity entity = new InputStreamEntity(in, -1);
        httpResponse.setEntity(entity);
        return this;
    } 
 
    public PersitingActorTestCase<T> given(String httpResponseBody) {
        httpResponse = new BasicHttpResponse(new BasicStatusLine(new ProtocolVersion("http", 1, 1),
                200, "OK")); 
        StringEntity entity = null;
        try { 
            entity = new StringEntity(httpResponseBody);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setHeader, setEntity
        String pushJSON = "{\"ok\" : false,\"operation_id\" : \"OpID\"," +
                "\"error\" : \"Could not parse request body\"," + 
                "\"error_code\" : 40000," + 
                "\"details\" : {\"error\" : \"Unexpected token '#'\"," + 
                "\"location\" : {\"line\" : 10,\"column\" : 3}}}"; 
        HttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine(
                new ProtocolVersion("HTTP",1,1), 400, "Unauthorized"));
        InputStreamEntity inputStreamEntity = new InputStreamEntity(
                new ByteArrayInputStream(pushJSON.getBytes()),
                pushJSON.getBytes().length);
        httpResponse.setEntity(inputStreamEntity);
        httpResponse.setHeader(new BasicHeader(CONTENT_TYPE_KEY, UA_JSON_RESPONSE));
 
        /* Test handling */ 
        PushAPIResponseHandler handler = new PushAPIResponseHandler();
        try{ 
            handler.handleResponse(httpResponse);
        } 
        catch (APIRequestException ex){
            System.out.println("Exception " + ex.getMessage());

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:addHeader, removeHeaders
    public static Test suite() {
        return buildTestSuite(HttpCoreUtilsTest.class); 
    } 
 
    public void testHasHeaderListValueExactMatch() { 
        BasicHttpResponse msg = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, ""));
        BasicHeader header1 = new BasicHeader("key", "value1");
        BasicHeader header2 = new BasicHeader("key", "value2");
        msg.addHeader(header1);
        msg.addHeader(header2);
         
        assertTrue(HttpCoreUtils.hasHeaderListValue(msg, "key", "value1"));
        assertTrue(HttpCoreUtils.hasHeaderListValue(msg, "key", "value2"));
        assertFalse(HttpCoreUtils.hasHeaderListValue(msg, "key", "value3"));
        assertFalse(HttpCoreUtils.hasHeaderListValue(msg, "key1", "value1"));
        assertFalse(HttpCoreUtils.hasHeaderListValue(msg, "", ""));
         
        msg.removeHeaders("key");
        assertFalse(HttpCoreUtils.hasHeaderListValue(msg, "key", "value1"));
        assertFalse(HttpCoreUtils.hasHeaderListValue(msg, "key", "value2"));

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
public class APIRequestExceptionTest { 
 
    @Test 
    @SuppressWarnings({"ThrowableResultOfMethodCallIgnored", "ThrowableInstanceNeverThrown"}) 
    public void testAPIException(){ 
        HttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine( 
                new ProtocolVersion("HTTP",1,1), 404, "Not Found")); 
        String testMsg = "Test Message"; 
        APIError apiError = APIError.newBuilder() 
                .setError("TEST") 
                .setErrorCode(42) 
                .setOperationId("OpID") 
                .build(); 
 
        RuntimeException runtimeException = 
                new RuntimeException("Test RuntimeException"); 
 
        APIRequestException testException = APIRequestException.newBuilder() 
                .setMessage(testMsg) 
                .setCause(runtimeException) 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
public class APIClientResponseTest { 
 
 
    @Test 
    public void testAPIScheduleResponse(){ 
        HttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine(
                new ProtocolVersion("HTTP",1,1), 200, "OK"));
        APIScheduleResponse scheduleResponse = APIScheduleResponse.newBuilder()
                .setScheduleUrls(Arrays.asList("ID1", "ID2"))
                .setOperationId("ID") 
                .build(); 
        APIClientResponse.Builder<APIScheduleResponse> builder = 
                APIClientResponse.newScheduleResponseBuilder() 
                                 .setApiResponse(scheduleResponse)
                                 .setHttpResponse(httpResponse);
        APIClientResponse<APIScheduleResponse> testResponse = builder.build();
        assertTrue("HTTP response not set properly", 
                   testResponse.getHttpResponse().equals(httpResponse));
 
        assertTrue("APIResponse not set properly", 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:addHeader
        Assert.assertFalse(reuseStrategy.keepAlive(response, context));
    } 
 
    @Test 
    public void testChunkedContent() throws Exception { 
        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        response.addHeader("Transfer-Encoding", "chunked");
        Assert.assertTrue(reuseStrategy.keepAlive(response, context));
    } 
 
    @Test 
    public void testIgnoreInvalidKeepAlive() throws Exception { 
        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_0, 200, "OK");
        response.addHeader("Connection", "keep-alive");
        Assert.assertFalse(reuseStrategy.keepAlive(response, context));
    } 
 
    @Test 
    public void testExplicitClose() throws Exception { 
        // Use HTTP 1.1 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android BasicHttpResponse Questions & Answers:

See Code Examples for Android BasicHttpResponse Methods: