XContent: Factor deprecation handling into callback (#28449)

Factors the way in which XContent parsing handles deprecated fields
into a callback that is set at parser construction time. The goals here
are:
1. Remove Log4J as a dependency of XContent so that XContent can be used
by clients without forcing log4j and our particular deprecation handling
scheme.
2. Simplify handling of deprecated fields in tests. Now tests can listen
directly for the deprecation callback rather than digging through a
ThreadLocal.

More accurately, this change begins this work. It deprecates a number of
methods, pointing folks to the new versions of those methods that take
`DeprecationHandler`. The plan is to slowly drop these deprecated
methods. Once they are entirely removed we can remove Log4j as
dependency of XContent.
This commit is contained in:
Nik Everett 2018-01-30 18:21:10 -05:00 committed by GitHub
parent 9aeed74fe9
commit 3b6af15a60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 349 additions and 89 deletions

View File

@ -23,6 +23,8 @@ import com.fasterxml.jackson.core.JsonFactory;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.common.xcontent.json.JsonXContentParser;
import org.elasticsearch.ingest.AbstractProcessor;
@ -95,8 +97,7 @@ 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);
JsonXContentParser parser = new JsonXContentParser(NamedXContentRegistry.EMPTY,
JSON_FACTORY.createParser(builder.bytes().streamInput()));
XContentParser parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, builder.bytes().streamInput());
Script script = Script.parse(parser);
Arrays.asList("id", "source", "inline", "lang", "params", "options").forEach(config::remove);

View File

