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"));
}
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);
}
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());
}
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));
}
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));
}
Aggregations