当前位置: 首页>>代码示例>>Java>>正文


Java RestChannel.sendResponse方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:codelibs,项目名称:elasticsearch-indexing-proxy,代码行数:20,代码来源:RestIndexingProxyProcessAction.java

示例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);
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:21,代码来源:ResponseUtil.java

示例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);
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:22,代码来源:CSVResultRestExecutor.java

示例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;
}
 
开发者ID:SnailFastGo,项目名称:elasticsearch_plugin,代码行数:34,代码来源:MyRestAction.java

示例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);
        }
    }
}
 
开发者ID:boundlessgeo,项目名称:elasticsearch-heatmap,代码行数:24,代码来源:GeoHeatmapRestAction.java

示例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);
        }
    }
}
 
开发者ID:petalmd,项目名称:armor,代码行数:24,代码来源:SecurityUtil.java

示例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);
    }
}
 
开发者ID:codelibs,项目名称:elasticsearch-configsync,代码行数:17,代码来源:RestConfigSyncAction.java

示例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}"));
		}
	}
 
开发者ID:raghavendar-ts,项目名称:Elasticsearch-Report-Plugin,代码行数:18,代码来源:ESReportPluginRestHandler.java

示例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));
    }
}
 
开发者ID:codelibs,项目名称:elasticsearch-benchmark-suite,代码行数:18,代码来源:RestBenchAction.java

示例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);
    }
}
 
开发者ID:codelibs,项目名称:elasticsearch-reindexing,代码行数:21,代码来源:ReindexRestAction.java

示例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);
    }
}
 
开发者ID:codelibs,项目名称:elasticsearch-taste,代码行数:22,代码来源:TasteActionRestAction.java

示例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);
        }
    }
}
 
开发者ID:codelibs,项目名称:elasticsearch-qrcache,代码行数:26,代码来源:RestStatsQRCacheAction.java

示例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));
        }
    }
}
 
开发者ID:jprante,项目名称:elasticsearch-plugin-deploy,代码行数:23,代码来源:RestDeployAction.java

示例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);
    }
}
 
开发者ID:codelibs,项目名称:elasticsearch-dataformat,代码行数:17,代码来源:RestDataAction.java

示例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);
        }
    }
}
 
开发者ID:codelibs,项目名称:elasticsearch-auth,代码行数:22,代码来源:ResponseUtil.java


注:本文中的org.elasticsearch.rest.RestChannel.sendResponse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。