本文整理汇总了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);
}
}
}
示例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;
}
示例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);
}
}
示例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);
}