@ -20,6 +20,9 @@ package org.elasticsearch.common;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.XContentParser;
import java.util.Collections;
import java.util.HashSet;
@ -31,9 +34,6 @@ import java.util.Set;
* variants, which may be deprecated.
*/
public class ParseField {
private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(ParseField.class));
private final String name;
private final String[] deprecatedNames;
private String allReplacedWith = null;
@ -99,12 +99,31 @@ public class ParseField {
}
/**
* Does {@code fieldName} match this field? Uses {@link LoggingDeprecationHandler}
* to prevent us from having to touch every call to {@code match} in the change
* that introduced {@linkplain LoggingDeprecationHandler}. In a followup this will
* be removed.
* @param fieldName
* the field name to match against this {@link ParseField}
* @return true if <code>fieldName</code> matches any of the acceptable
* names for this {@link ParseField}.
* @deprecated Use {@link #match(String, DeprecationHandler)} with
* {@link XContentParser#getDeprecationHandler()} instead.
*/
@Deprecated
public boolean match(String fieldName) {
return match(fieldName, LoggingDeprecationHandler.INSTANCE);
}
/**
* Does {@code fieldName} match this field?
* @param fieldName
* the field name to match against this {@link ParseField}
* @param deprecationHandler called if {@code fieldName} is deprecated
* @return true if <code>fieldName</code> matches any of the acceptable
* names for this {@link ParseField}.
*/
public boolean match(String fieldName, DeprecationHandler deprecationHandler) {
Objects.requireNonNull(fieldName, "fieldName cannot be null");
// if this parse field has not been completely deprecated then try to
// match the preferred name
@ -114,17 +133,13 @@ public class ParseField {
// Now try to match against one of the deprecated names. Note that if
// the parse field is entirely deprecated (allReplacedWith != null) all
// fields will be in the deprecatedNames array
String msg;
for (String depName : deprecatedNames) {
if (fieldName.equals(depName)) {
msg = "Deprecated field [" + fieldName + "] used, expected [" + name + "] instead";
if (allReplacedWith != null) {
// If the field is entirely deprecated then there is no
// preferred name so instead use the `allReplaceWith`
// message to indicate what should be used instead
msg = "Deprecated field [" + fieldName + "] used, replaced by [" + allReplacedWith + "]";
if (allReplacedWith == null) {
deprecationHandler.usedDeprecatedName(fieldName, name);
} else {
deprecationHandler.usedDeprecatedField(fieldName, allReplacedWith);
}
DEPRECATION_LOGGER.deprecated(msg);
return true;
}
}

View File

@ -29,6 +29,7 @@ import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.MemorySizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -1143,8 +1144,9 @@ public class Setting<T> implements ToXContentObject {
}
private static List<String> parseableStringToList(String parsableString) {
// EMPTY is safe here because we never call namedObject
try (XContentParser xContentParser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, parsableString)) {
// fromXContent doesn't use named xcontent or deprecation.
try (XContentParser xContentParser = XContentType.JSON.xContent()
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, parsableString)) {
XContentParser.Token token = xContentParser.nextToken();
if (token != XContentParser.Token.START_ARRAY) {
throw new IllegalArgumentException("expected START_ARRAY but got " + token);

View File

@ -37,6 +37,7 @@ import org.elasticsearch.common.unit.MemorySizeValue;
import org.elasticsearch.common.unit.RatioValue;
import org.elasticsearch.common.unit.SizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -1144,7 +1145,9 @@ public final class Settings implements ToXContentFragment {
} else {
throw new IllegalArgumentException("unable to detect content type from resource name [" + resourceName + "]");
}
try (XContentParser parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY, is)) {
// fromXContent doesn't use named xcontent or deprecation.
try (XContentParser parser = XContentFactory.xContent(xContentType)
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, is)) {
if (parser.currentToken() == null) {
if (parser.nextToken() == null) {
return this; // empty file

View File

@ -0,0 +1,60 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.common.xcontent;
/**
* Callback for notifying the creator of the {@link XContentParser} that
* parsing hit a deprecated field.
*/
public interface DeprecationHandler {
/**
* Throws an {@link UnsupportedOperationException} when parsing hits a
* deprecated field. Use this when creating an {@link XContentParser}
* that won't interact with deprecation logic at all or when you want
* to fail fast when parsing deprecated fields.
*/
DeprecationHandler THROW_UNSUPPORTED_OPERATION = new DeprecationHandler() {
@Override
public void usedDeprecatedField(String usedName, String replacedWith) {
throw new UnsupportedOperationException("deprecated fields not supported here but got ["
+ usedName + "] which is a deprecated name for [" + replacedWith + "]");
}
@Override
public void usedDeprecatedName(String usedName, String modernName) {
throw new UnsupportedOperationException("deprecated fields not supported here but got ["
+ usedName + "] which has been replaced with [" + modernName + "]");
}
};
/**
* Called when the provided field name matches a deprecated name for the field.
* @param usedName the provided field name
* @param modernName the modern name for the field
*/
void usedDeprecatedName(String usedName, String modernName);
/**
* Called when the provided field name matches the current field but the entire
* field has been marked as deprecated.
* @param usedName the provided field name
* @param replacedWith the name of the field that replaced this field
*/
void usedDeprecatedField(String usedName, String replacedWith);
}

View File

@ -0,0 +1,60 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.common.xcontent;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.Loggers;
/**
* Logs deprecations to the {@link DeprecationLogger}.
* <p>
* This is core's primary implementation of {@link DeprecationHandler} and
* should <strong>absolutely</strong> be used everywhere where it parses
* requests. It is much less appropriate when parsing responses from external
* sources because it will report deprecated fields back to the user as
* though the user sent them.
*/
public class LoggingDeprecationHandler implements DeprecationHandler {
public static LoggingDeprecationHandler INSTANCE = new LoggingDeprecationHandler();
/**
* The logger to which to send deprecation messages.
*
* This uses ParseField's logger because that is the logger that
* we have been using for many releases for deprecated fields.
* Changing that will require some research to make super duper
* sure it is safe.
*/
private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(ParseField.class));
private LoggingDeprecationHandler() {
// Singleton
}
@Override
public void usedDeprecatedName(String usedName, String modernName) {
DEPRECATION_LOGGER.deprecated("Deprecated field [{}] used, expected [{}] instead", usedName, modernName);
}
@Override
public void usedDeprecatedField(String usedName, String replacedWith) {
DEPRECATION_LOGGER.deprecated("Deprecated field [{}] used, replaced by [{}]", usedName, replacedWith);
}
}

View File

@ -165,7 +165,7 @@ public final class ObjectParser<Value, Context> extends AbstractObjectParser<Val
assert ignoreUnknownFields : "this should only be possible if configured to ignore known fields";
parser.skipChildren(); // noop if parser points to a value, skips children if parser is start object or start array
} else {
fieldParser.assertSupports(name, token, currentFieldName, parser.getTokenLocation());
fieldParser.assertSupports(name, parser, currentFieldName);
parseSub(parser, fieldParser, currentFieldName, value, context);
}
fieldParser = null;
@ -362,13 +362,14 @@ public final class ObjectParser<Value, Context> extends AbstractObjectParser<Val
this.type = type;
}
void assertSupports(String parserName, XContentParser.Token token, String currentFieldName, XContentLocation location) {
void assertSupports(String parserName, XContentParser parser, String currentFieldName) {
if (parseField.match(currentFieldName) == false) {
throw new ParsingException(location, "[" + parserName + "] parsefield doesn't accept: " + currentFieldName);
throw new ParsingException(parser.getTokenLocation(),
"[" + parserName + "] parsefield doesn't accept: " + currentFieldName);
}
if (supportedTokens.contains(token) == false) {
throw new ParsingException(location,
"[" + parserName + "] " + currentFieldName + " doesn't support values of type: " + token);
if (supportedTokens.contains(parser.currentToken()) == false) {
throw new ParsingException(parser.getTokenLocation(),
"[" + parserName + "] " + currentFieldName + " doesn't support values of type: " + parser.currentToken());
}
}

View File

@ -83,31 +83,102 @@ public interface XContent {
/**
* Creates a parser over the provided string content.
*/
XContentParser createParser(NamedXContentRegistry xContentRegistry, String content) throws IOException;
XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, String content) throws IOException;
/**
* Creates a parser over the provided input stream.
*/
XContentParser createParser(NamedXContentRegistry xContentRegistry, InputStream is) throws IOException;
XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, InputStream is) throws IOException;
/**
* Creates a parser over the provided bytes.
*/
XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data) throws IOException;
XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, byte[] data) throws IOException;
/**
* Creates a parser over the provided bytes.
*/
XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data, int offset, int length) throws IOException;
XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, byte[] data, int offset, int length) throws IOException;
/**
* Creates a parser over the provided bytes.
*/
XContentParser createParser(NamedXContentRegistry xContentRegistry, BytesReference bytes) throws IOException;
XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, BytesReference bytes) throws IOException;
/**
* Creates a parser over the provided reader.
*/
XContentParser createParser(NamedXContentRegistry xContentRegistry, Reader reader) throws IOException;
XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, Reader reader) throws IOException;
/**
* Creates a parser over the provided string content using
* {@link LoggingDeprecationHandler}.
* @deprecated This is a temporary shim so we can migrate all calls to createParser incrementally.
* Use {@link #createParser(NamedXContentRegistry, DeprecationHandler, String)} instead.
*/
@Deprecated
default XContentParser createParser(NamedXContentRegistry xContentRegistry, String content) throws IOException {
return createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, content);
}
/**
* Creates a parser over the provided input stream using
* {@link LoggingDeprecationHandler}.
* @deprecated This is a temporary shim so we can migrate all calls to createParser incrementally.
* Use {@link #createParser(NamedXContentRegistry, DeprecationHandler, InputStream)} instead.
*/
@Deprecated
default XContentParser createParser(NamedXContentRegistry xContentRegistry, InputStream is) throws IOException {
return createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, is);
}
/**
* Creates a parser over the provided bytes using
* {@link LoggingDeprecationHandler}.
* @deprecated This is a temporary shim so we can migrate all calls to createParser incrementally.
* Use {@link #createParser(NamedXContentRegistry, DeprecationHandler, byte[])} instead.
*/
@Deprecated
default XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data) throws IOException {
return createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, data);
}
/**
* Creates a parser over the provided bytes using
* {@link LoggingDeprecationHandler}.
* @deprecated This is a temporary shim so we can migrate all calls to createParser incrementally.
* Use {@link #createParser(NamedXContentRegistry, DeprecationHandler, byte[], int, int)} instead.
*/
@Deprecated
default XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data, int offset, int length) throws IOException {
return createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, data, offset, length);
}
/**
* Creates a parser over the provided bytes using
* {@link LoggingDeprecationHandler}.
* @deprecated This is a temporary shim so we can migrate all calls to createParser incrementally.
* Use {@link #createParser(NamedXContentRegistry, DeprecationHandler, BytesReference)} instead.
*/
@Deprecated
default XContentParser createParser(NamedXContentRegistry xContentRegistry, BytesReference bytes) throws IOException {
return createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, bytes);
}
/**
* Creates a parser over the provided reader using
* {@link LoggingDeprecationHandler}.
* @deprecated This is a temporary shim so we can migrate all calls to createParser incrementally.
* Use {@link #createParser(NamedXContentRegistry, DeprecationHandler, Reader)} instead.
*/
@Deprecated
default XContentParser createParser(NamedXContentRegistry xContentRegistry, Reader reader) throws IOException {
return createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, reader);
}
}

View File

@ -33,7 +33,8 @@ import java.util.Map;
*
* <pre>
* XContentType xContentType = XContentType.JSON;
* XContentParser parser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY, "{\"key\" : \"value\"}");
* XContentParser parser = xContentType.xContent().createParser(
* NamedXContentRegistry.EMPTY, ParserField."{\"key\" : \"value\"}");
* </pre>
*/
public interface XContentParser extends Releasable {
@ -277,4 +278,9 @@ public interface XContentParser extends Releasable {
NamedXContentRegistry getXContentRegistry();
boolean isClosed();
/**
* The callback to notify when parsing encounters a deprecated field.
*/
DeprecationHandler getDeprecationHandler();
}

View File

@ -26,6 +26,7 @@ import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.FastStringReader;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -79,33 +80,39 @@ public class CborXContent implements XContent {
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, String content) throws IOException {
return new CborXContentParser(xContentRegistry, cborFactory.createParser(new FastStringReader(content)));
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, String content) throws IOException {
return new CborXContentParser(xContentRegistry, deprecationHandler, cborFactory.createParser(new FastStringReader(content)));
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, InputStream is) throws IOException {
return new CborXContentParser(xContentRegistry, cborFactory.createParser(is));
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, InputStream is) throws IOException {
return new CborXContentParser(xContentRegistry, deprecationHandler, cborFactory.createParser(is));
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data) throws IOException {
return new CborXContentParser(xContentRegistry, cborFactory.createParser(data));
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, byte[] data) throws IOException {
return new CborXContentParser(xContentRegistry, deprecationHandler, cborFactory.createParser(data));
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data, int offset, int length) throws IOException {
return new CborXContentParser(xContentRegistry, cborFactory.createParser(data, offset, length));
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, byte[] data, int offset, int length) throws IOException {
return new CborXContentParser(xContentRegistry, deprecationHandler, cborFactory.createParser(data, offset, length));
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, BytesReference bytes) throws IOException {
return createParser(xContentRegistry, bytes.streamInput());
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, BytesReference bytes) throws IOException {
return createParser(xContentRegistry, deprecationHandler, bytes.streamInput());
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, Reader reader) throws IOException {
return new CborXContentParser(xContentRegistry, cborFactory.createParser(reader));
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, Reader reader) throws IOException {
return new CborXContentParser(xContentRegistry, deprecationHandler, cborFactory.createParser(reader));
}
}

View File

@ -20,15 +20,16 @@
package org.elasticsearch.common.xcontent.cbor;
import com.fasterxml.jackson.core.JsonParser;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContentParser;
public class CborXContentParser extends JsonXContentParser {
public CborXContentParser(NamedXContentRegistry xContentRegistry, JsonParser parser) {
super(xContentRegistry, parser);
public CborXContentParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, JsonParser parser) {
super(xContentRegistry, deprecationHandler, parser);
}
@Override

View File

@ -25,6 +25,7 @@ import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.FastStringReader;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -80,32 +81,38 @@ public class JsonXContent implements XContent {
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, String content) throws IOException {
return new JsonXContentParser(xContentRegistry, jsonFactory.createParser(new FastStringReader(content)));
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, String content) throws IOException {
return new JsonXContentParser(xContentRegistry, deprecationHandler, jsonFactory.createParser(new FastStringReader(content)));
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, InputStream is) throws IOException {
return new JsonXContentParser(xContentRegistry, jsonFactory.createParser(is));
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, InputStream is) throws IOException {
return new JsonXContentParser(xContentRegistry, deprecationHandler, jsonFactory.createParser(is));
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data) throws IOException {
return new JsonXContentParser(xContentRegistry, jsonFactory.createParser(data));
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, byte[] data) throws IOException {
return new JsonXContentParser(xContentRegistry, deprecationHandler, jsonFactory.createParser(data));
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data, int offset, int length) throws IOException {
return new JsonXContentParser(xContentRegistry, jsonFactory.createParser(data, offset, length));
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, byte[] data, int offset, int length) throws IOException {
return new JsonXContentParser(xContentRegistry, deprecationHandler, jsonFactory.createParser(data, offset, length));
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, BytesReference bytes) throws IOException {
return createParser(xContentRegistry, bytes.streamInput());
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, BytesReference bytes) throws IOException {
return createParser(xContentRegistry, deprecationHandler, bytes.streamInput());
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, Reader reader) throws IOException {
return new JsonXContentParser(xContentRegistry, jsonFactory.createParser(reader));
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, Reader reader) throws IOException {
return new JsonXContentParser(xContentRegistry, deprecationHandler, jsonFactory.createParser(reader));
}
}

