本文整理汇总了Java中org.elasticsearch.rest.RestChannel.sendResponse方法的典型用法代码示例。如果您正苦于以下问题:Java RestChannel.sendResponse方法的具体用法?Java RestChannel.sendResponse怎么用?Java RestChannel.sendResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.rest.RestChannel
的用法示例。
在下文中一共展示了RestChannel.sendResponse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendResponse
import org.elasticsearch.rest.RestChannel; //导入方法依赖的package包/类
protected void sendResponse(final RestChannel channel, final Map<String, Object> params, final boolean pretty) {
try {
final XContentBuilder builder = JsonXContent.contentBuilder();
if (pretty) {
builder.prettyPrint();
}
builder.startObject();
builder.field("acknowledged", true);
if (params != null) {
for (final Map.Entry<String, Object> entry : params.entrySet()) {
builder.field(entry.getKey(), entry.getValue());
}
}
builder.endObject();
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (final IOException e) {
throw new ElasticsearchException("Failed to create a resposne.", e);
}
}
示例2: send
import org.elasticsearch.rest.RestChannel; //导入方法依赖的package包/类
public static void send(final RestChannel channel, final RestStatus status, final String message) {
try {
final XContentBuilder builder = JsonXContent.contentBuilder();
builder.startObject()
.field("status", status.getStatus())
.field("message", message).endObject();
BytesRestResponse bytesRestResponse = new BytesRestResponse(status, builder);
if (status == RestStatus.UNAUTHORIZED) {
bytesRestResponse.addHeader("WWW-authenticate", "Basic realm=\"Elasticsearch Authentication\"");
}
channel.sendResponse(bytesRestResponse);
} catch (final IOException e) {
logger.error("Failed to send a response.", e);
try {
channel.sendResponse(new BytesRestResponse(channel, e));
} catch (final IOException e1) {
logger.error("Failed to send a failure response.", e1);
}
}
}
示例3: execute
import org.elasticsearch.rest.RestChannel; //导入方法依赖的package包/类
@Override
public void execute(Client client, Map<String, String> params, QueryAction queryAction, RestChannel channel) throws Exception {
Object queryResult = QueryActionElasticExecutor.executeAnyAction(client, queryAction);
boolean flat = getBooleanOrDefault(params,"flat",false);
String separator = ",";
if(params.containsKey("separator")){
separator = params.get("separator");
}
boolean includeScore = getBooleanOrDefault(params,"_score",false);
boolean includeType = getBooleanOrDefault(params,"_type",false);
boolean includeId = getBooleanOrDefault(params,"_id",false);
CSVResult result = new CSVResultsExtractor(includeScore,includeType,includeId).extractResults(queryResult,flat,separator);
String newLine = "\n";
if(params.containsKey("newLine")){
newLine = params.get("newLine");
}
String csvString = buildString(separator, result, newLine);
BytesRestResponse bytesRestResponse = new BytesRestResponse(RestStatus.OK, csvString);
channel.sendResponse(bytesRestResponse);
}
示例4: prepareRequest
import org.elasticsearch.rest.RestChannel; //导入方法依赖的package包/类
/**
*@description 插件的业务处理方法
*@time 创建时间:2017年8月31日下午4:21:52
*@param request
*@param client
*@return
*@throws IOException
*@author dzn
*/
@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client)
throws IOException {
LOGGER.info("My Rest Action Handler");
Map<String, String> params = request.params();
LOGGER.info("Param : {}", params);
final String actionParam = request.param("action");
LOGGER.info("actionParam : {}", actionParam);
RestChannelConsumer res = new RestChannelConsumer(){
@Override
public void accept(RestChannel channel) throws Exception {
XContentBuilder builder = channel.newBuilder();
builder.startObject();
//返回给页面的信息
builder.field("message", "This is my first plugin");
if(null != actionParam && actionParam.trim().length() > 0){
builder.field("接收到参数actionParam", actionParam);
}
builder.endObject();
channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));
}
};
return res;
}
示例5: handleRequest
import org.elasticsearch.rest.RestChannel; //导入方法依赖的package包/类
@Override
protected void handleRequest(final RestRequest request,
final RestChannel channel, Client client) {
try {
final XContentBuilder builder = JsonXContent.contentBuilder();
if (request.hasParam("pretty")) {
builder.prettyPrint().lfAtEnd();
}
builder.startObject();
builder.field("index", request.param("index"));
builder.field("type", request.param("type"));
builder.field("description", "This is a elasticsearch-heatmap response: "
+ new Date().toString());
builder.endObject();
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (final IOException e) {
try {
channel.sendResponse(new BytesRestResponse(channel, e));
} catch (final IOException e1) {
logger.error("Failed to send a failure response.", e1);
}
}
}
示例6: send
import org.elasticsearch.rest.RestChannel; //导入方法依赖的package包/类
public static void send(final RestChannel channel, final RestStatus status, final String arg) {
try {
final XContentBuilder builder = channel.newBuilder();
builder.startObject();
builder.field("status", status.getStatus());
if (arg != null && !arg.isEmpty()) {
builder.field("message", arg);
}
builder.endObject();
channel.sendResponse(new BytesRestResponse(status, builder));
} catch (final Exception e) {
log.error("Failed to send a response.", e);
try {
channel.sendResponse(new BytesRestResponse(channel, e));
} catch (final IOException e1) {
log.error("Failed to send a failure response.", e1);
}
}
}
示例7: sendResponse
import org.elasticsearch.rest.RestChannel; //导入方法依赖的package包/类
protected void sendResponse(final RestChannel channel, final Map<String, Object> params) {
try {
final XContentBuilder builder = JsonXContent.contentBuilder();
builder.startObject();
builder.field("acknowledged", true);
if (params != null) {
for (final Map.Entry<String, Object> entry : params.entrySet()) {
builder.field(entry.getKey(), entry.getValue());
}
}
builder.endObject();
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (final IOException e) {
throw new ElasticsearchException("Failed to create a resposne.", e);
}
}
示例8: handleRequest
import org.elasticsearch.rest.RestChannel; //导入方法依赖的package包/类
public void handleRequest(final RestRequest request, final RestChannel channel) {
String inputStr = new String(request.content().toBytes(), Charsets.UTF_8);
JSONObject input = null;
if (!request.method().equals(GET)) {
input = new JSONObject(inputStr);
}
System.out.println("Path:" + request.path());
if (request.path().equals("/_river/report/now")) {
ESReport esReport = new ESReport(client);
esReport.process(inputStr);
channel.sendResponse(new BytesRestResponse(OK, "{status:finished}"));
}
}
示例9: handleRequest
import org.elasticsearch.rest.RestChannel; //导入方法依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
switch (request.method()) {
case POST:
handleAbortRequest(request, channel, client);
break;
case PUT:
handleSubmitRequest(request, channel, client);
break;
case GET:
handleStatusRequest(request, channel, client);
break;
default:
// Politely ignore methods we don't support
channel.sendResponse(new BytesRestResponse(METHOD_NOT_ALLOWED));
}
}
示例10: sendResponse
import org.elasticsearch.rest.RestChannel; //导入方法依赖的package包/类
private void sendResponse(final RestRequest request,
final RestChannel channel, final Map<String, Object> params) {
try {
final XContentBuilder builder = JsonXContent.contentBuilder();
if (request.hasParam("pretty")) {
builder.prettyPrint().lfAtEnd();
}
builder.startObject();
builder.field("acknowledged", true);
if (params != null) {
for (final Map.Entry<String, Object> entry : params.entrySet()) {
builder.field(entry.getKey(), entry.getValue());
}
}
builder.endObject();
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (final Exception e) {
sendErrorResponse(channel, e);
}
}
示例11: sendResponse
import org.elasticsearch.rest.RestChannel; //导入方法依赖的package包/类
private void sendResponse(final RestRequest request,
final RestChannel channel, final Map<String, Object> params,
final boolean acknowledged) {
try {
final XContentBuilder builder = JsonXContent.contentBuilder();
if (request.hasParam("pretty")) {
builder.prettyPrint().lfAtEnd();
}
builder.startObject();
builder.field("acknowledged", acknowledged);
if (params != null) {
for (final Map.Entry<String, Object> entry : params.entrySet()) {
builder.field(entry.getKey(), entry.getValue());
}
}
builder.endObject();
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (final Exception e) {
sendErrorResponse(channel, e);
}
}
示例12: handleRequest
import org.elasticsearch.rest.RestChannel; //导入方法依赖的package包/类
@Override
public void handleRequest(final RestRequest request,
final RestChannel channel, final Client client) {
try {
final QueryResultCacheStats stats = queryResultCache.stats();
final XContentBuilder builder = JsonXContent.contentBuilder();
final String pretty = request.param("pretty");
if (pretty != null && !"false".equalsIgnoreCase(pretty)) {
builder.prettyPrint().lfAtEnd();
}
builder.startObject();
builder.startObject("_all");
stats.toXContent(builder, null);
builder.endObject();
builder.endObject();
channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));
} catch (final IOException e) {
try {
channel.sendResponse(new BytesRestResponse(channel, e));
} catch (final IOException e1) {
logger.error("Failed to send a failure response.", e1);
}
}
}
示例13: handleRequest
import org.elasticsearch.rest.RestChannel; //导入方法依赖的package包/类
@Override
public void handleRequest(final RestRequest request, final RestChannel channel) {
try {
Map<String, Object> body = XContentHelper.convertToMap(request.content(), false).v2();
String name = body.containsKey("name") ? body.get("name").toString() : request.param("name");
String path = body.containsKey("path") ? body.get("path").toString() : request.param("path");
DeployRequestBuilder deployRequestBuilder = new DeployRequestBuilder(client.admin().cluster())
.setName(name)
.setPath(settings, path);
final DeployRequest deployRequest = deployRequestBuilder.request();
client.admin().cluster().execute(DeployAction.INSTANCE, deployRequest,
new RestToXContentListener<DeployResponse>(channel));
} catch (Throwable ex) {
logger.error(ex.getMessage(), ex);
try {
channel.sendResponse(new BytesRestResponse(channel, ex));
} catch (IOException ex2) {
logger.error(ex2.getMessage(), ex2);
channel.sendResponse(new BytesRestResponse(RestStatus.INTERNAL_SERVER_ERROR));
}
}
}
示例14: sendResponse
import org.elasticsearch.rest.RestChannel; //导入方法依赖的package包/类
private void sendResponse(final RestRequest request, final RestChannel channel, final String file) {
try {
final XContentBuilder builder = JsonXContent.contentBuilder();
final String pretty = request.param("pretty");
if (pretty != null && !"false".equalsIgnoreCase(pretty)) {
builder.prettyPrint().lfAtEnd();
}
builder.startObject();
builder.field("acknowledged", true);
builder.field("file", file);
builder.endObject();
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (final IOException e) {
throw new ElasticsearchException("Failed to create a resposne.", e);
}
}
示例15: send
import org.elasticsearch.rest.RestChannel; //导入方法依赖的package包/类
public static void send(final RestRequest request,
final RestChannel channel, final RestStatus status,
final String... args) {
try {
final XContentBuilder builder = JsonXContent.contentBuilder();
builder.startObject();
builder.field("status", status.getStatus());
for (int i = 0; i < args.length; i += 2) {
builder.field(args[i], args[i + 1]);
}
builder.endObject();
channel.sendResponse(new BytesRestResponse(status, builder));
} catch (final IOException e) {
logger.error("Failed to send a response.", e);
try {
channel.sendResponse(new BytesRestResponse(channel, e));
} catch (final IOException e1) {
logger.error("Failed to send a failure response.", e1);
}
}
}