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

* Move more XContent.createParser calls to non-deprecated version

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

Relates to https://github.com/elastic/elasticsearch/issues/28504

* Mockito ಠ_ಠ

Original commit: elastic/x-pack-elasticsearch@81cb99ba52
This commit is contained in:
Lee Hinman 2018-02-14 09:24:47 -07:00 committed by GitHub
parent 0023572acb
commit e8ef20b219
21 changed files with 88 additions and 36 deletions

View File

@ -6,6 +6,7 @@
package org.elasticsearch.license; package org.elasticsearch.license;
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.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -56,8 +57,8 @@ class SelfGeneratedLicense {
byteBuffer.get(content); byteBuffer.get(content);
final License expectedLicense; final License expectedLicense;
// EMPTY is safe here because we don't call namedObject // EMPTY is safe here because we don't call namedObject
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, try (XContentParser parser = XContentFactory.xContent(XContentType.JSON)
decrypt(content))) { .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, decrypt(content))) {
parser.nextToken(); parser.nextToken();
expectedLicense = License.builder().fromLicenseSpec(License.fromXContent(parser), expectedLicense = License.builder().fromLicenseSpec(License.fromXContent(parser),
license.signature()).version(-version).build(); license.signature()).version(-version).build();

View File

@ -33,6 +33,7 @@ import org.elasticsearch.common.logging.LoggerMessageFormat;
import org.elasticsearch.common.logging.ServerLoggers; import org.elasticsearch.common.logging.ServerLoggers;
import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.lucene.search.Queries;
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.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -131,7 +132,7 @@ public class SecurityIndexSearcherWrapper extends IndexSearcherWrapper {
QueryShardContext queryShardContext = queryShardContextProvider.apply(shardId); QueryShardContext queryShardContext = queryShardContextProvider.apply(shardId);
String templateResult = evaluateTemplate(bytesReference.utf8ToString()); String templateResult = evaluateTemplate(bytesReference.utf8ToString());
try (XContentParser parser = XContentFactory.xContent(templateResult) try (XContentParser parser = XContentFactory.xContent(templateResult)
.createParser(queryShardContext.getXContentRegistry(), templateResult)) { .createParser(queryShardContext.getXContentRegistry(), LoggingDeprecationHandler.INSTANCE, templateResult)) {
QueryBuilder queryBuilder = queryShardContext.parseInnerQueryBuilder(parser); QueryBuilder queryBuilder = queryShardContext.parseInnerQueryBuilder(parser);
verifyRoleQuery(queryBuilder); verifyRoleQuery(queryBuilder);
failIfQueryUsesClient(queryBuilder, queryShardContext); failIfQueryUsesClient(queryBuilder, queryShardContext);
@ -249,7 +250,8 @@ public class SecurityIndexSearcherWrapper extends IndexSearcherWrapper {
String evaluateTemplate(String querySource) throws IOException { String evaluateTemplate(String querySource) throws IOException {
// EMPTY is safe here because we never use namedObject // EMPTY is safe here because we never use namedObject
try (XContentParser parser = XContentFactory.xContent(querySource).createParser(NamedXContentRegistry.EMPTY, querySource)) { try (XContentParser parser = XContentFactory.xContent(querySource).createParser(NamedXContentRegistry.EMPTY,
LoggingDeprecationHandler.INSTANCE, querySource)) {
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();
if (token != XContentParser.Token.START_OBJECT) { if (token != XContentParser.Token.START_OBJECT) {
throw new ElasticsearchParseException("Unexpected token [" + token + "]"); throw new ElasticsearchParseException("Unexpected token [" + token + "]");

View File

@ -27,6 +27,7 @@ import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.network.InetAddresses; import org.elasticsearch.common.network.InetAddresses;
import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.ConstructingObjectParser;
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;
@ -301,7 +302,8 @@ public class CertificateGenerateTool extends EnvironmentAwareCommand {
static Collection<CertificateInformation> parseFile(Path file) throws Exception { static Collection<CertificateInformation> parseFile(Path file) throws Exception {
try (Reader reader = Files.newBufferedReader(file)) { try (Reader reader = Files.newBufferedReader(file)) {
// EMPTY is safe here because we never use namedObject // EMPTY is safe here because we never use namedObject
XContentParser xContentParser = XContentType.YAML.xContent().createParser(NamedXContentRegistry.EMPTY, reader); XContentParser xContentParser = XContentType.YAML.xContent()
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, reader);
return InputFileParser.PARSER.parse(xContentParser, new ArrayList<>(), null); return InputFileParser.PARSER.parse(xContentParser, new ArrayList<>(), null);
} }
} }

View File

@ -32,6 +32,7 @@ import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.network.InetAddresses; import org.elasticsearch.common.network.InetAddresses;
import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.ConstructingObjectParser;
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;
@ -907,7 +908,8 @@ public class CertificateTool extends LoggingAwareMultiCommand {
static Collection<CertificateInformation> parseFile(Path file) throws Exception { static Collection<CertificateInformation> parseFile(Path file) throws Exception {
try (Reader reader = Files.newBufferedReader(file)) { try (Reader reader = Files.newBufferedReader(file)) {
// EMPTY is safe here because we never use namedObject // EMPTY is safe here because we never use namedObject
XContentParser xContentParser = XContentType.YAML.xContent().createParser(NamedXContentRegistry.EMPTY, reader); XContentParser xContentParser = XContentType.YAML.xContent()
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, reader);
return CertificateToolParser.PARSER.parse(xContentParser, new ArrayList<>(), null); return CertificateToolParser.PARSER.parse(xContentParser, new ArrayList<>(), null);
} }
} }

View File

@ -17,6 +17,7 @@ import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.compress.NotXContentException; import org.elasticsearch.common.compress.NotXContentException;
import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.io.Streams;
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.XContentHelper; import org.elasticsearch.common.xcontent.XContentHelper;
@ -45,7 +46,8 @@ public class TemplateUtils {
public static void loadTemplateIntoMap(String resource, Map<String, IndexTemplateMetaData> map, String templateName, String version, public static void loadTemplateIntoMap(String resource, Map<String, IndexTemplateMetaData> map, String templateName, String version,
String versionProperty, Logger logger) { String versionProperty, Logger logger) {
final String template = loadTemplate(resource, version, versionProperty); final String template = loadTemplate(resource, version, versionProperty);
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, template)) { try (XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, template)) {
map.put(templateName, IndexTemplateMetaData.Builder.fromXContent(parser, templateName)); map.put(templateName, IndexTemplateMetaData.Builder.fromXContent(parser, templateName));
} catch (IOException e) { } catch (IOException e) {
// TODO: should we handle this with a thrown exception? // TODO: should we handle this with a thrown exception?

View File

@ -11,6 +11,8 @@ import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
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.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.DeprecationHandler;
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;
@ -151,14 +153,16 @@ public class DatafeedConfigTests extends AbstractSerializingTestCase<DatafeedCon
"}"; "}";
public void testFutureConfigParse() throws IOException { public void testFutureConfigParse() throws IOException {
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, FUTURE_DATAFEED); XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, FUTURE_DATAFEED);
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
() -> DatafeedConfig.CONFIG_PARSER.apply(parser, null).build()); () -> DatafeedConfig.CONFIG_PARSER.apply(parser, null).build());
assertEquals("[datafeed_config] unknown field [tomorrows_technology_today], parser not found", e.getMessage()); assertEquals("[datafeed_config] unknown field [tomorrows_technology_today], parser not found", e.getMessage());
} }
public void testFutureMetadataParse() throws IOException { public void testFutureMetadataParse() throws IOException {
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, FUTURE_DATAFEED); XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, FUTURE_DATAFEED);
// Unlike the config version of this test, the metadata parser should tolerate the unknown future field // Unlike the config version of this test, the metadata parser should tolerate the unknown future field
assertNotNull(DatafeedConfig.METADATA_PARSER.apply(parser, null).build()); assertNotNull(DatafeedConfig.METADATA_PARSER.apply(parser, null).build());
} }

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.core.ml.job.config;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
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;
@ -44,21 +45,24 @@ public class AnalysisLimitsTests extends AbstractSerializingTestCase<AnalysisLim
public void testParseModelMemoryLimitGivenNegativeNumber() throws IOException { public void testParseModelMemoryLimitGivenNegativeNumber() throws IOException {
String json = "{\"model_memory_limit\": -1}"; String json = "{\"model_memory_limit\": -1}";
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, json); XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
ParsingException e = expectThrows(ParsingException.class, () -> AnalysisLimits.CONFIG_PARSER.apply(parser, null)); ParsingException e = expectThrows(ParsingException.class, () -> AnalysisLimits.CONFIG_PARSER.apply(parser, null));
assertThat(e.getRootCause().getMessage(), containsString("model_memory_limit must be at least 1 MiB. Value = -1")); assertThat(e.getRootCause().getMessage(), containsString("model_memory_limit must be at least 1 MiB. Value = -1"));
} }
public void testParseModelMemoryLimitGivenZero() throws IOException { public void testParseModelMemoryLimitGivenZero() throws IOException {
String json = "{\"model_memory_limit\": 0}"; String json = "{\"model_memory_limit\": 0}";
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, json); XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
ParsingException e = expectThrows(ParsingException.class, () -> AnalysisLimits.CONFIG_PARSER.apply(parser, null)); ParsingException e = expectThrows(ParsingException.class, () -> AnalysisLimits.CONFIG_PARSER.apply(parser, null));
assertThat(e.getRootCause().getMessage(), containsString("model_memory_limit must be at least 1 MiB. Value = 0")); assertThat(e.getRootCause().getMessage(), containsString("model_memory_limit must be at least 1 MiB. Value = 0"));
} }
public void testParseModelMemoryLimitGivenPositiveNumber() throws IOException { public void testParseModelMemoryLimitGivenPositiveNumber() throws IOException {
String json = "{\"model_memory_limit\": 2048}"; String json = "{\"model_memory_limit\": 2048}";
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, json); XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
AnalysisLimits limits = AnalysisLimits.CONFIG_PARSER.apply(parser, null); AnalysisLimits limits = AnalysisLimits.CONFIG_PARSER.apply(parser, null);
@ -67,28 +71,32 @@ public class AnalysisLimitsTests extends AbstractSerializingTestCase<AnalysisLim
public void testParseModelMemoryLimitGivenNegativeString() throws IOException { public void testParseModelMemoryLimitGivenNegativeString() throws IOException {
String json = "{\"model_memory_limit\":\"-4MB\"}"; String json = "{\"model_memory_limit\":\"-4MB\"}";
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, json); XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
ParsingException e = expectThrows(ParsingException.class, () -> AnalysisLimits.CONFIG_PARSER.apply(parser, null)); ParsingException e = expectThrows(ParsingException.class, () -> AnalysisLimits.CONFIG_PARSER.apply(parser, null));
assertThat(e.getRootCause().getMessage(), containsString("Values less than -1 bytes are not supported: -4mb")); assertThat(e.getRootCause().getMessage(), containsString("Values less than -1 bytes are not supported: -4mb"));
} }
public void testParseModelMemoryLimitGivenZeroString() throws IOException { public void testParseModelMemoryLimitGivenZeroString() throws IOException {
String json = "{\"model_memory_limit\":\"0MB\"}"; String json = "{\"model_memory_limit\":\"0MB\"}";
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, json); XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
ParsingException e = expectThrows(ParsingException.class, () -> AnalysisLimits.CONFIG_PARSER.apply(parser, null)); ParsingException e = expectThrows(ParsingException.class, () -> AnalysisLimits.CONFIG_PARSER.apply(parser, null));
assertThat(e.getRootCause().getMessage(), containsString("model_memory_limit must be at least 1 MiB. Value = 0")); assertThat(e.getRootCause().getMessage(), containsString("model_memory_limit must be at least 1 MiB. Value = 0"));
} }
public void testParseModelMemoryLimitGivenLessThanOneMBString() throws IOException { public void testParseModelMemoryLimitGivenLessThanOneMBString() throws IOException {
String json = "{\"model_memory_limit\":\"1000Kb\"}"; String json = "{\"model_memory_limit\":\"1000Kb\"}";
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, json); XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
ParsingException e = expectThrows(ParsingException.class, () -> AnalysisLimits.CONFIG_PARSER.apply(parser, null)); ParsingException e = expectThrows(ParsingException.class, () -> AnalysisLimits.CONFIG_PARSER.apply(parser, null));
assertThat(e.getRootCause().getMessage(), containsString("model_memory_limit must be at least 1 MiB. Value = 0")); assertThat(e.getRootCause().getMessage(), containsString("model_memory_limit must be at least 1 MiB. Value = 0"));
} }
public void testParseModelMemoryLimitGivenStringMultipleOfMBs() throws IOException { public void testParseModelMemoryLimitGivenStringMultipleOfMBs() throws IOException {
String json = "{\"model_memory_limit\":\"4g\"}"; String json = "{\"model_memory_limit\":\"4g\"}";
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, json); XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
AnalysisLimits limits = AnalysisLimits.CONFIG_PARSER.apply(parser, null); AnalysisLimits limits = AnalysisLimits.CONFIG_PARSER.apply(parser, null);
@ -97,7 +105,8 @@ public class AnalysisLimitsTests extends AbstractSerializingTestCase<AnalysisLim
public void testParseModelMemoryLimitGivenStringNonMultipleOfMBs() throws IOException { public void testParseModelMemoryLimitGivenStringNonMultipleOfMBs() throws IOException {
String json = "{\"model_memory_limit\":\"1300kb\"}"; String json = "{\"model_memory_limit\":\"1300kb\"}";
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, json); XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
AnalysisLimits limits = AnalysisLimits.CONFIG_PARSER.apply(parser, null); AnalysisLimits limits = AnalysisLimits.CONFIG_PARSER.apply(parser, null);

View File

@ -12,6 +12,7 @@ import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
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.XContentHelper; import org.elasticsearch.common.xcontent.XContentHelper;
@ -74,14 +75,16 @@ public class JobTests extends AbstractSerializingTestCase<Job> {
} }
public void testFutureConfigParse() throws IOException { public void testFutureConfigParse() throws IOException {
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, FUTURE_JOB); XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, FUTURE_JOB);
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
() -> Job.CONFIG_PARSER.apply(parser, null).build()); () -> Job.CONFIG_PARSER.apply(parser, null).build());
assertEquals("[job_details] unknown field [tomorrows_technology_today], parser not found", e.getMessage()); assertEquals("[job_details] unknown field [tomorrows_technology_today], parser not found", e.getMessage());
} }
public void testFutureMetadataParse() throws IOException { public void testFutureMetadataParse() throws IOException {
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, FUTURE_JOB); XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, FUTURE_JOB);
// Unlike the config version of this test, the metadata parser should tolerate the unknown future field // Unlike the config version of this test, the metadata parser should tolerate the unknown future field
assertNotNull(Job.METADATA_PARSER.apply(parser, null).build()); assertNotNull(Job.METADATA_PARSER.apply(parser, null).build());
} }

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.ml.job.process.autodetect.output;
import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ElasticsearchParseException;
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;
@ -33,7 +34,8 @@ public class AutodetectResultsParser extends AbstractComponent {
public Iterator<AutodetectResult> parseResults(InputStream in) throws ElasticsearchParseException { public Iterator<AutodetectResult> parseResults(InputStream in) throws ElasticsearchParseException {
try { try {
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, in); XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, in);
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();
// if start of an array ignore it, we expect an array of results // if start of an array ignore it, we expect an array of results
if (token != XContentParser.Token.START_ARRAY) { if (token != XContentParser.Token.START_ARRAY) {

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.ml.job.process.autodetect.writer;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
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;
@ -79,7 +80,7 @@ class JsonDataToProcessWriter extends AbstractDataToProcessWriter {
private void writeJsonXContent(CategorizationAnalyzer categorizationAnalyzer, InputStream inputStream) throws IOException { private void writeJsonXContent(CategorizationAnalyzer categorizationAnalyzer, InputStream inputStream) throws IOException {
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON) try (XContentParser parser = XContentFactory.xContent(XContentType.JSON)
.createParser(xContentRegistry, inputStream)) { .createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, inputStream)) {
writeJson(categorizationAnalyzer, parser); writeJson(categorizationAnalyzer, parser);
} }
} }
@ -91,7 +92,7 @@ class JsonDataToProcessWriter extends AbstractDataToProcessWriter {
break; break;
} }
try (XContentParser parser = XContentFactory.xContent(XContentType.SMILE) try (XContentParser parser = XContentFactory.xContent(XContentType.SMILE)
.createParser(xContentRegistry, nextObject)) { .createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, nextObject)) {
writeJson(categorizationAnalyzer, parser); writeJson(categorizationAnalyzer, parser);
} }
} }

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.ml.job.process.autodetect.writer;
import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParseException;
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.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;
@ -228,7 +229,8 @@ public class XContentRecordReaderTests extends ESTestCase {
InputStream inputStream2 = new CountingInputStream(inputStream, InputStream inputStream2 = new CountingInputStream(inputStream,
mock(DataCountsReporter.class)); mock(DataCountsReporter.class));
return XContentFactory.xContent(XContentType.JSON) return XContentFactory.xContent(XContentType.JSON)
.createParser(new NamedXContentRegistry(Collections.emptyList()), inputStream2); .createParser(new NamedXContentRegistry(Collections.emptyList()),
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, inputStream2);
} }
private Map<String, Integer> createFieldMap() { private Map<String, Integer> createFieldMap() {

View File

@ -6,6 +6,7 @@
package org.elasticsearch.xpack.ml.job.process.logging; package org.elasticsearch.xpack.ml.job.process.logging;
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.XContent; import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentFactory;
@ -39,7 +40,7 @@ public class CppLogMessageTests extends AbstractSerializingTestCase<CppLogMessag
String input = "{\"logger\":\"controller\",\"level\":\"INFO\"," String input = "{\"logger\":\"controller\",\"level\":\"INFO\","
+ "\"pid\":42,\"thread\":\"0x7fff7d2a8000\",\"message\":\"message 1\",\"class\":\"ml\"," + "\"pid\":42,\"thread\":\"0x7fff7d2a8000\",\"message\":\"message 1\",\"class\":\"ml\","
+ "\"method\":\"core::SomeNoiseMaker\",\"file\":\"Noisemaker.cc\",\"line\":333}\n"; + "\"method\":\"core::SomeNoiseMaker\",\"file\":\"Noisemaker.cc\",\"line\":333}\n";
XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, input); XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, input);
CppLogMessage msg = CppLogMessage.PARSER.apply(parser, null); CppLogMessage msg = CppLogMessage.PARSER.apply(parser, null);
Instant after = Instant.now(); Instant after = Instant.now();

