本文整理匯總了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);
}