Search in sources :

Example 76 with BasicHeader

use of org.apache.http.message.BasicHeader in project hbase by apache.

the class TestGzipFilter method testScannerResultCodes.

void testScannerResultCodes() throws Exception {
    Header[] headers = new Header[3];
    headers[0] = new BasicHeader("Content-Type", Constants.MIMETYPE_XML);
    headers[1] = new BasicHeader("Accept", Constants.MIMETYPE_JSON);
    headers[2] = new BasicHeader("Accept-Encoding", "gzip");
    Response response = client.post("/" + TABLE + "/scanner", headers, "<Scanner/>".getBytes());
    assertEquals(response.getCode(), 201);
    String scannerUrl = response.getLocation();
    assertNotNull(scannerUrl);
    response = client.get(scannerUrl);
    assertEquals(response.getCode(), 200);
    response = client.get(scannerUrl);
    assertEquals(response.getCode(), 204);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) BasicHeader(org.apache.http.message.BasicHeader)

Example 77 with BasicHeader

use of org.apache.http.message.BasicHeader in project hbase by apache.

the class Client method get.

/**
   * Send a GET request
   * @param cluster the cluster definition
   * @param path the path or URI
   * @param accept Accept header value
   * @return a Response object with response detail
   * @throws IOException
   */
public Response get(Cluster cluster, String path, String accept) throws IOException {
    Header[] headers = new Header[1];
    headers[0] = new BasicHeader("Accept", accept);
    return get(cluster, path, headers);
}
Also used : Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) BasicHeader(org.apache.http.message.BasicHeader)

Example 78 with BasicHeader

use of org.apache.http.message.BasicHeader in project hbase by apache.

the class Client method put.

/**
   * Send a PUT request
   * @param cluster the cluster definition
   * @param path the path or URI
   * @param contentType the content MIME type
   * @param content the content bytes
   * @param extraHdr additional Header to send
   * @return a Response object with response detail
   * @throws IOException for error
   */
public Response put(Cluster cluster, String path, String contentType, byte[] content, Header extraHdr) throws IOException {
    int cnt = extraHdr == null ? 1 : 2;
    Header[] headers = new Header[cnt];
    headers[0] = new BasicHeader("Content-Type", contentType);
    if (extraHdr != null) {
        headers[1] = extraHdr;
    }
    return put(cluster, path, headers, content);
}
Also used : Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) BasicHeader(org.apache.http.message.BasicHeader)

Example 79 with BasicHeader

use of org.apache.http.message.BasicHeader in project hbase by apache.

the class Client method post.

/**
   * Send a POST request
   * @param cluster the cluster definition
   * @param path the path or URI
   * @param contentType the content MIME type
   * @param content the content bytes
   * @return a Response object with response detail
   * @throws IOException for error
   */
public Response post(Cluster cluster, String path, String contentType, byte[] content) throws IOException {
    Header[] headers = new Header[1];
    headers[0] = new BasicHeader("Content-Type", contentType);
    return post(cluster, path, headers, content);
}
Also used : Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) BasicHeader(org.apache.http.message.BasicHeader)

Example 80 with BasicHeader

use of org.apache.http.message.BasicHeader in project hbase by apache.

the class TestRemoteTable method testResponse.

/**
   * Test a some methods of class Response.
   */
@Test
public void testResponse() {
    Response response = new Response(200);
    assertEquals(200, response.getCode());
    Header[] headers = new Header[2];
    headers[0] = new BasicHeader("header1", "value1");
    headers[1] = new BasicHeader("header2", "value2");
    response = new Response(200, headers);
    assertEquals("value1", response.getHeader("header1"));
    assertFalse(response.hasBody());
    response.setCode(404);
    assertEquals(404, response.getCode());
    headers = new Header[2];
    headers[0] = new BasicHeader("header1", "value1.1");
    headers[1] = new BasicHeader("header2", "value2");
    response.setHeaders(headers);
    assertEquals("value1.1", response.getHeader("header1"));
    response.setBody(Bytes.toBytes("body"));
    assertTrue(response.hasBody());
}
Also used : Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) BasicHeader(org.apache.http.message.BasicHeader) Test(org.junit.Test)

Aggregations

BasicHeader (org.apache.http.message.BasicHeader)128 Header (org.apache.http.Header)67 Test (org.junit.Test)29 List (java.util.List)21 HashMap (java.util.HashMap)19 HttpGet (org.apache.http.client.methods.HttpGet)18 BasicStatusLine (org.apache.http.message.BasicStatusLine)17 ProtocolVersion (org.apache.http.ProtocolVersion)16 StatusLine (org.apache.http.StatusLine)16 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)16 IOException (java.io.IOException)15 HttpURLConnection (java.net.HttpURLConnection)15 URL (java.net.URL)15 HttpResponse (org.apache.http.HttpResponse)15 Response (org.elasticsearch.client.Response)10 ArrayList (java.util.ArrayList)9 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)9 TestHttpResponse (org.robolectric.shadows.httpclient.TestHttpResponse)9 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)8 StringEntity (org.apache.http.entity.StringEntity)8