Search in sources :

Example 1 with Response

use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.

the class TestVersionResource method doTestGetStorageClusterVersionJSON.

@Test
public void doTestGetStorageClusterVersionJSON() throws IOException {
    Response response = client.get("/version/cluster", Constants.MIMETYPE_JSON);
    assertTrue(response.getCode() == 200);
    assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type"));
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) Test(org.junit.Test)

Example 2 with Response

use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.

the class TestNamespacesResource method testNamespaceListXMLandJSON.

@Test
public void testNamespaceListXMLandJSON() throws IOException, JAXBException {
    String namespacePath = "/namespaces/";
    NamespacesModel model;
    Response response;
    // Check that namespace does not yet exist via non-REST call.
    Admin admin = TEST_UTIL.getAdmin();
    assertFalse(doesNamespaceExist(admin, NAMESPACE1));
    model = testNamespacesModel.buildTestModel();
    testNamespacesModel.checkModel(model);
    // Check that REST GET finds only default namespaces via XML and JSON responses.
    response = client.get(namespacePath, Constants.MIMETYPE_XML);
    assertEquals(200, response.getCode());
    model = fromXML(response.getBody());
    testNamespacesModel.checkModel(model, "hbase", "default");
    response = client.get(namespacePath, Constants.MIMETYPE_JSON);
    assertEquals(200, response.getCode());
    model = testNamespacesModel.fromJSON(Bytes.toString(response.getBody()));
    testNamespacesModel.checkModel(model, "hbase", "default");
    // Create namespace and check that REST GET finds one additional namespace.
    createNamespaceViaAdmin(admin, NAMESPACE1);
    response = client.get(namespacePath, Constants.MIMETYPE_XML);
    assertEquals(200, response.getCode());
    model = fromXML(response.getBody());
    testNamespacesModel.checkModel(model, NAMESPACE1, "hbase", "default");
    response = client.get(namespacePath, Constants.MIMETYPE_JSON);
    assertEquals(200, response.getCode());
    model = testNamespacesModel.fromJSON(Bytes.toString(response.getBody()));
    testNamespacesModel.checkModel(model, NAMESPACE1, "hbase", "default");
    // Create another namespace and check that REST GET finds one additional namespace.
    createNamespaceViaAdmin(admin, NAMESPACE2);
    response = client.get(namespacePath, Constants.MIMETYPE_XML);
    assertEquals(200, response.getCode());
    model = fromXML(response.getBody());
    testNamespacesModel.checkModel(model, NAMESPACE1, NAMESPACE2, "hbase", "default");
    response = client.get(namespacePath, Constants.MIMETYPE_JSON);
    assertEquals(200, response.getCode());
    model = testNamespacesModel.fromJSON(Bytes.toString(response.getBody()));
    testNamespacesModel.checkModel(model, NAMESPACE1, NAMESPACE2, "hbase", "default");
    // Delete namespace and check that REST still finds correct namespaces.
    admin.deleteNamespace(NAMESPACE1);
    response = client.get(namespacePath, Constants.MIMETYPE_XML);
    assertEquals(200, response.getCode());
    model = fromXML(response.getBody());
    testNamespacesModel.checkModel(model, NAMESPACE2, "hbase", "default");
    response = client.get(namespacePath, Constants.MIMETYPE_JSON);
    assertEquals(200, response.getCode());
    model = testNamespacesModel.fromJSON(Bytes.toString(response.getBody()));
    testNamespacesModel.checkModel(model, NAMESPACE2, "hbase", "default");
    admin.deleteNamespace(NAMESPACE2);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) NamespacesModel(org.apache.hadoop.hbase.rest.model.NamespacesModel) TestNamespacesModel(org.apache.hadoop.hbase.rest.model.TestNamespacesModel) Admin(org.apache.hadoop.hbase.client.Admin) Test(org.junit.Test)

Example 3 with Response

use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.

the class TestResourceFilter method testFilter.

@Test
public void testFilter() throws Exception {
    String path = "/status/cluster";
    Response response = client.get(path);
    assertEquals(404, response.getCode());
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) Test(org.junit.Test)

Example 4 with Response

use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.