View File

@ -25,6 +25,7 @@ import com.fasterxml.jackson.core.JsonToken;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOUtils;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentLocation;
import org.elasticsearch.common.xcontent.XContentType;
@ -37,8 +38,9 @@ public class JsonXContentParser extends AbstractXContentParser {
final JsonParser parser;
public JsonXContentParser(NamedXContentRegistry xContentRegistry, JsonParser parser) {
super(xContentRegistry);
public JsonXContentParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, JsonParser parser) {
super(xContentRegistry, deprecationHandler);
this.parser = parser;
}

View File

@ -26,6 +26,7 @@ import com.fasterxml.jackson.dataformat.smile.SmileFactory;
import com.fasterxml.jackson.dataformat.smile.SmileGenerator;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.FastStringReader;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -80,32 +81,38 @@ public class SmileXContent implements XContent {
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, String content) throws IOException {
return new SmileXContentParser(xContentRegistry, smileFactory.createParser(new FastStringReader(content)));
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, String content) throws IOException {
return new SmileXContentParser(xContentRegistry, deprecationHandler, smileFactory.createParser(new FastStringReader(content)));
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, InputStream is) throws IOException {
return new SmileXContentParser(xContentRegistry, smileFactory.createParser(is));
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, InputStream is) throws IOException {
return new SmileXContentParser(xContentRegistry, deprecationHandler, smileFactory.createParser(is));
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data) throws IOException {
return new SmileXContentParser(xContentRegistry, smileFactory.createParser(data));
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, byte[] data) throws IOException {
return new SmileXContentParser(xContentRegistry, deprecationHandler, smileFactory.createParser(data));
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data, int offset, int length) throws IOException {
return new SmileXContentParser(xContentRegistry, smileFactory.createParser(data, offset, length));
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, byte[] data, int offset, int length) throws IOException {
return new SmileXContentParser(xContentRegistry, deprecationHandler, smileFactory.createParser(data, offset, length));
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, BytesReference bytes) throws IOException {
return createParser(xContentRegistry, bytes.streamInput());
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, BytesReference bytes) throws IOException {
return createParser(xContentRegistry, deprecationHandler, bytes.streamInput());
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, Reader reader) throws IOException {
return new SmileXContentParser(xContentRegistry, smileFactory.createParser(reader));
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, Reader reader) throws IOException {
return new SmileXContentParser(xContentRegistry, deprecationHandler, smileFactory.createParser(reader));
}
}

