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


Java BytesRestResponse.addHeader方法代码示例

本文整理汇总了Java中org.elasticsearch.rest.BytesRestResponse.addHeader方法的典型用法代码示例。如果您正苦于以下问题:Java BytesRestResponse.addHeader方法的具体用法?Java BytesRestResponse.addHeader怎么用?Java BytesRestResponse.addHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.rest.BytesRestResponse的用法示例。


在下文中一共展示了BytesRestResponse.addHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: send

import org.elasticsearch.rest.BytesRestResponse; //导入方法依赖的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

示例2: reRequestAuthentication

import org.elasticsearch.rest.BytesRestResponse; //导入方法依赖的package包/类
@Override
public boolean reRequestAuthentication(final RestChannel channel, AuthCredentials creds) {
    final BytesRestResponse wwwAuthenticateResponse = new BytesRestResponse(RestStatus.UNAUTHORIZED, "Unauthorized");
    wwwAuthenticateResponse.addHeader("WWW-Authenticate", "Basic realm=\"Search Guard\"");
    channel.sendResponse(wwwAuthenticateResponse);
    return true;
}
 
开发者ID:floragunncom,项目名称:search-guard,代码行数:8,代码来源:HTTPBasicAuthenticator.java

示例3: writeResponse

import org.elasticsearch.rest.BytesRestResponse; //导入方法依赖的package包/类
private void writeResponse(final RestRequest request, final RestChannel channel, final File outputFile,
                           final long limit, final DataContent dataContent) {
    if (outputFile.length() > limit) {
        onFailure(new ElasticsearchException("Content size is too large " + outputFile.length()));
        return;
    }

    try (FileInputStream fis = new FileInputStream(outputFile)) {
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        final byte[] bytes = new byte[1024];
        int len;
        while ((len = fis.read(bytes)) > 0) {
            out.write(bytes, 0, len);
        }

        final ContentType contentType = dataContent.getContentType();
        final BytesRestResponse response = new BytesRestResponse(
                RestStatus.OK, contentType.contentType(),
                out.toByteArray());
        response.addHeader("Content-Disposition",
                "attachment; filename=\""
                        + contentType.fileName(request) + "\"");
        channel.sendResponse(response);
    } catch (final Throwable e) {
        throw new ElasticsearchException("Failed to render the content.", e);
    }
}
 
开发者ID:codelibs,项目名称:elasticsearch-dataformat,代码行数:28,代码来源:RestDataAction.java

示例4: askAgain

import org.elasticsearch.rest.BytesRestResponse; //导入方法依赖的package包/类
private void askAgain(final RestChannel channel) {
    final BytesRestResponse wwwAuthenticateResponse = new BytesRestResponse(RestStatus.UNAUTHORIZED);
    wwwAuthenticateResponse.addHeader("WWW-Authenticate", "Basic realm=\"Search Guard\"");
    channel.sendResponse(wwwAuthenticateResponse);
}
 
开发者ID:petalmd,项目名称:armor,代码行数:6,代码来源:HTTPBasicAuthenticator.java


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