View File

@ -9,6 +9,7 @@ import org.apache.logging.log4j.Logger;
import org.elasticsearch.client.Response; import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseListener; import org.elasticsearch.client.ResponseListener;
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.XContent; import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -51,7 +52,8 @@ class HttpExportBulkResponseListener implements ResponseListener {
@Override @Override
public void onSuccess(final Response response) { public void onSuccess(final Response response) {
// EMPTY is safe here because we never call namedObject // EMPTY is safe here because we never call namedObject
try (XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, response.getEntity().getContent())) { try (XContentParser parser = xContent
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, response.getEntity().getContent())) {
// avoid parsing the entire payload if we don't need too // avoid parsing the entire payload if we don't need too
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();

View File

@ -9,6 +9,7 @@ import org.apache.http.HttpEntity;
import org.apache.http.entity.ContentType; import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.elasticsearch.client.Response; import org.elasticsearch.client.Response;
import org.elasticsearch.common.xcontent.DeprecationHandler;
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.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -51,7 +52,8 @@ public class HttpExportBulkResponseListenerTests extends ESTestCase {
when(response.getEntity()).thenReturn(entity); when(response.getEntity()).thenReturn(entity);
when(entity.getContent()).thenReturn(stream); when(entity.getContent()).thenReturn(stream);
when(xContent.createParser(Mockito.any(NamedXContentRegistry.class), Mockito.eq(stream))).thenReturn(parser); when(xContent.createParser(Mockito.any(NamedXContentRegistry.class),
Mockito.any(DeprecationHandler.class), Mockito.eq(stream))).thenReturn(parser);
// {, "took", 4, "errors", false // {, "took", 4, "errors", false
when(parser.nextToken()).thenReturn(Token.START_OBJECT, when(parser.nextToken()).thenReturn(Token.START_OBJECT,
@ -107,7 +109,8 @@ public class HttpExportBulkResponseListenerTests extends ESTestCase {
when(response.getEntity()).thenReturn(entity); when(response.getEntity()).thenReturn(entity);
when(entity.getContent()).thenReturn(stream); when(entity.getContent()).thenReturn(stream);
when(xContent.createParser(Mockito.any(NamedXContentRegistry.class), Mockito.eq(stream))).thenReturn(parser); when(xContent.createParser(Mockito.any(NamedXContentRegistry.class),
Mockito.any(DeprecationHandler.class), Mockito.eq(stream))).thenReturn(parser);
// {, "took", 4, "errors", false nextToken, currentName // {, "took", 4, "errors", false nextToken, currentName
when(parser.nextToken()).thenReturn(Token.START_OBJECT, // 1 when(parser.nextToken()).thenReturn(Token.START_OBJECT, // 1

View File

@ -42,6 +42,7 @@ import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.common.util.PageCacheRecycler;
import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.concurrent.ThreadContext;
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.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;
@ -888,7 +889,8 @@ public class Security extends Plugin implements ActionPlugin, IngestPlugin, Netw
final byte[] auditTemplate = TemplateUtils.loadTemplate("/" + IndexAuditTrail.INDEX_TEMPLATE_NAME + ".json", final byte[] auditTemplate = TemplateUtils.loadTemplate("/" + IndexAuditTrail.INDEX_TEMPLATE_NAME + ".json",
Version.CURRENT.toString(), IndexLifecycleManager.TEMPLATE_VERSION_PATTERN).getBytes(StandardCharsets.UTF_8); Version.CURRENT.toString(), IndexLifecycleManager.TEMPLATE_VERSION_PATTERN).getBytes(StandardCharsets.UTF_8);
try (XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, auditTemplate)) { try (XContentParser parser = xContent
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, auditTemplate)) {
IndexTemplateMetaData auditMetadata = new IndexTemplateMetaData.Builder( IndexTemplateMetaData auditMetadata = new IndexTemplateMetaData.Builder(
IndexTemplateMetaData.Builder.fromXContent(parser, IndexAuditTrail.INDEX_TEMPLATE_NAME)) IndexTemplateMetaData.Builder.fromXContent(parser, IndexAuditTrail.INDEX_TEMPLATE_NAME))
.settings(IndexAuditTrail.customAuditIndexSettings(settings, logger)) .settings(IndexAuditTrail.customAuditIndexSettings(settings, logger))

View File

@ -30,6 +30,7 @@ import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.logging.ServerLoggers; import org.elasticsearch.common.logging.ServerLoggers;
import org.elasticsearch.common.settings.SecureString; import org.elasticsearch.common.settings.SecureString;
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.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
@ -205,7 +206,8 @@ public class ESNativeRealmMigrateTool extends LoggingAwareMultiCommand {
Set<String> existingUsers = new HashSet<>(); Set<String> existingUsers = new HashSet<>();
String allUsersJson = postURL(settings, env, "GET", this.url.value(options) + "/_xpack/security/user/", options, null); String allUsersJson = postURL(settings, env, "GET", this.url.value(options) + "/_xpack/security/user/", options, null);
// EMPTY is safe here because we never use namedObject // EMPTY is safe here because we never use namedObject
try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, allUsersJson)) { try (XContentParser parser = JsonXContent.jsonXContent
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, allUsersJson)) {
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();
String userName; String userName;
if (token == XContentParser.Token.START_OBJECT) { if (token == XContentParser.Token.START_OBJECT) {
@ -287,7 +289,8 @@ public class ESNativeRealmMigrateTool extends LoggingAwareMultiCommand {
Set<String> existingRoles = new HashSet<>(); Set<String> existingRoles = new HashSet<>();
String allRolesJson = postURL(settings, env, "GET", this.url.value(options) + "/_xpack/security/role/", options, null); String allRolesJson = postURL(settings, env, "GET", this.url.value(options) + "/_xpack/security/role/", options, null);
// EMPTY is safe here because we never use namedObject // EMPTY is safe here because we never use namedObject
try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, allRolesJson)) { try (XContentParser parser = JsonXContent.jsonXContent
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, allRolesJson)) {
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();
String roleName; String roleName;
if (token == XContentParser.Token.START_OBJECT) { if (token == XContentParser.Token.START_OBJECT) {

View File

@ -12,6 +12,7 @@ import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
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.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.yaml.YamlXContent; import org.elasticsearch.common.xcontent.yaml.YamlXContent;
@ -207,7 +208,8 @@ public class FileRolesStore extends AbstractComponent {
String roleName = null; String roleName = null;
try { try {
// EMPTY is safe here because we never use namedObject // EMPTY is safe here because we never use namedObject
XContentParser parser = YamlXContent.yamlXContent.createParser(NamedXContentRegistry.EMPTY, segment); XContentParser parser = YamlXContent.yamlXContent
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, segment);
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();
if (token == XContentParser.Token.START_OBJECT) { if (token == XContentParser.Token.START_OBJECT) {
token = parser.nextToken(); token = parser.nextToken();

View File

@ -16,6 +16,7 @@ import org.elasticsearch.common.CheckedSupplier;
import org.elasticsearch.common.settings.KeyStoreWrapper; import org.elasticsearch.common.settings.KeyStoreWrapper;
import org.elasticsearch.common.settings.SecureString; import org.elasticsearch.common.settings.SecureString;
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;
@ -418,7 +419,8 @@ public class SetupPasswordToolTests extends CommandTestCase {
} }
private String parsePassword(String value) throws IOException { private String parsePassword(String value) throws IOException {
try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, value)) { try (XContentParser parser = JsonXContent.jsonXContent
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, value)) {
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();
if (token == XContentParser.Token.START_OBJECT) { if (token == XContentParser.Token.START_OBJECT) {
if (parser.nextToken() == XContentParser.Token.FIELD_NAME) { if (parser.nextToken() == XContentParser.Token.FIELD_NAME) {

View File

@ -25,6 +25,7 @@ package org.elasticsearch.xpack.security.authc.support.mapper;
import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.ParsingException;
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.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.XContentType;
@ -149,7 +150,8 @@ public class ExpressionRoleMappingTests extends ESTestCase {
private ExpressionRoleMapping parse(String json, String name) throws IOException { private ExpressionRoleMapping parse(String json, String name) throws IOException {
final NamedXContentRegistry registry = NamedXContentRegistry.EMPTY; final NamedXContentRegistry registry = NamedXContentRegistry.EMPTY;
final XContentParser parser = XContentType.JSON.xContent().createParser(registry, json); final XContentParser parser = XContentType.JSON.xContent()
.createParser(registry, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
final ExpressionRoleMapping mapping = ExpressionRoleMapping.parse(name, parser); final ExpressionRoleMapping mapping = ExpressionRoleMapping.parse(name, parser);
assertThat(mapping, notNullValue()); assertThat(mapping, notNullValue());
assertThat(mapping.getName(), equalTo(name)); assertThat(mapping.getName(), equalTo(name));

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.security.rest.action.oauth2;
import org.apache.lucene.util.SetOnce; import org.apache.lucene.util.SetOnce;
import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.ActionRequestValidationException;
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.XContentHelper; import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
@ -89,7 +90,8 @@ public class RestGetTokenActionTests extends ESTestCase {
"\"password\": \"" + SecuritySettingsSourceField.TEST_PASSWORD + "\"," + "\"password\": \"" + SecuritySettingsSourceField.TEST_PASSWORD + "\"," +
"\"scope\": \"FULL\"" + "\"scope\": \"FULL\"" +
"}"; "}";
try (XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, request)) { try (XContentParser parser = XContentType.JSON.xContent()
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, request)) {
CreateTokenRequest createTokenRequest = RestGetTokenAction.PARSER.parse(parser, null); CreateTokenRequest createTokenRequest = RestGetTokenAction.PARSER.parse(parser, null);
assertEquals("password", createTokenRequest.getGrantType()); assertEquals("password", createTokenRequest.getGrantType());
assertEquals("user1", createTokenRequest.getUsername()); assertEquals("user1", createTokenRequest.getUsername());
@ -105,7 +107,8 @@ public class RestGetTokenActionTests extends ESTestCase {
"\"refresh_token\": \"" + token + "\"," + "\"refresh_token\": \"" + token + "\"," +
"\"scope\": \"FULL\"" + "\"scope\": \"FULL\"" +
"}"; "}";
try (XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, request)) { try (XContentParser parser = XContentType.JSON.xContent()
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, request)) {
CreateTokenRequest createTokenRequest = RestGetTokenAction.PARSER.parse(parser, null); CreateTokenRequest createTokenRequest = RestGetTokenAction.PARSER.parse(parser, null);
assertEquals("refresh_token", createTokenRequest.getGrantType()); assertEquals("refresh_token", createTokenRequest.getGrantType());
assertEquals(token, createTokenRequest.getRefreshToken()); assertEquals(token, createTokenRequest.getRefreshToken());

View File

@ -7,6 +7,7 @@ package org.elasticsearch.xpack.ml.integration;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
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;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
@ -162,7 +163,8 @@ public class RevertModelSnapshotIT extends MlNativeAutodetectIntegTestCase {
SearchHits hits = response.getHits(); SearchHits hits = response.getHits();
assertThat(hits.getTotalHits(), equalTo(1L)); assertThat(hits.getTotalHits(), equalTo(1L));
try { try {
XContentParser parser = JsonXContent.jsonXContent.createParser(null, hits.getAt(0).getSourceAsString()); XContentParser parser = JsonXContent.jsonXContent
.createParser(null, LoggingDeprecationHandler.INSTANCE, hits.getAt(0).getSourceAsString());
return Quantiles.PARSER.apply(parser, null); return Quantiles.PARSER.apply(parser, null);
} catch (IOException e) { } catch (IOException e) {
throw new IllegalStateException(e); throw new IllegalStateException(e);