View File

@ -20,15 +20,16 @@
package org.elasticsearch.common.xcontent.smile;
import com.fasterxml.jackson.core.JsonParser;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContentParser;
public class SmileXContentParser extends JsonXContentParser {
public SmileXContentParser(NamedXContentRegistry xContentRegistry, JsonParser parser) {
super(xContentRegistry, parser);
public SmileXContentParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, JsonParser parser) {
super(xContentRegistry, deprecationHandler, parser);
}
@Override

View File

@ -23,6 +23,7 @@ import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.Numbers;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentParser;
@ -52,9 +53,11 @@ public abstract class AbstractXContentParser implements XContentParser {
}
private final NamedXContentRegistry xContentRegistry;
private final DeprecationHandler deprecationHandler;
public AbstractXContentParser(NamedXContentRegistry xContentRegistry) {
public AbstractXContentParser(NamedXContentRegistry xContentRegistry, DeprecationHandler deprecationHandler) {
this.xContentRegistry = xContentRegistry;
this.deprecationHandler = deprecationHandler;
}
// The 3rd party parsers we rely on are known to silently truncate fractions: see
@ -409,4 +412,9 @@ public abstract class AbstractXContentParser implements XContentParser {
@Override
public abstract boolean isClosed();
@Override
public DeprecationHandler getDeprecationHandler() {
return deprecationHandler;
}
}

View File

@ -25,6 +25,7 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.FastStringReader;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -75,32 +76,38 @@ public class YamlXContent implements XContent {
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, String content) throws IOException {
return new YamlXContentParser(xContentRegistry, yamlFactory.createParser(new FastStringReader(content)));
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, String content) throws IOException {
return new YamlXContentParser(xContentRegistry, deprecationHandler, yamlFactory.createParser(new FastStringReader(content)));
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, InputStream is) throws IOException {
return new YamlXContentParser(xContentRegistry, yamlFactory.createParser(is));
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, InputStream is) throws IOException {
return new YamlXContentParser(xContentRegistry, deprecationHandler, yamlFactory.createParser(is));
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data) throws IOException {
return new YamlXContentParser(xContentRegistry, yamlFactory.createParser(data));
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, byte[] data) throws IOException {
return new YamlXContentParser(xContentRegistry, deprecationHandler, yamlFactory.createParser(data));
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, byte[] data, int offset, int length) throws IOException {
return new YamlXContentParser(xContentRegistry, yamlFactory.createParser(data, offset, length));
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, byte[] data, int offset, int length) throws IOException {
return new YamlXContentParser(xContentRegistry, deprecationHandler, yamlFactory.createParser(data, offset, length));
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, BytesReference bytes) throws IOException {
return createParser(xContentRegistry, bytes.streamInput());
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, BytesReference bytes) throws IOException {
return createParser(xContentRegistry, deprecationHandler, bytes.streamInput());
}
@Override
public XContentParser createParser(NamedXContentRegistry xContentRegistry, Reader reader) throws IOException {
return new YamlXContentParser(xContentRegistry, yamlFactory.createParser(reader));
public XContentParser createParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, Reader reader) throws IOException {
return new YamlXContentParser(xContentRegistry, deprecationHandler, yamlFactory.createParser(reader));
}
}

View File

@ -20,15 +20,16 @@
package org.elasticsearch.common.xcontent.yaml;
import com.fasterxml.jackson.core.JsonParser;
import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContentParser;
public class YamlXContentParser extends JsonXContentParser {
public YamlXContentParser(NamedXContentRegistry xContentRegistry, JsonParser parser) {
super(xContentRegistry, parser);
public YamlXContentParser(NamedXContentRegistry xContentRegistry,
DeprecationHandler deprecationHandler, JsonParser parser) {
super(xContentRegistry, deprecationHandler, parser);
}
@Override