Pass InputStream when creating XContent parser (#28754)
* Pass InputStream when creating XContent parser Rather than passing the raw `BytesReference` in when creating the xcontent parser, this passes the StreamInput (which is an InputStream), this allows us to decouple XContent from BytesReference. This also removes the use of `commons.Booleans` so it doesn't require more external commons classes. Related to #28504 * Undo boolean removal * Enhance deprecation javadoc
This commit is contained in:
parent
260d68aad0
commit
d7eae4b90f
|
@ -78,7 +78,7 @@ public final class JsonProcessor extends AbstractProcessor {
|
||||||
Object fieldValue = document.getFieldValue(field, Object.class);
|
Object fieldValue = document.getFieldValue(field, Object.class);
|
||||||
BytesReference bytesRef = (fieldValue == null) ? new BytesArray("null") : new BytesArray(fieldValue.toString());
|
BytesReference bytesRef = (fieldValue == null) ? new BytesArray("null") : new BytesArray(fieldValue.toString());
|
||||||
try (XContentParser parser = JsonXContent.jsonXContent
|
try (XContentParser parser = JsonXContent.jsonXContent
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytesRef)) {
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytesRef.streamInput())) {
|
||||||
XContentParser.Token token = parser.nextToken();
|
XContentParser.Token token = parser.nextToken();
|
||||||
Object value = null;
|
Object value = null;
|
||||||
if (token == XContentParser.Token.VALUE_NULL) {
|
if (token == XContentParser.Token.VALUE_NULL) {
|
||||||
|
|
|
@ -91,7 +91,7 @@ public abstract class AbstractBulkByQueryRestHandler<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return parser.contentType().xContent().createParser(parser.getXContentRegistry(),
|
return parser.contentType().xContent().createParser(parser.getXContentRegistry(),
|
||||||
parser.getDeprecationHandler(), builder.map(body).bytes());
|
parser.getDeprecationHandler(), builder.map(body).bytes().streamInput());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler<ReindexReq
|
||||||
XContentBuilder builder = XContentFactory.contentBuilder(parser.contentType());
|
XContentBuilder builder = XContentFactory.contentBuilder(parser.contentType());
|
||||||
builder.map(source);
|
builder.map(source);
|
||||||
try (XContentParser innerParser = parser.contentType().xContent()
|
try (XContentParser innerParser = parser.contentType().xContent()
|
||||||
.createParser(parser.getXContentRegistry(), parser.getDeprecationHandler(), builder.bytes())) {
|
.createParser(parser.getXContentRegistry(), parser.getDeprecationHandler(), builder.bytes().streamInput())) {
|
||||||
request.getSearchRequest().source().parseXContent(innerParser);
|
request.getSearchRequest().source().parseXContent(innerParser);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -339,7 +339,8 @@ public class TransportReindexAction extends HandledTransportAction<ReindexReques
|
||||||
if (mainRequestXContentType != null && doc.getXContentType() != mainRequestXContentType) {
|
if (mainRequestXContentType != null && doc.getXContentType() != mainRequestXContentType) {
|
||||||
// we need to convert
|
// we need to convert
|
||||||
try (XContentParser parser = sourceXContentType.xContent()
|
try (XContentParser parser = sourceXContentType.xContent()
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, doc.getSource());
|
.createParser(NamedXContentRegistry.EMPTY,
|
||||||
|
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, doc.getSource().streamInput());
|
||||||
XContentBuilder builder = XContentBuilder.builder(mainRequestXContentType.xContent())) {
|
XContentBuilder builder = XContentBuilder.builder(mainRequestXContentType.xContent())) {
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
builder.copyCurrentStructure(parser);
|
builder.copyCurrentStructure(parser);
|
||||||
|
|
|
@ -307,7 +307,7 @@ public class BulkRequest extends ActionRequest implements CompositeIndicesReques
|
||||||
// EMPTY is safe here because we never call namedObject
|
// EMPTY is safe here because we never call namedObject
|
||||||
try (XContentParser parser = xContent
|
try (XContentParser parser = xContent
|
||||||
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE,
|
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE,
|
||||||
data.slice(from, nextMarker - from))) {
|
data.slice(from, nextMarker - from).streamInput())) {
|
||||||
// move pointers
|
// move pointers
|
||||||
from = nextMarker + 1;
|
from = nextMarker + 1;
|
||||||
|
|
||||||
|
@ -432,7 +432,7 @@ public class BulkRequest extends ActionRequest implements CompositeIndicesReques
|
||||||
.parent(parent);
|
.parent(parent);
|
||||||
// EMPTY is safe here because we never call namedObject
|
// EMPTY is safe here because we never call namedObject
|
||||||
try (XContentParser sliceParser = xContent.createParser(NamedXContentRegistry.EMPTY,
|
try (XContentParser sliceParser = xContent.createParser(NamedXContentRegistry.EMPTY,
|
||||||
LoggingDeprecationHandler.INSTANCE, sliceTrimmingCarriageReturn(data, from, nextMarker, xContentType))) {
|
LoggingDeprecationHandler.INSTANCE, sliceTrimmingCarriageReturn(data, from, nextMarker, xContentType).streamInput())) {
|
||||||
updateRequest.fromXContent(sliceParser);
|
updateRequest.fromXContent(sliceParser);
|
||||||
}
|
}
|
||||||
if (fetchSourceContext != null) {
|
if (fetchSourceContext != null) {
|
||||||
|
|
|
@ -208,7 +208,8 @@ public class MultiSearchRequest extends ActionRequest implements CompositeIndice
|
||||||
// now parse the action
|
// now parse the action
|
||||||
if (nextMarker - from > 0) {
|
if (nextMarker - from > 0) {
|
||||||
try (XContentParser parser = xContent
|
try (XContentParser parser = xContent
|
||||||
.createParser(registry, LoggingDeprecationHandler.INSTANCE, data.slice(from, nextMarker - from))) {
|
.createParser(registry, LoggingDeprecationHandler.INSTANCE,
|
||||||
|
data.slice(from, nextMarker - from).streamInput())) {
|
||||||
Map<String, Object> source = parser.map();
|
Map<String, Object> source = parser.map();
|
||||||
for (Map.Entry<String, Object> entry : source.entrySet()) {
|
for (Map.Entry<String, Object> entry : source.entrySet()) {
|
||||||
Object value = entry.getValue();
|
Object value = entry.getValue();
|
||||||
|
@ -244,7 +245,7 @@ public class MultiSearchRequest extends ActionRequest implements CompositeIndice
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
BytesReference bytes = data.slice(from, nextMarker - from);
|
BytesReference bytes = data.slice(from, nextMarker - from);
|
||||||
try (XContentParser parser = xContent.createParser(registry, LoggingDeprecationHandler.INSTANCE, bytes)) {
|
try (XContentParser parser = xContent.createParser(registry, LoggingDeprecationHandler.INSTANCE, bytes.streamInput())) {
|
||||||
consumer.accept(searchRequest, parser);
|
consumer.accept(searchRequest, parser);
|
||||||
}
|
}
|
||||||
// move pointers
|
// move pointers
|
||||||
|
|
|
@ -106,7 +106,10 @@ public interface XContent {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a parser over the provided bytes.
|
* Creates a parser over the provided bytes.
|
||||||
|
* @deprecated use {@link #createParser(NamedXContentRegistry, DeprecationHandler, InputStream)} instead,
|
||||||
|
* the BytesReference coupling in this class will be removed in a future commit
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
XContentParser createParser(NamedXContentRegistry xContentRegistry,
|
XContentParser createParser(NamedXContentRegistry xContentRegistry,
|
||||||
DeprecationHandler deprecationHandler, BytesReference bytes) throws IOException;
|
DeprecationHandler deprecationHandler, BytesReference bytes) throws IOException;
|
||||||
|
|
||||||
|
|
|
@ -183,7 +183,7 @@ public abstract class DecayFunctionBuilder<DFB extends DecayFunctionBuilder<DFB>
|
||||||
AbstractDistanceScoreFunction scoreFunction;
|
AbstractDistanceScoreFunction scoreFunction;
|
||||||
// EMPTY is safe because parseVariable doesn't use namedObject
|
// EMPTY is safe because parseVariable doesn't use namedObject
|
||||||
try (XContentParser parser = XContentFactory.xContent(functionBytes)
|
try (XContentParser parser = XContentFactory.xContent(functionBytes)
|
||||||
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, functionBytes)) {
|
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, functionBytes.streamInput())) {
|
||||||
scoreFunction = parseVariable(fieldName, parser, context, multiValueMode);
|
scoreFunction = parseVariable(fieldName, parser, context, multiValueMode);
|
||||||
}
|
}
|
||||||
return scoreFunction;
|
return scoreFunction;
|
||||||
|
|
|
@ -343,7 +343,7 @@ public abstract class RestRequest implements ToXContent.Params {
|
||||||
*/
|
*/
|
||||||
public final XContentParser contentParser() throws IOException {
|
public final XContentParser contentParser() throws IOException {
|
||||||
BytesReference content = requiredContent(); // will throw exception if body or content type missing
|
BytesReference content = requiredContent(); // will throw exception if body or content type missing
|
||||||
return xContentType.get().xContent().createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, content);
|
return xContentType.get().xContent().createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, content.streamInput());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -372,7 +372,7 @@ public abstract class RestRequest implements ToXContent.Params {
|
||||||
*/
|
*/
|
||||||
public final XContentParser contentOrSourceParamParser() throws IOException {
|
public final XContentParser contentOrSourceParamParser() throws IOException {
|
||||||
Tuple<XContentType, BytesReference> tuple = contentOrSourceParam();
|
Tuple<XContentType, BytesReference> tuple = contentOrSourceParam();
|
||||||
return tuple.v1().xContent().createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, tuple.v2());
|
return tuple.v1().xContent().createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, tuple.v2().streamInput());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -386,7 +386,7 @@ public abstract class RestRequest implements ToXContent.Params {
|
||||||
BytesReference content = tuple.v2();
|
BytesReference content = tuple.v2();
|
||||||
XContentType xContentType = tuple.v1();
|
XContentType xContentType = tuple.v1();
|
||||||
try (XContentParser parser = xContentType.xContent()
|
try (XContentParser parser = xContentType.xContent()
|
||||||
.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, content)) {
|
.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, content.streamInput())) {
|
||||||
withParser.accept(parser);
|
withParser.accept(parser);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -283,7 +283,7 @@ public final class Script implements ToXContentObject, Writeable {
|
||||||
settings.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
settings.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
return parse(JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY,
|
return parse(JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY,
|
||||||
LoggingDeprecationHandler.INSTANCE, builder.bytes()));
|
LoggingDeprecationHandler.INSTANCE, builder.bytes().streamInput()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// it should not happen since we are not actually reading from a stream but an in-memory byte[]
|
// it should not happen since we are not actually reading from a stream but an in-memory byte[]
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
|
|
|
@ -244,7 +244,7 @@ public class StoredScriptSource extends AbstractDiffable<StoredScriptSource> imp
|
||||||
*/
|
*/
|
||||||
public static StoredScriptSource parse(BytesReference content, XContentType xContentType) {
|
public static StoredScriptSource parse(BytesReference content, XContentType xContentType) {
|
||||||
try (XContentParser parser = xContentType.xContent()
|
try (XContentParser parser = xContentType.xContent()
|
||||||
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, content)) {
|
.createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, content.streamInput())) {
|
||||||
Token token = parser.nextToken();
|
Token token = parser.nextToken();
|
||||||
|
|
||||||
if (token != Token.START_OBJECT) {
|
if (token != Token.START_OBJECT) {
|
||||||
|
|
|
@ -1015,7 +1015,7 @@ public abstract class BaseXContentTestCase extends ESTestCase {
|
||||||
new NamedXContentRegistry.Entry(Object.class, new ParseField("str"), p -> p.text())));
|
new NamedXContentRegistry.Entry(Object.class, new ParseField("str"), p -> p.text())));
|
||||||
XContentBuilder b = XContentBuilder.builder(xcontentType().xContent());
|
XContentBuilder b = XContentBuilder.builder(xcontentType().xContent());
|
||||||
b.value("test");
|
b.value("test");
|
||||||
XContentParser p = xcontentType().xContent().createParser(registry, LoggingDeprecationHandler.INSTANCE, b.bytes());
|
XContentParser p = xcontentType().xContent().createParser(registry, LoggingDeprecationHandler.INSTANCE, b.bytes().streamInput());
|
||||||
assertEquals(test1, p.namedObject(Object.class, "test1", null));
|
assertEquals(test1, p.namedObject(Object.class, "test1", null));
|
||||||
assertEquals(test2, p.namedObject(Object.class, "test2", null));
|
assertEquals(test2, p.namedObject(Object.class, "test2", null));
|
||||||
assertEquals(test2, p.namedObject(Object.class, "deprecated", null));
|
assertEquals(test2, p.namedObject(Object.class, "deprecated", null));
|
||||||
|
|
|
@ -167,7 +167,7 @@ public class XContentParserUtilsTests extends ESTestCase {
|
||||||
BytesReference bytes = toXContent((builder, params) -> builder.startObject("name").field("field", 0).endObject(), xContentType,
|
BytesReference bytes = toXContent((builder, params) -> builder.startObject("name").field("field", 0).endObject(), xContentType,
|
||||||
randomBoolean());
|
randomBoolean());
|
||||||
try (XContentParser parser = xContentType.xContent()
|
try (XContentParser parser = xContentType.xContent()
|
||||||
.createParser(namedXContentRegistry, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes)) {
|
.createParser(namedXContentRegistry, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes.streamInput())) {
|
||||||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
|
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
|
||||||
ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.nextToken(), parser::getTokenLocation);
|
ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.nextToken(), parser::getTokenLocation);
|
||||||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
|
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
|
||||||
|
@ -183,7 +183,7 @@ public class XContentParserUtilsTests extends ESTestCase {
|
||||||
bytes = toXContent((builder, params) -> builder.startObject("type" + delimiter + "name").field("bool", true).endObject(),
|
bytes = toXContent((builder, params) -> builder.startObject("type" + delimiter + "name").field("bool", true).endObject(),
|
||||||
xContentType, randomBoolean());
|
xContentType, randomBoolean());
|
||||||
try (XContentParser parser = xContentType.xContent()
|
try (XContentParser parser = xContentType.xContent()
|
||||||
.createParser(namedXContentRegistry, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes)) {
|
.createParser(namedXContentRegistry, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes.streamInput())) {
|
||||||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
|
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
|
||||||
ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.nextToken(), parser::getTokenLocation);
|
ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.nextToken(), parser::getTokenLocation);
|
||||||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
|
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
|
||||||
|
@ -203,7 +203,7 @@ public class XContentParserUtilsTests extends ESTestCase {
|
||||||
}, xContentType, randomBoolean());
|
}, xContentType, randomBoolean());
|
||||||
|
|
||||||
try (XContentParser parser = xContentType.xContent()
|
try (XContentParser parser = xContentType.xContent()
|
||||||
.createParser(namedXContentRegistry, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes)) {
|
.createParser(namedXContentRegistry, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes.streamInput())) {
|
||||||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
|
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
|
||||||
|
|
||||||
ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.nextToken(), parser::getTokenLocation);
|
ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.nextToken(), parser::getTokenLocation);
|
||||||
|
@ -230,7 +230,7 @@ public class XContentParserUtilsTests extends ESTestCase {
|
||||||
BytesReference bytes = toXContent((builder, params) -> builder.startObject("name").field("field", 0).endObject(), xContentType,
|
BytesReference bytes = toXContent((builder, params) -> builder.startObject("name").field("field", 0).endObject(), xContentType,
|
||||||
randomBoolean());
|
randomBoolean());
|
||||||
try (XContentParser parser = xContentType.xContent()
|
try (XContentParser parser = xContentType.xContent()
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes)) {
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes.streamInput())) {
|
||||||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
|
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
|
||||||
ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.nextToken(), parser::getTokenLocation);
|
ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.nextToken(), parser::getTokenLocation);
|
||||||
ParsingException exception = expectThrows(ParsingException.class,
|
ParsingException exception = expectThrows(ParsingException.class,
|
||||||
|
@ -243,7 +243,7 @@ public class XContentParserUtilsTests extends ESTestCase {
|
||||||
BytesReference bytes = toXContent((builder, params) -> builder.startObject("").field("field", 0).endObject(), xContentType,
|
BytesReference bytes = toXContent((builder, params) -> builder.startObject("").field("field", 0).endObject(), xContentType,
|
||||||
randomBoolean());
|
randomBoolean());
|
||||||
try (XContentParser parser = xContentType.xContent()
|
try (XContentParser parser = xContentType.xContent()
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes)) {
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes.streamInput())) {
|
||||||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
|
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
|
||||||
ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.nextToken(), parser::getTokenLocation);
|
ensureExpectedToken(XContentParser.Token.FIELD_NAME, parser.nextToken(), parser::getTokenLocation);
|
||||||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
|
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser::getTokenLocation);
|
||||||
|
|
|
@ -95,7 +95,7 @@ public class XContentHelperTests extends ESTestCase {
|
||||||
} else {
|
} else {
|
||||||
BytesReference bytes = XContentHelper.toXContent(toXContent, xContentType, randomBoolean());
|
BytesReference bytes = XContentHelper.toXContent(toXContent, xContentType, randomBoolean());
|
||||||
try (XContentParser parser = xContentType.xContent()
|
try (XContentParser parser = xContentType.xContent()
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes)) {
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes.streamInput())) {
|
||||||
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
|
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
|
||||||
assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken());
|
assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken());
|
||||||
assertTrue(parser.nextToken().isValue());
|
assertTrue(parser.nextToken().isValue());
|
||||||
|
|
|
@ -76,9 +76,11 @@ public abstract class AbstractXContentFilteringTestCase extends AbstractFilterin
|
||||||
try {
|
try {
|
||||||
XContent xContent = XContentFactory.xContent(actual.contentType());
|
XContent xContent = XContentFactory.xContent(actual.contentType());
|
||||||
XContentParser jsonParser =
|
XContentParser jsonParser =
|
||||||
xContent.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, expected.bytes());
|
xContent.createParser(NamedXContentRegistry.EMPTY,
|
||||||
|
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, expected.bytes().streamInput());
|
||||||
XContentParser testParser =
|
XContentParser testParser =
|
||||||
xContent.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, actual.bytes());
|
xContent.createParser(NamedXContentRegistry.EMPTY,
|
||||||
|
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, actual.bytes().streamInput());
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
XContentParser.Token token1 = jsonParser.nextToken();
|
XContentParser.Token token1 = jsonParser.nextToken();
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class PipelineConfigurationTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
XContentParser xContentParser = xContentType.xContent()
|
XContentParser xContentParser = xContentType.xContent()
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes);
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes.streamInput());
|
||||||
PipelineConfiguration parsed = parser.parse(xContentParser, null);
|
PipelineConfiguration parsed = parser.parse(xContentParser, null);
|
||||||
assertEquals(xContentType, parsed.getXContentType());
|
assertEquals(xContentType, parsed.getXContentType());
|
||||||
assertEquals("{}", XContentHelper.convertToJson(parsed.getConfig(), false, parsed.getXContentType()));
|
assertEquals("{}", XContentHelper.convertToJson(parsed.getConfig(), false, parsed.getXContentType()));
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class ScriptMetaDataTests extends AbstractSerializingTestCase<ScriptMetaD
|
||||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||||
builder.startObject().field("lang0#id0", "script0").field("lang1#id0", "script1").endObject();
|
builder.startObject().field("lang0#id0", "script0").field("lang1#id0", "script1").endObject();
|
||||||
XContentParser parser0 = XContentType.JSON.xContent()
|
XContentParser parser0 = XContentType.JSON.xContent()
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, builder.bytes());
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, builder.bytes().streamInput());
|
||||||
expectThrows(IllegalArgumentException.class, () -> ScriptMetaData.fromXContent(parser0));
|
expectThrows(IllegalArgumentException.class, () -> ScriptMetaData.fromXContent(parser0));
|
||||||
|
|
||||||
// failure to load a new namespace script and old namespace script with the same id but different langs
|
// failure to load a new namespace script and old namespace script with the same id but different langs
|
||||||
|
@ -47,7 +47,7 @@ public class ScriptMetaDataTests extends AbstractSerializingTestCase<ScriptMetaD
|
||||||
builder.startObject().field("lang0#id0", "script0")
|
builder.startObject().field("lang0#id0", "script0")
|
||||||
.startObject("id0").field("lang", "lang1").field("source", "script1").endObject().endObject();
|
.startObject("id0").field("lang", "lang1").field("source", "script1").endObject().endObject();
|
||||||
XContentParser parser1 = XContentType.JSON.xContent()
|
XContentParser parser1 = XContentType.JSON.xContent()
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, builder.bytes());
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, builder.bytes().streamInput());
|
||||||
expectThrows(IllegalArgumentException.class, () -> ScriptMetaData.fromXContent(parser1));
|
expectThrows(IllegalArgumentException.class, () -> ScriptMetaData.fromXContent(parser1));
|
||||||
|
|
||||||
// failure to load a new namespace script and old namespace script with the same id but different langs with additional scripts
|
// failure to load a new namespace script and old namespace script with the same id but different langs with additional scripts
|
||||||
|
@ -56,7 +56,7 @@ public class ScriptMetaDataTests extends AbstractSerializingTestCase<ScriptMetaD
|
||||||
.startObject("id1").field("lang", "lang0").field("source", "script0").endObject()
|
.startObject("id1").field("lang", "lang0").field("source", "script0").endObject()
|
||||||
.startObject("id0").field("lang", "lang1").field("source", "script1").endObject().endObject();
|
.startObject("id0").field("lang", "lang1").field("source", "script1").endObject().endObject();
|
||||||
XContentParser parser2 = XContentType.JSON.xContent()
|
XContentParser parser2 = XContentType.JSON.xContent()
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, builder.bytes());
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, builder.bytes().streamInput());
|
||||||
expectThrows(IllegalArgumentException.class, () -> ScriptMetaData.fromXContent(parser2));
|
expectThrows(IllegalArgumentException.class, () -> ScriptMetaData.fromXContent(parser2));
|
||||||
|
|
||||||
// okay to load the same script from the new and old namespace if the lang is the same
|
// okay to load the same script from the new and old namespace if the lang is the same
|
||||||
|
@ -64,7 +64,7 @@ public class ScriptMetaDataTests extends AbstractSerializingTestCase<ScriptMetaD
|
||||||
builder.startObject().field("lang0#id0", "script0")
|
builder.startObject().field("lang0#id0", "script0")
|
||||||
.startObject("id0").field("lang", "lang0").field("source", "script1").endObject().endObject();
|
.startObject("id0").field("lang", "lang0").field("source", "script1").endObject().endObject();
|
||||||
XContentParser parser3 = XContentType.JSON.xContent()
|
XContentParser parser3 = XContentType.JSON.xContent()
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, builder.bytes());
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, builder.bytes().streamInput());
|
||||||
ScriptMetaData.fromXContent(parser3);
|
ScriptMetaData.fromXContent(parser3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -311,7 +311,8 @@ public class RandomSearchRequestGenerator {
|
||||||
jsonBuilder.endArray();
|
jsonBuilder.endArray();
|
||||||
jsonBuilder.endObject();
|
jsonBuilder.endObject();
|
||||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON)
|
XContentParser parser = XContentFactory.xContent(XContentType.JSON)
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, jsonBuilder.bytes());
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
|
||||||
|
jsonBuilder.bytes().streamInput());
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
parser.nextToken();
|
parser.nextToken();
|
||||||
|
|
|
@ -1096,7 +1096,7 @@ public abstract class ESTestCase extends LuceneTestCase {
|
||||||
*/
|
*/
|
||||||
protected final XContentParser createParser(XContentBuilder builder) throws IOException {
|
protected final XContentParser createParser(XContentBuilder builder) throws IOException {
|
||||||
return builder.generator().contentType().xContent()
|
return builder.generator().contentType().xContent()
|
||||||
.createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, builder.bytes());
|
.createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, builder.bytes().streamInput());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1124,7 +1124,7 @@ public abstract class ESTestCase extends LuceneTestCase {
|
||||||
* Create a new {@link XContentParser}.
|
* Create a new {@link XContentParser}.
|
||||||
*/
|
*/
|
||||||
protected final XContentParser createParser(XContent xContent, BytesReference data) throws IOException {
|
protected final XContentParser createParser(XContent xContent, BytesReference data) throws IOException {
|
||||||
return xContent.createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, data);
|
return xContent.createParser(xContentRegistry(), LoggingDeprecationHandler.INSTANCE, data.streamInput());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -837,10 +837,10 @@ public class ElasticsearchAssertions {
|
||||||
Map<String, Object> actualMap = null;
|
Map<String, Object> actualMap = null;
|
||||||
Map<String, Object> expectedMap = null;
|
Map<String, Object> expectedMap = null;
|
||||||
try (XContentParser actualParser = xContentType.xContent()
|
try (XContentParser actualParser = xContentType.xContent()
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, actual)) {
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, actual.streamInput())) {
|
||||||
actualMap = actualParser.map();
|
actualMap = actualParser.map();
|
||||||
try (XContentParser expectedParser = xContentType.xContent()
|
try (XContentParser expectedParser = xContentType.xContent()
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, expected)) {
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, expected.streamInput())) {
|
||||||
expectedMap = expectedParser.map();
|
expectedMap = expectedParser.map();
|
||||||
try {
|
try {
|
||||||
assertMapEquals(expectedMap, actualMap);
|
assertMapEquals(expectedMap, actualMap);
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class ObjectPath {
|
||||||
|
|
||||||
public static ObjectPath createFromXContent(XContent xContent, BytesReference input) throws IOException {
|
public static ObjectPath createFromXContent(XContent xContent, BytesReference input) throws IOException {
|
||||||
try (XContentParser parser = xContent
|
try (XContentParser parser = xContent
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, input)) {
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, input.streamInput())) {
|
||||||
if (parser.nextToken() == XContentParser.Token.START_ARRAY) {
|
if (parser.nextToken() == XContentParser.Token.START_ARRAY) {
|
||||||
return new ObjectPath(parser.listOrderedMap());
|
return new ObjectPath(parser.listOrderedMap());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue