use of java.io.StringWriter in project hadoop by apache.
the class TestRMWebServicesAppsModification method appPriorityToJSON.
protected static String appPriorityToJSON(AppPriority targetPriority) throws Exception {
StringWriter sw = new StringWriter();
JSONJAXBContext ctx = new JSONJAXBContext(AppPriority.class);
JSONMarshaller jm = ctx.createJSONMarshaller();
jm.marshallToJSON(targetPriority, sw);
return sw.toString();
}
use of java.io.StringWriter in project hbase by apache.
the class RetriesExhaustedWithDetailsException method getExhaustiveDescription.
public String getExhaustiveDescription() {
StringWriter errorWriter = new StringWriter();
PrintWriter pw = new PrintWriter(errorWriter);
for (int i = 0; i < this.exceptions.size(); ++i) {
Throwable t = this.exceptions.get(i);
Row action = this.actions.get(i);
String server = this.hostnameAndPort.get(i);
pw.append("exception");
if (this.exceptions.size() > 1) {
pw.append(" #" + i);
}
pw.append(" from " + server + " for " + ((action == null) ? "unknown key" : Bytes.toStringBinary(action.getRow())));
if (t != null) {
pw.println();
t.printStackTrace(pw);
}
}
pw.flush();
return errorWriter.toString();
}
use of java.io.StringWriter 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(response.getCode(), 201);
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(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel) unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
assertEquals(countCellSet(cellSet), 5);
}
use of java.io.StringWriter in project hbase by apache.
the class TestNamespacesInstanceResource method toXML.
private static byte[] toXML(NamespacesInstanceModel model) throws JAXBException {
StringWriter writer = new StringWriter();
context.createMarshaller().marshal(model, writer);
return Bytes.toBytes(writer.toString());
}
use of java.io.StringWriter in project hbase by apache.
the class TestGetAndPutResource method testMultiColumnGetXML.
@Test
public void testMultiColumnGetXML() throws Exception {
String path = "/" + TABLE + "/fakerow";
CellSetModel cellSetModel = new CellSetModel();
RowModel rowModel = new RowModel(ROW_1);
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_1), Bytes.toBytes(VALUE_1)));
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_2), Bytes.toBytes(VALUE_2)));
rowModel.addCell(new CellModel(Bytes.toBytes(COLUMN_3), Bytes.toBytes(VALUE_2)));
cellSetModel.addRow(rowModel);
StringWriter writer = new StringWriter();
xmlMarshaller.marshal(cellSetModel, writer);
Response response = client.put(path, Constants.MIMETYPE_XML, Bytes.toBytes(writer.toString()));
Thread.yield();
// make sure the fake row was not actually created
response = client.get(path, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 404);
// Try getting all the column values at once.
path = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1 + "," + COLUMN_2 + "," + COLUMN_3;
response = client.get(path, Constants.MIMETYPE_XML);
assertEquals(200, response.getCode());
CellSetModel cellSet = (CellSetModel) xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
assertTrue(cellSet.getRows().size() == 1);
assertTrue(cellSet.getRows().get(0).getCells().size() == 3);
List<CellModel> cells = cellSet.getRows().get(0).getCells();
assertTrue(containsCellModel(cells, COLUMN_1, VALUE_1));
assertTrue(containsCellModel(cells, COLUMN_2, VALUE_2));
assertTrue(containsCellModel(cells, COLUMN_3, VALUE_2));
response = deleteRow(TABLE, ROW_1);
assertEquals(response.getCode(), 200);
}
Aggregations