}
}
private Response updateBinary(byte[] message, HttpHeaders headers,
boolean replace) {
HTablePool pool;
try {
pool = RESTServlet.getInstance().getTablePool();
} catch (IOException e) {
throw new WebApplicationException(e,
Response.Status.INTERNAL_SERVER_ERROR);
}
HTable table = null;
try {
byte[] row = rowspec.getRow();
byte[][] columns = rowspec.getColumns();
byte[] column = null;
if (columns != null) {
column = columns[0];
}
long timestamp = HConstants.LATEST_TIMESTAMP;
List<String> vals = headers.getRequestHeader("X-Row");
if (vals != null && !vals.isEmpty()) {
row = Bytes.toBytes(vals.get(0));
}
vals = headers.getRequestHeader("X-Column");
if (vals != null && !vals.isEmpty()) {
column = Bytes.toBytes(vals.get(0));
}
vals = headers.getRequestHeader("X-Timestamp");
if (vals != null && !vals.isEmpty()) {
timestamp = Long.valueOf(vals.get(0));
}
if (column == null) {
throw new WebApplicationException(Response.Status.BAD_REQUEST);
}
Put put = new Put(row);
byte parts[][] = KeyValue.parseColumn(column);
put.add(parts[0], parts[1], timestamp, message);
table = pool.getTable(this.table);
table.put(put);
if (LOG.isDebugEnabled()) {
LOG.debug("PUT " + put.toString());
}
table.flushCommits();
return Response.ok().build();
} catch (IOException e) {
throw new WebApplicationException(e,
Response.Status.SERVICE_UNAVAILABLE);
} finally {
if (table != null) {
pool.putTable(table);
}
}
}