Android BasicHttpEntityEnclosingRequest - 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 BasicHttpEntityEnclosingRequest class.

This code example shows how to use the following methods:setEntity
    try { 
      HttpClient client = newHttpClientWithTimeout();
      String url = remoteURL + request.getPath();
      BasicHttpEntityEnclosingRequest
          r =
          new BasicHttpEntityEnclosingRequest(request.getMethod(), url);
      if (request.hasPayload()) {
        r.setEntity(new StringEntity(request.getPayload().toString(), "UTF-8"));
      } 
 
      HttpHost h = new HttpHost(remoteURL.getHost(), remoteURL.getPort());
      long start = System.currentTimeMillis();
      HttpResponse res = client.execute(h, r);
      total = System.currentTimeMillis() - start;
 
      response = Helper.exctractResponse(res);
    } catch (Exception e) {
      throw new WebDriverException(e);
    } 
    response = errorHandler.throwIfResponseFailed(response, total);
7
CodeRank
This code example shows how to use the following methods:
  private String url;
 
  private JSONArray getSessions() throws Exception {
    HttpClient client = HttpClientFactory.getClient();
    URL u = new URL(url);
    BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("GET", url);
 
    HttpHost h = new HttpHost(u.getHost(), u.getPort());
    HttpResponse response = client.execute(h, r);
 
    Response resp = Helper.exctractResponse(response);
    String value = (String) resp.getValue();
    return new JSONArray(value);
  } 
 
  @Test 
  public void canGetSessionsFromServer() throws JSONException, Exception { 
    url = getRemoteURL() + "/sessions";
 
    Assert.assertEquals(getSessions().length(), 0);
6
CodeRank
This code example shows how to use the following methods:setEntity
    try { 
      HttpClient client = HttpClientFactory.getClient();
      String url = remoteURL + request.getPath();
      BasicHttpEntityEnclosingRequest
          r =
          new BasicHttpEntityEnclosingRequest(request.getMethod(), url);
      if (request.hasPayload()) {
        r.setEntity(new StringEntity(request.getPayload().toString(), "UTF-8"));
      } 
 
      HttpHost h = new HttpHost(host, port);
      long start = System.currentTimeMillis();
      HttpResponse res = client.execute(h, r);
      total = System.currentTimeMillis() - start;
 
      response = Helper.exctractResponse(res);
    } catch (Exception e) {
      throw new WebDriverException(e);
    } 
    response = errorHandler.throwIfResponseFailed(response, total);
6
CodeRank
This code example shows how to use the following methods:
 
    try { 
      HttpClient client = HttpClientFactory.getClient();
      String url = getEndPoint() + "/status";
      URL u = new URL(url);
      BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("GET", url);
 
      HttpHost h = new HttpHost(u.getHost(), u.getPort());
      HttpResponse response = client.execute(h, r);
 
      JSONObject o = Helper.extractObject(response);
 
      return o;
    } catch (Exception e) {
      throw new WebDriverException(e.getMessage(), e);
    } 
 
  } 
 
} 
6
CodeRank
This code example shows how to use the following methods:setEntity, addHeader
                connReuseStrategy,
                responseFactory,
                handlerResolver);
        final HttpCoreContext context = HttpCoreContext.create();
        final HttpServerConnection conn = Mockito.mock(HttpServerConnection.class);
        final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
        final InputStream instream = Mockito.mock(InputStream.class);
        final InputStreamEntity entity = new InputStreamEntity(instream, -1);
        request.setEntity(entity);
 
        Mockito.when(conn.receiveRequestHeader()).thenReturn(request);
        final HttpResponse resp100 = new BasicHttpResponse(HttpVersion.HTTP_1_1, 100, "Continue");
        Mockito.when(responseFactory.newHttpResponse(HttpVersion.HTTP_1_1, 100, context)).thenReturn(resp100);
        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);
 

6
CodeRank
This code example shows how to use the following methods:setEntity, addHeader
        final HttpProcessor httprocessor = Mockito.mock(HttpProcessor.class);
        final HttpClientConnection conn = Mockito.mock(HttpClientConnection.class);
        final HttpRequestExecutor executor = new HttpRequestExecutor();
 
        final HttpCoreContext context = HttpCoreContext.create();
        final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
        final HttpEntity entity = Mockito.mock(HttpEntity.class);
        request.setEntity(entity);
 
        executor.preProcess(request, httprocessor, context);
        Mockito.verify(httprocessor).process(request, context);
 
        Mockito.when(conn.receiveResponseHeader()).thenReturn(
                new BasicHttpResponse(HttpVersion.HTTP_1_1, 101, "OK"));
        Mockito.when(conn.isResponseAvailable(Mockito.anyInt())).thenReturn(Boolean.TRUE);
 
        try { 
            executor.execute(request, conn, context);
            Assert.fail("ProtocolException should have been thrown");
6
CodeRank
This code example shows how to use the following methods:getFirstHeader, getParams, setEntity
This code example shows how to use the following methods:setEntity
    } 
     
    @Test 
    public void removesEntityFromTRACERequest() throws Exception { 
        HttpEntityEnclosingRequest req = 
            new BasicHttpEntityEnclosingRequest("TRACE", "/", HttpVersion.HTTP_1_1);
        req.setEntity(HttpTestUtils.makeBody(50));
        result = impl.makeRequestCompliant(req);
        if (result instanceof HttpEntityEnclosingRequest) {
            assertNull(((HttpEntityEnclosingRequest)result).getEntity());
        } 
    } 
     
    @Test 
    public void upgrades1_0RequestTo1_1() throws Exception { 
        req = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_0);
        result = impl.makeRequestCompliant(req);
        assertEquals(HttpVersion.HTTP_1_1, result.getProtocolVersion());
    } 
 
5
CodeRank
This code example shows how to use the following methods:setEntity, addHeader
        HttpProcessor httprocessor = Mockito.mock(HttpProcessor.class);
        HttpClientConnection conn = Mockito.mock(HttpClientConnection.class);
        HttpRequestExecutor executor = new HttpRequestExecutor();
 
        HttpContext context = new BasicHttpContext();
        HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
        HttpEntity entity = Mockito.mock(HttpEntity.class);
        request.setEntity(entity);
 
        executor.preProcess(request, httprocessor, context);
        Mockito.verify(httprocessor).process(request, context);
 
        Mockito.when(conn.receiveResponseHeader()).thenReturn(
                new BasicHttpResponse(HttpVersion.HTTP_1_1, 101, "OK"));
        Mockito.when(conn.isResponseAvailable(Mockito.anyInt())).thenReturn(true);
 
        try { 
            executor.execute(request, conn, context);
            Assert.fail("ProtocolException should have been thrown");
5
CodeRank
This code example shows how to use the following methods:setEntity, setHeader
        verifyMocks(); 
    } 
 
    @Test 
    public void testInvalidatesUrisInContentLocationHeadersOnPUTs() throws Exception { 
        HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
        request.setEntity(HttpTestUtils.makeBody(128));
        request.setHeader("Content-Length","128");
 
        String contentLocation = "http://foo.example.com/content";
        request.setHeader("Content-Location", contentLocation);
 
        final String theUri = "http://foo.example.com:80/";
        cacheEntryHasVariantMap(new HashMap<String,String>());
 
        cacheReturnsEntryForUri(theUri);
        entryIsRemoved(theUri);
        entryIsRemoved("http://foo.example.com:80/content"); 
 
        replayMocks(); 

5
CodeRank
See Code Examples for Android BasicHttpEntityEnclosingRequest Methods: