Search in sources :

Example 6 with JacksonJaxbJsonProvider

use of org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider in project hbase by apache.

the class RowResourceBase method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    conf = TEST_UTIL.getConfiguration();
    TEST_UTIL.startMiniCluster(3);
    REST_TEST_UTIL.startServletContainer(conf);
    context = JAXBContext.newInstance(CellModel.class, CellSetModel.class, RowModel.class);
    xmlMarshaller = context.createMarshaller();
    xmlUnmarshaller = context.createUnmarshaller();
    jsonMapper = new JacksonJaxbJsonProvider().locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE);
    client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort()));
}
Also used : CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) Cluster(org.apache.hadoop.hbase.rest.client.Cluster) CellModel(org.apache.hadoop.hbase.rest.model.CellModel) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) JacksonJaxbJsonProvider(org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider) Client(org.apache.hadoop.hbase.rest.client.Client) BeforeClass(org.junit.BeforeClass)

Example 7 with JacksonJaxbJsonProvider

use of org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider in project hbase by apache.

the class TestTableScan method testStreamingJSON.

@Test
public void testStreamingJSON() throws Exception {
    // 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 + "=20");
    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(20, 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());
    count = 0;
    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) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) JsonFactory(org.codehaus.jackson.JsonFactory) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) JacksonJaxbJsonProvider(org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JsonParser(org.codehaus.jackson.JsonParser) Test(org.junit.Test)

Example 8 with JacksonJaxbJsonProvider

use of org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider in project hbase by apache.

the class TestTableScan method testSimpleScannerJson.

@Test
public void testSimpleScannerJson() throws IOException, JAXBException {
    // 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 + "=20");
    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(20, 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.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Aggregations

JacksonJaxbJsonProvider (org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider)8 CellSetModel (org.apache.hadoop.hbase.rest.model.CellSetModel)7 Response (org.apache.hadoop.hbase.rest.client.Response)6 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)6 Test (org.junit.Test)5 RowModel (org.apache.hadoop.hbase.rest.model.RowModel)4 Client (org.apache.hadoop.hbase.rest.client.Client)2 Cluster (org.apache.hadoop.hbase.rest.client.Cluster)2 CellModel (org.apache.hadoop.hbase.rest.model.CellModel)2 BeforeClass (org.junit.BeforeClass)2 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 JsonFactory (org.codehaus.jackson.JsonFactory)1 JsonParser (org.codehaus.jackson.JsonParser)1