the class TestScannersWithLabels method testSimpleScannerXMLWithLabelsThatReceivesData.

@Test
public void testSimpleScannerXMLWithLabelsThatReceivesData() throws IOException, JAXBException {
    // new scanner
    ScannerModel model = new ScannerModel();
    model.setBatch(5);
    model.addColumn(Bytes.toBytes(COLUMN_1));
    model.addLabel(SECRET);
    StringWriter writer = new StringWriter();
    marshaller.marshal(model, writer);
    byte[] body = Bytes.toBytes(writer.toString());
    // recall previous put operation with read-only off
    conf.set("hbase.rest.readonly", "false");
    Response response = client.put("/" + TABLE + "/scanner", Constants.MIMETYPE_XML, body);
    assertEquals(201, response.getCode());
    String scannerURI = response.getLocation();
    assertNotNull(scannerURI);
    // get a cell set
    response = client.get(scannerURI, Constants.MIMETYPE_XML);
    // Respond with 204 as there are no cells to be retrieved
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
    CellSetModel cellSet = (CellSetModel) unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
    assertEquals(5, countCellSet(cellSet));
}
Also used : VisibilityLabelsResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse) Response(org.apache.hadoop.hbase.rest.client.Response) StringWriter(java.io.StringWriter) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) ByteArrayInputStream(java.io.ByteArrayInputStream) ScannerModel(org.apache.hadoop.hbase.rest.model.ScannerModel) Test(org.junit.Test)

Example 5 with Response

use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.

the class TestSecurityHeadersFilter method testDefaultValues.

@Test
public void testDefaultValues() throws Exception {
    TEST_UTIL.startMiniCluster();
    REST_TEST_UTIL.startServletContainer(TEST_UTIL.getConfiguration());
    client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort()));
    String path = "/version/cluster";
    Response response = client.get(path);
    assertThat(response.getCode(), equalTo(200));
    assertThat("Header 'X-Content-Type-Options' is missing from Rest response", response.getHeader("X-Content-Type-Options"), is(not((String) null)));
    assertThat("Header 'X-Content-Type-Options' has invalid default value", response.getHeader("X-Content-Type-Options"), equalTo("nosniff"));
    assertThat("Header 'X-XSS-Protection' is missing from Rest response", response.getHeader("X-XSS-Protection"), is(not((String) null)));
    assertThat("Header 'X-XSS-Protection' has invalid default value", response.getHeader("X-XSS-Protection"), equalTo("1; mode=block"));
    assertThat("Header 'Strict-Transport-Security' should be missing from Rest response," + "but it's present", response.getHeader("Strict-Transport-Security"), is((String) null));
    assertThat("Header 'Content-Security-Policy' should be missing from Rest response," + "but it's present", response.getHeader("Content-Security-Policy"), is((String) null));
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) Cluster(org.apache.hadoop.hbase.rest.client.Cluster) Client(org.apache.hadoop.hbase.rest.client.Client) Test(org.junit.Test)

Aggregations

Response (org.apache.hadoop.hbase.rest.client.Response)111 Test (org.junit.Test)90 CellSetModel (org.apache.hadoop.hbase.rest.model.CellSetModel)44 RowModel (org.apache.hadoop.hbase.rest.model.RowModel)34 CellModel (org.apache.hadoop.hbase.rest.model.CellModel)27 ByteArrayInputStream (java.io.ByteArrayInputStream)17 StringWriter (java.io.StringWriter)16 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 JacksonJaxbJsonProvider (org.apache.hbase.thirdparty.com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)11 ScannerModel (org.apache.hadoop.hbase.rest.model.ScannerModel)10 HashMap (java.util.HashMap)9 Admin (org.apache.hadoop.hbase.client.Admin)9 JAXBContext (javax.xml.bind.JAXBContext)8 Unmarshaller (javax.xml.bind.Unmarshaller)8 Header (org.apache.http.Header)6 Map (java.util.Map)5 StorageClusterVersionModel (org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel)5 NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)4 NamespacesInstanceModel (org.apache.hadoop.hbase.rest.model.NamespacesInstanceModel)4 TestNamespacesInstanceModel (org.apache.hadoop.hbase.rest.model.TestNamespacesInstanceModel)4