Remove calls to deprecated xcontent method (#84733)

This removes many calls to the last remaining `createParser` method that
I deprecated in #79814, migrating callers to one of the new methods that
it created.
This commit is contained in:
Nik Everett 2022-08-01 08:48:03 -04:00 committed by GitHub
parent 4607182ce8
commit 87ab933c8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 75 additions and 173 deletions

View file

@ -8,8 +8,6 @@ import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import org.elasticsearch.search.fetch.subphase.FetchSourcePhase; import org.elasticsearch.search.fetch.subphase.FetchSourcePhase;
import org.elasticsearch.search.lookup.SourceLookup; import org.elasticsearch.search.lookup.SourceLookup;
import org.elasticsearch.xcontent.DeprecationHandler;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration; import org.elasticsearch.xcontent.XContentParserConfiguration;
@ -108,8 +106,7 @@ public class FetchSourcePhaseBenchmark {
XContentType.JSON.toParsedMediaType() XContentType.JSON.toParsedMediaType()
); );
try ( try (
XContentParser parser = XContentType.JSON.xContent() XContentParser parser = XContentType.JSON.xContent().createParser(XContentParserConfiguration.EMPTY, sourceBytes.streamInput())
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, sourceBytes.streamInput())
) { ) {
builder.copyCurrentStructure(parser); builder.copyCurrentStructure(parser);
return BytesReference.bytes(builder); return BytesReference.bytes(builder);

View file

@ -177,6 +177,7 @@ import org.elasticsearch.xcontent.DeprecationHandler;
import org.elasticsearch.xcontent.NamedXContentRegistry; import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.XContentType;
import java.io.Closeable; import java.io.Closeable;
@ -244,7 +245,7 @@ public class RestHighLevelClient implements Closeable {
// To be called using performClientRequest and performClientRequestAsync to ensure version compatibility check // To be called using performClientRequest and performClientRequestAsync to ensure version compatibility check
private final RestClient client; private final RestClient client;
private final NamedXContentRegistry registry; private final XContentParserConfiguration parserConfig;
private final CheckedConsumer<RestClient, IOException> doClose; private final CheckedConsumer<RestClient, IOException> doClose;
private final boolean useAPICompatibility; private final boolean useAPICompatibility;
@ -297,11 +298,19 @@ public class RestHighLevelClient implements Closeable {
) { ) {
this.client = Objects.requireNonNull(restClient, "restClient must not be null"); this.client = Objects.requireNonNull(restClient, "restClient must not be null");
this.doClose = Objects.requireNonNull(doClose, "doClose consumer must not be null"); this.doClose = Objects.requireNonNull(doClose, "doClose consumer must not be null");
this.registry = new NamedXContentRegistry( NamedXContentRegistry registry = new NamedXContentRegistry(
Stream.of(getDefaultNamedXContents().stream(), getProvidedNamedXContents().stream(), namedXContentEntries.stream()) Stream.of(getDefaultNamedXContents().stream(), getProvidedNamedXContents().stream(), namedXContentEntries.stream())
.flatMap(Function.identity()) .flatMap(Function.identity())
.collect(toList()) .collect(toList())
); );
/*
* Ignores deprecation warnings. This is appropriate because it is only
* used to parse responses from Elasticsearch. Any deprecation warnings
* emitted there just mean that you are talking to an old version of
* Elasticsearch. There isn't anything you can do about the deprecation.
*/
this.parserConfig = XContentParserConfiguration.EMPTY.withRegistry(registry)
.withDeprecationHandler(DeprecationHandler.IGNORE_DEPRECATIONS);
if (useAPICompatibility == null && "true".equals(System.getenv(API_VERSIONING_ENV_VARIABLE))) { if (useAPICompatibility == null && "true".equals(System.getenv(API_VERSIONING_ENV_VARIABLE))) {
this.useAPICompatibility = true; this.useAPICompatibility = true;
} else { } else {
@ -1165,7 +1174,7 @@ public class RestHighLevelClient implements Closeable {
if (xContentType == null) { if (xContentType == null) {
throw new IllegalStateException("Unsupported Content-Type: " + entity.getContentType().getValue()); throw new IllegalStateException("Unsupported Content-Type: " + entity.getContentType().getValue());
} }
try (XContentParser parser = xContentType.xContent().createParser(registry, DEPRECATION_HANDLER, entity.getContent())) { try (XContentParser parser = xContentType.xContent().createParser(parserConfig, entity.getContent())) {
return entityParser.apply(parser); return entityParser.apply(parser);
} }
} }
@ -1506,14 +1515,6 @@ public class RestHighLevelClient implements Closeable {
return Optional.empty(); return Optional.empty();
} }
/**
* Ignores deprecation warnings. This is appropriate because it is only
* used to parse responses from Elasticsearch. Any deprecation warnings
* emitted there just mean that you are talking to an old version of
* Elasticsearch. There isn't anything you can do about the deprecation.
*/
private static final DeprecationHandler DEPRECATION_HANDLER = DeprecationHandler.IGNORE_DEPRECATIONS;
static List<NamedXContentRegistry.Entry> getDefaultNamedXContents() { static List<NamedXContentRegistry.Entry> getDefaultNamedXContents() {
Map<String, ContextParser<Object, ? extends Aggregation>> map = new HashMap<>(); Map<String, ContextParser<Object, ? extends Aggregation>> map = new HashMap<>();
map.put(CardinalityAggregationBuilder.NAME, (p, c) -> ParsedCardinality.fromXContent(p, (String) c)); map.put(CardinalityAggregationBuilder.NAME, (p, c) -> ParsedCardinality.fromXContent(p, (String) c));

View file

@ -21,13 +21,12 @@ import com.fasterxml.jackson.core.util.JsonGeneratorDelegate;
import org.elasticsearch.core.CheckedConsumer; import org.elasticsearch.core.CheckedConsumer;
import org.elasticsearch.core.Streams; import org.elasticsearch.core.Streams;
import org.elasticsearch.xcontent.DeprecationHandler;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContent; import org.elasticsearch.xcontent.XContent;
import org.elasticsearch.xcontent.XContentFactory; import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.XContentGenerationException; import org.elasticsearch.xcontent.XContentGenerationException;
import org.elasticsearch.xcontent.XContentGenerator; import org.elasticsearch.xcontent.XContentGenerator;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xcontent.provider.filtering.FilterPathBasedFilter; import org.elasticsearch.xcontent.provider.filtering.FilterPathBasedFilter;
@ -444,14 +443,7 @@ public class JsonXContentGenerator implements XContentGenerator {
@Override @Override
public void writeRawField(String name, InputStream content, XContentType contentType) throws IOException { public void writeRawField(String name, InputStream content, XContentType contentType) throws IOException {
if (mayWriteRawData(contentType) == false) { if (mayWriteRawData(contentType) == false) {
// EMPTY is safe here because we never call namedObject when writing raw data try (XContentParser parser = XContentFactory.xContent(contentType).createParser(XContentParserConfiguration.EMPTY, content)) {
try (
XContentParser parser = XContentFactory.xContent(contentType)
// It's okay to pass the throwing deprecation handler
// because we should not be writing raw fields when
// generating JSON
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, content)
) {
parser.nextToken(); parser.nextToken();
writeFieldName(name); writeFieldName(name);
copyCurrentStructure(parser); copyCurrentStructure(parser);
@ -493,13 +485,7 @@ public class JsonXContentGenerator implements XContentGenerator {
} }
protected void copyRawValue(InputStream stream, XContent xContent) throws IOException { protected void copyRawValue(InputStream stream, XContent xContent) throws IOException {
// EMPTY is safe here because we never call namedObject try (XContentParser parser = xContent.createParser(XContentParserConfiguration.EMPTY, stream)) {
try (
XContentParser parser = xContent
// It's okay to pass the throwing deprecation handler because we
// should not be writing raw fields when generating JSON
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, stream)
) {
copyCurrentStructure(parser); copyCurrentStructure(parser);
} }
} }

View file

@ -14,9 +14,8 @@ import org.elasticsearch.ingest.AbstractProcessor;
import org.elasticsearch.ingest.ConfigurationUtils; import org.elasticsearch.ingest.ConfigurationUtils;
import org.elasticsearch.ingest.IngestDocument; import org.elasticsearch.ingest.IngestDocument;
import org.elasticsearch.ingest.Processor; import org.elasticsearch.ingest.Processor;
import org.elasticsearch.xcontent.DeprecationHandler;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.json.JsonXContent; import org.elasticsearch.xcontent.json.JsonXContent;
import java.io.IOException; import java.io.IOException;
@ -77,11 +76,7 @@ public final class JsonProcessor extends AbstractProcessor {
BytesReference bytesRef = fieldValue == null ? new BytesArray("null") : new BytesArray(fieldValue.toString()); BytesReference bytesRef = fieldValue == null ? new BytesArray("null") : new BytesArray(fieldValue.toString());
try ( try (
InputStream stream = bytesRef.streamInput(); InputStream stream = bytesRef.streamInput();
XContentParser parser = JsonXContent.jsonXContent.createParser( XContentParser parser = JsonXContent.jsonXContent.createParser(XContentParserConfiguration.EMPTY, stream)
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
stream
)
) { ) {
parser.allowDuplicateKeys(allowDuplicateKeys); parser.allowDuplicateKeys(allowDuplicateKeys);
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();

View file

@ -19,9 +19,9 @@ import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptException; import org.elasticsearch.script.ScriptException;
import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptService;
import org.elasticsearch.script.ScriptType; import org.elasticsearch.script.ScriptType;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xcontent.json.JsonXContent; import org.elasticsearch.xcontent.json.JsonXContent;
@ -110,7 +110,7 @@ public final class ScriptProcessor extends AbstractProcessor {
XContentBuilder builder = XContentBuilder.builder(JsonXContent.jsonXContent).map(config); XContentBuilder builder = XContentBuilder.builder(JsonXContent.jsonXContent).map(config);
InputStream stream = BytesReference.bytes(builder).streamInput(); InputStream stream = BytesReference.bytes(builder).streamInput();
XContentParser parser = XContentType.JSON.xContent() XContentParser parser = XContentType.JSON.xContent()
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, stream) .createParser(XContentParserConfiguration.EMPTY.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE), stream)
) { ) {
Script script = Script.parse(parser); Script script = Script.parse(parser);

View file

@ -9,10 +9,10 @@
package org.elasticsearch.ingest.useragent; package org.elasticsearch.ingest.useragent;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; import org.elasticsearch.ingest.useragent.UserAgentParser.VersionedName;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentFactory; import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.XContentType;
import java.io.IOException; import java.io.IOException;
@ -24,7 +24,6 @@ import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static org.elasticsearch.ingest.useragent.UserAgentParser.VersionedName;
import static org.elasticsearch.ingest.useragent.UserAgentParser.readParserConfigurations; import static org.elasticsearch.ingest.useragent.UserAgentParser.readParserConfigurations;
public class DeviceTypeParser { public class DeviceTypeParser {
@ -40,9 +39,8 @@ public class DeviceTypeParser {
private final HashMap<String, ArrayList<DeviceTypeSubPattern>> deviceTypePatterns = new HashMap<>(); private final HashMap<String, ArrayList<DeviceTypeSubPattern>> deviceTypePatterns = new HashMap<>();
public void init(InputStream regexStream) throws IOException { public void init(InputStream regexStream) throws IOException {
// EMPTY is safe here because we don't use namedObject
XContentParser yamlParser = XContentFactory.xContent(XContentType.YAML) XContentParser yamlParser = XContentFactory.xContent(XContentType.YAML)
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, regexStream); .createParser(XContentParserConfiguration.EMPTY, regexStream);
XContentParser.Token token = yamlParser.nextToken(); XContentParser.Token token = yamlParser.nextToken();

View file

@ -9,10 +9,9 @@
package org.elasticsearch.ingest.useragent; package org.elasticsearch.ingest.useragent;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentFactory; import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.XContentType;
import java.io.IOException; import java.io.IOException;
@ -50,7 +49,7 @@ final class UserAgentParser {
private void init(InputStream regexStream) throws IOException { private void init(InputStream regexStream) throws IOException {
// EMPTY is safe here because we don't use namedObject // EMPTY is safe here because we don't use namedObject
XContentParser yamlParser = XContentFactory.xContent(XContentType.YAML) XContentParser yamlParser = XContentFactory.xContent(XContentType.YAML)
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, regexStream); .createParser(XContentParserConfiguration.EMPTY, regexStream);
XContentParser.Token token = yamlParser.nextToken(); XContentParser.Token token = yamlParser.nextToken();

View file

@ -8,11 +8,11 @@
package org.elasticsearch.ingest.useragent; package org.elasticsearch.ingest.useragent;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; import org.elasticsearch.ingest.useragent.UserAgentParser.VersionedName;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentFactory; import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.XContentType;
import org.junit.BeforeClass; import org.junit.BeforeClass;
@ -23,7 +23,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static org.elasticsearch.ingest.useragent.UserAgentParser.VersionedName;
import static org.elasticsearch.ingest.useragent.UserAgentParser.readParserConfigurations; import static org.elasticsearch.ingest.useragent.UserAgentParser.readParserConfigurations;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
@ -33,7 +32,7 @@ public class DeviceTypeParserTests extends ESTestCase {
private ArrayList<HashMap<String, String>> readTestDevices(InputStream regexStream, String keyName) throws IOException { private ArrayList<HashMap<String, String>> readTestDevices(InputStream regexStream, String keyName) throws IOException {
XContentParser yamlParser = XContentFactory.xContent(XContentType.YAML) XContentParser yamlParser = XContentFactory.xContent(XContentType.YAML)
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, regexStream); .createParser(XContentParserConfiguration.EMPTY, regexStream);
XContentParser.Token token = yamlParser.nextToken(); XContentParser.Token token = yamlParser.nextToken();

View file

@ -15,6 +15,7 @@ import org.elasticsearch.painless.action.PainlessContextInfo;
import org.elasticsearch.painless.action.PainlessContextInstanceBindingInfo; import org.elasticsearch.painless.action.PainlessContextInstanceBindingInfo;
import org.elasticsearch.painless.action.PainlessContextMethodInfo; import org.elasticsearch.painless.action.PainlessContextMethodInfo;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.json.JsonXContent; import org.elasticsearch.xcontent.json.JsonXContent;
import java.io.IOException; import java.io.IOException;
@ -36,7 +37,7 @@ public class ContextGeneratorCommon {
public static List<PainlessContextInfo> getContextInfos() throws IOException { public static List<PainlessContextInfo> getContextInfos() throws IOException {
URLConnection getContextNames = new URL("http://" + System.getProperty("cluster.uri") + "/_scripts/painless/_context") URLConnection getContextNames = new URL("http://" + System.getProperty("cluster.uri") + "/_scripts/painless/_context")
.openConnection(); .openConnection();
XContentParser parser = JsonXContent.jsonXContent.createParser(null, null, getContextNames.getInputStream()); XContentParser parser = JsonXContent.jsonXContent.createParser(XContentParserConfiguration.EMPTY, getContextNames.getInputStream());
parser.nextToken(); parser.nextToken();
parser.nextToken(); parser.nextToken();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -50,7 +51,7 @@ public class ContextGeneratorCommon {
URLConnection getContextInfo = new URL( URLConnection getContextInfo = new URL(
"http://" + System.getProperty("cluster.uri") + "/_scripts/painless/_context?context=" + contextName "http://" + System.getProperty("cluster.uri") + "/_scripts/painless/_context?context=" + contextName
).openConnection(); ).openConnection();
parser = JsonXContent.jsonXContent.createParser(null, null, getContextInfo.getInputStream()); parser = JsonXContent.jsonXContent.createParser(XContentParserConfiguration.EMPTY, getContextInfo.getInputStream());
contextInfos.add(PainlessContextInfo.fromXContent(parser)); contextInfos.add(PainlessContextInfo.fromXContent(parser));
((HttpURLConnection) getContextInfo).disconnect(); ((HttpURLConnection) getContextInfo).disconnect();
} }

View file

@ -9,10 +9,8 @@ package org.elasticsearch.painless.action;
import org.elasticsearch.common.bytes.BytesReference; 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.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.index.query.MatchAllQueryBuilder; import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.painless.action.PainlessExecuteAction.Request.ContextSetup; import org.elasticsearch.painless.action.PainlessExecuteAction.Request.ContextSetup;
@ -51,8 +49,7 @@ public class PainlessExecuteRequestTests extends AbstractWireSerializingTestCase
try (XContentBuilder builder = XContentBuilder.builder(xContent)) { try (XContentBuilder builder = XContentBuilder.builder(xContent)) {
builder.value(testInstance); builder.value(testInstance);
StreamInput instanceInput = BytesReference.bytes(builder).streamInput(); try (XContentParser parser = createParser(xContent, BytesReference.bytes(builder).streamInput())) {
try (XContentParser parser = xContent.createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, instanceInput)) {
PainlessExecuteAction.Request result = PainlessExecuteAction.Request.parse(parser); PainlessExecuteAction.Request result = PainlessExecuteAction.Request.parse(parser);
assertThat(result, equalTo(testInstance)); assertThat(result, equalTo(testInstance));
} }

View file

@ -54,10 +54,9 @@ import org.elasticsearch.script.ReindexScript;
import org.elasticsearch.script.Script; import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptService; import org.elasticsearch.script.ScriptService;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xcontent.DeprecationHandler;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.XContentType;
import java.io.IOException; import java.io.IOException;
@ -323,8 +322,7 @@ public class Reindexer {
// we need to convert // we need to convert
try ( try (
InputStream stream = doc.getSource().streamInput(); InputStream stream = doc.getSource().streamInput();
XContentParser parser = sourceXContentType.xContent() XContentParser parser = sourceXContentType.xContent().createParser(XContentParserConfiguration.EMPTY, stream);
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, stream);
XContentBuilder builder = XContentBuilder.builder(mainRequestXContentType.xContent()) XContentBuilder builder = XContentBuilder.builder(mainRequestXContentType.xContent())
) { ) {
parser.nextToken(); parser.nextToken();

View file

@ -33,9 +33,9 @@ import org.elasticsearch.index.reindex.RemoteInfo;
import org.elasticsearch.index.reindex.ScrollableHitSource; import org.elasticsearch.index.reindex.ScrollableHitSource;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentParseException; import org.elasticsearch.xcontent.XContentParseException;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.XContentType;
import java.io.IOException; import java.io.IOException;
@ -192,7 +192,10 @@ public class RemoteScrollableHitSource extends ScrollableHitSource {
// EMPTY is safe here because we don't call namedObject // EMPTY is safe here because we don't call namedObject
try ( try (
XContentParser xContentParser = xContentType.xContent() XContentParser xContentParser = xContentType.xContent()
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, content) .createParser(
XContentParserConfiguration.EMPTY.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE),
content
)
) { ) {
parsedResponse = parser.apply(xContentParser, xContentType); parsedResponse = parser.apply(xContentParser, xContentType);
} catch (XContentParseException e) { } catch (XContentParseException e) {

View file

@ -43,9 +43,9 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions; import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.ObjectPath; import org.elasticsearch.test.rest.ObjectPath;
import org.elasticsearch.xcontent.DeprecationHandler; import org.elasticsearch.test.rest.yaml.ObjectPath;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.json.JsonXContent; import org.elasticsearch.xcontent.json.JsonXContent;
import java.io.IOException; import java.io.IOException;
@ -189,8 +189,7 @@ public class SearchStatesIT extends ESRestTestCase {
Response response = localClient.performRequest(request); Response response = localClient.performRequest(request);
try ( try (
XContentParser parser = JsonXContent.jsonXContent.createParser( XContentParser parser = JsonXContent.jsonXContent.createParser(
NamedXContentRegistry.EMPTY, XContentParserConfiguration.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
response.getEntity().getContent() response.getEntity().getContent()
) )
) { ) {

View file

@ -19,7 +19,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.snapshots.SnapshotsService; import org.elasticsearch.snapshots.SnapshotsService;
import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.ObjectPath; import org.elasticsearch.test.rest.ObjectPath;
import org.elasticsearch.xcontent.DeprecationHandler;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.json.JsonXContent; import org.elasticsearch.xcontent.json.JsonXContent;
@ -243,11 +242,7 @@ public class MultiVersionRepositoryAccessIT extends ESRestTestCase {
private List<Map<String, Object>> listSnapshots(String repoName) throws IOException { private List<Map<String, Object>> listSnapshots(String repoName) throws IOException {
try ( try (
InputStream entity = client().performRequest(new Request("GET", "/_snapshot/" + repoName + "/_all")).getEntity().getContent(); InputStream entity = client().performRequest(new Request("GET", "/_snapshot/" + repoName + "/_all")).getEntity().getContent();
XContentParser parser = JsonXContent.jsonXContent.createParser( XContentParser parser = createParser(JsonXContent.jsonXContent, entity)
xContentRegistry(),
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
entity
)
) { ) {
return (List<Map<String, Object>>) parser.map().get("snapshots"); return (List<Map<String, Object>>) parser.map().get("snapshots");
} }

View file

@ -23,9 +23,8 @@ import org.elasticsearch.snapshots.AbstractSnapshotIntegTestCase;
import org.elasticsearch.snapshots.SnapshotInfo; import org.elasticsearch.snapshots.SnapshotInfo;
import org.elasticsearch.snapshots.SnapshotsService; import org.elasticsearch.snapshots.SnapshotsService;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xcontent.DeprecationHandler;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.json.JsonXContent; import org.elasticsearch.xcontent.json.JsonXContent;
import java.io.IOException; import java.io.IOException;
@ -444,11 +443,7 @@ public class RestGetSnapshotsIT extends AbstractSnapshotRestTestCase {
private static GetSnapshotsResponse readSnapshotInfos(Response response) throws IOException { private static GetSnapshotsResponse readSnapshotInfos(Response response) throws IOException {
try ( try (
InputStream input = response.getEntity().getContent(); InputStream input = response.getEntity().getContent();
XContentParser parser = JsonXContent.jsonXContent.createParser( XContentParser parser = JsonXContent.jsonXContent.createParser(XContentParserConfiguration.EMPTY, input)
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
input
)
) { ) {
return GetSnapshotsResponse.fromXContent(parser); return GetSnapshotsResponse.fromXContent(parser);
} }

View file

@ -18,7 +18,6 @@ import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.xcontent.AbstractObjectParser; import org.elasticsearch.xcontent.AbstractObjectParser;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ObjectParser; import org.elasticsearch.xcontent.ObjectParser;
import org.elasticsearch.xcontent.ObjectParser.ValueType; import org.elasticsearch.xcontent.ObjectParser.ValueType;
import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.xcontent.ParseField;
@ -28,6 +27,7 @@ import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory; import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParser.Token; import org.elasticsearch.xcontent.XContentParser.Token;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xcontent.json.JsonXContent; import org.elasticsearch.xcontent.json.JsonXContent;
@ -303,8 +303,7 @@ public final class Script implements ToXContentObject, Writeable {
try ( try (
InputStream stream = BytesReference.bytes(builder).streamInput(); InputStream stream = BytesReference.bytes(builder).streamInput();
XContentParser parser = JsonXContent.jsonXContent.createParser( XContentParser parser = JsonXContent.jsonXContent.createParser(
NamedXContentRegistry.EMPTY, XContentParserConfiguration.EMPTY.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE),
LoggingDeprecationHandler.INSTANCE,
stream stream
) )
) { ) {

View file

@ -18,7 +18,6 @@ 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.LoggingDeprecationHandler;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ObjectParser; import org.elasticsearch.xcontent.ObjectParser;
import org.elasticsearch.xcontent.ObjectParser.ValueType; import org.elasticsearch.xcontent.ObjectParser.ValueType;
import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.xcontent.ParseField;
@ -27,6 +26,7 @@ import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory; import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParser.Token; import org.elasticsearch.xcontent.XContentParser.Token;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.XContentType;
import java.io.IOException; import java.io.IOException;
@ -188,7 +188,7 @@ public class StoredScriptSource implements SimpleDiffable<StoredScriptSource>, W
try ( try (
InputStream stream = content.streamInput(); InputStream stream = content.streamInput();
XContentParser parser = xContentType.xContent() XContentParser parser = xContentType.xContent()
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, stream) .createParser(XContentParserConfiguration.EMPTY.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE), stream)
) { ) {
Token token = parser.nextToken(); Token token = parser.nextToken();

View file

@ -12,12 +12,11 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.core.CheckedFunction; import org.elasticsearch.core.CheckedFunction;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xcontent.DeprecationHandler;
import org.elasticsearch.xcontent.FilterXContentParserWrapper; import org.elasticsearch.xcontent.FilterXContentParserWrapper;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContent; import org.elasticsearch.xcontent.XContent;
import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.XContentType;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -52,10 +51,7 @@ public abstract class AbstractFilteringTestCase extends ESTestCase {
return builder -> { return builder -> {
try (InputStream stream = AbstractFilteringTestCase.class.getResourceAsStream(file)) { try (InputStream stream = AbstractFilteringTestCase.class.getResourceAsStream(file)) {
assertThat("Couldn't find [" + file + "]", stream, notNullValue()); assertThat("Couldn't find [" + file + "]", stream, notNullValue());
try ( try (XContentParser parser = XContentType.JSON.xContent().createParser(XContentParserConfiguration.EMPTY, stream)) {
XContentParser parser = XContentType.JSON.xContent()
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, stream)
) {
// copyCurrentStructure does not property handle filters when it is passed a json parser. So we hide it. // copyCurrentStructure does not property handle filters when it is passed a json parser. So we hide it.
return builder.copyCurrentStructure(new FilterXContentParserWrapper(parser) { return builder.copyCurrentStructure(new FilterXContentParserWrapper(parser) {
}); });

View file

@ -42,8 +42,8 @@ import org.elasticsearch.repositories.ShardGenerations;
import org.elasticsearch.snapshots.SnapshotId; import org.elasticsearch.snapshots.SnapshotId;
import org.elasticsearch.snapshots.SnapshotInfo; import org.elasticsearch.snapshots.SnapshotInfo;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.XContentType;
import java.io.DataInputStream; import java.io.DataInputStream;
@ -114,7 +114,7 @@ public final class BlobStoreTestUtil {
try ( try (
InputStream blob = blobContainer.readBlob(BlobStoreRepository.INDEX_FILE_PREFIX + latestGen); InputStream blob = blobContainer.readBlob(BlobStoreRepository.INDEX_FILE_PREFIX + latestGen);
XContentParser parser = XContentType.JSON.xContent() XContentParser parser = XContentType.JSON.xContent()
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, blob) .createParser(XContentParserConfiguration.EMPTY.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE), blob)
) { ) {
repositoryData = RepositoryData.snapshotsFromXContent(parser, latestGen, false); repositoryData = RepositoryData.snapshotsFromXContent(parser, latestGen, false);
} }

View file

@ -34,11 +34,10 @@ import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.search.suggest.SuggestBuilder; import org.elasticsearch.search.suggest.SuggestBuilder;
import org.elasticsearch.search.vectors.KnnSearchBuilder; import org.elasticsearch.search.vectors.KnnSearchBuilder;
import org.elasticsearch.test.AbstractQueryTestCase; import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.xcontent.DeprecationHandler;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory; import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.XContentType;
import java.io.IOException; import java.io.IOException;
@ -310,11 +309,7 @@ public class RandomSearchRequestGenerator {
jsonBuilder.endArray(); jsonBuilder.endArray();
jsonBuilder.endObject(); jsonBuilder.endObject();
XContentParser parser = XContentFactory.xContent(XContentType.JSON) XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser( .createParser(XContentParserConfiguration.EMPTY, BytesReference.bytes(jsonBuilder).streamInput());
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
BytesReference.bytes(jsonBuilder).streamInput()
);
parser.nextToken(); parser.nextToken();
parser.nextToken(); parser.nextToken();
parser.nextToken(); parser.nextToken();

View file

@ -11,11 +11,10 @@ import org.apache.http.util.EntityUtils;
import org.elasticsearch.client.Response; import org.elasticsearch.client.Response;
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.xcontent.DeprecationHandler;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContent; import org.elasticsearch.xcontent.XContent;
import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.XContentType;
import java.io.IOException; import java.io.IOException;
@ -38,13 +37,7 @@ public class ObjectPath {
} }
public static ObjectPath createFromXContent(XContent xContent, BytesReference input) throws IOException { public static ObjectPath createFromXContent(XContent xContent, BytesReference input) throws IOException {
try ( try (XContentParser parser = xContent.createParser(XContentParserConfiguration.EMPTY, input.streamInput())) {
XContentParser parser = xContent.createParser(
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
input.streamInput()
)
) {
if (parser.nextToken() == XContentParser.Token.START_ARRAY) { if (parser.nextToken() == XContentParser.Token.START_ARRAY) {
return new ObjectPath(parser.listOrderedMap()); return new ObjectPath(parser.listOrderedMap());
} }

View file

@ -7,10 +7,9 @@
*/ */
package org.elasticsearch.test.rest.yaml.restspec; package org.elasticsearch.test.rest.yaml.restspec;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.test.ClasspathUtils; import org.elasticsearch.test.ClasspathUtils;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.json.JsonXContent; import org.elasticsearch.xcontent.json.JsonXContent;
import java.io.IOException; import java.io.IOException;
@ -94,13 +93,7 @@ public class ClientYamlSuiteRestSpec {
private static void parseSpecFile(ClientYamlSuiteRestApiParser restApiParser, Path jsonFile, ClientYamlSuiteRestSpec restSpec) { private static void parseSpecFile(ClientYamlSuiteRestApiParser restApiParser, Path jsonFile, ClientYamlSuiteRestSpec restSpec) {
try (InputStream stream = Files.newInputStream(jsonFile)) { try (InputStream stream = Files.newInputStream(jsonFile)) {
try ( try (XContentParser parser = JsonXContent.jsonXContent.createParser(XContentParserConfiguration.EMPTY, stream)) {
XContentParser parser = JsonXContent.jsonXContent.createParser(
NamedXContentRegistry.EMPTY,
LoggingDeprecationHandler.INSTANCE,
stream
)
) {
String filename = jsonFile.getFileName().toString(); String filename = jsonFile.getFileName().toString();
if (filename.equals("_common.json")) { if (filename.equals("_common.json")) {
parseCommonSpec(parser, restSpec); parseCommonSpec(parser, restSpec);

View file

@ -10,10 +10,10 @@ package org.elasticsearch.test.rest.yaml.section;
import org.elasticsearch.client.NodeSelector; import org.elasticsearch.client.NodeSelector;
import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.io.Channels; import org.elasticsearch.common.io.Channels;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.xcontent.NamedXContentRegistry; import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentParseException; import org.elasticsearch.xcontent.XContentParseException;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.yaml.YamlXContent; import org.elasticsearch.xcontent.yaml.YamlXContent;
import java.io.IOException; import java.io.IOException;
@ -63,8 +63,7 @@ public class ClientYamlTestSuite {
try ( try (
XContentParser parser = YamlXContent.yamlXContent.createParser( XContentParser parser = YamlXContent.yamlXContent.createParser(
executeableSectionRegistry, XContentParserConfiguration.EMPTY.withRegistry(executeableSectionRegistry),
LoggingDeprecationHandler.INSTANCE,
Files.newInputStream(file) Files.newInputStream(file)
) )
) { ) {

View file

@ -10,12 +10,11 @@ import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xcontent.DeprecationHandler;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ToXContent; import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory; import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.XContentType;
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
@ -37,11 +36,7 @@ public class HttpProxyTests extends ESTestCase {
builder.endObject(); builder.endObject();
try ( try (
XContentParser parser = XContentFactory.xContent(XContentType.JSON) XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser( .createParser(XContentParserConfiguration.EMPTY, BytesReference.bytes(builder).streamInput())
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
BytesReference.bytes(builder).streamInput()
)
) { ) {
parser.nextToken(); parser.nextToken();
HttpProxy proxy = HttpProxy.parse(parser); HttpProxy proxy = HttpProxy.parse(parser);
@ -63,11 +58,7 @@ public class HttpProxyTests extends ESTestCase {
.endObject(); .endObject();
try ( try (
XContentParser parser = XContentFactory.xContent(XContentType.JSON) XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser( .createParser(XContentParserConfiguration.EMPTY, BytesReference.bytes(builder).streamInput())
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
BytesReference.bytes(builder).streamInput()
)
) { ) {
parser.nextToken(); parser.nextToken();
expectThrows(IllegalArgumentException.class, () -> HttpProxy.parse(parser)); expectThrows(IllegalArgumentException.class, () -> HttpProxy.parse(parser));
@ -78,11 +69,7 @@ public class HttpProxyTests extends ESTestCase {
XContentBuilder builder = jsonBuilder().startObject().field("host", "localhost").field("port", -1).endObject(); XContentBuilder builder = jsonBuilder().startObject().field("host", "localhost").field("port", -1).endObject();
try ( try (
XContentParser parser = XContentFactory.xContent(XContentType.JSON) XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser( .createParser(XContentParserConfiguration.EMPTY, BytesReference.bytes(builder).streamInput())
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
BytesReference.bytes(builder).streamInput()
)
) { ) {
parser.nextToken(); parser.nextToken();
expectThrows(ElasticsearchParseException.class, () -> HttpProxy.parse(parser)); expectThrows(ElasticsearchParseException.class, () -> HttpProxy.parse(parser));
@ -93,11 +80,7 @@ public class HttpProxyTests extends ESTestCase {
XContentBuilder builder = jsonBuilder().startObject().field("port", -1).endObject(); XContentBuilder builder = jsonBuilder().startObject().field("port", -1).endObject();
try ( try (
XContentParser parser = XContentFactory.xContent(XContentType.JSON) XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser( .createParser(XContentParserConfiguration.EMPTY, BytesReference.bytes(builder).streamInput())
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
BytesReference.bytes(builder).streamInput()
)
) { ) {
parser.nextToken(); parser.nextToken();
expectThrows(ElasticsearchParseException.class, () -> HttpProxy.parse(parser)); expectThrows(ElasticsearchParseException.class, () -> HttpProxy.parse(parser));
@ -108,11 +91,7 @@ public class HttpProxyTests extends ESTestCase {
XContentBuilder builder = jsonBuilder().startObject().field("host", "localhost").endObject(); XContentBuilder builder = jsonBuilder().startObject().field("host", "localhost").endObject();
try ( try (
XContentParser parser = XContentFactory.xContent(XContentType.JSON) XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser( .createParser(XContentParserConfiguration.EMPTY, BytesReference.bytes(builder).streamInput())
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
BytesReference.bytes(builder).streamInput()
)
) { ) {
parser.nextToken(); parser.nextToken();
expectThrows(ElasticsearchParseException.class, () -> HttpProxy.parse(parser)); expectThrows(ElasticsearchParseException.class, () -> HttpProxy.parse(parser));

View file

@ -34,11 +34,10 @@ import org.elasticsearch.index.get.GetResult;
import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xcontent.DeprecationHandler;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ObjectPath; import org.elasticsearch.xcontent.ObjectPath;
import org.elasticsearch.xcontent.XContentFactory; import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xpack.core.security.authc.Authentication; import org.elasticsearch.xpack.core.security.authc.Authentication;
import org.elasticsearch.xpack.core.security.authc.AuthenticationField; import org.elasticsearch.xpack.core.security.authc.AuthenticationField;
@ -1136,11 +1135,7 @@ public class ExecutionServiceTests extends ESTestCase {
UpdateRequest request = (UpdateRequest) invocation.getArguments()[0]; UpdateRequest request = (UpdateRequest) invocation.getArguments()[0];
try ( try (
XContentParser parser = XContentFactory.xContent(XContentType.JSON) XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser( .createParser(XContentParserConfiguration.EMPTY, request.doc().source().streamInput())
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
request.doc().source().streamInput()
)
) { ) {
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);

View file

@ -13,13 +13,12 @@ import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.Maps; import org.elasticsearch.common.util.Maps;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xcontent.DeprecationHandler;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ObjectPath; import org.elasticsearch.xcontent.ObjectPath;
import org.elasticsearch.xcontent.ToXContent; import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory; import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext;
import org.elasticsearch.xpack.core.watcher.support.xcontent.WatcherParams; import org.elasticsearch.xpack.core.watcher.support.xcontent.WatcherParams;
@ -356,7 +355,7 @@ public class HttpInputTests extends ESTestCase {
BytesReference bytes = BytesReference.bytes(builder); BytesReference bytes = BytesReference.bytes(builder);
try ( try (
XContentParser parser = XContentFactory.xContent(XContentType.JSON) XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes.streamInput()) .createParser(XContentParserConfiguration.EMPTY, bytes.streamInput())
) { ) {
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);

View file

@ -26,12 +26,12 @@ import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.internal.InternalSearchResponse; import org.elasticsearch.search.internal.InternalSearchResponse;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xcontent.DeprecationHandler;
import org.elasticsearch.xcontent.NamedXContentRegistry; import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ToXContent; import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory; import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext;
import org.elasticsearch.xpack.core.watcher.input.Input; import org.elasticsearch.xpack.core.watcher.input.Input;
@ -209,11 +209,7 @@ public class SearchInputTests extends ESTestCase {
.endObject() .endObject()
.endObject(); .endObject();
XContentParser parser = XContentFactory.xContent(XContentType.JSON) XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser( .createParser(XContentParserConfiguration.EMPTY, BytesReference.bytes(builder).streamInput())
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
BytesReference.bytes(builder).streamInput()
)
) { ) {
parser.nextToken(); // advance past the first starting object parser.nextToken(); // advance past the first starting object

View file

@ -26,11 +26,10 @@ import org.elasticsearch.rest.action.search.RestSearchAction;
import org.elasticsearch.test.StreamsUtils; import org.elasticsearch.test.StreamsUtils;
import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.upgrades.AbstractFullClusterRestartTestCase; import org.elasticsearch.upgrades.AbstractFullClusterRestartTestCase;
import org.elasticsearch.xcontent.DeprecationHandler;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ObjectPath; import org.elasticsearch.xcontent.ObjectPath;
import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser; import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentParserConfiguration;
import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xcontent.json.JsonXContent; import org.elasticsearch.xcontent.json.JsonXContent;
import org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken; import org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken;
@ -629,11 +628,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
XContentType xContentType = XContentType.fromMediaType(response.getEntity().getContentType().getValue()); XContentType xContentType = XContentType.fromMediaType(response.getEntity().getContentType().getValue());
try ( try (
XContentParser parser = xContentType.xContent() XContentParser parser = xContentType.xContent()
.createParser( .createParser(XContentParserConfiguration.EMPTY, response.getEntity().getContent())
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
response.getEntity().getContent()
)
) { ) {
assertEquals(new SnapshotLifecycleStats(), SnapshotLifecycleStats.parse(parser)); assertEquals(new SnapshotLifecycleStats(), SnapshotLifecycleStats.parse(parser));
} }