Cleanup Rest Response

simplify rest response class hierarchy, by using BytesReference for content, and handling JSONP internally in the respective channel that sends the response.
Also, handle the future case where bytes might be releasable, when we start to potentially recycle bytes output stream.
This commit is contained in:
Shay Banon 2014-03-31 03:24:14 +02:00
parent 0ff30ade69
commit f19f729498
96 changed files with 449 additions and 829 deletions

View File

@ -17,27 +17,26 @@
* under the License.
*/
package org.elasticsearch.rest;
package org.elasticsearch.common.netty;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.UnicodeUtil;
import org.elasticsearch.common.lease.Releasable;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelFutureListener;
/**
*
* A channel listener that releases a {@link org.elasticsearch.common.lease.Releasable} when
* the operation is complete.
*/
public class StringRestResponse extends Utf8RestResponse {
public class ReleaseChannelFutureListener implements ChannelFutureListener {
public StringRestResponse(RestStatus status) {
super(status);
private final Releasable releasable;
public ReleaseChannelFutureListener(Releasable releasable) {
this.releasable = releasable;
}
public StringRestResponse(RestStatus status, String content) {
super(status, convert(content));
@Override
public void operationComplete(ChannelFuture future) throws Exception {
releasable.release();
}
private static BytesRef convert(String content) {
BytesRef result = new BytesRef();
UnicodeUtil.UTF16toUTF8(content, 0, content.length(), result);
return result;
}
}
}

View File

@ -1,29 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.http;
import org.elasticsearch.rest.RestResponse;
/**
*
*/
public interface HttpResponse extends RestResponse {
}

View File

@ -132,17 +132,16 @@ public class HttpServer extends AbstractLifecycleComponent<HttpServer> {
void handlePluginSite(HttpRequest request, HttpChannel channel) {
if (disableSites) {
channel.sendResponse(new StringRestResponse(FORBIDDEN));
channel.sendResponse(new BytesRestResponse(FORBIDDEN));
return;
}
if (request.method() == RestRequest.Method.OPTIONS) {
// when we have OPTIONS request, simply send OK by default (with the Access Control Origin header which gets automatically added)
StringRestResponse response = new StringRestResponse(OK);
channel.sendResponse(response);
channel.sendResponse(new BytesRestResponse(OK));
return;
}
if (request.method() != RestRequest.Method.GET) {
channel.sendResponse(new StringRestResponse(FORBIDDEN));
channel.sendResponse(new BytesRestResponse(FORBIDDEN));
return;
}
// TODO for a "/_plugin" endpoint, we should have a page that lists all the plugins?
@ -155,7 +154,7 @@ public class HttpServer extends AbstractLifecycleComponent<HttpServer> {
pluginName = path;
sitePath = null;
// If a trailing / is missing, we redirect to the right page #2654
channel.sendResponse(new HttpRedirectRestResponse(request.rawPath() + "/"));
channel.sendResponse(new BytesRestResponse(RestStatus.MOVED_PERMANENTLY, "text/html", "<head><meta http-equiv=\"refresh\" content=\"0; URL=" + request.rawPath() + "/\"></head>"));
return;
} else {
pluginName = path.substring(0, i1);
@ -173,31 +172,31 @@ public class HttpServer extends AbstractLifecycleComponent<HttpServer> {
File siteFile = new File(new File(environment.pluginsFile(), pluginName), "_site");
File file = new File(siteFile, sitePath);
if (!file.exists() || file.isHidden()) {
channel.sendResponse(new StringRestResponse(NOT_FOUND));
channel.sendResponse(new BytesRestResponse(NOT_FOUND));
return;
}
if (!file.isFile()) {
// If it's not a dir, we send a 403
if (!file.isDirectory()) {
channel.sendResponse(new StringRestResponse(FORBIDDEN));
channel.sendResponse(new BytesRestResponse(FORBIDDEN));
return;
}
// We don't serve dir but if index.html exists in dir we should serve it
file = new File(file, "index.html");
if (!file.exists() || file.isHidden() || !file.isFile()) {
channel.sendResponse(new StringRestResponse(FORBIDDEN));
channel.sendResponse(new BytesRestResponse(FORBIDDEN));
return;
}
}
if (!file.getAbsolutePath().startsWith(siteFile.getAbsolutePath())) {
channel.sendResponse(new StringRestResponse(FORBIDDEN));
channel.sendResponse(new BytesRestResponse(FORBIDDEN));
return;
}
try {
byte[] data = Streams.copyToByteArray(file);
channel.sendResponse(new BytesRestResponse(data, guessMimeType(sitePath)));
channel.sendResponse(new BytesRestResponse(OK, guessMimeType(sitePath), data));
} catch (IOException e) {
channel.sendResponse(new StringRestResponse(INTERNAL_SERVER_ERROR));
channel.sendResponse(new BytesRestResponse(INTERNAL_SERVER_ERROR));
}
}

View File

@ -40,7 +40,8 @@ public class HttpRequestHandler extends SimpleChannelUpstreamHandler {
HttpRequest request = (HttpRequest) e.getMessage();
// the netty HTTP handling always copy over the buffer to its own buffer, either in NioWorker internally
// when reading, or using a cumalation buffer
serverTransport.dispatchRequest(new NettyHttpRequest(request, e.getChannel()), new NettyHttpChannel(serverTransport, e.getChannel(), request));
NettyHttpRequest httpRequest = new NettyHttpRequest(request, e.getChannel());
serverTransport.dispatchRequest(httpRequest, new NettyHttpChannel(serverTransport, e.getChannel(), httpRequest));
super.messageReceived(ctx, e);
}

View File

@ -19,12 +19,14 @@
package org.elasticsearch.http.netty;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.UnicodeUtil;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.lease.Releasable;
import org.elasticsearch.common.netty.ReleaseChannelFutureListener;
import org.elasticsearch.http.HttpChannel;
import org.elasticsearch.http.HttpException;
import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.rest.XContentRestResponse;
import org.elasticsearch.rest.support.RestUtils;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
@ -33,7 +35,6 @@ import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelFutureListener;
import org.jboss.netty.handler.codec.http.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -42,24 +43,34 @@ import java.util.Set;
*
*/
public class NettyHttpChannel implements HttpChannel {
private static final ChannelBuffer END_JSONP;
static {
BytesRef U_END_JSONP = new BytesRef();
UnicodeUtil.UTF16toUTF8(");", 0, ");".length(), U_END_JSONP);
END_JSONP = ChannelBuffers.wrappedBuffer(U_END_JSONP.bytes, U_END_JSONP.offset, U_END_JSONP.length);
}
private final NettyHttpServerTransport transport;
private final Channel channel;
private final org.jboss.netty.handler.codec.http.HttpRequest request;
private final NettyHttpRequest request;
private final org.jboss.netty.handler.codec.http.HttpRequest nettyRequest;
public NettyHttpChannel(NettyHttpServerTransport transport, Channel channel, org.jboss.netty.handler.codec.http.HttpRequest request) {
public NettyHttpChannel(NettyHttpServerTransport transport, Channel channel, NettyHttpRequest request) {
this.transport = transport;
this.channel = channel;
this.request = request;
this.nettyRequest = request.request();
}
@Override
public void sendResponse(RestResponse response) {
// Decide whether to close the connection or not.
boolean http10 = request.getProtocolVersion().equals(HttpVersion.HTTP_1_0);
boolean http10 = nettyRequest.getProtocolVersion().equals(HttpVersion.HTTP_1_0);
boolean close =
HttpHeaders.Values.CLOSE.equalsIgnoreCase(request.headers().get(HttpHeaders.Names.CONNECTION)) ||
(http10 && !HttpHeaders.Values.KEEP_ALIVE.equalsIgnoreCase(request.headers().get(HttpHeaders.Names.CONNECTION)));
HttpHeaders.Values.CLOSE.equalsIgnoreCase(nettyRequest.headers().get(HttpHeaders.Names.CONNECTION)) ||
(http10 && !HttpHeaders.Values.KEEP_ALIVE.equalsIgnoreCase(nettyRequest.headers().get(HttpHeaders.Names.CONNECTION)));
// Build the response object.
HttpResponseStatus status = getStatus(response.status());
@ -72,11 +83,11 @@ public class NettyHttpChannel implements HttpChannel {
} else {
resp = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status);
}
if (RestUtils.isBrowser(request.headers().get(HttpHeaders.Names.USER_AGENT))) {
if (RestUtils.isBrowser(nettyRequest.headers().get(HttpHeaders.Names.USER_AGENT))) {
if (transport.settings().getAsBoolean("http.cors.enabled", true)) {
// Add support for cross-origin Ajax requests (CORS)
resp.headers().add("Access-Control-Allow-Origin", transport.settings().get("http.cors.allow-origin", "*"));
if (request.getMethod() == HttpMethod.OPTIONS) {
if (nettyRequest.getMethod() == HttpMethod.OPTIONS) {
// Allow Ajax requests based on the CORS "preflight" request
resp.headers().add("Access-Control-Max-Age", transport.settings().getAsInt("http.cors.max-age", 1728000));
resp.headers().add("Access-Control-Allow-Methods", transport.settings().get("http.cors.allow-methods", "OPTIONS, HEAD, GET, POST, PUT, DELETE"));
@ -85,7 +96,7 @@ public class NettyHttpChannel implements HttpChannel {
}
}
String opaque = request.headers().get("X-Opaque-Id");
String opaque = nettyRequest.headers().get("X-Opaque-Id");
if (opaque != null) {
resp.headers().add("X-Opaque-Id", opaque);
}
@ -100,65 +111,60 @@ public class NettyHttpChannel implements HttpChannel {
}
}
// Convert the response content to a ChannelBuffer.
ChannelBuffer buf;
BytesReference content = response.content();
ChannelBuffer buffer;
boolean addedReleaseListener = false;
try {
if (response instanceof XContentRestResponse) {
// if its a builder based response, and it was created with a CachedStreamOutput, we can release it
// after we write the response, and no need to do an extra copy because its not thread safe
XContentBuilder builder = ((XContentRestResponse) response).builder();
if (response.contentThreadSafe()) {
buf = builder.bytes().toChannelBuffer();
} else {
buf = builder.bytes().copyBytesArray().toChannelBuffer();
}
if (response.contentThreadSafe()) {
buffer = content.toChannelBuffer();
} else {
if (response.contentThreadSafe()) {
buf = ChannelBuffers.wrappedBuffer(response.content(), response.contentOffset(), response.contentLength());
} else {
buf = ChannelBuffers.copiedBuffer(response.content(), response.contentOffset(), response.contentLength());
}
buffer = content.copyBytesArray().toChannelBuffer();
}
} catch (IOException e) {
throw new HttpException("Failed to convert response to bytes", e);
}
if (response.prefixContent() != null || response.suffixContent() != null) {
ChannelBuffer prefixBuf = ChannelBuffers.EMPTY_BUFFER;
if (response.prefixContent() != null) {
prefixBuf = ChannelBuffers.copiedBuffer(response.prefixContent(), response.prefixContentOffset(), response.prefixContentLength());
// handle JSONP
String callback = request.param("callback");
if (callback != null) {
final BytesRef callbackBytes = new BytesRef(callback.length() * 4 + 1);
UnicodeUtil.UTF16toUTF8(callback, 0, callback.length(), callbackBytes);
callbackBytes.bytes[callbackBytes.length] = '(';
callbackBytes.length++;
buffer = ChannelBuffers.wrappedBuffer(
ChannelBuffers.wrappedBuffer(callbackBytes.bytes, callbackBytes.offset, callbackBytes.length),
buffer,
ChannelBuffers.wrappedBuffer(END_JSONP)
);
}
ChannelBuffer suffixBuf = ChannelBuffers.EMPTY_BUFFER;
if (response.suffixContent() != null) {
suffixBuf = ChannelBuffers.copiedBuffer(response.suffixContent(), response.suffixContentOffset(), response.suffixContentLength());
}
buf = ChannelBuffers.wrappedBuffer(prefixBuf, buf, suffixBuf);
}
resp.setContent(buf);
resp.headers().add(HttpHeaders.Names.CONTENT_TYPE, response.contentType());
resp.setContent(buffer);
resp.headers().add(HttpHeaders.Names.CONTENT_TYPE, response.contentType());
resp.headers().add(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(buffer.readableBytes()));
resp.headers().add(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(buf.readableBytes()));
if (transport.resetCookies) {
String cookieString = request.headers().get(HttpHeaders.Names.COOKIE);
if (cookieString != null) {
CookieDecoder cookieDecoder = new CookieDecoder();
Set<Cookie> cookies = cookieDecoder.decode(cookieString);
if (!cookies.isEmpty()) {
// Reset the cookies if necessary.
CookieEncoder cookieEncoder = new CookieEncoder(true);
for (Cookie cookie : cookies) {
cookieEncoder.addCookie(cookie);
if (transport.resetCookies) {
String cookieString = nettyRequest.headers().get(HttpHeaders.Names.COOKIE);
if (cookieString != null) {
CookieDecoder cookieDecoder = new CookieDecoder();
Set<Cookie> cookies = cookieDecoder.decode(cookieString);
if (!cookies.isEmpty()) {
// Reset the cookies if necessary.
CookieEncoder cookieEncoder = new CookieEncoder(true);
for (Cookie cookie : cookies) {
cookieEncoder.addCookie(cookie);
}
resp.headers().add(HttpHeaders.Names.SET_COOKIE, cookieEncoder.encode());
}
resp.headers().add(HttpHeaders.Names.SET_COOKIE, cookieEncoder.encode());
}
}
}
// Write the response.
ChannelFuture future = channel.write(resp);
// Close the connection after the write operation is done if necessary.
if (close) {
future.addListener(ChannelFutureListener.CLOSE);
ChannelFuture future = channel.write(resp);
if (response.contentThreadSafe() && content instanceof Releasable) {
future.addListener(new ReleaseChannelFutureListener((Releasable) content));
addedReleaseListener = true;
}
if (close) {
future.addListener(ChannelFutureListener.CLOSE);
}
} finally {
if (!addedReleaseListener && content instanceof Releasable) {
((Releasable) content).release();
}
}
}

View File

@ -62,6 +62,10 @@ public class NettyHttpRequest extends HttpRequest {
}
}
public org.jboss.netty.handler.codec.http.HttpRequest request() {
return this.request;
}
@Override
public Method method() {
HttpMethod httpMethod = request.getMethod();

View File

@ -1,81 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.rest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
/**
*
*/
public abstract class AbstractRestResponse implements RestResponse {
Map<String, List<String>> customHeaders;
@Override
public byte[] prefixContent() {
return null;
}
@Override
public int prefixContentLength() {
return -1;
}
@Override
public int prefixContentOffset() {
return 0;
}
@Override
public byte[] suffixContent() {
return null;
}
@Override
public int suffixContentLength() {
return -1;
}
@Override
public int suffixContentOffset() {
return 0;
}
@Override
public void addHeader(String name, String value) {
if (customHeaders == null) {
customHeaders = new HashMap<>(2);
}
List<String> header = customHeaders.get(name);
if (header == null) {
header = new ArrayList<>();
customHeaders.put(name, header);
}
header.add(value);
}
@Override
public Map<String, List<String>> getHeaders() {
return customHeaders;
}
}

View File

@ -44,7 +44,7 @@ public abstract class AbstractRestResponseActionListener<T extends ActionRespons
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -44,7 +44,7 @@ public class AcknowledgedRestResponseActionListener<T extends AcknowledgedRespon
.field(Fields.ACKNOWLEDGED, response.isAcknowledged());
addCustomFields(builder, response);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (IOException e) {
onFailure(e);
}

View File

@ -19,46 +19,137 @@
package org.elasticsearch.rest;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
public class BytesRestResponse extends AbstractRestResponse {
import static org.elasticsearch.ExceptionsHelper.detailedMessage;
import static org.elasticsearch.rest.action.support.RestXContentBuilder.restContentBuilder;
private final byte[] bytes;
public class BytesRestResponse extends RestResponse {
public static final String TEXT_CONTENT_TYPE = "text/plain; charset=UTF-8";
private final RestStatus status;
private final BytesReference content;
private final boolean contentThreadSafe;
private final String contentType;
public BytesRestResponse(byte[] bytes, String contentType) {
this.bytes = bytes;
public BytesRestResponse(RestStatus status) {
this(status, TEXT_CONTENT_TYPE, BytesArray.EMPTY, true);
}
/**
* Creates a new response based on {@link XContentBuilder}.
*/
public BytesRestResponse(RestStatus status, XContentBuilder builder) {
this(status, builder.contentType().restContentType(), builder.bytes(), true);
}
/**
* Creates a new plain text response.
*/
public BytesRestResponse(RestStatus status, String content) {
this(status, TEXT_CONTENT_TYPE, new BytesArray(content), true);
}
/**
* Creates a new plain text response.
*/
public BytesRestResponse(RestStatus status, String contentType, String content) {
this(status, contentType, new BytesArray(content), true);
}
/**
* Creates a binary response.
*/
public BytesRestResponse(RestStatus status, String contentType, byte[] content) {
this(status, contentType, new BytesArray(content), true);
}
/**
* Creates a binary response.
*/
public BytesRestResponse(RestStatus status, String contentType, BytesReference content, boolean contentThreadSafe) {
this.status = status;
this.content = content;
this.contentThreadSafe = contentThreadSafe;
this.contentType = contentType;
}
@Override
public boolean contentThreadSafe() {
return true;
public BytesRestResponse(RestRequest request, Throwable t) throws IOException {
this(request, ((t instanceof ElasticsearchException) ? ((ElasticsearchException) t).status() : RestStatus.INTERNAL_SERVER_ERROR), t);
}
public BytesRestResponse(RestRequest request, RestStatus status, Throwable t) throws IOException {
this(status, convert(request, status, t));
}
@Override
public String contentType() {
return contentType;
return this.contentType;
}
@Override
public byte[] content() throws IOException {
return bytes;
public boolean contentThreadSafe() {
return this.contentThreadSafe;
}
@Override
public int contentLength() throws IOException {
return bytes.length;
}
@Override
public int contentOffset() throws IOException {
return 0;
public BytesReference content() {
return this.content;
}
@Override
public RestStatus status() {
return RestStatus.OK;
return this.status;
}
private static XContentBuilder convert(RestRequest request, RestStatus status, Throwable t) throws IOException {
XContentBuilder builder = restContentBuilder(request).startObject()
.field("error", detailedMessage(t))
.field("status", status.getStatus());
if (t != null && request.paramAsBoolean("error_trace", false)) {
builder.startObject("error_trace");
boolean first = true;
int counter = 0;
while (t != null) {
// bail if there are more than 10 levels, becomes useless really...
if (counter++ > 10) {
break;
}
if (!first) {
builder.startObject("cause");
}
buildThrowable(t, builder);
if (!first) {
builder.endObject();
}
t = t.getCause();
first = false;
}
builder.endObject();
}
builder.endObject();
return builder;
}
private static void buildThrowable(Throwable t, XContentBuilder builder) throws IOException {
builder.field("message", t.getMessage());
for (StackTraceElement stElement : t.getStackTrace()) {
builder.startObject("at")
.field("class", stElement.getClassName())
.field("method", stElement.getMethodName());
if (stElement.getFileName() != null) {
builder.field("file", stElement.getFileName());
}
if (stElement.getLineNumber() >= 0) {
builder.field("line", stElement.getLineNumber());
}
builder.endObject();
}
}
}

View File

@ -1,35 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.rest;
/**
* Redirect to another web page
*/
public class HttpRedirectRestResponse extends StringRestResponse {
public HttpRedirectRestResponse(String url) {
super(RestStatus.MOVED_PERMANENTLY, "<head><meta http-equiv=\"refresh\" content=\"0; URL="+url+"\"></head>");
}
@Override
public String contentType() {
return "text/html";
}
}

View File

@ -142,7 +142,7 @@ public class RestController extends AbstractLifecycleComponent<RestController> {
executeHandler(request, channel);
} catch (Exception e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response for uri [" + request.uri() + "]", e1);
}
@ -160,10 +160,9 @@ public class RestController extends AbstractLifecycleComponent<RestController> {
} else {
if (request.method() == RestRequest.Method.OPTIONS) {
// when we have OPTIONS request, simply send OK by default (with the Access Control Origin header which gets automatically added)
StringRestResponse response = new StringRestResponse(OK);
channel.sendResponse(response);
channel.sendResponse(new BytesRestResponse(OK));
} else {
channel.sendResponse(new StringRestResponse(BAD_REQUEST, "No handler found for uri [" + request.uri() + "] and method [" + request.method() + "]"));
channel.sendResponse(new BytesRestResponse(BAD_REQUEST, "No handler found for uri [" + request.uri() + "] and method [" + request.method() + "]"));
}
}
}
@ -220,7 +219,7 @@ public class RestController extends AbstractLifecycleComponent<RestController> {
}
} catch (Exception e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response for uri [" + request.uri() + "]", e1);
}

View File

@ -19,53 +19,63 @@
package org.elasticsearch.rest;
import java.io.IOException;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.bytes.BytesReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
*/
public interface RestResponse {
public abstract class RestResponse {
protected Map<String, List<String>> customHeaders;
/**
* The response content type.
*/
public abstract String contentType();
/**
* Can the content byte[] be used only with this thread (<tt>false</tt>), or by any thread (<tt>true</tt>).
*/
boolean contentThreadSafe();
String contentType();
public abstract boolean contentThreadSafe();
/**
* Returns the actual content. Note, use {@link #contentLength()} in order to know the
* content length of the byte array.
* The response content. Note, if the content is {@link org.elasticsearch.common.lease.Releasable} it
* should automatically be released when done by the channel sending it.
*/
byte[] content() throws IOException;
public abstract BytesReference content();
/**
* The content length.
* The rest status code.
*/
int contentLength() throws IOException;
int contentOffset() throws IOException;
byte[] prefixContent();
int prefixContentLength();
int prefixContentOffset();
byte[] suffixContent();
int suffixContentLength();
int suffixContentOffset();
RestStatus status();
void addHeader(String name, String value);
public abstract RestStatus status();
/**
* @return The custom headers or null if none have been set
* Add a custom header.
*/
Map<String, List<String>> getHeaders();
public void addHeader(String name, String value) {
if (customHeaders == null) {
customHeaders = new HashMap<>(2);
}
List<String> header = customHeaders.get(name);
if (header == null) {
header = new ArrayList<>();
customHeaders.put(name, header);
}
header.add(value);
}
/**
* Returns custom headers that have been added, or null if none have been set.
*/
@Nullable
public Map<String, List<String>> getHeaders() {
return customHeaders;
}
}

View File

@ -1,116 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.rest;
import org.apache.lucene.util.BytesRef;
/**
* An http response that is built on top of {@link org.apache.lucene.util.BytesRef}.
* <p/>
* <p>Note, this class assumes that the utf8 result is not thread safe.
*/
public class Utf8RestResponse extends AbstractRestResponse implements RestResponse {
public static final BytesRef EMPTY = new BytesRef();
private final RestStatus status;
private final BytesRef utf8Result;
private final BytesRef prefixUtf8Result;
private final BytesRef suffixUtf8Result;
public Utf8RestResponse(RestStatus status) {
this(status, EMPTY);
}
public Utf8RestResponse(RestStatus status, BytesRef utf8Result) {
this(status, utf8Result, null, null);
}
public Utf8RestResponse(RestStatus status, BytesRef utf8Result,
BytesRef prefixUtf8Result, BytesRef suffixUtf8Result) {
this.status = status;
this.utf8Result = utf8Result;
this.prefixUtf8Result = prefixUtf8Result;
this.suffixUtf8Result = suffixUtf8Result;
}
@Override
public boolean contentThreadSafe() {
return true;
}
@Override
public String contentType() {
return "text/plain; charset=UTF-8";
}
@Override
public byte[] content() {
return utf8Result.bytes;
}
@Override
public int contentLength() {
return utf8Result.length;
}
@Override
public int contentOffset() {
return utf8Result.offset;
}
@Override
public RestStatus status() {
return status;
}
@Override
public byte[] prefixContent() {
return prefixUtf8Result != null ? prefixUtf8Result.bytes : null;
}
@Override
public int prefixContentLength() {
return prefixUtf8Result != null ? prefixUtf8Result.length : 0;
}
@Override
public int prefixContentOffset() {
return prefixUtf8Result != null ? prefixUtf8Result.offset : 0;
}
@Override
public byte[] suffixContent() {
return suffixUtf8Result != null ? suffixUtf8Result.bytes : null;
}
@Override
public int suffixContentLength() {
return suffixUtf8Result != null ? suffixUtf8Result.length : 0;
}
@Override
public int suffixContentOffset() {
return suffixUtf8Result != null ? suffixUtf8Result.offset : 0;
}
}

View File

@ -1,148 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.rest;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.UnicodeUtil;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
/**
*
*/
public class XContentRestResponse extends AbstractRestResponse {
private static final byte[] END_JSONP;
static {
BytesRef U_END_JSONP = new BytesRef();
UnicodeUtil.UTF16toUTF8(");", 0, ");".length(), U_END_JSONP);
END_JSONP = new byte[U_END_JSONP.length];
System.arraycopy(U_END_JSONP.bytes, U_END_JSONP.offset, END_JSONP, 0, U_END_JSONP.length);
}
private final BytesRef prefixUtf8Result;
private final RestStatus status;
private final XContentBuilder builder;
public XContentRestResponse(RestRequest request, RestStatus status, XContentBuilder builder) throws IOException {
if (request == null) {
throw new ElasticsearchIllegalArgumentException("request must be set");
}
this.builder = builder;
this.status = status;
this.prefixUtf8Result = startJsonp(request);
}
public XContentBuilder builder() {
return this.builder;
}
@Override
public String contentType() {
return builder.contentType().restContentType();
}
@Override
public boolean contentThreadSafe() {
return true;
}
@Override
public byte[] content() throws IOException {
return builder.bytes().array();
}
@Override
public int contentLength() throws IOException {
return builder.bytes().length();
}
@Override
public int contentOffset() throws IOException {
return 0;
}
@Override
public RestStatus status() {
return this.status;
}
@Override
public byte[] prefixContent() {
if (prefixUtf8Result != null) {
return prefixUtf8Result.bytes;
}
return null;
}
@Override
public int prefixContentLength() {
if (prefixUtf8Result != null) {
return prefixUtf8Result.length;
}
return 0;
}
@Override
public int prefixContentOffset() {
if (prefixUtf8Result != null) {
return prefixUtf8Result.offset;
}
return 0;
}
@Override
public byte[] suffixContent() {
if (prefixUtf8Result != null) {
return END_JSONP;
}
return null;
}
@Override
public int suffixContentLength() {
if (prefixUtf8Result != null) {
return END_JSONP.length;
}
return 0;
}
@Override
public int suffixContentOffset() {
return 0;
}
private static BytesRef startJsonp(RestRequest request) {
String callback = request.param("callback");
if (callback == null) {
return null;
}
final BytesRef result = new BytesRef();
UnicodeUtil.UTF16toUTF8(callback, 0, callback.length(), result);
result.bytes[result.length] = '(';
result.length++;
return result;
}
}

View File

@ -1,82 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.rest;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
import static org.elasticsearch.ExceptionsHelper.detailedMessage;
import static org.elasticsearch.rest.action.support.RestXContentBuilder.restContentBuilder;
/**
*
*/
public class XContentThrowableRestResponse extends XContentRestResponse {
public XContentThrowableRestResponse(RestRequest request, Throwable t) throws IOException {
this(request, ((t instanceof ElasticsearchException) ? ((ElasticsearchException) t).status() : RestStatus.INTERNAL_SERVER_ERROR), t);
}
public XContentThrowableRestResponse(RestRequest request, RestStatus status, Throwable t) throws IOException {
super(request, status, convert(request, status, t));
}
private static XContentBuilder convert(RestRequest request, RestStatus status, Throwable t) throws IOException {
XContentBuilder builder = restContentBuilder(request).startObject()
.field("error", detailedMessage(t))
.field("status", status.getStatus());
if (t != null && request.paramAsBoolean("error_trace", false)) {
builder.startObject("error_trace");
boolean first = true;
while (t != null) {
if (!first) {
builder.startObject("cause");
}
buildThrowable(t, builder);
if (!first) {
builder.endObject();
}
t = t.getCause();
first = false;
}
builder.endObject();
}
builder.endObject();
return builder;
}
private static void buildThrowable(Throwable t, XContentBuilder builder) throws IOException {
builder.field("message", t.getMessage());
for (StackTraceElement stElement : t.getStackTrace()) {
builder.startObject("at")
.field("class", stElement.getClassName())
.field("method", stElement.getMethodName());
if (stElement.getFileName() != null) {
builder.field("file", stElement.getFileName());
}
if (stElement.getLineNumber() >= 0) {
builder.field("line", stElement.getLineNumber());
}
builder.endObject();
}
}
}

View File

@ -68,7 +68,7 @@ public class RestClusterHealthAction extends BaseRestHandler {
} catch (Exception e) {
try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new XContentRestResponse(request, PRECONDITION_FAILED, builder.startObject().field("error", e.getMessage()).endObject()));
channel.sendResponse(new BytesRestResponse(PRECONDITION_FAILED, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
@ -90,7 +90,7 @@ public class RestClusterHealthAction extends BaseRestHandler {
response.toXContent(builder, request);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, status, builder));
channel.sendResponse(new BytesRestResponse(status, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -99,7 +99,7 @@ public class RestClusterHealthAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -69,7 +69,7 @@ public class RestNodesHotThreadsAction extends BaseRestHandler {
Strings.spaceify(3, node.getHotThreads(), sb);
sb.append('\n');
}
channel.sendResponse(new StringRestResponse(RestStatus.OK, sb.toString()));
channel.sendResponse(new BytesRestResponse(RestStatus.OK, sb.toString()));
} catch (Throwable e) {
onFailure(e);
}
@ -78,7 +78,7 @@ public class RestNodesHotThreadsAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -111,7 +111,7 @@ public class RestNodesInfoAction extends BaseRestHandler {
builder.startObject();
response.toXContent(builder, request);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, RestStatus.OK, builder));
channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -120,7 +120,7 @@ public class RestNodesInfoAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -69,7 +69,7 @@ public class RestNodesRestartAction extends BaseRestHandler {
builder.endObject();
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, RestStatus.OK, builder));
channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -78,7 +78,7 @@ public class RestNodesRestartAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -72,7 +72,7 @@ public class RestNodesShutdownAction extends BaseRestHandler {
builder.endObject();
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, RestStatus.OK, builder));
channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -81,7 +81,7 @@ public class RestNodesShutdownAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -119,7 +119,7 @@ public class RestNodesStatsAction extends BaseRestHandler {
builder.startObject();
response.toXContent(builder, request);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, RestStatus.OK, builder));
channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -128,7 +128,7 @@ public class RestNodesStatsAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -67,7 +67,7 @@ public class RestGetRepositoriesAction extends BaseRestHandler {
}
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -76,7 +76,7 @@ public class RestGetRepositoriesAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -59,7 +59,7 @@ public class RestClusterRerouteAction extends BaseRestHandler {
clusterRerouteRequest.source(request.content());
} catch (Exception e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.warn("Failed to send response", e1);
}

View File

@ -66,7 +66,7 @@ public class RestClusterGetSettingsAction extends BaseRestHandler {
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, RestStatus.OK, builder));
channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -75,7 +75,7 @@ public class RestClusterGetSettingsAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -58,7 +58,7 @@ public class RestClusterUpdateSettingsAction extends BaseRestHandler {
}
} catch (Exception e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.warn("Failed to send response", e1);
}

View File

@ -72,7 +72,7 @@ public class RestClusterSearchShardsAction extends BaseRestHandler {
builder.startObject();
response.toXContent(builder, request);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, RestStatus.OK, builder));
channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -81,7 +81,7 @@ public class RestClusterSearchShardsAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -63,7 +63,7 @@ public class RestCreateSnapshotAction extends BaseRestHandler {
builder.startObject();
response.toXContent(builder, request);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, response.status(), builder));
channel.sendResponse(new BytesRestResponse(response.status(), builder));
} catch (IOException e) {
onFailure(e);
}
@ -72,7 +72,7 @@ public class RestCreateSnapshotAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -65,7 +65,7 @@ public class RestGetSnapshotsAction extends BaseRestHandler {
builder.startObject();
response.toXContent(builder, request);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (IOException e) {
onFailure(e);
}
@ -74,7 +74,7 @@ public class RestGetSnapshotsAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -60,7 +60,7 @@ public class RestRestoreSnapshotAction extends BaseRestHandler {
builder.startObject();
response.toXContent(builder, request);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (IOException e) {
onFailure(e);
}
@ -69,7 +69,7 @@ public class RestRestoreSnapshotAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -67,7 +67,7 @@ public class RestSnapshotsStatusAction extends BaseRestHandler {
builder.startObject();
response.toXContent(builder, request);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (IOException e) {
onFailure(e);
}

View File

@ -87,7 +87,7 @@ public class RestClusterStateAction extends BaseRestHandler {
builder.field(Fields.CLUSTER_NAME, response.getClusterName().value());
response.getState().settingsFilter(settingsFilter).toXContent(builder, request);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, RestStatus.OK, builder));
channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -99,7 +99,7 @@ public class RestClusterStateAction extends BaseRestHandler {
logger.debug("failed to handle cluster state", e);
}
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -56,7 +56,7 @@ public class RestClusterStatsAction extends BaseRestHandler {
builder.startObject();
response.toXContent(builder, request);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, RestStatus.OK, builder));
channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -65,7 +65,7 @@ public class RestClusterStatsAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -55,7 +55,7 @@ public class RestPendingClusterTasksAction extends BaseRestHandler {
builder.startObject();
response.toXContent(builder, request);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, RestStatus.OK, builder));
channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -67,7 +67,7 @@ public class RestPendingClusterTasksAction extends BaseRestHandler {
logger.debug("failed to get pending cluster tasks", e);
}
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -133,7 +133,7 @@ public class RestIndicesAliasesAction extends BaseRestHandler {
}
} catch (Exception e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.warn("Failed to send response", e1);
}

View File

@ -72,7 +72,7 @@ public class RestGetAliasesAction extends BaseRestHandler {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
// empty body, if indices were specified but no aliases were
if (indices.length > 0 && response.getAliases().isEmpty()) {
channel.sendResponse(new XContentRestResponse(request, OK, RestXContentBuilder.emptyBuilder(request)));
channel.sendResponse(new BytesRestResponse(OK, RestXContentBuilder.emptyBuilder(request)));
return;
} else if (response.getAliases().isEmpty()) {
String message = String.format(Locale.ROOT, "alias [%s] missing", toNamesString(getAliasesRequest.aliases()));
@ -80,7 +80,7 @@ public class RestGetAliasesAction extends BaseRestHandler {
.field("error", message)
.field("status", RestStatus.NOT_FOUND.getStatus())
.endObject();
channel.sendResponse(new XContentRestResponse(request, RestStatus.NOT_FOUND, builder));
channel.sendResponse(new BytesRestResponse(RestStatus.NOT_FOUND, builder));
return;
}
@ -95,7 +95,7 @@ public class RestGetAliasesAction extends BaseRestHandler {
builder.endObject();
}
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -104,7 +104,7 @@ public class RestGetAliasesAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -92,7 +92,7 @@ public class RestGetIndicesAliasesAction extends BaseRestHandler {
}
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -101,7 +101,7 @@ public class RestGetIndicesAliasesAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -61,9 +61,9 @@ public class RestAliasesExistAction extends BaseRestHandler {
public void onResponse(AliasesExistResponse response) {
try {
if (response.isExists()) {
channel.sendResponse(new StringRestResponse(OK));
channel.sendResponse(new BytesRestResponse(OK));
} else {
channel.sendResponse(new StringRestResponse(NOT_FOUND));
channel.sendResponse(new BytesRestResponse(NOT_FOUND));
}
} catch (Throwable e) {
onFailure(e);
@ -73,7 +73,7 @@ public class RestAliasesExistAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new StringRestResponse(ExceptionsHelper.status(e)));
channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e)));
} catch (Exception e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -100,7 +100,7 @@ public class RestIndexPutAliasAction extends BaseRestHandler {
}
} catch (Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.warn("Failed to send response", e1);
}

View File

@ -57,7 +57,7 @@ public class RestAnalyzeAction extends BaseRestHandler {
}
if (text == null) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, new ElasticsearchIllegalArgumentException("text is missing")));
channel.sendResponse(new BytesRestResponse(request, new ElasticsearchIllegalArgumentException("text is missing")));
} catch (IOException e1) {
logger.warn("Failed to send response", e1);
}
@ -80,7 +80,7 @@ public class RestAnalyzeAction extends BaseRestHandler {
builder.startObject();
response.toXContent(builder, request);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -89,7 +89,7 @@ public class RestAnalyzeAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -94,7 +94,7 @@ public class RestClearIndicesCacheAction extends BaseRestHandler {
} catch (Exception e) {
try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new XContentRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
channel.sendResponse(new BytesRestResponse(BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
@ -110,7 +110,7 @@ public class RestClearIndicesCacheAction extends BaseRestHandler {
buildBroadcastShardsHeader(builder, response);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -119,7 +119,7 @@ public class RestClearIndicesCacheAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -50,7 +50,7 @@ public class RestCreateIndexAction extends BaseRestHandler {
createIndexRequest.source(request.content());
} catch (Exception e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.warn("Failed to send response", e1);
}

View File

@ -62,9 +62,9 @@ public class RestIndicesExistsAction extends BaseRestHandler {
public void onResponse(IndicesExistsResponse response) {
try {
if (response.isExists()) {
channel.sendResponse(new StringRestResponse(OK));
channel.sendResponse(new BytesRestResponse(OK));
} else {
channel.sendResponse(new StringRestResponse(NOT_FOUND));
channel.sendResponse(new BytesRestResponse(NOT_FOUND));
}
} catch (Throwable e) {
onFailure(e);
@ -74,7 +74,7 @@ public class RestIndicesExistsAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new StringRestResponse(ExceptionsHelper.status(e)));
channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e)));
} catch (Exception e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -57,9 +57,9 @@ public class RestTypesExistsAction extends BaseRestHandler {
public void onResponse(TypesExistsResponse response) {
try {
if (response.isExists()) {
channel.sendResponse(new StringRestResponse(OK));
channel.sendResponse(new BytesRestResponse(OK));
} else {
channel.sendResponse(new StringRestResponse(NOT_FOUND));
channel.sendResponse(new BytesRestResponse(NOT_FOUND));
}
} catch (Throwable e) {
onFailure(e);
@ -69,7 +69,7 @@ public class RestTypesExistsAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new StringRestResponse(ExceptionsHelper.status(e)));
channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e)));
} catch (Exception e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -77,7 +77,7 @@ public class RestFlushAction extends BaseRestHandler {
buildBroadcastShardsHeader(builder, response);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -86,7 +86,7 @@ public class RestFlushAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -76,7 +76,7 @@ public class RestGetFieldMappingAction extends BaseRestHandler {
boolean isPossibleSingleFieldRequest = indices.length == 1 && types.length == 1 && fields.length == 1;
if (isPossibleSingleFieldRequest && isFieldMappingMissingField(mappingsByIndex)) {
channel.sendResponse(new XContentRestResponse(request, OK, emptyBuilder(request)));
channel.sendResponse(new BytesRestResponse(OK, emptyBuilder(request)));
return;
}
@ -89,7 +89,7 @@ public class RestGetFieldMappingAction extends BaseRestHandler {
builder.startObject();
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, status, builder));
channel.sendResponse(new BytesRestResponse(status, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -98,7 +98,7 @@ public class RestGetFieldMappingAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -78,14 +78,14 @@ public class RestGetMappingAction extends BaseRestHandler {
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappingsByIndex = response.getMappings();
if (mappingsByIndex.isEmpty()) {
if (indices.length != 0 && types.length != 0) {
channel.sendResponse(new XContentRestResponse(request, OK, RestXContentBuilder.emptyBuilder(request)));
channel.sendResponse(new BytesRestResponse(OK, RestXContentBuilder.emptyBuilder(request)));
} else if (indices.length != 0) {
channel.sendResponse(new XContentThrowableRestResponse(request, new IndexMissingException(new Index(indices[0]))));
channel.sendResponse(new BytesRestResponse(request, new IndexMissingException(new Index(indices[0]))));
} else if (types.length != 0) {
channel.sendResponse(new XContentThrowableRestResponse(request, new TypeMissingException(new Index("_all"), types[0])));
channel.sendResponse(new BytesRestResponse(request, new TypeMissingException(new Index("_all"), types[0])));
} else {
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
}
return;
}
@ -105,7 +105,7 @@ public class RestGetMappingAction extends BaseRestHandler {
}
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -114,7 +114,7 @@ public class RestGetMappingAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -76,7 +76,7 @@ public class RestOptimizeAction extends BaseRestHandler {
} catch (Exception e) {
try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new XContentRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
channel.sendResponse(new BytesRestResponse(BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
@ -92,7 +92,7 @@ public class RestOptimizeAction extends BaseRestHandler {
buildBroadcastShardsHeader(builder, response);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -101,7 +101,7 @@ public class RestOptimizeAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -71,7 +71,7 @@ public class RestRecoveryAction extends BaseRestHandler {
response.toXContent(builder, request);
builder.endObject();
}
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -80,7 +80,7 @@ public class RestRecoveryAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException ioe) {
logger.error("Failed to send failure response", ioe);
}

View File

@ -76,7 +76,7 @@ public class RestRefreshAction extends BaseRestHandler {
buildBroadcastShardsHeader(builder, response);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -85,7 +85,7 @@ public class RestRefreshAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -69,7 +69,7 @@ public class RestIndicesSegmentsAction extends BaseRestHandler {
buildBroadcastShardsHeader(builder, response);
response.toXContent(builder, request);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -78,7 +78,7 @@ public class RestIndicesSegmentsAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -78,7 +78,7 @@ public class RestGetSettingsAction extends BaseRestHandler {
builder.endObject();
}
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (IOException e) {
onFailure(e);
}
@ -87,7 +87,7 @@ public class RestGetSettingsAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -72,7 +72,7 @@ public class RestUpdateSettingsAction extends BaseRestHandler {
}
} catch (Exception e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, BAD_REQUEST, new SettingsException("Failed to parse index settings", e)));
channel.sendResponse(new BytesRestResponse(request, BAD_REQUEST, new SettingsException("Failed to parse index settings", e)));
} catch (IOException e1) {
logger.warn("Failed to send response", e1);
}

View File

@ -109,7 +109,7 @@ public class RestIndicesStatsAction extends BaseRestHandler {
buildBroadcastShardsHeader(builder, response);
response.toXContent(builder, request);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -118,7 +118,7 @@ public class RestIndicesStatsAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -78,7 +78,7 @@ public class RestIndicesStatusAction extends BaseRestHandler {
buildBroadcastShardsHeader(builder, response);
response.toXContent(builder, request, settingsFilter);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -87,7 +87,7 @@ public class RestIndicesStatusAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -80,7 +80,7 @@ public class RestGetIndexTemplateAction extends BaseRestHandler {
RestStatus restStatus = (templateExists || implicitAll) ? OK : NOT_FOUND;
channel.sendResponse(new XContentRestResponse(request, restStatus, builder));
channel.sendResponse(new BytesRestResponse(restStatus, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -89,7 +89,7 @@ public class RestGetIndexTemplateAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (Exception e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -54,9 +54,9 @@ public class RestHeadIndexTemplateAction extends BaseRestHandler {
boolean templateExists = getIndexTemplatesResponse.getIndexTemplates().size() > 0;
if (templateExists) {
channel.sendResponse(new StringRestResponse(OK));
channel.sendResponse(new BytesRestResponse(OK));
} else {
channel.sendResponse(new StringRestResponse(NOT_FOUND));
channel.sendResponse(new BytesRestResponse(NOT_FOUND));
}
} catch (Throwable e) {
onFailure(e);
@ -66,7 +66,7 @@ public class RestHeadIndexTemplateAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new StringRestResponse(ExceptionsHelper.status(e)));
channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e)));
} catch (Exception e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -62,7 +62,7 @@ public class RestPutIndexTemplateAction extends BaseRestHandler {
putRequest.source(request.content());
} catch (Exception e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.warn("Failed to send response", e1);
}

View File

@ -93,7 +93,7 @@ public class RestValidateQueryAction extends BaseRestHandler {
} catch (Exception e) {
try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new XContentRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
channel.sendResponse(new BytesRestResponse(BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
@ -129,7 +129,7 @@ public class RestValidateQueryAction extends BaseRestHandler {
builder.endArray();
}
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -138,7 +138,7 @@ public class RestValidateQueryAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -70,7 +70,7 @@ public class RestGetWarmerAction extends BaseRestHandler {
public void onResponse(GetWarmersResponse response) {
try {
if (indices.length > 0 && response.warmers().isEmpty()) {
channel.sendResponse(new XContentRestResponse(request, OK, RestXContentBuilder.emptyBuilder(request)));
channel.sendResponse(new BytesRestResponse(OK, RestXContentBuilder.emptyBuilder(request)));
return;
}
@ -87,7 +87,7 @@ public class RestGetWarmerAction extends BaseRestHandler {
}
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -96,7 +96,7 @@ public class RestGetWarmerAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -95,7 +95,7 @@ public class RestBulkAction extends BaseRestHandler {
} catch (Exception e) {
try {
XContentBuilder builder = restContentBuilder(request);
channel.sendResponse(new XContentRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
channel.sendResponse(new BytesRestResponse(BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
@ -155,7 +155,7 @@ public class RestBulkAction extends BaseRestHandler {
builder.endArray();
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -164,7 +164,7 @@ public class RestBulkAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -36,7 +36,9 @@ public abstract class AbstractCatAction extends BaseRestHandler {
}
abstract void doRequest(final RestRequest request, final RestChannel channel);
abstract void documentation(StringBuilder sb);
abstract Table getTableWithHeader(final RestRequest request);
@Override
@ -55,7 +57,7 @@ public abstract class AbstractCatAction extends BaseRestHandler {
pad(new Table.Cell(cell.attr.containsKey("desc") ? cell.attr.get("desc") : "not available"), width[2], request, out);
out.append("\n");
}
channel.sendResponse(new StringRestResponse(RestStatus.OK, out.toString()));
channel.sendResponse(new BytesRestResponse(RestStatus.OK, out.toString()));
} else {
doRequest(request, channel);
}

View File

@ -28,10 +28,10 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.Table;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.XContentThrowableRestResponse;
import org.elasticsearch.rest.action.support.RestTable;
import java.io.IOException;
@ -73,7 +73,7 @@ public class RestAliasAction extends AbstractCatAction {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -34,10 +34,10 @@ import org.elasticsearch.common.Table;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.XContentThrowableRestResponse;
import org.elasticsearch.rest.action.support.RestTable;
import java.io.IOException;
@ -87,7 +87,7 @@ public class RestAllocationAction extends AbstractCatAction {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
@ -98,7 +98,7 @@ public class RestAllocationAction extends AbstractCatAction {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -50,10 +50,10 @@ public class RestCatAction extends BaseRestHandler {
@Override
public void handleRequest(final RestRequest request, final RestChannel channel) {
try {
channel.sendResponse(new StringRestResponse(RestStatus.OK, HELP));
channel.sendResponse(new BytesRestResponse(RestStatus.OK, HELP));
} catch (Throwable t) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, t));
channel.sendResponse(new BytesRestResponse(request, t));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -29,10 +29,10 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.Table;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.XContentThrowableRestResponse;
import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.rest.action.support.RestTable;
import org.joda.time.format.DateTimeFormat;
@ -87,7 +87,7 @@ public class RestCountAction extends AbstractCatAction {
@Override
public void onFailure(Throwable t) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, t));
channel.sendResponse(new BytesRestResponse(request, t));
} catch (IOException e) {
logger.error("Failed to send failure response", e);
}

View File

@ -26,10 +26,10 @@ import org.elasticsearch.client.Client;
import org.elasticsearch.common.Table;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.XContentThrowableRestResponse;
import org.elasticsearch.rest.action.support.RestTable;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
@ -70,7 +70,7 @@ public class RestHealthAction extends AbstractCatAction {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -91,7 +91,7 @@ public class RestIndicesAction extends AbstractCatAction {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
@ -103,7 +103,7 @@ public class RestIndicesAction extends AbstractCatAction {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
@ -114,7 +114,7 @@ public class RestIndicesAction extends AbstractCatAction {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -28,10 +28,10 @@ import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.common.Table;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.XContentThrowableRestResponse;
import org.elasticsearch.rest.action.support.RestTable;
import java.io.IOException;
@ -71,7 +71,7 @@ public class RestMasterAction extends AbstractCatAction {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -36,10 +36,10 @@ import org.elasticsearch.common.Table;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.XContentThrowableRestResponse;
import org.elasticsearch.rest.action.support.RestTable;
import java.io.IOException;
@ -90,7 +90,7 @@ public class RestNodesAction extends AbstractCatAction {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
@ -101,7 +101,7 @@ public class RestNodesAction extends AbstractCatAction {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
@ -112,7 +112,7 @@ public class RestNodesAction extends AbstractCatAction {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -65,7 +65,7 @@ public class RestPendingClusterTasksAction extends AbstractCatAction {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -30,10 +30,10 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.Table;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.XContentThrowableRestResponse;
import org.elasticsearch.rest.action.support.RestTable;
import org.apache.lucene.util.CollectionUtil;
@ -79,7 +79,7 @@ public class RestRecoveryAction extends AbstractCatAction {
channel.sendResponse(RestTable.buildResponse(buildRecoveryTable(request, response), request, channel));
} catch (Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e2) {
logger.error("Unable to send recovery status response", e2);
}
@ -89,7 +89,7 @@ public class RestRecoveryAction extends AbstractCatAction {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -78,7 +78,7 @@ public class RestSegmentsAction extends AbstractCatAction {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
@ -90,7 +90,7 @@ public class RestSegmentsAction extends AbstractCatAction {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -90,7 +90,7 @@ public class RestCountAction extends BaseRestHandler {
} catch (Exception e) {
try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new XContentRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
channel.sendResponse(new BytesRestResponse(BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
@ -108,7 +108,7 @@ public class RestCountAction extends BaseRestHandler {
buildBroadcastShardsHeader(builder, response);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, response.status(), builder));
channel.sendResponse(new BytesRestResponse(response.status(), builder));
} catch (Throwable e) {
onFailure(e);
}
@ -117,7 +117,7 @@ public class RestCountAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -90,7 +90,7 @@ public class RestDeleteAction extends BaseRestHandler {
if (!result.isFound()) {
status = NOT_FOUND;
}
channel.sendResponse(new XContentRestResponse(request, status, builder));
channel.sendResponse(new BytesRestResponse(status, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -99,7 +99,7 @@ public class RestDeleteAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -90,7 +90,7 @@ public class RestDeleteByQueryAction extends BaseRestHandler {
} catch (Exception e) {
try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new XContentRestResponse(request, PRECONDITION_FAILED, builder.startObject().field("error", e.getMessage()).endObject()));
channel.sendResponse(new BytesRestResponse(PRECONDITION_FAILED, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
@ -129,7 +129,7 @@ public class RestDeleteByQueryAction extends BaseRestHandler {
}
builder.endObject();
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, restStatus, builder));
channel.sendResponse(new BytesRestResponse(restStatus, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -138,7 +138,7 @@ public class RestDeleteByQueryAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -127,7 +127,7 @@ public class RestExplainAction extends BaseRestHandler {
builder.endObject();
}
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, response.isExists() ? OK : NOT_FOUND, builder));
channel.sendResponse(new BytesRestResponse(response.isExists() ? OK : NOT_FOUND, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -151,7 +151,7 @@ public class RestExplainAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -82,9 +82,9 @@ public class RestGetAction extends BaseRestHandler {
XContentBuilder builder = restContentBuilder(request);
response.toXContent(builder, request);
if (!response.isExists()) {
channel.sendResponse(new XContentRestResponse(request, NOT_FOUND, builder));
channel.sendResponse(new BytesRestResponse(NOT_FOUND, builder));
} else {
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
}
} catch (Throwable e) {
onFailure(e);
@ -94,7 +94,7 @@ public class RestGetAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -66,7 +66,7 @@ public class RestGetSourceAction extends BaseRestHandler {
try {
ActionRequestValidationException validationError = new ActionRequestValidationException();
validationError.addValidationError("fetching source can not be disabled");
channel.sendResponse(new XContentThrowableRestResponse(request, validationError));
channel.sendResponse(new BytesRestResponse(request, validationError));
} catch (IOException e) {
logger.error("Failed to send failure response", e);
}
@ -79,10 +79,10 @@ public class RestGetSourceAction extends BaseRestHandler {
try {
XContentBuilder builder = restContentBuilder(request, response.getSourceInternal());
if (!response.isExists()) {
channel.sendResponse(new XContentRestResponse(request, NOT_FOUND, builder));
channel.sendResponse(new BytesRestResponse(NOT_FOUND, builder));
} else {
RestXContentBuilder.directSource(response.getSourceInternal(), builder, request);
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
}
} catch (Throwable e) {
onFailure(e);
@ -92,7 +92,7 @@ public class RestGetSourceAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -64,9 +64,9 @@ public class RestHeadAction extends BaseRestHandler {
public void onResponse(GetResponse response) {
try {
if (!response.isExists()) {
channel.sendResponse(new StringRestResponse(NOT_FOUND));
channel.sendResponse(new BytesRestResponse(NOT_FOUND));
} else {
channel.sendResponse(new StringRestResponse(OK));
channel.sendResponse(new BytesRestResponse(OK));
}
} catch (Throwable e) {
onFailure(e);
@ -76,7 +76,7 @@ public class RestHeadAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new StringRestResponse(ExceptionsHelper.status(e)));
channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e)));
} catch (Exception e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -77,7 +77,7 @@ public class RestMultiGetAction extends BaseRestHandler {
} catch (Exception e) {
try {
XContentBuilder builder = restContentBuilder(request);
channel.sendResponse(new XContentRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
channel.sendResponse(new BytesRestResponse(BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
@ -90,7 +90,7 @@ public class RestMultiGetAction extends BaseRestHandler {
try {
XContentBuilder builder = restContentBuilder(request);
response.toXContent(builder, request);
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -99,7 +99,7 @@ public class RestMultiGetAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -88,7 +88,7 @@ public class RestIndexAction extends BaseRestHandler {
} else {
try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new XContentRestResponse(request, BAD_REQUEST, builder.startObject().field("error", "opType [" + sOpType + "] not allowed, either [index] or [create] are allowed").endObject()));
channel.sendResponse(new BytesRestResponse(BAD_REQUEST, builder.startObject().field("error", "opType [" + sOpType + "] not allowed, either [index] or [create] are allowed").endObject()));
} catch (IOException e1) {
logger.warn("Failed to send response", e1);
return;
@ -119,7 +119,7 @@ public class RestIndexAction extends BaseRestHandler {
if (response.isCreated()) {
status = CREATED;
}
channel.sendResponse(new XContentRestResponse(request, status, builder));
channel.sendResponse(new BytesRestResponse(status, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -128,7 +128,7 @@ public class RestIndexAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -67,7 +67,7 @@ public class RestMainAction extends BaseRestHandler {
status = RestStatus.SERVICE_UNAVAILABLE;
}
if (request.method() == RestRequest.Method.HEAD) {
channel.sendResponse(new StringRestResponse(status));
channel.sendResponse(new BytesRestResponse(status));
return;
}
@ -97,7 +97,7 @@ public class RestMainAction extends BaseRestHandler {
.endObject();
builder.field("tagline", "You Know, for Search");
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, status, builder));
channel.sendResponse(new BytesRestResponse(status, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -107,9 +107,9 @@ public class RestMainAction extends BaseRestHandler {
public void onFailure(Throwable e) {
try {
if (request.method() == HEAD) {
channel.sendResponse(new StringRestResponse(ExceptionsHelper.status(e)));
channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e)));
} else {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
}
} catch (Exception e1) {
logger.warn("Failed to send response", e);

View File

@ -94,7 +94,7 @@ public class RestMoreLikeThisAction extends BaseRestHandler {
} catch (Exception e) {
try {
XContentBuilder builder = restContentBuilder(request);
channel.sendResponse(new XContentRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
channel.sendResponse(new BytesRestResponse(BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
@ -109,7 +109,7 @@ public class RestMoreLikeThisAction extends BaseRestHandler {
builder.startObject();
response.toXContent(builder, request);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -118,7 +118,7 @@ public class RestMoreLikeThisAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -69,7 +69,7 @@ public class RestMultiPercolateAction extends BaseRestHandler {
multiPercolateRequest.add(RestActions.getRestContent(restRequest), restRequest.contentUnsafe(), allowExplicitIndex);
} catch (Exception e) {
try {
restChannel.sendResponse(new XContentThrowableRestResponse(restRequest, e));
restChannel.sendResponse(new BytesRestResponse(restRequest, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
@ -83,7 +83,7 @@ public class RestMultiPercolateAction extends BaseRestHandler {
try {
XContentBuilder builder = restContentBuilder(restRequest);
response.toXContent(builder, restRequest);
restChannel.sendResponse(new XContentRestResponse(restRequest, OK, builder));
restChannel.sendResponse(new BytesRestResponse(OK, builder));
} catch (IOException e) {
onFailure(e);
}
@ -92,7 +92,7 @@ public class RestMultiPercolateAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
restChannel.sendResponse(new XContentThrowableRestResponse(restRequest, e));
restChannel.sendResponse(new BytesRestResponse(restRequest, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -118,7 +118,7 @@ public class RestPercolateAction extends BaseRestHandler {
try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(restRequest);
response.toXContent(builder, restRequest);
restChannel.sendResponse(new XContentRestResponse(restRequest, OK, builder));
restChannel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -127,7 +127,7 @@ public class RestPercolateAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
restChannel.sendResponse(new XContentThrowableRestResponse(restRequest, e));
restChannel.sendResponse(new BytesRestResponse(restRequest, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -62,7 +62,7 @@ public class RestClearScrollAction extends BaseRestHandler {
XContentBuilder builder = restContentBuilder(request);
builder.startObject();
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -71,7 +71,7 @@ public class RestClearScrollAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -73,7 +73,7 @@ public class RestMultiSearchAction extends BaseRestHandler {
} catch (Exception e) {
try {
XContentBuilder builder = restContentBuilder(request);
channel.sendResponse(new XContentRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
channel.sendResponse(new BytesRestResponse(BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
@ -88,7 +88,7 @@ public class RestMultiSearchAction extends BaseRestHandler {
builder.startObject();
response.toXContent(builder, request);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -97,7 +97,7 @@ public class RestMultiSearchAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -89,7 +89,7 @@ public class RestSearchAction extends BaseRestHandler {
}
try {
XContentBuilder builder = restContentBuilder(request);
channel.sendResponse(new XContentRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
channel.sendResponse(new BytesRestResponse(BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
@ -103,7 +103,7 @@ public class RestSearchAction extends BaseRestHandler {
builder.startObject();
response.toXContent(builder, request);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, response.status(), builder));
channel.sendResponse(new BytesRestResponse(response.status(), builder));
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("failed to execute search (building response)", e);
@ -115,7 +115,7 @@ public class RestSearchAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -78,7 +78,7 @@ public class RestSearchScrollAction extends BaseRestHandler {
} catch (Exception e) {
try {
XContentBuilder builder = restContentBuilder(request);
channel.sendResponse(new XContentRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
channel.sendResponse(new BytesRestResponse(BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
@ -93,7 +93,7 @@ public class RestSearchScrollAction extends BaseRestHandler {
builder.startObject();
response.toXContent(builder, request);
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, response.status(), builder));
channel.sendResponse(new BytesRestResponse(response.status(), builder));
} catch (Throwable e) {
onFailure(e);
}
@ -102,7 +102,7 @@ public class RestSearchScrollAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -83,7 +83,7 @@ public class RestSuggestAction extends BaseRestHandler {
} catch (Exception e) {
try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new XContentRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
channel.sendResponse(new BytesRestResponse(BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}
@ -102,7 +102,7 @@ public class RestSuggestAction extends BaseRestHandler {
suggest.toXContent(builder, request);
}
builder.endObject();
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -111,7 +111,7 @@ public class RestSuggestAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -58,7 +58,7 @@ public class RestTable {
}
builder.endArray();
return new XContentRestResponse(request, RestStatus.OK, builder);
return new BytesRestResponse(RestStatus.OK, builder);
}
public static RestResponse buildTextPlainResponse(Table table, RestRequest request, RestChannel channel) {
@ -86,7 +86,7 @@ public class RestTable {
out.append("\n");
}
return new StringRestResponse(RestStatus.OK, out.toString());
return new BytesRestResponse(RestStatus.OK, out.toString());
}
private static List<DisplayHeader> buildDisplayHeaders(Table table, RestRequest request) {

View File

@ -64,7 +64,7 @@ public class RestMultiTermVectorsAction extends BaseRestHandler {
multiTermVectorsRequest.add(template, RestActions.getRestContent(request));
} catch (Throwable t) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, t));
channel.sendResponse(new BytesRestResponse(request, t));
} catch (Throwable tIO) {
logger.error("Failed to send failure response", tIO);
}
@ -77,7 +77,7 @@ public class RestMultiTermVectorsAction extends BaseRestHandler {
try {
XContentBuilder builder = restContentBuilder(request);
response.toXContent(builder, request);
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable t) {
onFailure(t);
}
@ -86,7 +86,7 @@ public class RestMultiTermVectorsAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (Throwable t) {
logger.error("Failed to send failure response", t);
}

View File

@ -67,7 +67,7 @@ public class RestTermVectorAction extends BaseRestHandler {
} catch (IOException e) {
try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new XContentRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
channel.sendResponse(new BytesRestResponse(BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) {
logger.warn("Failed to send response", e1);
@ -87,7 +87,7 @@ public class RestTermVectorAction extends BaseRestHandler {
try {
XContentBuilder builder = restContentBuilder(request);
response.toXContent(builder, request);
channel.sendResponse(new XContentRestResponse(request, OK, builder));
channel.sendResponse(new BytesRestResponse(OK, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -96,7 +96,7 @@ public class RestTermVectorAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -117,7 +117,7 @@ public class RestUpdateAction extends BaseRestHandler {
}
} catch (Exception e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.warn("Failed to send response", e1);
}
@ -147,7 +147,7 @@ public class RestUpdateAction extends BaseRestHandler {
if (response.isCreated()) {
status = CREATED;
}
channel.sendResponse(new XContentRestResponse(request, status, builder));
channel.sendResponse(new BytesRestResponse(status, builder));
} catch (Throwable e) {
onFailure(e);
}
@ -156,7 +156,7 @@ public class RestUpdateAction extends BaseRestHandler {
@Override
public void onFailure(Throwable e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, e));
channel.sendResponse(new BytesRestResponse(request, e));
} catch (IOException e1) {
logger.error("Failed to send failure response", e1);
}

View File

@ -34,11 +34,11 @@ public class TestResponseHeaderRestAction extends BaseRestHandler {
@Override
public void handleRequest(RestRequest request, RestChannel channel) {
if ("password".equals(request.header("Secret"))) {
RestResponse response = new StringRestResponse(RestStatus.OK, "Access granted");
RestResponse response = new BytesRestResponse(RestStatus.OK, "Access granted");
response.addHeader("Secret", "granted");
channel.sendResponse(response);
} else {
RestResponse response = new StringRestResponse(RestStatus.UNAUTHORIZED, "Access denied");
RestResponse response = new BytesRestResponse(RestStatus.UNAUTHORIZED, "Access denied");
response.addHeader("Secret", "required");
channel.sendResponse(response);
}