continue abstracting json into xcontent

This commit is contained in:
kimchy 2010-04-29 00:34:25 +03:00
parent 37dfc443aa
commit cfc8ec5165
44 changed files with 186 additions and 141 deletions

View File

@ -27,6 +27,8 @@ import org.elasticsearch.util.io.stream.StreamInput;
import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.StreamOutput;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.json.ToJson; import org.elasticsearch.util.json.ToJson;
import org.elasticsearch.util.xcontent.ToXContent;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -38,7 +40,7 @@ import static org.elasticsearch.search.internal.InternalSearchResponse.*;
* *
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
*/ */
public class SearchResponse implements ActionResponse, ToJson { public class SearchResponse implements ActionResponse, ToXContent {
private InternalSearchResponse internalResponse; private InternalSearchResponse internalResponse;
@ -161,7 +163,7 @@ public class SearchResponse implements ActionResponse, ToJson {
return scrollId; return scrollId;
} }
@Override public void toJson(JsonBuilder builder, Params params) throws IOException { @Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
if (scrollId != null) { if (scrollId != null) {
builder.field("_scrollId", scrollId); builder.field("_scrollId", scrollId);
} }
@ -185,7 +187,7 @@ public class SearchResponse implements ActionResponse, ToJson {
} }
builder.endObject(); builder.endObject();
internalResponse.toJson(builder, params); internalResponse.toXContent(builder, params);
} }
public static SearchResponse readSearchResponse(StreamInput in) throws IOException { public static SearchResponse readSearchResponse(StreamInput in) throws IOException {

View File

@ -21,7 +21,7 @@ package org.elasticsearch.rest;
import org.apache.lucene.util.UnicodeUtil; import org.apache.lucene.util.UnicodeUtil;
import org.elasticsearch.util.ThreadLocals; import org.elasticsearch.util.ThreadLocals;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -49,16 +49,16 @@ public class JsonRestResponse extends AbstractRestResponse {
private final Status status; private final Status status;
private final JsonBuilder jsonBuilder; private final XContentBuilder builder;
public JsonRestResponse(RestRequest request, Status status) { public JsonRestResponse(RestRequest request, Status status) {
this.jsonBuilder = null; this.builder = null;
this.status = status; this.status = status;
this.prefixUtf8Result = startJsonp(request); this.prefixUtf8Result = startJsonp(request);
} }
public JsonRestResponse(RestRequest request, Status status, JsonBuilder jsonBuilder) throws IOException { public JsonRestResponse(RestRequest request, Status status, XContentBuilder builder) throws IOException {
this.jsonBuilder = jsonBuilder; this.builder = builder;
this.status = status; this.status = status;
this.prefixUtf8Result = startJsonp(request); this.prefixUtf8Result = startJsonp(request);
} }
@ -72,11 +72,11 @@ public class JsonRestResponse extends AbstractRestResponse {
} }
@Override public byte[] content() throws IOException { @Override public byte[] content() throws IOException {
return jsonBuilder.unsafeBytes(); return builder.unsafeBytes();
} }
@Override public int contentLength() throws IOException { @Override public int contentLength() throws IOException {
return jsonBuilder.unsafeBytesLength(); return builder.unsafeBytesLength();
} }
@Override public Status status() { @Override public Status status() {

View File

@ -19,12 +19,12 @@
package org.elasticsearch.rest; package org.elasticsearch.rest;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.ExceptionsHelper.*; import static org.elasticsearch.ExceptionsHelper.*;
import static org.elasticsearch.util.json.JsonBuilder.*; import static org.elasticsearch.rest.action.support.RestXContentBuilder.*;
/** /**
* @author kimchy (Shay Banon) * @author kimchy (Shay Banon)
@ -39,8 +39,8 @@ public class JsonThrowableRestResponse extends JsonRestResponse {
super(request, status, convert(request, t)); super(request, status, convert(request, t));
} }
private static JsonBuilder convert(RestRequest request, Throwable t) throws IOException { private static XContentBuilder convert(RestRequest request, Throwable t) throws IOException {
JsonBuilder builder = binaryJsonBuilder().prettyPrint() XContentBuilder builder = restContentBuilder(request)
.startObject().field("error", detailedMessage(t)); .startObject().field("error", detailedMessage(t));
if (t != null && request.paramAsBoolean("error_trace", false)) { if (t != null && request.paramAsBoolean("error_trace", false)) {
builder.startObject("error_trace"); builder.startObject("error_trace");
@ -62,7 +62,7 @@ public class JsonThrowableRestResponse extends JsonRestResponse {
return builder; return builder;
} }
private static void buildThrowable(Throwable t, JsonBuilder builder) throws IOException { private static void buildThrowable(Throwable t, XContentBuilder builder) throws IOException {
builder.field("message", t.getMessage()); builder.field("message", t.getMessage());
for (StackTraceElement stElement : t.getStackTrace()) { for (StackTraceElement stElement : t.getStackTrace()) {
builder.startObject("at") builder.startObject("at")

View File

@ -21,7 +21,7 @@ package org.elasticsearch.rest;
import org.elasticsearch.util.SizeValue; import org.elasticsearch.util.SizeValue;
import org.elasticsearch.util.TimeValue; import org.elasticsearch.util.TimeValue;
import org.elasticsearch.util.json.ToJson; import org.elasticsearch.util.xcontent.ToXContent;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
@ -31,7 +31,7 @@ import java.util.Set;
/** /**
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
*/ */
public interface RestRequest extends ToJson.Params { public interface RestRequest extends ToXContent.Params {
enum Method { enum Method {
GET, POST, PUT, DELETE GET, POST, PUT, DELETE

View File

@ -19,15 +19,16 @@
package org.elasticsearch.rest.action.admin.cluster.health; package org.elasticsearch.rest.action.admin.cluster.health;
import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.health.*; import org.elasticsearch.action.admin.cluster.health.*;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.rest.action.support.RestJsonBuilder;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -68,7 +69,7 @@ public class RestClusterHealthAction extends BaseRestHandler {
} }
} catch (Exception e) { } catch (Exception e) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new JsonRestResponse(request, PRECONDITION_FAILED, builder.startObject().field("error", e.getMessage()).endObject())); channel.sendResponse(new JsonRestResponse(request, PRECONDITION_FAILED, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) { } catch (IOException e1) {
logger.error("Failed to send failure response", e1); logger.error("Failed to send failure response", e1);
@ -79,7 +80,7 @@ public class RestClusterHealthAction extends BaseRestHandler {
client.admin().cluster().health(clusterHealthRequest, new ActionListener<ClusterHealthResponse>() { client.admin().cluster().health(clusterHealthRequest, new ActionListener<ClusterHealthResponse>() {
@Override public void onResponse(ClusterHealthResponse response) { @Override public void onResponse(ClusterHealthResponse response) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject(); builder.startObject();
builder.field("status", response.status().name().toLowerCase()); builder.field("status", response.status().name().toLowerCase());

View File

@ -19,6 +19,7 @@
package org.elasticsearch.rest.action.admin.cluster.node.info; package org.elasticsearch.rest.action.admin.cluster.node.info;
import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
@ -27,9 +28,9 @@ import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.rest.action.support.RestJsonBuilder;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
@ -54,7 +55,7 @@ public class RestNodesInfoAction extends BaseRestHandler {
client.admin().cluster().nodesInfo(nodesInfoRequest, new ActionListener<NodesInfoResponse>() { client.admin().cluster().nodesInfo(nodesInfoRequest, new ActionListener<NodesInfoResponse>() {
@Override public void onResponse(NodesInfoResponse result) { @Override public void onResponse(NodesInfoResponse result) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject(); builder.startObject();
builder.field("cluster_name", result.clusterName().value()); builder.field("cluster_name", result.clusterName().value());

View File

@ -19,6 +19,7 @@
package org.elasticsearch.rest.action.admin.cluster.node.shutdown; package org.elasticsearch.rest.action.admin.cluster.node.shutdown;
import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.node.shutdown.NodesShutdownRequest; import org.elasticsearch.action.admin.cluster.node.shutdown.NodesShutdownRequest;
@ -26,12 +27,14 @@ import org.elasticsearch.action.admin.cluster.node.shutdown.NodesShutdownRespons
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.rest.action.support.RestJsonBuilder;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.rest.action.support.RestXContentBuilder.restContentBuilder;
/** /**
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
*/ */
@ -52,7 +55,7 @@ public class RestNodesShutdownAction extends BaseRestHandler {
client.admin().cluster().nodesShutdown(nodesShutdownRequest, new ActionListener<NodesShutdownResponse>() { client.admin().cluster().nodesShutdown(nodesShutdownRequest, new ActionListener<NodesShutdownResponse>() {
@Override public void onResponse(NodesShutdownResponse result) { @Override public void onResponse(NodesShutdownResponse result) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = restContentBuilder(request);
builder.startObject(); builder.startObject();
builder.field("cluster_name", result.clusterName().value()); builder.field("cluster_name", result.clusterName().value());

View File

@ -27,9 +27,10 @@ import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -59,7 +60,7 @@ public class RestBroadcastPingAction extends BaseRestHandler {
client.admin().cluster().ping(broadcastPingRequest, new ActionListener<BroadcastPingResponse>() { client.admin().cluster().ping(broadcastPingRequest, new ActionListener<BroadcastPingResponse>() {
@Override public void onResponse(BroadcastPingResponse response) { @Override public void onResponse(BroadcastPingResponse response) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject(); builder.startObject();
builder.field("ok", true); builder.field("ok", true);
buildBroadcastShardsHeader(builder, response); buildBroadcastShardsHeader(builder, response);

View File

@ -28,9 +28,10 @@ import org.elasticsearch.action.admin.cluster.ping.replication.ShardReplicationP
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -54,7 +55,7 @@ public class RestReplicationPingAction extends BaseRestHandler {
client.admin().cluster().ping(replicationPingRequest, new ActionListener<ReplicationPingResponse>() { client.admin().cluster().ping(replicationPingRequest, new ActionListener<ReplicationPingResponse>() {
@Override public void onResponse(ReplicationPingResponse result) { @Override public void onResponse(ReplicationPingResponse result) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject(); builder.startObject();
builder.field("ok", true); builder.field("ok", true);
for (IndexReplicationPingResponse indexResponse : result.indices().values()) { for (IndexReplicationPingResponse indexResponse : result.indices().values()) {

View File

@ -19,15 +19,16 @@
package org.elasticsearch.rest.action.admin.cluster.ping.single; package org.elasticsearch.rest.action.admin.cluster.ping.single;
import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.ping.single.SinglePingRequest; import org.elasticsearch.action.admin.cluster.ping.single.SinglePingRequest;
import org.elasticsearch.action.admin.cluster.ping.single.SinglePingResponse; import org.elasticsearch.action.admin.cluster.ping.single.SinglePingResponse;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestJsonBuilder;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -53,7 +54,7 @@ public class RestSinglePingAction extends BaseRestHandler {
client.admin().cluster().ping(singlePingRequest, new ActionListener<SinglePingResponse>() { client.admin().cluster().ping(singlePingRequest, new ActionListener<SinglePingResponse>() {
@Override public void onResponse(SinglePingResponse result) { @Override public void onResponse(SinglePingResponse result) {
try { try {
JsonBuilder generator = RestJsonBuilder.restJsonBuilder(request); XContentBuilder generator = RestXContentBuilder.restContentBuilder(request);
generator.startObject().field("ok", true).endObject(); generator.startObject().field("ok", true).endObject();
channel.sendResponse(new JsonRestResponse(request, OK, generator)); channel.sendResponse(new JsonRestResponse(request, OK, generator));
} catch (Exception e) { } catch (Exception e) {

View File

@ -19,7 +19,6 @@
package org.elasticsearch.rest.action.admin.cluster.state; package org.elasticsearch.rest.action.admin.cluster.state;
import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
@ -31,9 +30,10 @@ import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.cluster.routing.RoutingNode;
import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
@ -54,7 +54,7 @@ public class RestClusterStateAction extends BaseRestHandler {
@Override public void onResponse(ClusterStateResponse response) { @Override public void onResponse(ClusterStateResponse response) {
try { try {
ClusterState state = response.state(); ClusterState state = response.state();
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject(); builder.startObject();
// meta data // meta data
@ -125,7 +125,7 @@ public class RestClusterStateAction extends BaseRestHandler {
} }
} }
private void jsonShardRouting(JsonBuilder builder, ShardRouting shardRouting) throws IOException { private void jsonShardRouting(XContentBuilder builder, ShardRouting shardRouting) throws IOException {
builder.startObject() builder.startObject()
.field("state", shardRouting.state()) .field("state", shardRouting.state())
.field("primary", shardRouting.primary()) .field("primary", shardRouting.primary())

View File

@ -19,7 +19,6 @@
package org.elasticsearch.rest.action.admin.indices.alias; package org.elasticsearch.rest.action.admin.indices.alias;
import org.elasticsearch.util.guice.inject.Inject;
import org.codehaus.jackson.JsonParser; import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken; import org.codehaus.jackson.JsonToken;
import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.ElasticSearchIllegalArgumentException;
@ -29,15 +28,16 @@ import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.AliasAction; import org.elasticsearch.cluster.metadata.AliasAction;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.util.json.Jackson; import org.elasticsearch.util.json.Jackson;
import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.rest.RestRequest.Method.*; import static org.elasticsearch.rest.RestRequest.Method.*;
import static org.elasticsearch.rest.RestResponse.Status.*; import static org.elasticsearch.rest.RestResponse.Status.*;
import static org.elasticsearch.rest.action.support.RestXContentBuilder.*;
/** /**
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
@ -116,7 +116,7 @@ public class RestIndicesAliasesAction extends BaseRestHandler {
client.admin().indices().aliases(indicesAliasesRequest, new ActionListener<IndicesAliasesResponse>() { client.admin().indices().aliases(indicesAliasesRequest, new ActionListener<IndicesAliasesResponse>() {
@Override public void onResponse(IndicesAliasesResponse response) { @Override public void onResponse(IndicesAliasesResponse response) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = restContentBuilder(request);
builder.startObject() builder.startObject()
.field("ok", true) .field("ok", true)
.endObject(); .endObject();

View File

@ -19,6 +19,7 @@
package org.elasticsearch.rest.action.admin.indices.cache.clear; package org.elasticsearch.rest.action.admin.indices.cache.clear;
import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest; import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest;
@ -27,9 +28,8 @@ import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.rest.action.support.RestJsonBuilder;
import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -66,7 +66,7 @@ public class RestClearIndicesCacheAction extends BaseRestHandler {
clearIndicesCacheRequest.operationThreading(operationThreading); clearIndicesCacheRequest.operationThreading(operationThreading);
} catch (Exception e) { } catch (Exception e) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject())); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) { } catch (IOException e1) {
logger.error("Failed to send failure response", e1); logger.error("Failed to send failure response", e1);
@ -76,7 +76,7 @@ public class RestClearIndicesCacheAction extends BaseRestHandler {
client.admin().indices().clearCache(clearIndicesCacheRequest, new ActionListener<ClearIndicesCacheResponse>() { client.admin().indices().clearCache(clearIndicesCacheRequest, new ActionListener<ClearIndicesCacheResponse>() {
@Override public void onResponse(ClearIndicesCacheResponse response) { @Override public void onResponse(ClearIndicesCacheResponse response) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject(); builder.startObject();
builder.field("ok", true); builder.field("ok", true);

View File

@ -19,7 +19,6 @@
package org.elasticsearch.rest.action.admin.indices.create; package org.elasticsearch.rest.action.admin.indices.create;
import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
@ -27,12 +26,13 @@ import org.elasticsearch.client.Client;
import org.elasticsearch.indices.IndexAlreadyExistsException; import org.elasticsearch.indices.IndexAlreadyExistsException;
import org.elasticsearch.indices.InvalidIndexNameException; import org.elasticsearch.indices.InvalidIndexNameException;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.Strings; import org.elasticsearch.util.Strings;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.util.settings.ImmutableSettings; import org.elasticsearch.util.settings.ImmutableSettings;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.settings.SettingsException; import org.elasticsearch.util.settings.SettingsException;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -71,7 +71,7 @@ public class RestCreateIndexAction extends BaseRestHandler {
client.admin().indices().create(createIndexRequest, new ActionListener<CreateIndexResponse>() { client.admin().indices().create(createIndexRequest, new ActionListener<CreateIndexResponse>() {
@Override public void onResponse(CreateIndexResponse response) { @Override public void onResponse(CreateIndexResponse response) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject() builder.startObject()
.field("ok", true) .field("ok", true)
.field("acknowledged", response.acknowledged()) .field("acknowledged", response.acknowledged())
@ -86,7 +86,7 @@ public class RestCreateIndexAction extends BaseRestHandler {
try { try {
Throwable t = unwrapCause(e); Throwable t = unwrapCause(e);
if (t instanceof IndexAlreadyExistsException || t instanceof InvalidIndexNameException) { if (t instanceof IndexAlreadyExistsException || t instanceof InvalidIndexNameException) {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", t.getMessage()).endObject())); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", t.getMessage()).endObject()));
} else { } else {
channel.sendResponse(new JsonThrowableRestResponse(request, e)); channel.sendResponse(new JsonThrowableRestResponse(request, e));

View File

@ -19,6 +19,7 @@
package org.elasticsearch.rest.action.admin.indices.delete; package org.elasticsearch.rest.action.admin.indices.delete;
import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
@ -26,9 +27,9 @@ import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestJsonBuilder;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -52,7 +53,7 @@ public class RestDeleteIndexAction extends BaseRestHandler {
client.admin().indices().delete(deleteIndexRequest, new ActionListener<DeleteIndexResponse>() { client.admin().indices().delete(deleteIndexRequest, new ActionListener<DeleteIndexResponse>() {
@Override public void onResponse(DeleteIndexResponse response) { @Override public void onResponse(DeleteIndexResponse response) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject() builder.startObject()
.field("ok", true) .field("ok", true)
.field("acknowledged", response.acknowledged()) .field("acknowledged", response.acknowledged())
@ -67,7 +68,7 @@ public class RestDeleteIndexAction extends BaseRestHandler {
try { try {
Throwable t = unwrapCause(e); Throwable t = unwrapCause(e);
if (t instanceof IndexMissingException) { if (t instanceof IndexMissingException) {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", t.getMessage()).endObject())); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", t.getMessage()).endObject()));
} else { } else {
channel.sendResponse(new JsonThrowableRestResponse(request, e)); channel.sendResponse(new JsonThrowableRestResponse(request, e));

View File

@ -19,6 +19,7 @@
package org.elasticsearch.rest.action.admin.indices.flush; package org.elasticsearch.rest.action.admin.indices.flush;
import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.flush.FlushRequest; import org.elasticsearch.action.admin.indices.flush.FlushRequest;
@ -27,9 +28,9 @@ import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.rest.action.support.RestJsonBuilder;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -65,7 +66,7 @@ public class RestFlushAction extends BaseRestHandler {
client.admin().indices().flush(flushRequest, new ActionListener<FlushResponse>() { client.admin().indices().flush(flushRequest, new ActionListener<FlushResponse>() {
@Override public void onResponse(FlushResponse response) { @Override public void onResponse(FlushResponse response) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject(); builder.startObject();
builder.field("ok", true); builder.field("ok", true);

View File

@ -27,9 +27,10 @@ import org.elasticsearch.action.admin.indices.gateway.snapshot.IndexGatewaySnaps
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -55,7 +56,7 @@ public class RestGatewaySnapshotAction extends BaseRestHandler {
client.admin().indices().gatewaySnapshot(gatewaySnapshotRequest, new ActionListener<GatewaySnapshotResponse>() { client.admin().indices().gatewaySnapshot(gatewaySnapshotRequest, new ActionListener<GatewaySnapshotResponse>() {
@Override public void onResponse(GatewaySnapshotResponse result) { @Override public void onResponse(GatewaySnapshotResponse result) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject(); builder.startObject();
builder.field("ok", true); builder.field("ok", true);
builder.startObject("indices"); builder.startObject("indices");

View File

@ -28,9 +28,10 @@ import org.elasticsearch.index.mapper.InvalidTypeNameException;
import org.elasticsearch.index.mapper.MergeMappingException; import org.elasticsearch.index.mapper.MergeMappingException;
import org.elasticsearch.indices.IndexMissingException; import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -64,7 +65,7 @@ public class RestPutMappingAction extends BaseRestHandler {
client.admin().indices().putMapping(putMappingRequest, new ActionListener<PutMappingResponse>() { client.admin().indices().putMapping(putMappingRequest, new ActionListener<PutMappingResponse>() {
@Override public void onResponse(PutMappingResponse response) { @Override public void onResponse(PutMappingResponse response) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject() builder.startObject()
.field("ok", true) .field("ok", true)
.field("acknowledged", response.acknowledged()); .field("acknowledged", response.acknowledged());
@ -77,7 +78,7 @@ public class RestPutMappingAction extends BaseRestHandler {
@Override public void onFailure(Throwable e) { @Override public void onFailure(Throwable e) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
Throwable t = unwrapCause(e); Throwable t = unwrapCause(e);
if (t instanceof IndexMissingException || t instanceof InvalidTypeNameException || t instanceof MergeMappingException) { if (t instanceof IndexMissingException || t instanceof InvalidTypeNameException || t instanceof MergeMappingException) {
channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", t.getMessage()).endObject())); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", t.getMessage()).endObject()));

View File

@ -19,6 +19,7 @@
package org.elasticsearch.rest.action.admin.indices.optimize; package org.elasticsearch.rest.action.admin.indices.optimize;
import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest; import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest;
@ -27,9 +28,8 @@ import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.rest.action.support.RestJsonBuilder;
import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -70,7 +70,7 @@ public class RestOptimizeAction extends BaseRestHandler {
optimizeRequest.operationThreading(operationThreading); optimizeRequest.operationThreading(operationThreading);
} catch (Exception e) { } catch (Exception e) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject())); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) { } catch (IOException e1) {
logger.error("Failed to send failure response", e1); logger.error("Failed to send failure response", e1);
@ -80,7 +80,7 @@ public class RestOptimizeAction extends BaseRestHandler {
client.admin().indices().optimize(optimizeRequest, new ActionListener<OptimizeResponse>() { client.admin().indices().optimize(optimizeRequest, new ActionListener<OptimizeResponse>() {
@Override public void onResponse(OptimizeResponse response) { @Override public void onResponse(OptimizeResponse response) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject(); builder.startObject();
builder.field("ok", true); builder.field("ok", true);

View File

@ -27,9 +27,10 @@ import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -64,7 +65,7 @@ public class RestRefreshAction extends BaseRestHandler {
client.admin().indices().refresh(refreshRequest, new ActionListener<RefreshResponse>() { client.admin().indices().refresh(refreshRequest, new ActionListener<RefreshResponse>() {
@Override public void onResponse(RefreshResponse response) { @Override public void onResponse(RefreshResponse response) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject(); builder.startObject();
builder.field("ok", true); builder.field("ok", true);

View File

@ -19,15 +19,16 @@
package org.elasticsearch.rest.action.admin.indices.status; package org.elasticsearch.rest.action.admin.indices.status;
import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.status.*; import org.elasticsearch.action.admin.indices.status.*;
import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestJsonBuilder;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
@ -60,7 +61,7 @@ public class RestIndicesStatusAction extends BaseRestHandler {
client.admin().indices().status(indicesStatusRequest, new ActionListener<IndicesStatusResponse>() { client.admin().indices().status(indicesStatusRequest, new ActionListener<IndicesStatusResponse>() {
@Override public void onResponse(IndicesStatusResponse response) { @Override public void onResponse(IndicesStatusResponse response) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject(); builder.startObject();
builder.field("ok", true); builder.field("ok", true);

View File

@ -19,7 +19,6 @@
package org.elasticsearch.rest.action.count; package org.elasticsearch.rest.action.count;
import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.count.CountRequest; import org.elasticsearch.action.count.CountRequest;
import org.elasticsearch.action.count.CountResponse; import org.elasticsearch.action.count.CountResponse;
@ -27,9 +26,10 @@ import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -74,7 +74,7 @@ public class RestCountAction extends BaseRestHandler {
} }
} catch (Exception e) { } catch (Exception e) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject())); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) { } catch (IOException e1) {
logger.error("Failed to send failure response", e1); logger.error("Failed to send failure response", e1);
@ -85,7 +85,7 @@ public class RestCountAction extends BaseRestHandler {
client.count(countRequest, new ActionListener<CountResponse>() { client.count(countRequest, new ActionListener<CountResponse>() {
@Override public void onResponse(CountResponse response) { @Override public void onResponse(CountResponse response) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject(); builder.startObject();
builder.field("count", response.count()); builder.field("count", response.count());

View File

@ -19,15 +19,16 @@
package org.elasticsearch.rest.action.delete; package org.elasticsearch.rest.action.delete;
import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse; import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestJsonBuilder;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -54,7 +55,7 @@ public class RestDeleteAction extends BaseRestHandler {
client.delete(deleteRequest, new ActionListener<DeleteResponse>() { client.delete(deleteRequest, new ActionListener<DeleteResponse>() {
@Override public void onResponse(DeleteResponse result) { @Override public void onResponse(DeleteResponse result) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject() builder.startObject()
.field("ok", true) .field("ok", true)
.field("_index", result.index()) .field("_index", result.index())

View File

@ -19,6 +19,7 @@
package org.elasticsearch.rest.action.deletebyquery; package org.elasticsearch.rest.action.deletebyquery;
import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.deletebyquery.DeleteByQueryRequest; import org.elasticsearch.action.deletebyquery.DeleteByQueryRequest;
@ -28,9 +29,9 @@ import org.elasticsearch.action.deletebyquery.ShardDeleteByQueryRequest;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.rest.action.support.RestJsonBuilder;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -63,7 +64,7 @@ public class RestDeleteByQueryAction extends BaseRestHandler {
deleteByQueryRequest.timeout(request.paramAsTime("timeout", ShardDeleteByQueryRequest.DEFAULT_TIMEOUT)); deleteByQueryRequest.timeout(request.paramAsTime("timeout", ShardDeleteByQueryRequest.DEFAULT_TIMEOUT));
} catch (Exception e) { } catch (Exception e) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new JsonRestResponse(request, PRECONDITION_FAILED, builder.startObject().field("error", e.getMessage()).endObject())); channel.sendResponse(new JsonRestResponse(request, PRECONDITION_FAILED, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) { } catch (IOException e1) {
logger.error("Failed to send failure response", e1); logger.error("Failed to send failure response", e1);
@ -73,7 +74,7 @@ public class RestDeleteByQueryAction extends BaseRestHandler {
client.deleteByQuery(deleteByQueryRequest, new ActionListener<DeleteByQueryResponse>() { client.deleteByQuery(deleteByQueryRequest, new ActionListener<DeleteByQueryResponse>() {
@Override public void onResponse(DeleteByQueryResponse result) { @Override public void onResponse(DeleteByQueryResponse result) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject().field("ok", true); builder.startObject().field("ok", true);
builder.startObject("_indices"); builder.startObject("_indices");

View File

@ -28,13 +28,14 @@ import org.elasticsearch.client.Client;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static org.elasticsearch.rest.RestRequest.Method.*; import static org.elasticsearch.rest.RestRequest.Method.*;
import static org.elasticsearch.rest.RestResponse.Status.*; import static org.elasticsearch.rest.RestResponse.Status.*;
import static org.elasticsearch.rest.action.support.RestJsonBuilder.*; import static org.elasticsearch.rest.action.support.RestXContentBuilder.*;
/** /**
* @author kimchy (Shay Banon) * @author kimchy (Shay Banon)
@ -73,7 +74,7 @@ public class RestGetAction extends BaseRestHandler {
@Override public void onResponse(GetResponse response) { @Override public void onResponse(GetResponse response) {
try { try {
if (!response.exists()) { if (!response.exists()) {
JsonBuilder builder = restJsonBuilder(request); XContentBuilder builder = restContentBuilder(request);
builder.startObject(); builder.startObject();
builder.field("_index", response.index()); builder.field("_index", response.index());
builder.field("_type", response.type()); builder.field("_type", response.type());
@ -81,14 +82,13 @@ public class RestGetAction extends BaseRestHandler {
builder.endObject(); builder.endObject();
channel.sendResponse(new JsonRestResponse(request, NOT_FOUND, builder)); channel.sendResponse(new JsonRestResponse(request, NOT_FOUND, builder));
} else { } else {
JsonBuilder builder = restJsonBuilder(request); XContentBuilder builder = restContentBuilder(request);
builder.startObject(); builder.startObject();
builder.field("_index", response.index()); builder.field("_index", response.index());
builder.field("_type", response.type()); builder.field("_type", response.type());
builder.field("_id", response.id()); builder.field("_id", response.id());
if (response.source() != null) { if (response.source() != null) {
builder.raw(", \"_source\" : "); builder.rawField("_source", response.source());
builder.raw(response.source());
} }
if (response.fields() != null && !response.fields().isEmpty()) { if (response.fields() != null && !response.fields().isEmpty()) {

View File

@ -19,15 +19,16 @@
package org.elasticsearch.rest.action.index; package org.elasticsearch.rest.action.index;
import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestJsonBuilder;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -66,7 +67,7 @@ public class RestIndexAction extends BaseRestHandler {
indexRequest.opType(IndexRequest.OpType.CREATE); indexRequest.opType(IndexRequest.OpType.CREATE);
} else { } else {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", "opType [" + sOpType + "] not allowed, either [index] or [create] are allowed").endObject())); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", "opType [" + sOpType + "] not allowed, either [index] or [create] are allowed").endObject()));
} catch (IOException e1) { } catch (IOException e1) {
logger.warn("Failed to send response", e1); logger.warn("Failed to send response", e1);
@ -81,7 +82,7 @@ public class RestIndexAction extends BaseRestHandler {
client.index(indexRequest, new ActionListener<IndexResponse>() { client.index(indexRequest, new ActionListener<IndexResponse>() {
@Override public void onResponse(IndexResponse result) { @Override public void onResponse(IndexResponse result) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject() builder.startObject()
.field("ok", true) .field("ok", true)
.field("_index", result.index()) .field("_index", result.index())

View File

@ -19,19 +19,19 @@
package org.elasticsearch.rest.action.main; package org.elasticsearch.rest.action.main;
import org.elasticsearch.util.gcommon.collect.Iterators;
import org.elasticsearch.util.guice.inject.Inject;
import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.node.ArrayNode; import org.codehaus.jackson.node.ArrayNode;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestJsonBuilder; import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.Classes; import org.elasticsearch.util.Classes;
import org.elasticsearch.util.concurrent.jsr166y.ThreadLocalRandom; import org.elasticsearch.util.concurrent.jsr166y.ThreadLocalRandom;
import org.elasticsearch.util.gcommon.collect.Iterators;
import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.util.json.Jackson; import org.elasticsearch.util.json.Jackson;
import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -66,7 +66,7 @@ public class RestMainAction extends BaseRestHandler {
@Override public void handleRequest(RestRequest request, RestChannel channel) { @Override public void handleRequest(RestRequest request, RestChannel channel) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request).prettyPrint(); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request).prettyPrint();
builder.startObject(); builder.startObject();
builder.field("ok", true); builder.field("ok", true);
if (settings.get("name") != null) { if (settings.get("name") != null) {

View File

@ -30,13 +30,14 @@ import org.elasticsearch.search.Scroll;
import org.elasticsearch.util.Unicode; import org.elasticsearch.util.Unicode;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.client.Requests.*; import static org.elasticsearch.client.Requests.*;
import static org.elasticsearch.rest.RestRequest.Method.*; import static org.elasticsearch.rest.RestRequest.Method.*;
import static org.elasticsearch.rest.RestResponse.Status.*; import static org.elasticsearch.rest.RestResponse.Status.*;
import static org.elasticsearch.rest.action.support.RestJsonBuilder.*; import static org.elasticsearch.rest.action.support.RestXContentBuilder.*;
import static org.elasticsearch.util.TimeValue.*; import static org.elasticsearch.util.TimeValue.*;
/** /**
@ -82,7 +83,7 @@ public class RestMoreLikeThisAction extends BaseRestHandler {
} }
} catch (Exception e) { } catch (Exception e) {
try { try {
JsonBuilder builder = restJsonBuilder(request); XContentBuilder builder = restContentBuilder(request);
channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject())); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) { } catch (IOException e1) {
logger.error("Failed to send failure response", e1); logger.error("Failed to send failure response", e1);
@ -93,9 +94,9 @@ public class RestMoreLikeThisAction extends BaseRestHandler {
client.moreLikeThis(mltRequest, new ActionListener<SearchResponse>() { client.moreLikeThis(mltRequest, new ActionListener<SearchResponse>() {
@Override public void onResponse(SearchResponse response) { @Override public void onResponse(SearchResponse response) {
try { try {
JsonBuilder builder = restJsonBuilder(request); XContentBuilder builder = restContentBuilder(request);
builder.startObject(); builder.startObject();
response.toJson(builder, request); response.toXContent(builder, request);
builder.endObject(); builder.endObject();
channel.sendResponse(new JsonRestResponse(request, OK, builder)); channel.sendResponse(new JsonRestResponse(request, OK, builder));
} catch (Exception e) { } catch (Exception e) {

View File

@ -19,29 +19,29 @@
package org.elasticsearch.rest.action.search; package org.elasticsearch.rest.action.search;
import org.elasticsearch.index.query.xcontent.QueryBuilders;
import org.elasticsearch.index.query.xcontent.QueryStringQueryBuilder;
import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.search.SearchOperationThreading; import org.elasticsearch.action.search.SearchOperationThreading;
import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.index.query.xcontent.QueryBuilders;
import org.elasticsearch.index.query.xcontent.QueryStringQueryBuilder;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestActions; import org.elasticsearch.rest.action.support.RestActions;
import org.elasticsearch.search.Scroll; import org.elasticsearch.search.Scroll;
import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.util.Unicode; import org.elasticsearch.util.Unicode;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static org.elasticsearch.rest.RestRequest.Method.*; import static org.elasticsearch.rest.RestRequest.Method.*;
import static org.elasticsearch.rest.RestResponse.Status.*; import static org.elasticsearch.rest.RestResponse.Status.*;
import static org.elasticsearch.rest.action.support.RestJsonBuilder.*; import static org.elasticsearch.rest.action.support.RestXContentBuilder.*;
import static org.elasticsearch.util.TimeValue.*; import static org.elasticsearch.util.TimeValue.*;
/** /**
@ -81,7 +81,7 @@ public class RestSearchAction extends BaseRestHandler {
searchRequest.operationThreading(operationThreading); searchRequest.operationThreading(operationThreading);
} catch (Exception e) { } catch (Exception e) {
try { try {
JsonBuilder builder = restJsonBuilder(request); XContentBuilder builder = restContentBuilder(request);
channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject())); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) { } catch (IOException e1) {
logger.error("Failed to send failure response", e1); logger.error("Failed to send failure response", e1);
@ -91,9 +91,9 @@ public class RestSearchAction extends BaseRestHandler {
client.search(searchRequest, new ActionListener<SearchResponse>() { client.search(searchRequest, new ActionListener<SearchResponse>() {
@Override public void onResponse(SearchResponse response) { @Override public void onResponse(SearchResponse response) {
try { try {
JsonBuilder builder = restJsonBuilder(request); XContentBuilder builder = restContentBuilder(request);
builder.startObject(); builder.startObject();
response.toJson(builder, request); response.toXContent(builder, request);
builder.endObject(); builder.endObject();
channel.sendResponse(new JsonRestResponse(request, OK, builder)); channel.sendResponse(new JsonRestResponse(request, OK, builder));
} catch (Exception e) { } catch (Exception e) {

View File

@ -29,12 +29,13 @@ import org.elasticsearch.rest.*;
import org.elasticsearch.search.Scroll; import org.elasticsearch.search.Scroll;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.rest.RestRequest.Method.*; import static org.elasticsearch.rest.RestRequest.Method.*;
import static org.elasticsearch.rest.RestResponse.Status.*; import static org.elasticsearch.rest.RestResponse.Status.*;
import static org.elasticsearch.rest.action.support.RestJsonBuilder.*; import static org.elasticsearch.rest.action.support.RestXContentBuilder.*;
import static org.elasticsearch.util.TimeValue.*; import static org.elasticsearch.util.TimeValue.*;
/** /**
@ -67,7 +68,7 @@ public class RestSearchScrollAction extends BaseRestHandler {
searchScrollRequest.operationThreading(operationThreading); searchScrollRequest.operationThreading(operationThreading);
} catch (Exception e) { } catch (Exception e) {
try { try {
JsonBuilder builder = restJsonBuilder(request); XContentBuilder builder = restContentBuilder(request);
channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject())); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) { } catch (IOException e1) {
logger.error("Failed to send failure response", e1); logger.error("Failed to send failure response", e1);
@ -78,9 +79,9 @@ public class RestSearchScrollAction extends BaseRestHandler {
client.searchScroll(searchScrollRequest, new ActionListener<SearchResponse>() { client.searchScroll(searchScrollRequest, new ActionListener<SearchResponse>() {
@Override public void onResponse(SearchResponse response) { @Override public void onResponse(SearchResponse response) {
try { try {
JsonBuilder builder = restJsonBuilder(request); XContentBuilder builder = restContentBuilder(request);
builder.startObject(); builder.startObject();
response.toJson(builder, request); response.toXContent(builder, request);
builder.endObject(); builder.endObject();
channel.sendResponse(new JsonRestResponse(request, OK, builder)); channel.sendResponse(new JsonRestResponse(request, OK, builder));
} catch (Exception e) { } catch (Exception e) {

View File

@ -27,7 +27,7 @@ import org.elasticsearch.index.query.xcontent.QueryStringQueryBuilder;
import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.util.Strings; import org.elasticsearch.util.Strings;
import org.elasticsearch.util.Unicode; import org.elasticsearch.util.Unicode;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -41,7 +41,7 @@ public class RestActions {
public final static Pattern typesPattern = Pattern.compile(","); public final static Pattern typesPattern = Pattern.compile(",");
public final static Pattern nodesIdsPattern = Pattern.compile(","); public final static Pattern nodesIdsPattern = Pattern.compile(",");
public static void buildBroadcastShardsHeader(JsonBuilder builder, BroadcastOperationResponse response) throws IOException { public static void buildBroadcastShardsHeader(XContentBuilder builder, BroadcastOperationResponse response) throws IOException {
builder.startObject("_shards"); builder.startObject("_shards");
builder.field("total", response.totalShards()); builder.field("total", response.totalShards());
builder.field("successful", response.successfulShards()); builder.field("successful", response.successfulShards());

View File

@ -20,19 +20,19 @@
package org.elasticsearch.rest.action.support; package org.elasticsearch.rest.action.support;
import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.util.json.BinaryJsonBuilder; import org.elasticsearch.util.xcontent.XContentFactory;
import org.elasticsearch.util.xcontent.XContentType;
import org.elasticsearch.util.xcontent.builder.BinaryXContentBuilder;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.util.json.JsonBuilder.*;
/** /**
* @author kimchy (Shay Banon) * @author kimchy (shay.banon)
*/ */
public class RestJsonBuilder { public class RestXContentBuilder {
public static BinaryJsonBuilder restJsonBuilder(RestRequest request) throws IOException { public static BinaryXContentBuilder restContentBuilder(RestRequest request) throws IOException {
BinaryJsonBuilder builder = binaryJsonBuilder(); BinaryXContentBuilder builder = XContentFactory.contentBinaryBuilder(XContentType.JSON);
if (request.paramAsBoolean("pretty", false)) { if (request.paramAsBoolean("pretty", false)) {
builder.prettyPrint(); builder.prettyPrint();
} }

View File

@ -19,6 +19,7 @@
package org.elasticsearch.rest.action.terms; package org.elasticsearch.rest.action.terms;
import org.elasticsearch.rest.action.support.RestXContentBuilder;
import org.elasticsearch.util.guice.inject.Inject; import org.elasticsearch.util.guice.inject.Inject;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading; import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
@ -28,9 +29,9 @@ import org.elasticsearch.action.terms.TermsRequest;
import org.elasticsearch.action.terms.TermsResponse; import org.elasticsearch.action.terms.TermsResponse;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.rest.*; import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestJsonBuilder;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.settings.Settings; import org.elasticsearch.util.settings.Settings;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -108,7 +109,7 @@ public class RestTermsAction extends BaseRestHandler {
termsRequest.sortType(request.param("sort")); termsRequest.sortType(request.param("sort"));
} catch (Exception e) { } catch (Exception e) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject())); channel.sendResponse(new JsonRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) { } catch (IOException e1) {
logger.error("Failed to send failure response", e1); logger.error("Failed to send failure response", e1);
@ -120,7 +121,7 @@ public class RestTermsAction extends BaseRestHandler {
client.terms(termsRequest, new ActionListener<TermsResponse>() { client.terms(termsRequest, new ActionListener<TermsResponse>() {
@Override public void onResponse(TermsResponse response) { @Override public void onResponse(TermsResponse response) {
try { try {
JsonBuilder builder = RestJsonBuilder.restJsonBuilder(request); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject(); builder.startObject();
buildBroadcastShardsHeader(builder, response); buildBroadcastShardsHeader(builder, response);

View File

@ -24,6 +24,7 @@ import org.elasticsearch.ElasticSearchParseException;
import org.elasticsearch.search.highlight.HighlightField; import org.elasticsearch.search.highlight.HighlightField;
import org.elasticsearch.util.io.stream.Streamable; import org.elasticsearch.util.io.stream.Streamable;
import org.elasticsearch.util.json.ToJson; import org.elasticsearch.util.json.ToJson;
import org.elasticsearch.util.xcontent.ToXContent;
import java.util.Map; import java.util.Map;
@ -33,7 +34,7 @@ import java.util.Map;
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
* @see SearchHits * @see SearchHits
*/ */
public interface SearchHit extends Streamable, ToJson, Iterable<SearchHitField> { public interface SearchHit extends Streamable, ToXContent, Iterable<SearchHitField> {
/** /**
* The index of the hit. * The index of the hit.

View File

@ -21,13 +21,14 @@ package org.elasticsearch.search;
import org.elasticsearch.util.io.stream.Streamable; import org.elasticsearch.util.io.stream.Streamable;
import org.elasticsearch.util.json.ToJson; import org.elasticsearch.util.json.ToJson;
import org.elasticsearch.util.xcontent.ToXContent;
/** /**
* The hits of a search request. * The hits of a search request.
* *
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
*/ */
public interface SearchHits extends Streamable, ToJson, Iterable<SearchHit> { public interface SearchHits extends Streamable, ToXContent, Iterable<SearchHit> {
/** /**
* The total number of hits that matches the search request. * The total number of hits that matches the search request.

View File

@ -21,7 +21,7 @@ package org.elasticsearch.search.facets;
import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamInput;
import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.StreamOutput;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -82,7 +82,7 @@ public class CountFacet implements Facet {
count += increment; count += increment;
} }
@Override public void toJson(JsonBuilder builder, Params params) throws IOException { @Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
builder.field(name, count); builder.field(name, count);
} }

View File

@ -22,13 +22,14 @@ package org.elasticsearch.search.facets;
import org.elasticsearch.ElasticSearchIllegalArgumentException; import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.util.io.stream.Streamable; import org.elasticsearch.util.io.stream.Streamable;
import org.elasticsearch.util.json.ToJson; import org.elasticsearch.util.json.ToJson;
import org.elasticsearch.util.xcontent.ToXContent;
/** /**
* A search facet. * A search facet.
* *
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
*/ */
public interface Facet extends Streamable, ToJson { public interface Facet extends Streamable, ToXContent {
enum Type { enum Type {
/** /**

View File

@ -23,24 +23,24 @@ import org.elasticsearch.util.gcommon.collect.ImmutableList;
import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamInput;
import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.StreamOutput;
import org.elasticsearch.util.io.stream.Streamable; import org.elasticsearch.util.io.stream.Streamable;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.xcontent.ToXContent;
import org.elasticsearch.util.json.ToJson; import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static org.elasticsearch.search.facets.CountFacet.*;
import static org.elasticsearch.util.gcommon.collect.Lists.*; import static org.elasticsearch.util.gcommon.collect.Lists.*;
import static org.elasticsearch.util.gcommon.collect.Maps.*; import static org.elasticsearch.util.gcommon.collect.Maps.*;
import static org.elasticsearch.search.facets.CountFacet.*;
/** /**
* Facets of search action. * Facets of search action.
* *
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
*/ */
public class Facets implements Streamable, ToJson, Iterable<Facet> { public class Facets implements Streamable, ToXContent, Iterable<Facet> {
private final List<Facet> EMPTY = ImmutableList.of(); private final List<Facet> EMPTY = ImmutableList.of();
@ -109,10 +109,10 @@ public class Facets implements Streamable, ToJson, Iterable<Facet> {
return facetsAsMap().get(name); return facetsAsMap().get(name);
} }
@Override public void toJson(JsonBuilder builder, Params params) throws IOException { @Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject("facets"); builder.startObject("facets");
for (Facet facet : facets) { for (Facet facet : facets) {
facet.toJson(builder, params); facet.toXContent(builder, params);
} }
builder.endObject(); builder.endObject();
} }

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.internal; package org.elasticsearch.search.internal;
import org.elasticsearch.util.gcommon.collect.ImmutableMap;
import org.apache.lucene.search.Explanation; import org.apache.lucene.search.Explanation;
import org.elasticsearch.ElasticSearchParseException; import org.elasticsearch.ElasticSearchParseException;
import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHit;
@ -27,10 +26,12 @@ import org.elasticsearch.search.SearchHitField;
import org.elasticsearch.search.SearchShardTarget; import org.elasticsearch.search.SearchShardTarget;
import org.elasticsearch.search.highlight.HighlightField; import org.elasticsearch.search.highlight.HighlightField;
import org.elasticsearch.util.Unicode; import org.elasticsearch.util.Unicode;
import org.elasticsearch.util.gcommon.collect.ImmutableMap;
import org.elasticsearch.util.gnu.trove.TIntObjectHashMap; import org.elasticsearch.util.gnu.trove.TIntObjectHashMap;
import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamInput;
import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.StreamOutput;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.xcontent.XContentFactory;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.io.IOException; import java.io.IOException;
@ -189,7 +190,7 @@ public class InternalSearchHit implements SearchHit {
this.shard = target; this.shard = target;
} }
@Override public void toJson(JsonBuilder builder, Params params) throws IOException { @Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(); builder.startObject();
builder.field("_index", shard.index()); builder.field("_index", shard.index());
// builder.field("_shard", shard.shardId()); // builder.field("_shard", shard.shardId());
@ -197,8 +198,12 @@ public class InternalSearchHit implements SearchHit {
builder.field("_type", type()); builder.field("_type", type());
builder.field("_id", id()); builder.field("_id", id());
if (source() != null) { if (source() != null) {
builder.raw(", \"_source\" : "); if (XContentFactory.xContentType(source()) == builder.contentType()) {
builder.raw(source()); builder.field("_source");
builder.value(source());
} else {
builder.rawField("_source", source());
}
} }
if (fields != null && !fields.isEmpty()) { if (fields != null && !fields.isEmpty()) {
builder.startObject("fields"); builder.startObject("fields");
@ -242,7 +247,7 @@ public class InternalSearchHit implements SearchHit {
builder.endObject(); builder.endObject();
} }
private void buildExplanation(JsonBuilder builder, Explanation explanation) throws IOException { private void buildExplanation(XContentBuilder builder, Explanation explanation) throws IOException {
builder.startObject(); builder.startObject();
builder.field("value", explanation.getValue()); builder.field("value", explanation.getValue());
builder.field("description", explanation.getDescription()); builder.field("description", explanation.getDescription());

View File

@ -27,6 +27,7 @@ import org.elasticsearch.util.gnu.trove.TIntObjectHashMap;
import org.elasticsearch.util.io.stream.StreamInput; import org.elasticsearch.util.io.stream.StreamInput;
import org.elasticsearch.util.io.stream.StreamOutput; import org.elasticsearch.util.io.stream.StreamOutput;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.IdentityHashMap; import java.util.IdentityHashMap;
@ -84,13 +85,13 @@ public class InternalSearchHits implements SearchHits {
return this.hits; return this.hits;
} }
@Override public void toJson(JsonBuilder builder, Params params) throws IOException { @Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject("hits"); builder.startObject("hits");
builder.field("total", totalHits); builder.field("total", totalHits);
builder.field("hits"); builder.field("hits");
builder.startArray(); builder.startArray();
for (SearchHit hit : hits) { for (SearchHit hit : hits) {
hit.toJson(builder, params); hit.toXContent(builder, params);
} }
builder.endArray(); builder.endArray();
builder.endObject(); builder.endObject();

View File

@ -26,6 +26,8 @@ import org.elasticsearch.util.io.stream.StreamOutput;
import org.elasticsearch.util.io.stream.Streamable; import org.elasticsearch.util.io.stream.Streamable;
import org.elasticsearch.util.json.JsonBuilder; import org.elasticsearch.util.json.JsonBuilder;
import org.elasticsearch.util.json.ToJson; import org.elasticsearch.util.json.ToJson;
import org.elasticsearch.util.xcontent.ToXContent;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
@ -35,7 +37,7 @@ import static org.elasticsearch.search.internal.InternalSearchHits.*;
/** /**
* @author kimchy (Shay Banon) * @author kimchy (Shay Banon)
*/ */
public class InternalSearchResponse implements Streamable, ToJson { public class InternalSearchResponse implements Streamable, ToXContent {
private InternalSearchHits hits; private InternalSearchHits hits;
@ -57,10 +59,10 @@ public class InternalSearchResponse implements Streamable, ToJson {
return facets; return facets;
} }
@Override public void toJson(JsonBuilder builder, Params params) throws IOException { @Override public void toXContent(XContentBuilder builder, Params params) throws IOException {
hits.toJson(builder, params); hits.toXContent(builder, params);
if (facets != null) { if (facets != null) {
facets.toJson(builder, params); facets.toXContent(builder, params);
} }
} }

View File

@ -89,6 +89,8 @@ public interface XContentGenerator {
void writeObjectFieldStart(String fieldName) throws IOException; void writeObjectFieldStart(String fieldName) throws IOException;
void writeRawFieldStart(String fieldName) throws IOException;
void flush() throws IOException; void flush() throws IOException;
void close() throws IOException; void close() throws IOException;

View File

@ -280,7 +280,12 @@ public abstract class XContentBuilder<T extends XContentBuilder> {
return builder; return builder;
} }
public abstract T raw(byte[] json) throws IOException; public T rawField(String fieldName, byte[] content) throws IOException {
generator.writeRawFieldStart(fieldName);
return raw(content);
}
public abstract T raw(byte[] content) throws IOException;
public T value(Boolean value) throws IOException { public T value(Boolean value) throws IOException {
return value(value.booleanValue()); return value(value.booleanValue());

View File

@ -158,6 +158,11 @@ public class JsonXContentGenerator implements XContentGenerator {
generator.writeObjectFieldStart(fieldName); generator.writeObjectFieldStart(fieldName);
} }
@Override public void writeRawFieldStart(String fieldName) throws IOException {
generator.writeRaw(", \"" + fieldName + "\" : ");
}
@Override public void flush() throws IOException { @Override public void flush() throws IOException {
generator.flush(); generator.flush();
} }