Move more XContent.createParser calls to non-deprecated version (elastic/x-pack-elasticsearch#3928)

Part 2

This moves more of the callers to pass in the DeprecationHandler.

Relates to elastic/x-pack-elasticsearch#28504

Original commit: elastic/x-pack-elasticsearch@e0b52bf050
This commit is contained in:
Lee Hinman 2018-02-14 09:41:26 -07:00 committed by GitHub
parent e8ef20b219
commit affc9e3563
37 changed files with 137 additions and 62 deletions

View File

@ -19,6 +19,7 @@ import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.ToXContentObject;
@ -496,7 +497,8 @@ public class License implements ToXContentObject {
throw new ElasticsearchParseException("failed to parse license - no content-type provided"); throw new ElasticsearchParseException("failed to parse license - no content-type provided");
} }
// EMPTY is safe here because we don't call namedObject // EMPTY is safe here because we don't call namedObject
final XContentParser parser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY, bytes); final XContentParser parser = xContentType.xContent()
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, bytes);
License license = null; License license = null;
if (parser.nextToken() == XContentParser.Token.START_OBJECT) { if (parser.nextToken() == XContentParser.Token.START_OBJECT) {
if (parser.nextToken() == XContentParser.Token.FIELD_NAME) { if (parser.nextToken() == XContentParser.Token.FIELD_NAME) {

View File

@ -11,6 +11,7 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ObjectParser.ValueType; import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
@ -307,7 +308,8 @@ public class ModelSnapshot implements ToXContentObject, Writeable {
} }
public static ModelSnapshot fromJson(BytesReference bytesReference) { public static ModelSnapshot fromJson(BytesReference bytesReference) {
try (XContentParser parser = XContentFactory.xContent(bytesReference).createParser(NamedXContentRegistry.EMPTY, bytesReference)) { try (XContentParser parser = XContentFactory.xContent(bytesReference)
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, bytesReference)) {
return PARSER.apply(parser, null).build(); return PARSER.apply(parser, null).build();
} catch (IOException e) { } catch (IOException e) {
throw new ElasticsearchParseException("failed to parse modelSnapshot", e); throw new ElasticsearchParseException("failed to parse modelSnapshot", e);

View File

@ -12,6 +12,7 @@ import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.ValidationException; import org.elasticsearch.common.ValidationException;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.SecureString; import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
@ -65,7 +66,8 @@ public class ChangePasswordRequestBuilder
*/ */
public ChangePasswordRequestBuilder source(BytesReference source, XContentType xContentType) throws IOException { public ChangePasswordRequestBuilder source(BytesReference source, XContentType xContentType) throws IOException {
// EMPTY is ok here because we never call namedObject // EMPTY is ok here because we never call namedObject
try (XContentParser parser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY, source)) { try (XContentParser parser = xContentType.xContent()
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source)) {
XContentUtils.verifyObject(parser); XContentUtils.verifyObject(parser);
XContentParser.Token token; XContentParser.Token token;
String currentFieldName = null; String currentFieldName = null;

View File

@ -14,6 +14,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.ValidationException; import org.elasticsearch.common.ValidationException;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.SecureString; import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentParser.Token; import org.elasticsearch.common.xcontent.XContentParser.Token;
@ -98,7 +99,8 @@ public class PutUserRequestBuilder extends ActionRequestBuilder<PutUserRequest,
Objects.requireNonNull(xContentType); Objects.requireNonNull(xContentType);
username(username); username(username);
// EMPTY is ok here because we never call namedObject // EMPTY is ok here because we never call namedObject
try (XContentParser parser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY, source)) { try (XContentParser parser = xContentType.xContent()
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source)) {
XContentUtils.verifyObject(parser); XContentUtils.verifyObject(parser);
XContentParser.Token token; XContentParser.Token token;
String currentFieldName = null; String currentFieldName = null;

View File

@ -12,6 +12,7 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.ToXContentObject;
@ -143,7 +144,8 @@ public class ExpressionRoleMapping implements ToXContentObject, Writeable {
*/ */
public static ExpressionRoleMapping parse(String name, BytesReference source, XContentType xContentType) throws IOException { public static ExpressionRoleMapping parse(String name, BytesReference source, XContentType xContentType) throws IOException {
final NamedXContentRegistry registry = NamedXContentRegistry.EMPTY; final NamedXContentRegistry registry = NamedXContentRegistry.EMPTY;
try (XContentParser parser = xContentType.xContent().createParser(registry, source)) { try (XContentParser parser = xContentType.xContent()
.createParser(registry, LoggingDeprecationHandler.INSTANCE, source)) {
return parse(name, parser); return parse(name, parser);
} }
} }

View File

@ -16,6 +16,7 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -218,7 +219,8 @@ public class RoleDescriptor implements ToXContentObject {
throws IOException { throws IOException {
assert name != null; assert name != null;
// EMPTY is safe here because we never use namedObject // EMPTY is safe here because we never use namedObject
try (XContentParser parser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY, source)) { try (XContentParser parser = xContentType.xContent()
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source)) {
return parse(name, parser, allow2xFormat); return parse(name, parser, allow2xFormat);
} }
} }
@ -286,7 +288,8 @@ public class RoleDescriptor implements ToXContentObject {
public static RoleDescriptor parsePrivilegesCheck(String description, BytesReference source, XContentType xContentType) public static RoleDescriptor parsePrivilegesCheck(String description, BytesReference source, XContentType xContentType)
throws IOException { throws IOException {
try (XContentParser parser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY, source)) { try (XContentParser parser = xContentType.xContent()
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source)) {
// advance to the START_OBJECT token // advance to the START_OBJECT token
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();
if (token != XContentParser.Token.START_OBJECT) { if (token != XContentParser.Token.START_OBJECT) {

View File

@ -10,6 +10,7 @@ import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -105,7 +106,7 @@ public class XContentSource implements ToXContent {
} }
public XContentParser parser(NamedXContentRegistry xContentRegistry) throws IOException { public XContentParser parser(NamedXContentRegistry xContentRegistry) throws IOException {
return contentType.xContent().createParser(xContentRegistry, bytes); return contentType.xContent().createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, bytes);
} }
public static XContentSource readFrom(StreamInput in) throws IOException { public static XContentSource readFrom(StreamInput in) throws IOException {

View File

@ -5,6 +5,7 @@
*/ */
package org.elasticsearch.xpack.core.ml.action; package org.elasticsearch.xpack.core.ml.action;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -41,7 +42,7 @@ public class ValidateJobConfigActionRequestTests extends AbstractStreamableTestC
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
XContentBuilder xContentBuilder = jobConfiguration.toXContent(builder, ToXContent.EMPTY_PARAMS); XContentBuilder xContentBuilder = jobConfiguration.toXContent(builder, ToXContent.EMPTY_PARAMS);
XContentParser parser = XContentFactory.xContent(XContentType.JSON) XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, xContentBuilder.bytes()); .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, xContentBuilder.bytes());
expectThrows(IllegalArgumentException.class, () -> Request.parseRequest(parser)); expectThrows(IllegalArgumentException.class, () -> Request.parseRequest(parser));
} }

View File

@ -9,6 +9,7 @@ import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.common.xcontent.json.JsonXContent;
@ -199,7 +200,8 @@ public class DataDescriptionTests extends AbstractSerializingTestCase<DataDescri
public void testInvalidDataFormat() throws Exception { public void testInvalidDataFormat() throws Exception {
BytesArray json = new BytesArray("{ \"format\":\"INEXISTENT_FORMAT\" }"); BytesArray json = new BytesArray("{ \"format\":\"INEXISTENT_FORMAT\" }");
XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, json); XContentParser parser = JsonXContent.jsonXContent
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
ParsingException ex = expectThrows(ParsingException.class, ParsingException ex = expectThrows(ParsingException.class,
() -> DataDescription.CONFIG_PARSER.apply(parser, null)); () -> DataDescription.CONFIG_PARSER.apply(parser, null));
assertThat(ex.getMessage(), containsString("[data_description] failed to parse field [format]")); assertThat(ex.getMessage(), containsString("[data_description] failed to parse field [format]"));
@ -212,7 +214,8 @@ public class DataDescriptionTests extends AbstractSerializingTestCase<DataDescri
public void testInvalidFieldDelimiter() throws Exception { public void testInvalidFieldDelimiter() throws Exception {
BytesArray json = new BytesArray("{ \"field_delimiter\":\",,\" }"); BytesArray json = new BytesArray("{ \"field_delimiter\":\",,\" }");
XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, json); XContentParser parser = JsonXContent.jsonXContent
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
ParsingException ex = expectThrows(ParsingException.class, ParsingException ex = expectThrows(ParsingException.class,
() -> DataDescription.CONFIG_PARSER.apply(parser, null)); () -> DataDescription.CONFIG_PARSER.apply(parser, null));
assertThat(ex.getMessage(), containsString("[data_description] failed to parse field [field_delimiter]")); assertThat(ex.getMessage(), containsString("[data_description] failed to parse field [field_delimiter]"));
@ -225,7 +228,8 @@ public class DataDescriptionTests extends AbstractSerializingTestCase<DataDescri
public void testInvalidQuoteCharacter() throws Exception { public void testInvalidQuoteCharacter() throws Exception {
BytesArray json = new BytesArray("{ \"quote_character\":\"''\" }"); BytesArray json = new BytesArray("{ \"quote_character\":\"''\" }");
XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, json); XContentParser parser = JsonXContent.jsonXContent
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
ParsingException ex = expectThrows(ParsingException.class, ParsingException ex = expectThrows(ParsingException.class,
() -> DataDescription.CONFIG_PARSER.apply(parser, null)); () -> DataDescription.CONFIG_PARSER.apply(parser, null));
assertThat(ex.getMessage(), containsString("[data_description] failed to parse field [quote_character]")); assertThat(ex.getMessage(), containsString("[data_description] failed to parse field [quote_character]"));

View File

@ -19,6 +19,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -81,7 +82,8 @@ public class TransportGetFiltersAction extends HandledTransportAction<GetFilters
if (getDocResponse.isExists()) { if (getDocResponse.isExists()) {
BytesReference docSource = getDocResponse.getSourceAsBytesRef(); BytesReference docSource = getDocResponse.getSourceAsBytesRef();
XContentParser parser = XContentParser parser =
XContentFactory.xContent(docSource).createParser(NamedXContentRegistry.EMPTY, docSource); XContentFactory.xContent(docSource)
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, docSource);
MlFilter filter = MlFilter.PARSER.apply(parser, null).build(); MlFilter filter = MlFilter.PARSER.apply(parser, null).build();
responseBody = new QueryPage<>(Collections.singletonList(filter), 1, MlFilter.RESULTS_FIELD); responseBody = new QueryPage<>(Collections.singletonList(filter), 1, MlFilter.RESULTS_FIELD);
@ -120,7 +122,7 @@ public class TransportGetFiltersAction extends HandledTransportAction<GetFilters
for (SearchHit hit : response.getHits().getHits()) { for (SearchHit hit : response.getHits().getHits()) {
BytesReference docSource = hit.getSourceRef(); BytesReference docSource = hit.getSourceRef();
try (XContentParser parser = XContentFactory.xContent(docSource).createParser( try (XContentParser parser = XContentFactory.xContent(docSource).createParser(
NamedXContentRegistry.EMPTY, docSource)) { NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, docSource)) {
docs.add(MlFilter.PARSER.apply(parser, null).build()); docs.add(MlFilter.PARSER.apply(parser, null).build());
} catch (IOException e) { } catch (IOException e) {
this.onFailure(e); this.onFailure(e);

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.ml.job.persistence;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -28,7 +29,7 @@ class BatchedBucketsIterator extends BatchedResultsIterator<Bucket> {
BytesReference source = hit.getSourceRef(); BytesReference source = hit.getSourceRef();
XContentParser parser; XContentParser parser;
try { try {
parser = XContentFactory.xContent(source).createParser(NamedXContentRegistry.EMPTY, source); parser = XContentFactory.xContent(source).createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source);
} catch (IOException e) { } catch (IOException e) {
throw new ElasticsearchParseException("failed to parse bucket", e); throw new ElasticsearchParseException("failed to parse bucket", e);
} }

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.ml.job.persistence;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -27,7 +28,7 @@ class BatchedInfluencersIterator extends BatchedResultsIterator<Influencer> {
BytesReference source = hit.getSourceRef(); BytesReference source = hit.getSourceRef();
XContentParser parser; XContentParser parser;
try { try {
parser = XContentFactory.xContent(source).createParser(NamedXContentRegistry.EMPTY, source); parser = XContentFactory.xContent(source).createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source);
} catch (IOException e) { } catch (IOException e) {
throw new ElasticsearchParseException("failed to parser influencer", e); throw new ElasticsearchParseException("failed to parser influencer", e);
} }

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.ml.job.persistence;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -28,7 +29,7 @@ class BatchedRecordsIterator extends BatchedResultsIterator<AnomalyRecord> {
BytesReference source = hit.getSourceRef(); BytesReference source = hit.getSourceRef();
XContentParser parser; XContentParser parser;
try { try {
parser = XContentFactory.xContent(source).createParser(NamedXContentRegistry.EMPTY, source); parser = XContentFactory.xContent(source).createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source);
} catch (IOException e) { } catch (IOException e) {
throw new ElasticsearchParseException("failed to parse record", e); throw new ElasticsearchParseException("failed to parse record", e);
} }

View File

@ -45,6 +45,7 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -473,7 +474,8 @@ public class JobProvider {
private <T, U> T parseSearchHit(SearchHit hit, BiFunction<XContentParser, U, T> objectParser, private <T, U> T parseSearchHit(SearchHit hit, BiFunction<XContentParser, U, T> objectParser,
Consumer<Exception> errorHandler) { Consumer<Exception> errorHandler) {
BytesReference source = hit.getSourceRef(); BytesReference source = hit.getSourceRef();
try (XContentParser parser = XContentFactory.xContent(source).createParser(NamedXContentRegistry.EMPTY, source)) { try (XContentParser parser = XContentFactory.xContent(source)
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source)) {
return objectParser.apply(parser, null); return objectParser.apply(parser, null);
} catch (IOException e) { } catch (IOException e) {
errorHandler.accept(new ElasticsearchParseException("failed to parse " + hit.getType(), e)); errorHandler.accept(new ElasticsearchParseException("failed to parse " + hit.getType(), e));
@ -485,7 +487,8 @@ public class JobProvider {
Consumer<Exception> errorHandler) { Consumer<Exception> errorHandler) {
BytesReference source = getResponse.getSourceAsBytesRef(); BytesReference source = getResponse.getSourceAsBytesRef();
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, source)) { try (XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source)) {
return objectParser.apply(parser, null); return objectParser.apply(parser, null);
} catch (IOException e) { } catch (IOException e) {
errorHandler.accept(new ElasticsearchParseException("failed to parse " + getResponse.getType(), e)); errorHandler.accept(new ElasticsearchParseException("failed to parse " + getResponse.getType(), e));
@ -520,7 +523,8 @@ public class JobProvider {
List<Bucket> results = new ArrayList<>(); List<Bucket> results = new ArrayList<>();
for (SearchHit hit : hits.getHits()) { for (SearchHit hit : hits.getHits()) {
BytesReference source = hit.getSourceRef(); BytesReference source = hit.getSourceRef();
try (XContentParser parser = XContentFactory.xContent(source).createParser(NamedXContentRegistry.EMPTY, source)) { try (XContentParser parser = XContentFactory.xContent(source)
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source)) {
Bucket bucket = Bucket.PARSER.apply(parser, null); Bucket bucket = Bucket.PARSER.apply(parser, null);
results.add(bucket); results.add(bucket);
} catch (IOException e) { } catch (IOException e) {
@ -650,7 +654,8 @@ public class JobProvider {
List<CategoryDefinition> results = new ArrayList<>(hits.length); List<CategoryDefinition> results = new ArrayList<>(hits.length);
for (SearchHit hit : hits) { for (SearchHit hit : hits) {
BytesReference source = hit.getSourceRef(); BytesReference source = hit.getSourceRef();
try (XContentParser parser = XContentFactory.xContent(source).createParser(NamedXContentRegistry.EMPTY, source)) { try (XContentParser parser = XContentFactory.xContent(source)
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source)) {
CategoryDefinition categoryDefinition = CategoryDefinition.PARSER.apply(parser, null); CategoryDefinition categoryDefinition = CategoryDefinition.PARSER.apply(parser, null);
results.add(categoryDefinition); results.add(categoryDefinition);
} catch (IOException e) { } catch (IOException e) {
@ -683,7 +688,8 @@ public class JobProvider {
List<AnomalyRecord> results = new ArrayList<>(); List<AnomalyRecord> results = new ArrayList<>();
for (SearchHit hit : searchResponse.getHits().getHits()) { for (SearchHit hit : searchResponse.getHits().getHits()) {
BytesReference source = hit.getSourceRef(); BytesReference source = hit.getSourceRef();
try (XContentParser parser = XContentFactory.xContent(source).createParser(NamedXContentRegistry.EMPTY, source)) { try (XContentParser parser = XContentFactory.xContent(source)
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source)) {
results.add(AnomalyRecord.PARSER.apply(parser, null)); results.add(AnomalyRecord.PARSER.apply(parser, null));
} catch (IOException e) { } catch (IOException e) {
throw new ElasticsearchParseException("failed to parse records", e); throw new ElasticsearchParseException("failed to parse records", e);
@ -730,7 +736,8 @@ public class JobProvider {
List<Influencer> influencers = new ArrayList<>(); List<Influencer> influencers = new ArrayList<>();
for (SearchHit hit : response.getHits().getHits()) { for (SearchHit hit : response.getHits().getHits()) {
BytesReference source = hit.getSourceRef(); BytesReference source = hit.getSourceRef();
try (XContentParser parser = XContentFactory.xContent(source).createParser(NamedXContentRegistry.EMPTY, source)) { try (XContentParser parser = XContentFactory.xContent(source)
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source)) {
influencers.add(Influencer.PARSER.apply(parser, null)); influencers.add(Influencer.PARSER.apply(parser, null));
} catch (IOException e) { } catch (IOException e) {
throw new ElasticsearchParseException("failed to parse influencer", e); throw new ElasticsearchParseException("failed to parse influencer", e);
@ -873,7 +880,8 @@ public class JobProvider {
for (SearchHit hit : searchResponse.getHits().getHits()) { for (SearchHit hit : searchResponse.getHits().getHits()) {
BytesReference source = hit.getSourceRef(); BytesReference source = hit.getSourceRef();
try (XContentParser parser = XContentFactory.xContent(source).createParser(NamedXContentRegistry.EMPTY, source)) { try (XContentParser parser = XContentFactory.xContent(source)
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source)) {
ModelPlot modelPlot = ModelPlot.PARSER.apply(parser, null); ModelPlot modelPlot = ModelPlot.PARSER.apply(parser, null);
results.add(modelPlot); results.add(modelPlot);
} catch (IOException e) { } catch (IOException e) {
@ -1207,7 +1215,8 @@ public class JobProvider {
BytesReference docSource = getDocResponse.getSourceAsBytesRef(); BytesReference docSource = getDocResponse.getSourceAsBytesRef();
try (XContentParser parser = try (XContentParser parser =
XContentFactory.xContent(docSource).createParser(NamedXContentRegistry.EMPTY, docSource)) { XContentFactory.xContent(docSource)
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, docSource)) {
Calendar calendar = Calendar.PARSER.apply(parser, null).build(); Calendar calendar = Calendar.PARSER.apply(parser, null).build();
listener.onResponse(calendar); listener.onResponse(calendar);
} }

View File

@ -15,6 +15,7 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.bytes.CompositeBytesReference; import org.elasticsearch.common.bytes.CompositeBytesReference;
import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.util.concurrent.ConcurrentCollections; import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContent; import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
@ -220,7 +221,8 @@ public class CppLogMessageHandler implements Closeable {
private void parseMessage(XContent xContent, BytesReference bytesRef) { private void parseMessage(XContent xContent, BytesReference bytesRef) {
try { try {
XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, bytesRef); XContentParser parser = xContent
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, bytesRef);
CppLogMessage msg = CppLogMessage.PARSER.apply(parser, null); CppLogMessage msg = CppLogMessage.PARSER.apply(parser, null);
Level level = Level.getLevel(msg.getLevel()); Level level = Level.getLevel(msg.getLevel());
if (level == null) { if (level == null) {

View File

@ -10,6 +10,7 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.bytes.CompositeBytesReference; import org.elasticsearch.common.bytes.CompositeBytesReference;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContent; import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
@ -79,7 +80,8 @@ public class NormalizerResultHandler extends AbstractComponent {
} }
private void parseResult(XContent xContent, BytesReference bytesRef) throws IOException { private void parseResult(XContent xContent, BytesReference bytesRef) throws IOException {
XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, bytesRef); XContentParser parser = xContent
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, bytesRef);
NormalizerResult result = NormalizerResult.PARSER.apply(parser, null); NormalizerResult result = NormalizerResult.PARSER.apply(parser, null);
normalizedResults.add(result); normalizedResults.add(result);
} }

View File

@ -13,6 +13,7 @@ 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.common.logging.Loggers; import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -117,7 +118,7 @@ public class ExpiredForecastsRemover implements MlDataRemover {
for (SearchHit hit : hits.getHits()) { for (SearchHit hit : hits.getHits()) {
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser( XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(
NamedXContentRegistry.EMPTY, hit.getSourceRef()); NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, hit.getSourceRef());
ForecastRequestStats forecastRequestStats = ForecastRequestStats.PARSER.apply(parser, null); ForecastRequestStats forecastRequestStats = ForecastRequestStats.PARSER.apply(parser, null);
if (forecastRequestStats.getExpiryTime().toEpochMilli() < cutoffEpochMs) { if (forecastRequestStats.getExpiryTime().toEpochMilli() < cutoffEpochMs) {
forecastsToDelete.add(forecastRequestStats); forecastsToDelete.add(forecastRequestStats);

View File

@ -13,6 +13,7 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -95,7 +96,8 @@ public class AuditorTests extends ESTestCase {
} }
private AuditMessage parseAuditMessage(BytesReference msg) throws IOException { private AuditMessage parseAuditMessage(BytesReference msg) throws IOException {
XContentParser parser = XContentFactory.xContent(msg).createParser(NamedXContentRegistry.EMPTY, msg); XContentParser parser = XContentFactory.xContent(msg)
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, msg);
return AuditMessage.PARSER.apply(parser, null); return AuditMessage.PARSER.apply(parser, null);
} }
} }

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.monitoring.exporter;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.XContent; import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -59,7 +60,7 @@ public abstract class FilteredMonitoringDoc extends MonitoringDoc {
try (XContentBuilder filteredBuilder = new XContentBuilder(xContent, out, filters)) { try (XContentBuilder filteredBuilder = new XContentBuilder(xContent, out, filters)) {
super.toXContent(filteredBuilder, params); super.toXContent(filteredBuilder, params);
} }
try (XContentParser parser = xContent.createParser(EMPTY, out.bytes())) { try (XContentParser parser = xContent.createParser(EMPTY, LoggingDeprecationHandler.INSTANCE, out.bytes())) {
return builder.copyCurrentStructure(parser); return builder.copyCurrentStructure(parser);
} }
} }

View File

@ -12,6 +12,7 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -139,7 +140,8 @@ public abstract class BaseMonitoringDocTestCase<T extends MonitoringDoc> extends
final T document = createMonitoringDoc(cluster, timestamp, interval, node, system, type, id); final T document = createMonitoringDoc(cluster, timestamp, interval, node, system, type, id);
final BytesReference bytes = XContentHelper.toXContent(document, xContentType, false); final BytesReference bytes = XContentHelper.toXContent(document, xContentType, false);
try (XContentParser parser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY, bytes)) { try (XContentParser parser = xContentType.xContent()
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, bytes)) {
final Map<String, ?> map = parser.map(); final Map<String, ?> map = parser.map();
assertThat(map.get("cluster_uuid"), equalTo(cluster)); assertThat(map.get("cluster_uuid"), equalTo(cluster));

View File

@ -19,6 +19,7 @@ import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -157,7 +158,8 @@ public class NativeRoleMappingStore extends AbstractComponent implements UserRol
} }
private static XContentParser getParser(BytesReference source) throws IOException { private static XContentParser getParser(BytesReference source) throws IOException {
return XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, source); return XContentType.JSON.xContent()
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source);
} }
/** /**

View File

@ -34,6 +34,7 @@ import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
@ -201,7 +202,8 @@ public class TransportSamlInvalidateSessionActionTests extends SamlTestCase {
private SearchHit tokenHit(int idx, BytesReference source) { private SearchHit tokenHit(int idx, BytesReference source) {
try { try {
final Map<String, Object> sourceMap = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, source).map(); final Map<String, Object> sourceMap = XContentType.JSON.xContent()
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, source).map();
final Map<String, Object> accessToken = (Map<String, Object>) sourceMap.get("access_token"); final Map<String, Object> accessToken = (Map<String, Object>) sourceMap.get("access_token");
final Map<String, Object> userToken = (Map<String, Object>) accessToken.get("user_token"); final Map<String, Object> userToken = (Map<String, Object>) accessToken.get("user_token");
final SearchHit hit = new SearchHit(idx, "token_" + userToken.get("id"), null, null); final SearchHit hit = new SearchHit(idx, "token_" + userToken.get("id"), null, null);

View File

@ -7,6 +7,7 @@ package org.elasticsearch.xpack.security.rest;
import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestRequest;
@ -30,7 +31,8 @@ public class RestRequestFilterTests extends ESTestCase {
RestRequest filtered = filter.getFilteredRequest(restRequest); RestRequest filtered = filter.getFilteredRequest(restRequest);
assertNotEquals(content, filtered.content()); assertNotEquals(content, filtered.content());
Map<String, Object> map = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, filtered.content()).map(); Map<String, Object> map = XContentType.JSON.xContent()
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, filtered.content()).map();
Map<String, Object> root = (Map<String, Object>) map.get("root"); Map<String, Object> root = (Map<String, Object>) map.get("root");
assertNotNull(root); assertNotNull(root);
Map<String, Object> second = (Map<String, Object>) root.get("second"); Map<String, Object> second = (Map<String, Object>) root.get("second");
@ -47,7 +49,8 @@ public class RestRequestFilterTests extends ESTestCase {
RestRequest filtered = filter.getFilteredRequest(restRequest); RestRequest filtered = filter.getFilteredRequest(restRequest);
assertNotEquals(content, filtered.content()); assertNotEquals(content, filtered.content());
Map<String, Object> map = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, filtered.content()).map(); Map<String, Object> map = XContentType.JSON.xContent()
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, filtered.content()).map();
Map<String, Object> root = (Map<String, Object>) map.get("root"); Map<String, Object> root = (Map<String, Object>) map.get("root");
assertNotNull(root); assertNotNull(root);
Map<String, Object> second = (Map<String, Object>) root.get("second"); Map<String, Object> second = (Map<String, Object>) root.get("second");
@ -64,7 +67,8 @@ public class RestRequestFilterTests extends ESTestCase {
RestRequest filtered = filter.getFilteredRequest(restRequest); RestRequest filtered = filter.getFilteredRequest(restRequest);
assertNotEquals(content, filtered.content()); assertNotEquals(content, filtered.content());
Map<String, Object> map = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, filtered.content()).map(); Map<String, Object> map = XContentType.JSON.xContent()
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, filtered.content()).map();
Map<String, Object> root = (Map<String, Object>) map.get("root"); Map<String, Object> root = (Map<String, Object>) map.get("root");
assertNotNull(root); assertNotNull(root);
Map<String, Object> second = (Map<String, Object>) root.get("second"); Map<String, Object> second = (Map<String, Object>) root.get("second");

View File

@ -11,6 +11,7 @@ import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.common.xcontent.json.JsonXContent;
@ -143,8 +144,9 @@ public class SecurityRestFilterTests extends ESTestCase {
assertEquals(restRequest, handlerRequest.get()); assertEquals(restRequest, handlerRequest.get());
assertEquals(restRequest.content(), handlerRequest.get().content()); assertEquals(restRequest.content(), handlerRequest.get().content());
Map<String, Object> original = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, handlerRequest.get() Map<String, Object> original = XContentType.JSON.xContent()
.content()).map(); .createParser(NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, handlerRequest.get().content()).map();
assertEquals(2, original.size()); assertEquals(2, original.size());
assertEquals(SecuritySettingsSourceField.TEST_PASSWORD, original.get("password")); assertEquals(SecuritySettingsSourceField.TEST_PASSWORD, original.get("password"));
assertEquals("bar", original.get("foo")); assertEquals("bar", original.get("foo"));
@ -152,8 +154,9 @@ public class SecurityRestFilterTests extends ESTestCase {
assertNotEquals(restRequest, authcServiceRequest.get()); assertNotEquals(restRequest, authcServiceRequest.get());
assertNotEquals(restRequest.content(), authcServiceRequest.get().content()); assertNotEquals(restRequest.content(), authcServiceRequest.get().content());
Map<String, Object> map = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, authcServiceRequest.get() Map<String, Object> map = XContentType.JSON.xContent()
.content()).map(); .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
authcServiceRequest.get().content()).map();
assertEquals(1, map.size()); assertEquals(1, map.size());
assertEquals("bar", map.get("foo")); assertEquals("bar", map.get("foo"));
} }

View File

@ -11,6 +11,7 @@ import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentHelper;
@ -156,7 +157,7 @@ public class HttpClient {
private <Response> Response fromXContent(XContentType xContentType, BytesReference bytesReference, private <Response> Response fromXContent(XContentType xContentType, BytesReference bytesReference,
CheckedFunction<XContentParser, Response, IOException> responseParser) { CheckedFunction<XContentParser, Response, IOException> responseParser) {
try (XContentParser parser = xContentType.xContent().createParser(registry, bytesReference)) { try (XContentParser parser = xContentType.xContent().createParser(registry, LoggingDeprecationHandler.INSTANCE, bytesReference)) {
return responseParser.apply(parser); return responseParser.apply(parser);
} catch (IOException ex) { } catch (IOException ex) {
throw new ClientException("Cannot parse response", ex); throw new ClientException("Cannot parse response", ex);

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.watcher.input.http;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -79,7 +80,8 @@ public class ExecutableHttpInput extends ExecutableInput<HttpInput, HttpInput.Re
if (contentType != null) { if (contentType != null) {
// EMPTY is safe here because we never use namedObject // EMPTY is safe here because we never use namedObject
try (XContentParser parser = contentType.xContent().createParser(NamedXContentRegistry.EMPTY, response.body())) { try (XContentParser parser = contentType.xContent()
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, response.body())) {
if (input.getExtractKeys() != null) { if (input.getExtractKeys() != null) {
payloadMap.putAll(XContentFilterKeysUtils.filterMapOrdered(input.getExtractKeys(), parser)); payloadMap.putAll(XContentFilterKeysUtils.filterMapOrdered(input.getExtractKeys(), parser));
} else { } else {

View File

@ -15,6 +15,7 @@ import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -200,7 +201,8 @@ public class ReportingAttachmentParser implements EmailAttachmentParser<Reportin
*/ */
private String extractIdFromJson(String watchId, String attachmentId, BytesReference body) throws IOException { private String extractIdFromJson(String watchId, String attachmentId, BytesReference body) throws IOException {
// EMPTY is safe here becaus we never call namedObject // EMPTY is safe here becaus we never call namedObject
try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, body)) { try (XContentParser parser = JsonXContent.jsonXContent
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, body)) {
KibanaReportingPayload payload = new KibanaReportingPayload(); KibanaReportingPayload payload = new KibanaReportingPayload();
PAYLOAD_PARSER.parse(parser, payload, null); PAYLOAD_PARSER.parse(parser, payload, null);
String path = payload.getPath(); String path = payload.getPath();

View File

@ -10,6 +10,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsException; import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -79,7 +80,8 @@ public class JiraAccount {
settings.getAsSettings(ISSUE_DEFAULTS_SETTING).toXContent(builder, ToXContent.EMPTY_PARAMS); settings.getAsSettings(ISSUE_DEFAULTS_SETTING).toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.endObject(); builder.endObject();
this.issueDefaults = Collections.unmodifiableMap(XContentType.JSON.xContent() this.issueDefaults = Collections.unmodifiableMap(XContentType.JSON.xContent()
.createParser(new NamedXContentRegistry(Collections.emptyList()), builder.bytes()).map()); .createParser(new NamedXContentRegistry(Collections.emptyList()),
LoggingDeprecationHandler.INSTANCE, builder.bytes()).map());
} catch (IOException ex) { } catch (IOException ex) {
throw new UncheckedIOException(ex); throw new UncheckedIOException(ex);
} }

View File

@ -9,6 +9,7 @@ import org.apache.http.HttpStatus;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -147,7 +148,8 @@ public class JiraIssue implements ToXContentObject {
if (response.hasContent()) { if (response.hasContent()) {
final List<String> errors = new ArrayList<>(); final List<String> errors = new ArrayList<>();
// EMPTY is safe here because we never call namedObject // EMPTY is safe here because we never call namedObject
try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, response.body())) { try (XContentParser parser = JsonXContent.jsonXContent
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, response.body())) {
XContentParser.Token token = parser.currentToken(); XContentParser.Token token = parser.currentToken();
if (token == null) { if (token == null) {
token = parser.nextToken(); token = parser.nextToken();

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.watcher.notification.pagerduty;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -103,7 +104,8 @@ public class SentEvent implements ToXContentObject {
// based on https://developer.pagerduty.com/documentation/rest/errors // based on https://developer.pagerduty.com/documentation/rest/errors
try { try {
// EMPTY is safe here because we never call namedObject // EMPTY is safe here because we never call namedObject
XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, response.body()); XContentParser parser = JsonXContent.jsonXContent
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, response.body());
parser.nextToken(); parser.nextToken();
String message = null; String message = null;

View File

@ -9,6 +9,7 @@ import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -63,7 +64,8 @@ public class WatcherSearchTemplateService extends AbstractComponent {
SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource(); SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource();
BytesReference source = request.getSearchSource(); BytesReference source = request.getSearchSource();
if (source != null && source.length() > 0) { if (source != null && source.length() > 0) {
try (XContentParser parser = XContentFactory.xContent(source).createParser(xContentRegistry, source)) { try (XContentParser parser = XContentFactory.xContent(source)
.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, source)) {
sourceBuilder.parseXContent(parser); sourceBuilder.parseXContent(parser);
searchRequest.source(sourceBuilder); searchRequest.source(sourceBuilder);
} }

View File

@ -11,6 +11,7 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
@ -101,8 +102,9 @@ public class WatchParser extends AbstractComponent {
logger.trace("parsing watch [{}] ", source.utf8ToString()); logger.trace("parsing watch [{}] ", source.utf8ToString());
} }
// EMPTY is safe here because we never use namedObject // EMPTY is safe here because we never use namedObject
try (WatcherXContentParser parser = new WatcherXContentParser(xContentType.xContent().createParser(NamedXContentRegistry.EMPTY, try (WatcherXContentParser parser = new WatcherXContentParser(xContentType.xContent()
source), now, withSecrets ? cryptoService : null)) { .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source),
now, withSecrets ? cryptoService : null)) {
parser.nextToken(); parser.nextToken();
return parse(id, includeStatus, parser); return parse(id, includeStatus, parser);
} catch (IOException ioe) { } catch (IOException ioe) {

View File

@ -6,6 +6,7 @@
package org.elasticsearch.xpack.watcher.common.http; package org.elasticsearch.xpack.watcher.common.http;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -32,7 +33,7 @@ public class HttpProxyTests extends ESTestCase {
} }
builder.endObject(); builder.endObject();
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON) try (XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, builder.bytes())) { .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, builder.bytes())) {
parser.nextToken(); parser.nextToken();
HttpProxy proxy = HttpProxy.parse(parser); HttpProxy proxy = HttpProxy.parse(parser);
assertThat(proxy.getHost(), is(host)); assertThat(proxy.getHost(), is(host));
@ -50,7 +51,7 @@ public class HttpProxyTests extends ESTestCase {
.field("host", "localhost").field("port", 12345).field("scheme", "invalid") .field("host", "localhost").field("port", 12345).field("scheme", "invalid")
.endObject(); .endObject();
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON) try (XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, builder.bytes())) { .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, builder.bytes())) {
parser.nextToken(); parser.nextToken();
expectThrows(IllegalArgumentException.class, () -> HttpProxy.parse(parser)); expectThrows(IllegalArgumentException.class, () -> HttpProxy.parse(parser));
} }
@ -61,7 +62,7 @@ public class HttpProxyTests extends ESTestCase {
.field("host", "localhost").field("port", -1) .field("host", "localhost").field("port", -1)
.endObject(); .endObject();
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON) try (XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, builder.bytes())) { .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, builder.bytes())) {
parser.nextToken(); parser.nextToken();
expectThrows(ElasticsearchParseException.class, () -> HttpProxy.parse(parser)); expectThrows(ElasticsearchParseException.class, () -> HttpProxy.parse(parser));
} }
@ -72,7 +73,7 @@ public class HttpProxyTests extends ESTestCase {
.field("port", -1) .field("port", -1)
.endObject(); .endObject();
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON) try (XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, builder.bytes())) { .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, builder.bytes())) {
parser.nextToken(); parser.nextToken();
expectThrows(ElasticsearchParseException.class, () -> HttpProxy.parse(parser)); expectThrows(ElasticsearchParseException.class, () -> HttpProxy.parse(parser));
} }
@ -83,7 +84,7 @@ public class HttpProxyTests extends ESTestCase {
.field("host", "localhost") .field("host", "localhost")
.endObject(); .endObject();
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON) try (XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, builder.bytes())) { .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, builder.bytes())) {
parser.nextToken(); parser.nextToken();
expectThrows(ElasticsearchParseException.class, () -> HttpProxy.parse(parser)); expectThrows(ElasticsearchParseException.class, () -> HttpProxy.parse(parser));
} }

View File

@ -21,6 +21,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -1018,8 +1019,8 @@ public class ExecutionServiceTests extends ESTestCase {
final AtomicBoolean assertionsTriggered = new AtomicBoolean(false); final AtomicBoolean assertionsTriggered = new AtomicBoolean(false);
doAnswer(invocation -> { doAnswer(invocation -> {
UpdateRequest request = (UpdateRequest) invocation.getArguments()[0]; UpdateRequest request = (UpdateRequest) invocation.getArguments()[0];
try (XContentParser parser = try (XContentParser parser = XContentFactory.xContent(XContentType.JSON)
XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, request.doc().source())) { .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, request.doc().source())) {
Map<String, Object> map = parser.map(); Map<String, Object> map = parser.map();
Map<String, String> state = ObjectPath.eval("status.state", map); Map<String, String> state = ObjectPath.eval("status.state", map);
assertThat(state, is(nullValue())); assertThat(state, is(nullValue()));

View File

@ -9,6 +9,7 @@ import io.netty.handler.codec.http.HttpHeaders;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -334,7 +335,8 @@ public class HttpInputTests extends ESTestCase {
try (XContentBuilder builder = jsonBuilder()) { try (XContentBuilder builder = jsonBuilder()) {
result.toXContent(builder, ToXContent.EMPTY_PARAMS); result.toXContent(builder, ToXContent.EMPTY_PARAMS);
BytesReference bytes = builder.bytes(); BytesReference bytes = builder.bytes();
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, bytes)) { try (XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes)) {
Map<String, Object> data = parser.map(); Map<String, Object> data = parser.map();
String reason = ObjectPath.eval("error.reason", data); String reason = ObjectPath.eval("error.reason", data);
assertThat(reason, is("could not connect")); assertThat(reason, is("could not connect"));

View File

@ -15,6 +15,7 @@ import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -164,8 +165,8 @@ public class SearchInputTests extends ESTestCase {
try (XContentBuilder builder = jsonBuilder().startObject().startObject("request") try (XContentBuilder builder = jsonBuilder().startObject().startObject("request")
.startArray("indices").value("foo").endArray().endObject().endObject(); .startArray("indices").value("foo").endArray().endObject().endObject();
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, XContentParser parser = XContentFactory.xContent(XContentType.JSON)
builder.bytes())) { .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, builder.bytes())) {
parser.nextToken(); // advance past the first starting object parser.nextToken(); // advance past the first starting object

View File

@ -17,6 +17,7 @@ import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -354,7 +355,7 @@ abstract class MlNativeAutodetectIntegTestCase extends ESIntegTestCase {
assertThat(hits.getTotalHits(), equalTo(1L)); assertThat(hits.getTotalHits(), equalTo(1L));
try { try {
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser( XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(
NamedXContentRegistry.EMPTY, hits.getHits()[0].getSourceRef()); NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, hits.getHits()[0].getSourceRef());
return ForecastRequestStats.PARSER.apply(parser, null); return ForecastRequestStats.PARSER.apply(parser, null);
} catch (IOException e) { } catch (IOException e) {
throw new IllegalStateException(e); throw new IllegalStateException(e);
@ -373,7 +374,7 @@ abstract class MlNativeAutodetectIntegTestCase extends ESIntegTestCase {
for (SearchHit hit : hits) { for (SearchHit hit : hits) {
try { try {
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser( XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(
NamedXContentRegistry.EMPTY, hit.getSourceRef()); NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, hit.getSourceRef());
forecastStats.add(ForecastRequestStats.PARSER.apply(parser, null)); forecastStats.add(ForecastRequestStats.PARSER.apply(parser, null));
} catch (IOException e) { } catch (IOException e) {
throw new IllegalStateException(e); throw new IllegalStateException(e);
@ -407,7 +408,7 @@ abstract class MlNativeAutodetectIntegTestCase extends ESIntegTestCase {
for (SearchHit hit : hits) { for (SearchHit hit : hits) {
try { try {
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser( XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(
NamedXContentRegistry.EMPTY, hit.getSourceRef()); NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, hit.getSourceRef());
forecasts.add(Forecast.PARSER.apply(parser, null)); forecasts.add(Forecast.PARSER.apply(parser, null));
} catch (IOException e) { } catch (IOException e) {
throw new IllegalStateException(e); throw new IllegalStateException(e);