Use non deprecated xcontenthelper (#28503)
* Move to non-deprecated XContentHelper.createParser(...) This moves away from one of the now-deprecated XContentHelper.createParser methods in favor of specifying the deprecation logger at parser creation time. Relates to #28449 Note that this doesn't move all the `createParser` calls because some of them use the already-deprecated method that doesn't specify the XContentType. * Remove the deprecated (and now non-needed) createParser method
This commit is contained in:
parent
5c1d3aa2f0
commit
eebff4d2b3
|
@ -58,6 +58,7 @@ import org.elasticsearch.common.SuppressForbidden;
|
|||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.lucene.uid.Versions;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContent;
|
||||
|
@ -316,7 +317,8 @@ public final class Request {
|
|||
BytesReference indexSource = indexRequest.source();
|
||||
XContentType indexXContentType = indexRequest.getContentType();
|
||||
|
||||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, indexSource, indexXContentType)) {
|
||||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY,
|
||||
LoggingDeprecationHandler.INSTANCE, indexSource, indexXContentType)) {
|
||||
try (XContentBuilder builder = XContentBuilder.builder(bulkContentType.xContent())) {
|
||||
builder.copyCurrentStructure(parser);
|
||||
source = builder.bytes().toBytesRef();
|
||||
|
|
|
@ -51,6 +51,7 @@ import org.elasticsearch.common.CheckedConsumer;
|
|||
import org.elasticsearch.common.CheckedFunction;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.xcontent.ContextParser;
|
||||
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
|
@ -637,7 +638,8 @@ public class RestHighLevelClient implements Closeable {
|
|||
if (xContentType == null) {
|
||||
throw new IllegalStateException("Unsupported Content-Type: " + entity.getContentType().getValue());
|
||||
}
|
||||
try (XContentParser parser = xContentType.xContent().createParser(registry, entity.getContent())) {
|
||||
try (XContentParser parser = xContentType.xContent().createParser(registry,
|
||||
LoggingDeprecationHandler.INSTANCE, entity.getContent())) {
|
||||
return entityParser.apply(parser);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.ingest.common;
|
|||
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
|
||||
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -97,7 +98,8 @@ public final class ScriptProcessor extends AbstractProcessor {
|
|||
public ScriptProcessor create(Map<String, Processor.Factory> registry, String processorTag,
|
||||
Map<String, Object> config) throws Exception {
|
||||
XContentBuilder builder = XContentBuilder.builder(JsonXContent.jsonXContent).map(config);
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, builder.bytes().streamInput());
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY,
|
||||
LoggingDeprecationHandler.INSTANCE, builder.bytes().streamInput());
|
||||
Script script = Script.parse(parser);
|
||||
|
||||
Arrays.asList("id", "source", "inline", "lang", "params", "options").forEach(config::remove);
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
|||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
|
@ -105,7 +106,8 @@ public class TransportRankEvalAction extends HandledTransportAction<RankEvalRequ
|
|||
String templateId = ratedRequest.getTemplateId();
|
||||
TemplateScript.Factory templateScript = scriptsWithoutParams.get(templateId);
|
||||
String resolvedRequest = templateScript.newInstance(params).execute();
|
||||
try (XContentParser subParser = createParser(namedXContentRegistry, new BytesArray(resolvedRequest), XContentType.JSON)) {
|
||||
try (XContentParser subParser = createParser(namedXContentRegistry,
|
||||
LoggingDeprecationHandler.INSTANCE, new BytesArray(resolvedRequest), XContentType.JSON)) {
|
||||
ratedSearchSource = SearchSourceBuilder.fromXContent(subParser);
|
||||
} catch (IOException e) {
|
||||
// if we fail parsing, put the exception into the errors map and continue
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.elasticsearch.ElasticsearchException;
|
|||
import org.elasticsearch.ElasticsearchStatusException;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.bulk.BackoffPolicy;
|
||||
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
||||
import org.elasticsearch.index.reindex.ScrollableHitSource;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.client.ResponseException;
|
||||
|
@ -196,7 +197,7 @@ public class RemoteScrollableHitSource extends ScrollableHitSource {
|
|||
}
|
||||
// EMPTY is safe here because we don't call namedObject
|
||||
try (XContentParser xContentParser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY,
|
||||
content)) {
|
||||
LoggingDeprecationHandler.INSTANCE, content)) {
|
||||
parsedResponse = parser.apply(xContentParser, xContentType);
|
||||
} catch (ParsingException e) {
|
||||
/* Because we're streaming the response we can't get a copy of it here. The best we can do is hint that it
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.ingest.useragent;
|
||||
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -54,7 +55,8 @@ final class UserAgentParser {
|
|||
|
||||
private void init(InputStream regexStream) throws IOException {
|
||||
// EMPTY is safe here because we don't use namedObject
|
||||
XContentParser yamlParser = XContentFactory.xContent(XContentType.YAML).createParser(NamedXContentRegistry.EMPTY, regexStream);
|
||||
XContentParser yamlParser = XContentFactory.xContent(XContentType.YAML).createParser(NamedXContentRegistry.EMPTY,
|
||||
LoggingDeprecationHandler.INSTANCE, regexStream);
|
||||
|
||||
XContentParser.Token token = yamlParser.nextToken();
|
||||
|
||||
|
|
|
@ -205,16 +205,16 @@ public class Alias implements Streamable, ToXContentObject {
|
|||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
currentFieldName = parser.currentName();
|
||||
} else if (token == XContentParser.Token.START_OBJECT) {
|
||||
if (FILTER.match(currentFieldName)) {
|
||||
if (FILTER.match(currentFieldName, parser.getDeprecationHandler())) {
|
||||
Map<String, Object> filter = parser.mapOrdered();
|
||||
alias.filter(filter);
|
||||
}
|
||||
} else if (token == XContentParser.Token.VALUE_STRING) {
|
||||
if (ROUTING.match(currentFieldName)) {
|
||||
if (ROUTING.match(currentFieldName, parser.getDeprecationHandler())) {
|
||||
alias.routing(parser.text());
|
||||
} else if (INDEX_ROUTING.match(currentFieldName)) {
|
||||
} else if (INDEX_ROUTING.match(currentFieldName, parser.getDeprecationHandler())) {
|
||||
alias.indexRouting(parser.text());
|
||||
} else if (SEARCH_ROUTING.match(currentFieldName)) {
|
||||
} else if (SEARCH_ROUTING.match(currentFieldName, parser.getDeprecationHandler())) {
|
||||
alias.searchRouting(parser.text());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.elasticsearch.common.Nullable;
|
|||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.lucene.uid.Versions;
|
||||
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
@ -864,7 +865,8 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
|
|||
}
|
||||
if (doc != null) {
|
||||
XContentType xContentType = doc.getContentType();
|
||||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, doc.source(), xContentType)) {
|
||||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY,
|
||||
LoggingDeprecationHandler.INSTANCE, doc.source(), xContentType)) {
|
||||
builder.field("doc");
|
||||
builder.copyCurrentStructure(parser);
|
||||
}
|
||||
|
@ -874,7 +876,8 @@ public class UpdateRequest extends InstanceShardOperationRequest<UpdateRequest>
|
|||
}
|
||||
if (upsertRequest != null) {
|
||||
XContentType xContentType = upsertRequest.getContentType();
|
||||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, upsertRequest.source(), xContentType)) {
|
||||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY,
|
||||
LoggingDeprecationHandler.INSTANCE, upsertRequest.source(), xContentType)) {
|
||||
builder.field("upsert");
|
||||
builder.copyCurrentStructure(parser);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public class XContentHelper {
|
|||
|
||||
/**
|
||||
* Creates a parser based on the bytes provided
|
||||
* @deprecated use {@link #createParser(NamedXContentRegistry, BytesReference, XContentType)} to avoid content type auto-detection
|
||||
* @deprecated use {@link #createParser(NamedXContentRegistry, DeprecationHandler, BytesReference, XContentType)} to avoid content type auto-detection
|
||||
*/
|
||||
@Deprecated
|
||||
public static XContentParser createParser(NamedXContentRegistry xContentRegistry, BytesReference bytes) throws IOException {
|
||||
|
@ -60,8 +60,8 @@ public class XContentHelper {
|
|||
/**
|
||||
* Creates a parser for the bytes using the supplied content-type
|
||||
*/
|
||||
public static XContentParser createParser(NamedXContentRegistry xContentRegistry, BytesReference bytes,
|
||||
XContentType xContentType) throws IOException {
|
||||
public static XContentParser createParser(NamedXContentRegistry xContentRegistry, DeprecationHandler deprecationHandler,
|
||||
BytesReference bytes, XContentType xContentType) throws IOException {
|
||||
Objects.requireNonNull(xContentType);
|
||||
Compressor compressor = CompressorFactory.compressor(bytes);
|
||||
if (compressor != null) {
|
||||
|
@ -69,7 +69,7 @@ public class XContentHelper {
|
|||
if (compressedInput.markSupported() == false) {
|
||||
compressedInput = new BufferedInputStream(compressedInput);
|
||||
}
|
||||
return XContentFactory.xContent(xContentType).createParser(xContentRegistry, compressedInput);
|
||||
return XContentFactory.xContent(xContentType).createParser(xContentRegistry, deprecationHandler, compressedInput);
|
||||
} else {
|
||||
return xContentType.xContent().createParser(xContentRegistry, bytes.streamInput());
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ public class XContentHelper {
|
|||
public static Map<String, Object> convertToMap(XContent xContent, InputStream input, boolean ordered)
|
||||
throws ElasticsearchParseException {
|
||||
// It is safe to use EMPTY here because this never uses namedObject
|
||||
try (XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, input)) {
|
||||
try (XContentParser parser = xContent.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, input)) {
|
||||
return ordered ? parser.mapOrdered() : parser.map();
|
||||
} catch (IOException e) {
|
||||
throw new ElasticsearchParseException("Failed to parse content to map", e);
|
||||
|
@ -161,7 +161,7 @@ public class XContentHelper {
|
|||
|
||||
// It is safe to use EMPTY here because this never uses namedObject
|
||||
try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY,
|
||||
bytes.streamInput())) {
|
||||
LoggingDeprecationHandler.INSTANCE, bytes.streamInput())) {
|
||||
parser.nextToken();
|
||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||
if (prettyPrint) {
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.elasticsearch.Version;
|
|||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
import org.elasticsearch.common.joda.FormatDateTimeFormatter;
|
||||
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
|
@ -61,7 +62,8 @@ final class DocumentParser {
|
|||
final ParseContext.InternalParseContext context;
|
||||
final XContentType xContentType = source.getXContentType();
|
||||
|
||||
try (XContentParser parser = XContentHelper.createParser(docMapperParser.getXContentRegistry(), source.source(), xContentType)) {
|
||||
try (XContentParser parser = XContentHelper.createParser(docMapperParser.getXContentRegistry(),
|
||||
LoggingDeprecationHandler.INSTANCE, source.source(), xContentType)) {
|
||||
context = new ParseContext.InternalParseContext(indexSettings.getSettings(), docMapperParser, docMapper, source, parser);
|
||||
validateStart(parser);
|
||||
internalParseDocument(mapping, context, parser);
|
||||
|
|
|
@ -68,6 +68,7 @@ import org.elasticsearch.common.unit.ByteSizeUnit;
|
|||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.common.util.iterable.Iterables;
|
||||
import org.elasticsearch.common.util.set.Sets;
|
||||
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
@ -605,7 +606,8 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
|
|||
BytesStreamOutput out = new BytesStreamOutput();
|
||||
Streams.copy(blob, out);
|
||||
// EMPTY is safe here because RepositoryData#fromXContent calls namedObject
|
||||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, out.bytes(), XContentType.JSON)) {
|
||||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY,
|
||||
LoggingDeprecationHandler.INSTANCE, out.bytes(), XContentType.JSON)) {
|
||||
repositoryData = RepositoryData.snapshotsFromXContent(parser, indexGen);
|
||||
} catch (NotXContentException e) {
|
||||
logger.warn("[{}] index blob is not valid x-content [{} bytes]", snapshotsIndexBlobName, out.bytes().length());
|
||||
|
@ -617,7 +619,8 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
|
|||
try (InputStream blob = snapshotsBlobContainer.readBlob(INCOMPATIBLE_SNAPSHOTS_BLOB)) {
|
||||
BytesStreamOutput out = new BytesStreamOutput();
|
||||
Streams.copy(blob, out);
|
||||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, out.bytes(), XContentType.JSON)) {
|
||||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY,
|
||||
LoggingDeprecationHandler.INSTANCE, out.bytes(), XContentType.JSON)) {
|
||||
repositoryData = repositoryData.incompatibleSnapshotsFromXContent(parser);
|
||||
}
|
||||
} catch (NoSuchFileException e) {
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.elasticsearch.common.bytes.BytesReference;
|
|||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.unit.Fuzziness;
|
||||
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
|
@ -311,7 +312,8 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSug
|
|||
|
||||
static Map<String, List<ContextMapping.InternalQueryContext>> parseContextBytes(BytesReference contextBytes,
|
||||
NamedXContentRegistry xContentRegistry, ContextMappings contextMappings) throws IOException {
|
||||
try (XContentParser contextParser = XContentHelper.createParser(xContentRegistry, contextBytes, CONTEXT_BYTES_XCONTENT_TYPE)) {
|
||||
try (XContentParser contextParser = XContentHelper.createParser(xContentRegistry,
|
||||
LoggingDeprecationHandler.INSTANCE, contextBytes, CONTEXT_BYTES_XCONTENT_TYPE)) {
|
||||
contextParser.nextToken();
|
||||
Map<String, List<ContextMapping.InternalQueryContext>> queryContexts = new HashMap<>(contextMappings.size());
|
||||
assert contextParser.currentToken() == XContentParser.Token.START_OBJECT;
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.elasticsearch.common.collect.ImmutableOpenMap;
|
|||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.DeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
@ -102,7 +103,8 @@ public class IndexTemplateMetaDataTests extends ESTestCase {
|
|||
|
||||
BytesReference templateBytes = new BytesArray(template);
|
||||
final IndexTemplateMetaData indexTemplateMetaData;
|
||||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, templateBytes, XContentType.JSON)) {
|
||||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY,
|
||||
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, templateBytes, XContentType.JSON)) {
|
||||
indexTemplateMetaData = IndexTemplateMetaData.Builder.fromXContent(parser, "test");
|
||||
}
|
||||
|
||||
|
@ -115,7 +117,8 @@ public class IndexTemplateMetaDataTests extends ESTestCase {
|
|||
}
|
||||
|
||||
final IndexTemplateMetaData indexTemplateMetaDataRoundTrip;
|
||||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, templateBytesRoundTrip, XContentType.JSON)) {
|
||||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY,
|
||||
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, templateBytesRoundTrip, XContentType.JSON)) {
|
||||
indexTemplateMetaDataRoundTrip = IndexTemplateMetaData.Builder.fromXContent(parser, "test");
|
||||
}
|
||||
assertThat(indexTemplateMetaData, equalTo(indexTemplateMetaDataRoundTrip));
|
||||
|
@ -142,7 +145,8 @@ public class IndexTemplateMetaDataTests extends ESTestCase {
|
|||
randomAlphaOfLength(10) + "\":{\"type\":\"keyword\"}}" +
|
||||
"}}}";
|
||||
try (XContentParser parser =
|
||||
XContentHelper.createParser(NamedXContentRegistry.EMPTY, new BytesArray(templateWithEmptyPattern), XContentType.JSON)) {
|
||||
XContentHelper.createParser(NamedXContentRegistry.EMPTY,
|
||||
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, new BytesArray(templateWithEmptyPattern), XContentType.JSON)) {
|
||||
final IllegalArgumentException ex = expectThrows(IllegalArgumentException.class,
|
||||
() -> IndexTemplateMetaData.Builder.fromXContent(parser, randomAlphaOfLengthBetween(1, 100)));
|
||||
assertThat(ex.getMessage(), equalTo("Index patterns must not be null or empty; got []"));
|
||||
|
@ -156,7 +160,8 @@ public class IndexTemplateMetaDataTests extends ESTestCase {
|
|||
randomAlphaOfLength(10) + "\":{\"type\":\"keyword\"}}" +
|
||||
"}}}";
|
||||
try (XContentParser parser =
|
||||
XContentHelper.createParser(NamedXContentRegistry.EMPTY, new BytesArray(templateWithoutPattern), XContentType.JSON)) {
|
||||
XContentHelper.createParser(NamedXContentRegistry.EMPTY,
|
||||
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, new BytesArray(templateWithoutPattern), XContentType.JSON)) {
|
||||
final IllegalArgumentException ex = expectThrows(IllegalArgumentException.class,
|
||||
() -> IndexTemplateMetaData.Builder.fromXContent(parser, randomAlphaOfLengthBetween(1, 100)));
|
||||
assertThat(ex.getMessage(), equalTo("Index patterns must not be null or empty; got null"));
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.test;
|
||||
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.xcontent.DeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContent;
|
||||
|
@ -184,7 +185,8 @@ public final class XContentTestUtils {
|
|||
List<String> insertPaths;
|
||||
|
||||
// we can use NamedXContentRegistry.EMPTY here because we only traverse the xContent once and don't use it
|
||||
try (XContentParser parser = createParser(NamedXContentRegistry.EMPTY, xContent, contentType)) {
|
||||
try (XContentParser parser = createParser(NamedXContentRegistry.EMPTY,
|
||||
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, xContent, contentType)) {
|
||||
parser.nextToken();
|
||||
List<String> possiblePaths = XContentTestUtils.getInsertPaths(parser, new Stack<>());
|
||||
if (excludeFilter == null) {
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.util.Set;
|
|||
import java.util.stream.Stream;
|
||||
|
||||
import org.elasticsearch.common.io.PathUtils;
|
||||
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
|
@ -94,7 +95,8 @@ public class ClientYamlSuiteRestSpec {
|
|||
|
||||
private static void parseSpecFile(ClientYamlSuiteRestApiParser restApiParser, Path jsonFile, ClientYamlSuiteRestSpec restSpec) {
|
||||
try (InputStream stream = Files.newInputStream(jsonFile)) {
|
||||
try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, stream)) {
|
||||
try (XContentParser parser =
|
||||
JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, stream)) {
|
||||
String filename = jsonFile.getFileName().toString();
|
||||
if (filename.equals("_common.json")) {
|
||||
String currentFieldName = null;
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
package org.elasticsearch.test.rest.yaml.section;
|
||||
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.xcontent.DeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.yaml.YamlXContent;
|
||||
|
||||
|
@ -63,7 +65,7 @@ public class ClientYamlTestSuite {
|
|||
}
|
||||
|
||||
try (XContentParser parser = YamlXContent.yamlXContent.createParser(ExecutableSection.XCONTENT_REGISTRY,
|
||||
Files.newInputStream(file))) {
|
||||
LoggingDeprecationHandler.INSTANCE, Files.newInputStream(file))) {
|
||||
return parse(api, filename, parser);
|
||||
} catch(Exception e) {
|
||||
throw new IOException("Error parsing " + api + "/" + filename, e);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.test;
|
||||
|
||||
import org.elasticsearch.common.xcontent.DeprecationHandler;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
|
@ -71,7 +72,8 @@ public class XContentTestUtilsTests extends ESTestCase {
|
|||
}
|
||||
builder.endObject();
|
||||
|
||||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, builder.bytes(), builder.contentType())) {
|
||||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY,
|
||||
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, builder.bytes(), builder.contentType())) {
|
||||
parser.nextToken();
|
||||
List<String> insertPaths = XContentTestUtils.getInsertPaths(parser, new Stack<>());
|
||||
assertEquals(5, insertPaths.size());
|
||||
|
@ -96,7 +98,8 @@ public class XContentTestUtilsTests extends ESTestCase {
|
|||
Collections.singletonList("inn\\.er1"), () -> "inner2", () -> new HashMap<>());
|
||||
builder = XContentTestUtils.insertIntoXContent(XContentType.JSON.xContent(), builder.bytes(),
|
||||
Collections.singletonList("inn\\.er1"), () -> "field2", () -> "value2");
|
||||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, builder.bytes(), builder.contentType())) {
|
||||
try (XContentParser parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY,
|
||||
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, builder.bytes(), builder.contentType())) {
|
||||
Map<String, Object> map = parser.map();
|
||||
assertEquals(2, map.size());
|
||||
assertEquals("value1", map.get("field1"));
|
||||
|
|
Loading…
Reference in New Issue