@Override
public void handleRequest(final RestRequest request, final RestChannel channel, Client client) {
String subscriberId = request.hasParam("subscriber") ? request.param("subscriber") : null;
if (subscriberId == null) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, new IllegalArgumentException("no subscriber")));
} catch (IOException e) {
logger.error("error while sending failure response", e);
}
return;
}
try {
client.prepareDelete(pubSubIndexName, "subscribe", subscriberId)
.execute(new ActionListener<DeleteResponse>() {
@Override
public void onResponse(DeleteResponse response) {
try {
XContentBuilder builder = restContentBuilder(request);
builder.startObject().field("ok", true).field("id", response.getId()).endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
} catch (Exception e) {
onFailure(e);
}
}
@Override
public void onFailure(Throwable e) {
try {
logger.error("error while processing unsubscribe request", e);
channel.sendResponse(new XContentThrowableRestResponse(request, e));
} catch (IOException e1) {
logger.error("error while sending error response", e1);
}
}
});