當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。