From 3381d77c143579c5489b84d6824e7ed2b2eb8eb4 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Thu, 1 Sep 2011 01:34:27 +0300 Subject: [PATCH] more explicit places where we don't want to conversion to happen when transforming to xcontent --- .../admin/indices/stats/IndicesStats.java | 2 +- .../common/xcontent/XContentBuilder.java | 37 +++++++++++++++++++ .../index/indexing/IndexingStats.java | 2 +- .../node/info/RestNodesInfoAction.java | 2 +- .../shutdown/RestNodesShutdownAction.java | 4 +- .../node/stats/RestNodesStatsAction.java | 2 +- .../alias/RestGetIndicesAliasesAction.java | 15 +++++--- .../mapping/get/RestGetMappingAction.java | 2 +- .../settings/RestGetSettingsAction.java | 9 ++++- .../RestDeleteByQueryAction.java | 2 +- .../rest/action/support/RestActions.java | 2 +- 11 files changed, 63 insertions(+), 16 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStats.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStats.java index c648e8aacec..624bf144a73 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStats.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStats.java @@ -164,7 +164,7 @@ public class IndicesStats extends BroadcastOperationResponse implements ToXConte builder.startObject(Fields.INDICES); for (IndexStats indexStats : indices().values()) { - builder.startObject(indexStats.index()); + builder.startObject(indexStats.index(), XContentBuilder.FieldCaseConversion.NONE); builder.startObject("primaries"); indexStats.primaries().toXContent(builder, params); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java index a264bda4da4..7e585255e17 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java @@ -146,6 +146,12 @@ public final class XContentBuilder { return this; } + public XContentBuilder startObject(XContentBuilderString name, FieldCaseConversion conversion) throws IOException { + field(name, conversion); + startObject(); + return this; + } + public XContentBuilder startObject() throws IOException { generator.writeStartObject(); return this; @@ -231,6 +237,17 @@ public final class XContentBuilder { return this; } + public XContentBuilder field(XContentBuilderString name, FieldCaseConversion conversion) throws IOException { + if (conversion == FieldCaseConversion.UNDERSCORE) { + generator.writeFieldName(name.underscore()); + } else if (conversion == FieldCaseConversion.CAMELCASE) { + generator.writeFieldName(name.camelCase()); + } else { + generator.writeFieldName(name.underscore()); + } + return this; + } + public XContentBuilder field(String name) throws IOException { if (fieldCaseConversion == FieldCaseConversion.UNDERSCORE) { if (cachedStringBuilder == null) { @@ -293,6 +310,16 @@ public final class XContentBuilder { return this; } + public XContentBuilder field(String name, String value, FieldCaseConversion conversion) throws IOException { + field(name, conversion); + if (value == null) { + generator.writeNull(); + } else { + generator.writeString(value); + } + return this; + } + public XContentBuilder field(XContentBuilderString name, String value) throws IOException { field(name); if (value == null) { @@ -303,6 +330,16 @@ public final class XContentBuilder { return this; } + public XContentBuilder field(XContentBuilderString name, String value, FieldCaseConversion conversion) throws IOException { + field(name, conversion); + if (value == null) { + generator.writeNull(); + } else { + generator.writeString(value); + } + return this; + } + public XContentBuilder field(String name, Integer value) throws IOException { field(name); if (value == null) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java index baea68db9b8..648b0faf0d6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/indexing/IndexingStats.java @@ -195,7 +195,7 @@ public class IndexingStats implements Streamable, ToXContent { if (typeStats != null && !typeStats.isEmpty()) { builder.startObject(Fields.TYPES); for (Map.Entry entry : typeStats.entrySet()) { - builder.startObject(entry.getKey()); + builder.startObject(entry.getKey(), XContentBuilder.FieldCaseConversion.NONE); entry.getValue().toXContent(builder, params); builder.endObject(); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java index d59fdb3d23a..72b8ea7feb7 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/info/RestNodesInfoAction.java @@ -73,7 +73,7 @@ public class RestNodesInfoAction extends BaseRestHandler { for (NodeInfo nodeInfo : result) { builder.startObject(nodeInfo.node().id(), XContentBuilder.FieldCaseConversion.NONE); - builder.field("name", nodeInfo.node().name()); + builder.field("name", nodeInfo.node().name(), XContentBuilder.FieldCaseConversion.NONE); builder.field("transport_address", nodeInfo.node().address().toString()); builder.startObject("attributes"); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/shutdown/RestNodesShutdownAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/shutdown/RestNodesShutdownAction.java index 4d06a0a51a8..55b987910d1 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/shutdown/RestNodesShutdownAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/shutdown/RestNodesShutdownAction.java @@ -68,8 +68,8 @@ public class RestNodesShutdownAction extends BaseRestHandler { builder.startObject("nodes"); for (DiscoveryNode node : response.nodes()) { - builder.startObject(node.id()); - builder.field("name", node.name()); + builder.startObject(node.id(), XContentBuilder.FieldCaseConversion.NONE); + builder.field("name", node.name(), XContentBuilder.FieldCaseConversion.NONE); builder.endObject(); } builder.endObject(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/stats/RestNodesStatsAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/stats/RestNodesStatsAction.java index f370b28ee10..3474e7440d3 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/stats/RestNodesStatsAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/node/stats/RestNodesStatsAction.java @@ -65,7 +65,7 @@ public class RestNodesStatsAction extends BaseRestHandler { for (NodeStats nodeStats : result) { builder.startObject(nodeStats.node().id(), XContentBuilder.FieldCaseConversion.NONE); - builder.field("name", nodeStats.node().name()); + builder.field("name", nodeStats.node().name(), XContentBuilder.FieldCaseConversion.NONE); if (nodeStats.indices() != null) { nodeStats.indices().toXContent(builder, request); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/RestGetIndicesAliasesAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/RestGetIndicesAliasesAction.java index e75d399774f..4389f7af73f 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/RestGetIndicesAliasesAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/RestGetIndicesAliasesAction.java @@ -31,14 +31,19 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.rest.*; +import org.elasticsearch.rest.BaseRestHandler; +import org.elasticsearch.rest.RestChannel; +import org.elasticsearch.rest.RestController; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.XContentRestResponse; +import org.elasticsearch.rest.XContentThrowableRestResponse; import org.elasticsearch.rest.action.support.RestXContentBuilder; import java.io.IOException; -import static org.elasticsearch.rest.RestRequest.Method.GET; -import static org.elasticsearch.rest.RestStatus.OK; -import static org.elasticsearch.rest.action.support.RestActions.splitIndices; +import static org.elasticsearch.rest.RestRequest.Method.*; +import static org.elasticsearch.rest.RestStatus.*; +import static org.elasticsearch.rest.action.support.RestActions.*; /** * @author imotov @@ -67,7 +72,7 @@ public class RestGetIndicesAliasesAction extends BaseRestHandler { builder.startObject(); for (IndexMetaData indexMetaData : metaData) { - builder.startObject(indexMetaData.index()); + builder.startObject(indexMetaData.index(), XContentBuilder.FieldCaseConversion.NONE); builder.startObject("aliases"); for (AliasMetaData alias : indexMetaData.aliases().values()) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java index d6541da0d6e..af5125a475c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java @@ -109,7 +109,7 @@ public class RestGetMappingAction extends BaseRestHandler { } } else { for (IndexMetaData indexMetaData : metaData) { - builder.startObject(indexMetaData.index()); + builder.startObject(indexMetaData.index(), XContentBuilder.FieldCaseConversion.NONE); for (MappingMetaData mappingMd : indexMetaData.mappings().values()) { if (!types.isEmpty() && !types.contains(mappingMd.type())) { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/settings/RestGetSettingsAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/settings/RestGetSettingsAction.java index 54b0e520a2a..0565de34656 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/settings/RestGetSettingsAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/indices/settings/RestGetSettingsAction.java @@ -30,7 +30,12 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.rest.*; +import org.elasticsearch.rest.BaseRestHandler; +import org.elasticsearch.rest.RestChannel; +import org.elasticsearch.rest.RestController; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.XContentRestResponse; +import org.elasticsearch.rest.XContentThrowableRestResponse; import org.elasticsearch.rest.action.support.RestXContentBuilder; import java.io.IOException; @@ -68,7 +73,7 @@ public class RestGetSettingsAction extends BaseRestHandler { builder.startObject(); for (IndexMetaData indexMetaData : metaData) { - builder.startObject(indexMetaData.index()); + builder.startObject(indexMetaData.index(), XContentBuilder.FieldCaseConversion.NONE); builder.startObject("settings"); Settings settings = settingsFilter.filterSettings(indexMetaData.settings()); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/deletebyquery/RestDeleteByQueryAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/deletebyquery/RestDeleteByQueryAction.java index 45cb4729978..f7260cae5a9 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/deletebyquery/RestDeleteByQueryAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/deletebyquery/RestDeleteByQueryAction.java @@ -100,7 +100,7 @@ public class RestDeleteByQueryAction extends BaseRestHandler { builder.startObject("_indices"); for (IndexDeleteByQueryResponse indexDeleteByQueryResponse : result.indices().values()) { - builder.startObject(indexDeleteByQueryResponse.index()); + builder.startObject(indexDeleteByQueryResponse.index(), XContentBuilder.FieldCaseConversion.NONE); builder.startObject("_shards"); builder.field("total", indexDeleteByQueryResponse.totalShards()); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestActions.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestActions.java index cddac5d09a0..cfec46d73f6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestActions.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/support/RestActions.java @@ -56,7 +56,7 @@ public class RestActions { for (ShardOperationFailedException shardFailure : response.shardFailures()) { builder.startObject(); if (shardFailure.index() != null) { - builder.field("index", shardFailure.index()); + builder.field("index", shardFailure.index(), XContentBuilder.FieldCaseConversion.NONE); } if (shardFailure.shardId() != -1) { builder.field("shard", shardFailure.shardId());