Search in sources :

Example 11 with JacksonJaxbJsonProvider

use of org.apache.hbase.thirdparty.com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider in project hbase by apache.

the class TestTableScan method testStreamingJSON.

@Test
public void testStreamingJSON() throws Exception {
    // Test with start row and end row.
    StringBuilder builder = new StringBuilder();
    builder.append("/*");
    builder.append("?");
    builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
    builder.append("&");
    builder.append(Constants.SCAN_START_ROW + "=aaa");
    builder.append("&");
    builder.append(Constants.SCAN_END_ROW + "=aay");
    Response response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_JSON);
    assertEquals(200, response.getCode());
    int count = 0;
    ObjectMapper mapper = new JacksonJaxbJsonProvider().locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE);
    JsonFactory jfactory = new JsonFactory(mapper);
    JsonParser jParser = jfactory.createJsonParser(response.getStream());
    boolean found = false;
    while (jParser.nextToken() != JsonToken.END_OBJECT) {
        if (jParser.getCurrentToken() == JsonToken.START_OBJECT && found) {
            RowModel row = jParser.readValueAs(RowModel.class);
            assertNotNull(row.getKey());
            for (int i = 0; i < row.getCells().size(); i++) {
                if (count == 0) {
                    assertEquals("aaa", Bytes.toString(row.getKey()));
                }
                if (count == 23) {
                    assertEquals("aax", Bytes.toString(row.getKey()));
                }
                count++;
            }
            jParser.skipChildren();
        } else {
            found = jParser.getCurrentToken() == JsonToken.START_ARRAY;
        }
    }
    assertEquals(24, count);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) JsonFactory(com.fasterxml.jackson.core.JsonFactory) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) JacksonJaxbJsonProvider(org.apache.hbase.thirdparty.com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonParser(com.fasterxml.jackson.core.JsonParser) Test(org.junit.Test)

Example 12 with JacksonJaxbJsonProvider

use of org.apache.hbase.thirdparty.com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider in project hbase by apache.

the class TestTableScan method testSimpleScannerJson.

@Test
public void testSimpleScannerJson() throws IOException {
    // Test scanning particular columns with limit.
    StringBuilder builder = new StringBuilder();
    builder.append("/*");
    builder.append("?");
    builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
    builder.append("&");
    builder.append(Constants.SCAN_LIMIT + "=2");
    Response response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_JSON);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
    ObjectMapper mapper = new JacksonJaxbJsonProvider().locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE);
    CellSetModel model = mapper.readValue(response.getStream(), CellSetModel.class);
    int count = TestScannerResource.countCellSet(model);
    assertEquals(2, count);
    checkRowsNotNull(model);
    // Test scanning with no limit.
    builder = new StringBuilder();
    builder.append("/*");
    builder.append("?");
    builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_2);
    response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_JSON);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
    model = mapper.readValue(response.getStream(), CellSetModel.class);
    count = TestScannerResource.countCellSet(model);
    assertEquals(expectedRows2, count);
    checkRowsNotNull(model);
    // Test with start row and end row.
    builder = new StringBuilder();
    builder.append("/*");
    builder.append("?");
    builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
    builder.append("&");
    builder.append(Constants.SCAN_START_ROW + "=aaa");
    builder.append("&");
    builder.append(Constants.SCAN_END_ROW + "=aay");
    response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_JSON);
    assertEquals(200, response.getCode());
    model = mapper.readValue(response.getStream(), CellSetModel.class);
    RowModel startRow = model.getRows().get(0);
    assertEquals("aaa", Bytes.toString(startRow.getKey()));
    RowModel endRow = model.getRows().get(model.getRows().size() - 1);
    assertEquals("aax", Bytes.toString(endRow.getKey()));
    count = TestScannerResource.countCellSet(model);
    assertEquals(24, count);
    checkRowsNotNull(model);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) JacksonJaxbJsonProvider(org.apache.hbase.thirdparty.com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 13 with JacksonJaxbJsonProvider

use of org.apache.hbase.thirdparty.com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider in project hbase by apache.

the class TestVersionResource method testGetStorageClusterVersionJSON.

@Test
public void testGetStorageClusterVersionJSON() throws IOException {
    Response response = client.get("/version/cluster", Constants.MIMETYPE_JSON);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
    ObjectMapper mapper = new JacksonJaxbJsonProvider().locateMapper(StorageClusterVersionModel.class, MediaType.APPLICATION_JSON_TYPE);
    StorageClusterVersionModel clusterVersionModel = mapper.readValue(response.getBody(), StorageClusterVersionModel.class);
    assertNotNull(clusterVersionModel);
    assertNotNull(clusterVersionModel.getVersion());
    LOG.info("success retrieving storage cluster version as JSON");
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) JacksonJaxbJsonProvider(org.apache.hbase.thirdparty.com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider) StorageClusterVersionModel(org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 14 with JacksonJaxbJsonProvider

use of org.apache.hbase.thirdparty.com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider in project hbase by apache.

the class TestSecureRESTServer method testProxy.

public void testProxy(String extraArgs, String PRINCIPAL, File keytab, int responseCode) throws Exception {
    UserGroupInformation superuser = UserGroupInformation.loginUserFromKeytabAndReturnUGI(SERVICE_PRINCIPAL, serviceKeytab.getAbsolutePath());
    final TableName table = TableName.valueOf("publicTable");
    // Read that row as the client
    Pair<CloseableHttpClient, HttpClientContext> pair = getClient();
    CloseableHttpClient client = pair.getFirst();
    HttpClientContext context = pair.getSecond();
    HttpGet get = new HttpGet(new URL("http://localhost:" + REST_TEST.getServletPort()).toURI() + "/" + table + "/a" + extraArgs);
    get.addHeader("Accept", "application/json");
    UserGroupInformation user = UserGroupInformation.loginUserFromKeytabAndReturnUGI(PRINCIPAL, keytab.getAbsolutePath());
    String jsonResponse = user.doAs(new PrivilegedExceptionAction<String>() {

        @Override
        public String run() throws Exception {
            try (CloseableHttpResponse response = client.execute(get, context)) {
                final int statusCode = response.getStatusLine().getStatusCode();
                assertEquals(response.getStatusLine().toString(), responseCode, statusCode);
                HttpEntity entity = response.getEntity();
                return EntityUtils.toString(entity);
            }
        }
    });
    if (responseCode == HttpURLConnection.HTTP_OK) {
        ObjectMapper mapper = new JacksonJaxbJsonProvider().locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE);
        CellSetModel model = mapper.readValue(jsonResponse, CellSetModel.class);
        assertEquals(1, model.getRows().size());
        RowModel row = model.getRows().get(0);
        assertEquals("a", Bytes.toString(row.getKey()));
        assertEquals(1, row.getCells().size());
        CellModel cell = row.getCells().get(0);
        assertEquals("1", Bytes.toString(cell.getValue()));
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpEntity(org.apache.http.HttpEntity) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) HttpGet(org.apache.http.client.methods.HttpGet) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) URL(java.net.URL) IOException(java.io.IOException) TableName(org.apache.hadoop.hbase.TableName) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) CellModel(org.apache.hadoop.hbase.rest.model.CellModel) JacksonJaxbJsonProvider(org.apache.hbase.thirdparty.com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Aggregations

JacksonJaxbJsonProvider (org.apache.hbase.thirdparty.com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)14 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 Response (org.apache.hadoop.hbase.rest.client.Response)11 CellSetModel (org.apache.hadoop.hbase.rest.model.CellSetModel)10 Test (org.junit.Test)9 RowModel (org.apache.hadoop.hbase.rest.model.RowModel)7 CellModel (org.apache.hadoop.hbase.rest.model.CellModel)4 Client (org.apache.hadoop.hbase.rest.client.Client)2 Cluster (org.apache.hadoop.hbase.rest.client.Cluster)2 StorageClusterVersionModel (org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel)2 BeforeClass (org.junit.BeforeClass)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonParser (com.fasterxml.jackson.core.JsonParser)1 IOException (java.io.IOException)1 URL (java.net.URL)1 TableName (org.apache.hadoop.hbase.TableName)1 NamespacesInstanceModel (org.apache.hadoop.hbase.rest.model.NamespacesInstanceModel)1 TableListModel (org.apache.hadoop.hbase.rest.model.TableListModel)1 TestNamespacesInstanceModel (org.apache.hadoop.hbase.rest.model.TestNamespacesInstanceModel)1 VersionModel (org.apache.hadoop.hbase.rest.model.VersionModel)1