diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/RequestConverters.java b/client/rest-high-level/src/main/java/org/opensearch/client/RequestConverters.java index bdd1023d5edd7..b3144a75d1445 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/RequestConverters.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/RequestConverters.java @@ -79,7 +79,6 @@ import org.opensearch.common.unit.TimeValue; import org.opensearch.common.util.CollectionUtils; import org.opensearch.common.xcontent.DeprecationHandler; -import org.opensearch.common.xcontent.MediaType; import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.ToXContent; import org.opensearch.common.xcontent.XContent; @@ -113,11 +112,6 @@ import java.util.Map; import java.util.StringJoiner; -/** - * Converts OpenSearch writeable requests to an HTTP Request - * - * @opensearch.api - */ final class RequestConverters { static final XContentType REQUEST_BODY_CONTENT_TYPE = XContentType.JSON; @@ -520,7 +514,7 @@ static Request multiSearch(MultiSearchRequest multiSearchRequest) throws IOExcep XContent xContent = REQUEST_BODY_CONTENT_TYPE.xContent(); byte[] source = MultiSearchRequest.writeMultiLineFormat(multiSearchRequest, xContent); request.addParameters(params.asMap()); - request.setEntity(new NByteArrayEntity(source, createContentType(xContent.mediaType()))); + request.setEntity(new NByteArrayEntity(source, createContentType(xContent.type()))); return request; } @@ -555,7 +549,7 @@ static Request multiSearchTemplate(MultiSearchTemplateRequest multiSearchTemplat XContent xContent = REQUEST_BODY_CONTENT_TYPE.xContent(); byte[] source = MultiSearchTemplateRequest.writeMultiLineFormat(multiSearchTemplateRequest, xContent); - request.setEntity(new NByteArrayEntity(source, createContentType(xContent.mediaType()))); + request.setEntity(new NByteArrayEntity(source, createContentType(xContent.type()))); return request; } @@ -873,26 +867,12 @@ static String endpoint(String[] indices, String endpoint, String type) { * * @param xContentType the {@link XContentType} * @return the {@link ContentType} - * - * @deprecated use {@link #createContentType(MediaType)} instead */ - @Deprecated @SuppressForbidden(reason = "Only allowed place to convert a XContentType to a ContentType") public static ContentType createContentType(final XContentType xContentType) { return ContentType.create(xContentType.mediaTypeWithoutParameters(), (Charset) null); } - /** - * Returns a {@link ContentType} from a given {@link XContentType}. - * - * @param mediaType the {@link MediaType} - * @return the {@link ContentType} - */ - @SuppressForbidden(reason = "Only allowed place to convert a XContentType to a ContentType") - public static ContentType createContentType(final MediaType mediaType) { - return ContentType.create(mediaType.mediaTypeWithoutParameters(), (Charset) null); - } - /** * Utility class to help with common parameter names and patterns. Wraps * a {@link Request} and adds the parameters to it directly. diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/indices/CreateIndexRequest.java b/client/rest-high-level/src/main/java/org/opensearch/client/indices/CreateIndexRequest.java index 83e148f098f12..5bf65a6ea1989 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/indices/CreateIndexRequest.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/indices/CreateIndexRequest.java @@ -44,7 +44,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; import org.opensearch.common.xcontent.DeprecationHandler; -import org.opensearch.common.xcontent.MediaType; import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; @@ -65,8 +64,6 @@ /** * A request to create an index. - * - * @opensearch.api */ public class CreateIndexRequest extends TimedRequest implements Validatable, ToXContentObject { static final ParseField MAPPINGS = new ParseField("mappings"); @@ -125,23 +122,12 @@ public CreateIndexRequest settings(Settings settings) { /** * The settings to create the index with (either json or yaml format) - * - * @deprecated use {@link #settings(String source, MediaType mediaType)} instead */ - @Deprecated public CreateIndexRequest settings(String source, XContentType xContentType) { this.settings = Settings.builder().loadFromSource(source, xContentType).build(); return this; } - /** - * The settings to create the index with (either json or yaml format) - */ - public CreateIndexRequest settings(String source, MediaType mediaType) { - this.settings = Settings.builder().loadFromSource(source, mediaType).build(); - return this; - } - /** * Allows to set the settings using a json builder. */ @@ -173,26 +159,11 @@ public XContentType mappingsXContentType() { * * @param source The mapping source * @param xContentType The content type of the source - * - * @deprecated use {@link #mapping(String source, MediaType mediaType)} instead */ - @Deprecated public CreateIndexRequest mapping(String source, XContentType xContentType) { return mapping(new BytesArray(source), xContentType); } - /** - * Adds mapping that will be added when the index gets created. - * - * Note that the definition should *not* be nested under a type name. - * - * @param source The mapping source - * @param mediaType The media type of the source - */ - public CreateIndexRequest mapping(String source, MediaType mediaType) { - return mapping(new BytesArray(source), mediaType); - } - /** * Adds mapping that will be added when the index gets created. * @@ -228,10 +199,7 @@ public CreateIndexRequest mapping(Map source) { * * @param source The mapping source * @param xContentType the content type of the mapping source - * - * @deprecated use {@link #mapping(BytesReference source, MediaType mediaType)} instead */ - @Deprecated public CreateIndexRequest mapping(BytesReference source, XContentType xContentType) { Objects.requireNonNull(xContentType); mappings = source; @@ -239,21 +207,6 @@ public CreateIndexRequest mapping(BytesReference source, XContentType xContentTy return this; } - /** - * Adds mapping that will be added when the index gets created. - * - * Note that the definition should *not* be nested under a type name. - * - * @param source The mapping source - * @param mediaType the content type of the mapping source - */ - public CreateIndexRequest mapping(BytesReference source, MediaType mediaType) { - Objects.requireNonNull(mediaType); - mappings = source; - mappingsXContentType = (XContentType) mediaType; - return this; - } - public Set aliases() { return this.aliases; } @@ -280,10 +233,7 @@ public CreateIndexRequest aliases(XContentBuilder source) { /** * Sets the aliases that will be associated with the index when it gets created - * - * @deprecated use {@link #aliases(String, MediaType)} instead */ - @Deprecated public CreateIndexRequest aliases(String source, XContentType contentType) { return aliases(new BytesArray(source), contentType); } @@ -291,24 +241,7 @@ public CreateIndexRequest aliases(String source, XContentType contentType) { /** * Sets the aliases that will be associated with the index when it gets created */ - public CreateIndexRequest aliases(String source, MediaType mediaType) { - return aliases(new BytesArray(source), mediaType); - } - - /** - * Sets the aliases that will be associated with the index when it gets created - * - * @deprecated use {@link #aliases(BytesReference source, MediaType contentType)} instead - */ - @Deprecated public CreateIndexRequest aliases(BytesReference source, XContentType contentType) { - return aliases(source, (MediaType) contentType); - } - - /** - * Sets the aliases that will be associated with the index when it gets created - */ - public CreateIndexRequest aliases(BytesReference source, MediaType contentType) { // EMPTY is safe here because we never call namedObject try ( XContentParser parser = XContentHelper.createParser( @@ -349,23 +282,11 @@ public CreateIndexRequest aliases(Collection aliases) { * Sets the settings and mappings as a single source. * * Note that the mapping definition should *not* be nested under a type name. - * - * @deprecated use {@link #source(String, MediaType)} instead */ - @Deprecated public CreateIndexRequest source(String source, XContentType xContentType) { return source(new BytesArray(source), xContentType); } - /** - * Sets the settings and mappings as a single source. - * - * Note that the mapping definition should *not* be nested under a type name. - */ - public CreateIndexRequest source(String source, MediaType mediaType) { - return source(new BytesArray(source), mediaType); - } - /** * Sets the settings and mappings as a single source. * @@ -379,27 +300,13 @@ public CreateIndexRequest source(XContentBuilder source) { * Sets the settings and mappings as a single source. * * Note that the mapping definition should *not* be nested under a type name. - * - * @deprecated use {@link #source(BytesReference, MediaType)} instead */ - @Deprecated public CreateIndexRequest source(BytesReference source, XContentType xContentType) { Objects.requireNonNull(xContentType); source(XContentHelper.convertToMap(source, false, xContentType).v2()); return this; } - /** - * Sets the settings and mappings as a single source. - * - * Note that the mapping definition should *not* be nested under a type name. - */ - public CreateIndexRequest source(BytesReference source, MediaType mediaType) { - Objects.requireNonNull(mediaType); - source(XContentHelper.convertToMap(source, false, mediaType).v2()); - return this; - } - /** * Sets the settings and mappings as a single source. * diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutIndexTemplateRequest.java b/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutIndexTemplateRequest.java index 1f28ad10b63bf..5f43ec7f1d0fe 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutIndexTemplateRequest.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutIndexTemplateRequest.java @@ -43,7 +43,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; import org.opensearch.common.xcontent.DeprecationHandler; -import org.opensearch.common.xcontent.MediaType; import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.ToXContentFragment; import org.opensearch.common.xcontent.XContentBuilder; @@ -269,10 +268,9 @@ private PutIndexTemplateRequest internalMapping(Map source) { try { XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); builder.map(source); - MediaType mediaType = builder.contentType(); - Objects.requireNonNull(mediaType); + Objects.requireNonNull(builder.contentType()); try { - mappings = new BytesArray(XContentHelper.convertToJson(BytesReference.bytes(builder), false, false, mediaType)); + mappings = new BytesArray(XContentHelper.convertToJson(BytesReference.bytes(builder), false, false, builder.contentType())); return this; } catch (IOException e) { throw new UncheckedIOException("failed to convert source to json", e); @@ -344,10 +342,7 @@ public PutIndexTemplateRequest source(Map templateSource) { /** * The template source definition. - * - * @deprecated use {@link #source(String, MediaType)} instead */ - @Deprecated public PutIndexTemplateRequest source(String templateSource, XContentType xContentType) { return source(XContentHelper.convertToMap(xContentType.xContent(), templateSource, true)); } @@ -355,16 +350,6 @@ public PutIndexTemplateRequest source(String templateSource, XContentType xConte /** * The template source definition. */ - public PutIndexTemplateRequest source(String templateSource, MediaType mediaType) { - return source(XContentHelper.convertToMap(mediaType.xContent(), templateSource, true)); - } - - /** - * The template source definition. - * - * @deprecated use {@link #source(byte[], MediaType)} instead - */ - @Deprecated public PutIndexTemplateRequest source(byte[] source, XContentType xContentType) { return source(source, 0, source.length, xContentType); } @@ -372,16 +357,6 @@ public PutIndexTemplateRequest source(byte[] source, XContentType xContentType) /** * The template source definition. */ - public PutIndexTemplateRequest source(byte[] source, MediaType mediaType) { - return source(source, 0, source.length, mediaType); - } - - /** - * The template source definition. - * - * @deprecated use {@link #source(byte[], int, int, MediaType)} instead - */ - @Deprecated public PutIndexTemplateRequest source(byte[] source, int offset, int length, XContentType xContentType) { return source(new BytesArray(source, offset, length), xContentType); } @@ -389,27 +364,10 @@ public PutIndexTemplateRequest source(byte[] source, int offset, int length, XCo /** * The template source definition. */ - public PutIndexTemplateRequest source(byte[] source, int offset, int length, MediaType mediaType) { - return source(new BytesArray(source, offset, length), mediaType); - } - - /** - * The template source definition. - * - * @deprecated use {@link #source(BytesReference, MediaType)} instead - */ - @Deprecated public PutIndexTemplateRequest source(BytesReference source, XContentType xContentType) { return source(XContentHelper.convertToMap(source, true, xContentType).v2()); } - /** - * The template source definition. - */ - public PutIndexTemplateRequest source(BytesReference source, MediaType mediaType) { - return source(XContentHelper.convertToMap(source, true, mediaType).v2()); - } - public Set aliases() { return this.aliases; } diff --git a/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutMappingRequest.java b/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutMappingRequest.java index fc3423ee812fa..c8d5e4c95782a 100644 --- a/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutMappingRequest.java +++ b/client/rest-high-level/src/main/java/org/opensearch/client/indices/PutMappingRequest.java @@ -38,7 +38,6 @@ import org.opensearch.client.TimedRequest; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.xcontent.MediaType; import org.opensearch.common.xcontent.ToXContent; import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; @@ -53,8 +52,6 @@ * Put a mapping definition into one or more indices. If an index already contains mappings, * the new mappings will be merged with the existing one. If there are elements that cannot * be merged, the request will be rejected. - * - * @opensearch.api */ public class PutMappingRequest extends TimedRequest implements IndicesRequest, ToXContentObject { @@ -62,7 +59,7 @@ public class PutMappingRequest extends TimedRequest implements IndicesRequest, T private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, false, true, true); private BytesReference source; - private MediaType mediaType; + private XContentType xContentType; /** * Constructs a new put mapping request against one or more indices. If no indices @@ -99,19 +96,9 @@ public BytesReference source() { /** * The {@link XContentType} of the mapping source. - * - * @deprecated use {@link #mediaType()} instead */ - @Deprecated public XContentType xContentType() { - return (XContentType) mediaType; - } - - /** - * The {@link XContentType} of the mapping source. - */ - public MediaType mediaType() { - return mediaType; + return xContentType; } /** @@ -133,24 +120,10 @@ public PutMappingRequest source(Map mappingSource) { * The mapping source definition. * * Note that the definition should *not* be nested under a type name. - * - * @deprecated use {@link #source(String, MediaType)} instead */ - @Deprecated public PutMappingRequest source(String mappingSource, XContentType xContentType) { this.source = new BytesArray(mappingSource); - this.mediaType = xContentType; - return this; - } - - /** - * The mapping source definition. - * - * Note that the definition should *not* be nested under a type name. - */ - public PutMappingRequest source(String mappingSource, MediaType mediaType) { - this.source = new BytesArray(mappingSource); - this.mediaType = mediaType; + this.xContentType = xContentType; return this; } @@ -161,7 +134,7 @@ public PutMappingRequest source(String mappingSource, MediaType mediaType) { */ public PutMappingRequest source(XContentBuilder builder) { this.source = BytesReference.bytes(builder); - this.mediaType = builder.contentType(); + this.xContentType = builder.contentType(); return this; } @@ -169,24 +142,10 @@ public PutMappingRequest source(XContentBuilder builder) { * The mapping source definition. * * Note that the definition should *not* be nested under a type name. - * - * @deprecated use {@link #source(BytesReference, MediaType)} instead */ - @Deprecated public PutMappingRequest source(BytesReference source, XContentType xContentType) { this.source = source; - this.mediaType = xContentType; - return this; - } - - /** - * The mapping source definition. - * - * Note that the definition should *not* be nested under a type name. - */ - public PutMappingRequest source(BytesReference source, MediaType mediaType) { - this.source = source; - this.mediaType = mediaType; + this.xContentType = xContentType; return this; } @@ -194,7 +153,7 @@ public PutMappingRequest source(BytesReference source, MediaType mediaType) { public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { if (source != null) { try (InputStream stream = source.streamInput()) { - builder.rawValue(stream, mediaType); + builder.rawValue(stream, xContentType); } } else { builder.startObject().endObject(); diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/indices/PutMappingRequestTests.java b/client/rest-high-level/src/test/java/org/opensearch/client/indices/PutMappingRequestTests.java index 877d3cd77687d..6065be82ddb22 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/indices/PutMappingRequestTests.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/indices/PutMappingRequestTests.java @@ -74,8 +74,8 @@ protected boolean supportsUnknownFields() { protected void assertEqualInstances(PutMappingRequest expected, PutMappingRequest actual) { if (actual.source() != null) { try ( - XContentParser expectedJson = createParser(expected.mediaType().xContent(), expected.source()); - XContentParser actualJson = createParser(actual.mediaType().xContent(), actual.source()) + XContentParser expectedJson = createParser(expected.xContentType().xContent(), expected.source()); + XContentParser actualJson = createParser(actual.xContentType().xContent(), actual.source()) ) { assertEquals(expectedJson.mapOrdered(), actualJson.mapOrdered()); } catch (IOException e) { diff --git a/libs/x-content/src/main/java/org/opensearch/common/xcontent/MediaType.java b/libs/x-content/src/main/java/org/opensearch/common/xcontent/MediaType.java index f38457b5ffd4c..3fad89152cc45 100644 --- a/libs/x-content/src/main/java/org/opensearch/common/xcontent/MediaType.java +++ b/libs/x-content/src/main/java/org/opensearch/common/xcontent/MediaType.java @@ -63,11 +63,5 @@ default String typeWithSubtype() { return type() + "/" + subtype(); } - default String mediaType() { - return mediaTypeWithoutParameters(); - } - - String mediaTypeWithoutParameters(); - XContent xContent(); } diff --git a/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContent.java b/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContent.java index b9fff70ca9058..c8a8aa1a0cfa3 100644 --- a/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContent.java +++ b/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContent.java @@ -46,7 +46,7 @@ public interface XContent { /** * The type this content handles and produces. */ - MediaType mediaType(); + XContentType type(); byte streamSeparator(); diff --git a/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentBuilder.java b/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentBuilder.java index 7f4878d6336d0..7086cdb0fda83 100644 --- a/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentBuilder.java +++ b/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentBuilder.java @@ -995,42 +995,20 @@ public XContentBuilder rawField(String name, InputStream value) throws IOExcepti /** * Writes a raw field with the value taken from the bytes in the stream - * - * @deprecated use {@link #rawField(String, InputStream, MediaType)} instead */ - @Deprecated public XContentBuilder rawField(String name, InputStream value, XContentType contentType) throws IOException { generator.writeRawField(name, value, contentType); return this; } - /** - * Writes a raw field with the value taken from the bytes in the stream - */ - public XContentBuilder rawField(String name, InputStream value, MediaType mediaType) throws IOException { - generator.writeRawField(name, value, mediaType); - return this; - } - /** * Writes a value with the source coming directly from the bytes in the stream - * - * @deprecated use {@link #rawValue(InputStream, MediaType)} instead */ - @Deprecated public XContentBuilder rawValue(InputStream stream, XContentType contentType) throws IOException { generator.writeRawValue(stream, contentType); return this; } - /** - * Writes a value with the source coming directly from the bytes in the stream - */ - public XContentBuilder rawValue(InputStream stream, MediaType contentType) throws IOException { - generator.writeRawValue(stream, contentType); - return this; - } - public XContentBuilder copyCurrentStructure(XContentParser parser) throws IOException { generator.copyCurrentStructure(parser); return this; diff --git a/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentFactory.java b/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentFactory.java index 676c9618ba9f5..63b1ef6af752d 100644 --- a/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentFactory.java +++ b/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentFactory.java @@ -141,7 +141,7 @@ public static XContentBuilder contentBuilder(XContentType type) throws IOExcepti /** * Returns the {@link org.opensearch.common.xcontent.XContent} for the provided content type. */ - public static XContent xContent(MediaType type) { + public static XContent xContent(XContentType type) { if (type == null) { throw new IllegalArgumentException("Cannot get xcontent for unknown type"); } diff --git a/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentGenerator.java b/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentGenerator.java index c13a3c7fd283c..b0dacb3826be3 100644 --- a/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentGenerator.java +++ b/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentGenerator.java @@ -116,28 +116,14 @@ public interface XContentGenerator extends Closeable, Flushable { /** * Writes a raw field with the value taken from the bytes in the stream - * @deprecated use {@link #writeRawField(String, InputStream, MediaType)} instead */ - @Deprecated void writeRawField(String name, InputStream value, XContentType xContentType) throws IOException; - /** - * Writes a raw field with the value taken from the bytes in the stream - */ - void writeRawField(String name, InputStream value, MediaType mediaType) throws IOException; - /** * Writes a raw value taken from the bytes in the stream - * @deprecated use {@link #writeRawValue(InputStream, MediaType)} instead */ - @Deprecated void writeRawValue(InputStream value, XContentType xContentType) throws IOException; - /** - * Writes a raw value taken from the bytes in the stream - */ - void writeRawValue(InputStream value, MediaType mediaType) throws IOException; - void copyCurrentStructure(XContentParser parser) throws IOException; default void copyCurrentEvent(XContentParser parser) throws IOException { diff --git a/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentType.java b/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentType.java index d93df5b05be4a..32283698beaf8 100644 --- a/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentType.java +++ b/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentType.java @@ -186,6 +186,12 @@ public int index() { return index; } + public String mediaType() { + return mediaTypeWithoutParameters(); + } + + public abstract String mediaTypeWithoutParameters(); + @Override public String type() { return "application"; diff --git a/libs/x-content/src/main/java/org/opensearch/common/xcontent/cbor/CborXContent.java b/libs/x-content/src/main/java/org/opensearch/common/xcontent/cbor/CborXContent.java index 5b1a064ef5ee1..674b6566bdec0 100644 --- a/libs/x-content/src/main/java/org/opensearch/common/xcontent/cbor/CborXContent.java +++ b/libs/x-content/src/main/java/org/opensearch/common/xcontent/cbor/CborXContent.java @@ -37,7 +37,6 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.dataformat.cbor.CBORFactory; import org.opensearch.common.xcontent.DeprecationHandler; -import org.opensearch.common.xcontent.MediaType; import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.XContent; import org.opensearch.common.xcontent.XContentBuilder; @@ -76,7 +75,7 @@ public static XContentBuilder contentBuilder() throws IOException { private CborXContent() {} @Override - public MediaType mediaType() { + public XContentType type() { return XContentType.CBOR; } diff --git a/libs/x-content/src/main/java/org/opensearch/common/xcontent/json/JsonXContent.java b/libs/x-content/src/main/java/org/opensearch/common/xcontent/json/JsonXContent.java index 6e084f6a8e58c..a7872904b1126 100644 --- a/libs/x-content/src/main/java/org/opensearch/common/xcontent/json/JsonXContent.java +++ b/libs/x-content/src/main/java/org/opensearch/common/xcontent/json/JsonXContent.java @@ -37,7 +37,6 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import org.opensearch.common.xcontent.DeprecationHandler; -import org.opensearch.common.xcontent.MediaType; import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.XContent; import org.opensearch.common.xcontent.XContentBuilder; @@ -78,7 +77,7 @@ public static XContentBuilder contentBuilder() throws IOException { private JsonXContent() {} @Override - public MediaType mediaType() { + public XContentType type() { return XContentType.JSON; } diff --git a/libs/x-content/src/main/java/org/opensearch/common/xcontent/json/JsonXContentGenerator.java b/libs/x-content/src/main/java/org/opensearch/common/xcontent/json/JsonXContentGenerator.java index 88853f5bc1e61..b972f52c57201 100644 --- a/libs/x-content/src/main/java/org/opensearch/common/xcontent/json/JsonXContentGenerator.java +++ b/libs/x-content/src/main/java/org/opensearch/common/xcontent/json/JsonXContentGenerator.java @@ -42,7 +42,6 @@ import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import com.fasterxml.jackson.core.util.JsonGeneratorDelegate; import org.opensearch.common.xcontent.DeprecationHandler; -import org.opensearch.common.xcontent.MediaType; import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.XContent; import org.opensearch.common.xcontent.XContentFactory; @@ -346,11 +345,6 @@ public void writeRawField(String name, InputStream content) throws IOException { writeRawField(name, content, contentType); } - /** - * Writes a raw field with the value taken from the bytes in the stream - * @deprecated use {@link #writeRawField(String, InputStream, MediaType)} instead - */ - @Deprecated @Override public void writeRawField(String name, InputStream content, XContentType contentType) throws IOException { if (mayWriteRawData(contentType) == false) { @@ -374,38 +368,6 @@ public void writeRawField(String name, InputStream content, XContentType content } } - /** - * Writes a raw field with the value taken from the bytes in the stream - */ - @Override - public void writeRawField(String name, InputStream content, MediaType mediaType) throws IOException { - if (mayWriteRawData(mediaType) == false) { - // EMPTY is safe here because we never call namedObject when writing raw data - try ( - XContentParser parser = XContentFactory.xContent(mediaType) - // It's okay to pass the throwing deprecation handler - // because we should not be writing raw fields when - // generating JSON - .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, content) - ) { - parser.nextToken(); - writeFieldName(name); - copyCurrentStructure(parser); - } - } else { - writeStartRaw(name); - flush(); - Streams.copy(content, os); - writeEndRaw(); - } - } - - /** - * Writes the raw value to the stream - * - * @deprecated use {@link #writeRawValue(InputStream, MediaType)} instead - */ - @Deprecated @Override public void writeRawValue(InputStream stream, XContentType xContentType) throws IOException { if (mayWriteRawData(xContentType) == false) { @@ -421,30 +383,6 @@ public void writeRawValue(InputStream stream, XContentType xContentType) throws } } - /** - * Writes the raw value to the stream - */ - @Override - public void writeRawValue(InputStream stream, MediaType mediaType) throws IOException { - if (mayWriteRawData(mediaType) == false) { - copyRawValue(stream, mediaType.xContent()); - } else { - if (generator.getOutputContext().getCurrentName() != null) { - // If we've just started a field we'll need to add the separator - generator.writeRaw(':'); - } - flush(); - Streams.copy(stream, os, false); - writeEndRaw(); - } - } - - /** - * possibly copy the whole structure to correctly filter - * - * @deprecated use {@link #mayWriteRawData(MediaType)} instead - */ - @Deprecated private boolean mayWriteRawData(XContentType contentType) { // When the current generator is filtered (ie filter != null) // or the content is in a different format than the current generator, @@ -453,17 +391,6 @@ private boolean mayWriteRawData(XContentType contentType) { return supportsRawWrites() && isFiltered() == false && contentType == contentType() && prettyPrint == false; } - /** - * possibly copy the whole structure to correctly filter - */ - private boolean mayWriteRawData(MediaType contentType) { - // When the current generator is filtered (ie filter != null) - // or the content is in a different format than the current generator, - // we need to copy the whole structure so that it will be correctly - // filtered or converted - return supportsRawWrites() && isFiltered() == false && contentType == contentType() && prettyPrint == false; - } - /** Whether this generator supports writing raw data directly */ protected boolean supportsRawWrites() { return true; diff --git a/libs/x-content/src/main/java/org/opensearch/common/xcontent/smile/SmileXContent.java b/libs/x-content/src/main/java/org/opensearch/common/xcontent/smile/SmileXContent.java index 541c81eb1a364..82925c5f84f9c 100644 --- a/libs/x-content/src/main/java/org/opensearch/common/xcontent/smile/SmileXContent.java +++ b/libs/x-content/src/main/java/org/opensearch/common/xcontent/smile/SmileXContent.java @@ -38,7 +38,6 @@ import com.fasterxml.jackson.dataformat.smile.SmileFactory; import com.fasterxml.jackson.dataformat.smile.SmileGenerator; import org.opensearch.common.xcontent.DeprecationHandler; -import org.opensearch.common.xcontent.MediaType; import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.XContent; import org.opensearch.common.xcontent.XContentBuilder; @@ -78,7 +77,7 @@ public static XContentBuilder contentBuilder() throws IOException { private SmileXContent() {} @Override - public MediaType mediaType() { + public XContentType type() { return XContentType.SMILE; } diff --git a/libs/x-content/src/main/java/org/opensearch/common/xcontent/yaml/YamlXContent.java b/libs/x-content/src/main/java/org/opensearch/common/xcontent/yaml/YamlXContent.java index 0821ff09522c6..8ebdeca71c0ce 100644 --- a/libs/x-content/src/main/java/org/opensearch/common/xcontent/yaml/YamlXContent.java +++ b/libs/x-content/src/main/java/org/opensearch/common/xcontent/yaml/YamlXContent.java @@ -36,7 +36,6 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import org.opensearch.common.xcontent.DeprecationHandler; -import org.opensearch.common.xcontent.MediaType; import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.XContent; import org.opensearch.common.xcontent.XContentBuilder; @@ -71,7 +70,7 @@ public static XContentBuilder contentBuilder() throws IOException { private YamlXContent() {} @Override - public MediaType mediaType() { + public XContentType type() { return XContentType.YAML; } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java b/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java index 33cf7fcd5e779..95837d82be7ac 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java @@ -52,7 +52,6 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.xcontent.DeprecationHandler; import org.opensearch.common.xcontent.LoggingDeprecationHandler; -import org.opensearch.common.xcontent.MediaType; import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; @@ -213,23 +212,12 @@ public CreateIndexRequest settings(Settings settings) { /** * The settings to create the index with (either json or yaml format) - * - * @deprecated use {@link #settings(String source, MediaType mediaType)} instead */ - @Deprecated public CreateIndexRequest settings(String source, XContentType xContentType) { this.settings = Settings.builder().loadFromSource(source, xContentType).build(); return this; } - /** - * The settings to create the index with (either json or yaml format) - */ - public CreateIndexRequest settings(String source, MediaType mediaType) { - this.settings = Settings.builder().loadFromSource(source, mediaType).build(); - return this; - } - /** * Allows to set the settings using a json builder. */ @@ -264,55 +252,23 @@ public CreateIndexRequest mapping(String mapping) { * * @param source The mapping source * @param xContentType The content type of the source - * - * @deprecated use {@link #mapping(String source, MediaType mediaType)} instead */ - @Deprecated public CreateIndexRequest mapping(String source, XContentType xContentType) { return mapping(new BytesArray(source), xContentType); } - /** - * Adds mapping that will be added when the index gets created. - * - * Note that the definition should *not* be nested under a type name. - * - * @param source The mapping source - * @param mediaType The media type of the source - */ - public CreateIndexRequest mapping(String source, MediaType mediaType) { - return mapping(new BytesArray(source), mediaType); - } - /** * Adds mapping that will be added when the index gets created. * * @param source The mapping source * @param xContentType the content type of the mapping source - * - * @deprecated use {@link #mapping(BytesReference source, MediaType mediaType)} instead */ - @Deprecated private CreateIndexRequest mapping(BytesReference source, XContentType xContentType) { Objects.requireNonNull(xContentType); Map mappingAsMap = XContentHelper.convertToMap(source, false, xContentType).v2(); return mapping(MapperService.SINGLE_MAPPING_NAME, mappingAsMap); } - /** - * Adds mapping that will be added when the index gets created. - * - * Note that the definition should *not* be nested under a type name. - * - * @param source The mapping source - * @param mediaType The media type of the source - */ - public CreateIndexRequest mapping(BytesReference source, MediaType mediaType) { - Objects.requireNonNull(mediaType); - Map mappingAsMap = XContentHelper.convertToMap(source, false, mediaType).v2(); - return mapping(MapperService.SINGLE_MAPPING_NAME, mappingAsMap); - } - /** * Adds mapping that will be added when the index gets created. * @@ -427,23 +383,11 @@ public CreateIndexRequest alias(Alias alias) { /** * Sets the settings and mappings as a single source. - * - * @deprecated use {@link #source(String, MediaType)} instead */ - @Deprecated public CreateIndexRequest source(String source, XContentType xContentType) { return source(new BytesArray(source), xContentType); } - /** - * Sets the settings and mappings as a single source. - * - * Note that the mapping definition should *not* be nested under a type name. - */ - public CreateIndexRequest source(String source, MediaType mediaType) { - return source(new BytesArray(source), mediaType); - } - /** * Sets the settings and mappings as a single source. */ @@ -453,29 +397,14 @@ public CreateIndexRequest source(XContentBuilder source) { /** * Sets the settings and mappings as a single source. - * - * @deprecated use {@link #source(byte[], MediaType mediaType)} instead */ - @Deprecated public CreateIndexRequest source(byte[] source, XContentType xContentType) { return source(source, 0, source.length, xContentType); } /** * Sets the settings and mappings as a single source. - * - * Note that the mapping definition should *not* be nested under a type name. - */ - public CreateIndexRequest source(byte[] source, MediaType mediaType) { - return source(source, 0, source.length, mediaType); - } - - /** - * Sets the settings and mappings as a single source. - * - * @deprecated use {@link #source(byte[], int, int, MediaType)} instead */ - @Deprecated public CreateIndexRequest source(byte[] source, int offset, int length, XContentType xContentType) { return source(new BytesArray(source, offset, length), xContentType); } @@ -483,31 +412,12 @@ public CreateIndexRequest source(byte[] source, int offset, int length, XContent /** * Sets the settings and mappings as a single source. */ - public CreateIndexRequest source(byte[] source, int offset, int length, MediaType mediaType) { - return source(new BytesArray(source, offset, length), mediaType); - } - - /** - * Sets the settings and mappings as a single source. - * - * @deprecated use {@link #source(BytesReference, MediaType)} instead - */ - @Deprecated public CreateIndexRequest source(BytesReference source, XContentType xContentType) { Objects.requireNonNull(xContentType); source(XContentHelper.convertToMap(source, false, xContentType).v2(), LoggingDeprecationHandler.INSTANCE); return this; } - /** - * Sets the settings and mappings as a single source. - */ - public CreateIndexRequest source(BytesReference source, MediaType mediaType) { - Objects.requireNonNull(mediaType); - source(XContentHelper.convertToMap(source, false, mediaType).v2(), LoggingDeprecationHandler.INSTANCE); - return this; - } - /** * Sets the settings and mappings as a single source. */ diff --git a/server/src/main/java/org/opensearch/action/ingest/PutPipelineRequest.java b/server/src/main/java/org/opensearch/action/ingest/PutPipelineRequest.java index 63a9c4266d334..d5fbaa46810f7 100644 --- a/server/src/main/java/org/opensearch/action/ingest/PutPipelineRequest.java +++ b/server/src/main/java/org/opensearch/action/ingest/PutPipelineRequest.java @@ -37,7 +37,6 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; -import org.opensearch.common.xcontent.MediaType; import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; @@ -58,28 +57,13 @@ public class PutPipelineRequest extends AcknowledgedRequest /** * Create a new pipeline request with the id and source along with the content type of the source - * - * @deprecated use {@link #PutPipelineRequest(String, BytesReference, MediaType)} instead */ - @Deprecated public PutPipelineRequest(String id, BytesReference source, XContentType xContentType) { this.id = Objects.requireNonNull(id); this.source = Objects.requireNonNull(source); this.xContentType = Objects.requireNonNull(xContentType); } - /** - * Create a new pipeline request with the id and source along with the content type of the source - */ - public PutPipelineRequest(String id, BytesReference source, MediaType mediaType) { - this.id = Objects.requireNonNull(id); - this.source = Objects.requireNonNull(source); - if (mediaType instanceof XContentType == false) { - throw new IllegalArgumentException("PutPipelineRequest found unsupported media type [" + mediaType.getClass().getName() + "]"); - } - this.xContentType = (XContentType) Objects.requireNonNull(mediaType); - } - public PutPipelineRequest(StreamInput in) throws IOException { super(in); id = in.readString(); diff --git a/server/src/main/java/org/opensearch/common/settings/Settings.java b/server/src/main/java/org/opensearch/common/settings/Settings.java index 3e5f30f82512a..9e19134f3cfa0 100644 --- a/server/src/main/java/org/opensearch/common/settings/Settings.java +++ b/server/src/main/java/org/opensearch/common/settings/Settings.java @@ -49,7 +49,6 @@ import org.opensearch.common.unit.TimeValue; import org.opensearch.common.xcontent.DeprecationHandler; import org.opensearch.common.xcontent.LoggingDeprecationHandler; -import org.opensearch.common.xcontent.MediaType; import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.ToXContentFragment; import org.opensearch.common.xcontent.XContentBuilder; @@ -1091,7 +1090,7 @@ public Builder loadFromMap(Map map) { /** * Loads settings from the actual string content that represents them using {@link #fromXContent(XContentParser)} */ - public Builder loadFromSource(String source, MediaType xContentType) { + public Builder loadFromSource(String source, XContentType xContentType) { try ( XContentParser parser = XContentFactory.xContent(xContentType) .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source) diff --git a/server/src/main/java/org/opensearch/common/xcontent/XContentHelper.java b/server/src/main/java/org/opensearch/common/xcontent/XContentHelper.java index bfc85ce82da74..e4b35d6ee2753 100644 --- a/server/src/main/java/org/opensearch/common/xcontent/XContentHelper.java +++ b/server/src/main/java/org/opensearch/common/xcontent/XContentHelper.java @@ -61,7 +61,7 @@ public class XContentHelper { /** * Creates a parser based on the bytes provided - * @deprecated use {@link #createParser(NamedXContentRegistry, DeprecationHandler, BytesReference, MediaType)} + * @deprecated use {@link #createParser(NamedXContentRegistry, DeprecationHandler, BytesReference, XContentType)} * to avoid content type auto-detection */ @Deprecated @@ -96,9 +96,9 @@ public static XContentParser createParser( NamedXContentRegistry xContentRegistry, DeprecationHandler deprecationHandler, BytesReference bytes, - MediaType mediaType + XContentType xContentType ) throws IOException { - Objects.requireNonNull(mediaType); + Objects.requireNonNull(xContentType); Compressor compressor = CompressorFactory.compressor(bytes); if (compressor != null) { InputStream compressedInput = null; @@ -107,7 +107,7 @@ public static XContentParser createParser( if (compressedInput.markSupported() == false) { compressedInput = new BufferedInputStream(compressedInput); } - return XContentFactory.xContent(mediaType).createParser(xContentRegistry, deprecationHandler, compressedInput); + return XContentFactory.xContent(xContentType).createParser(xContentRegistry, deprecationHandler, compressedInput); } catch (Exception e) { if (compressedInput != null) compressedInput.close(); throw e; @@ -115,16 +115,16 @@ public static XContentParser createParser( } else { if (bytes instanceof BytesArray) { final BytesArray array = (BytesArray) bytes; - return mediaType.xContent() + return xContentType.xContent() .createParser(xContentRegistry, deprecationHandler, array.array(), array.offset(), array.length()); } - return mediaType.xContent().createParser(xContentRegistry, deprecationHandler, bytes.streamInput()); + return xContentType.xContent().createParser(xContentRegistry, deprecationHandler, bytes.streamInput()); } } /** * Converts the given bytes into a map that is optionally ordered. - * @deprecated this method relies on auto-detection of content type. Use {@link #convertToMap(BytesReference, boolean, MediaType)} + * @deprecated this method relies on auto-detection of content type. Use {@link #convertToMap(BytesReference, boolean, XContentType)} * instead with the proper {@link XContentType} */ @Deprecated @@ -135,29 +135,11 @@ public static Tuple> convertToMap(BytesReferen /** * Converts the given bytes into a map that is optionally ordered. The provided {@link XContentType} must be non-null. - * - * @deprecated use {@link #convertToMap(BytesReference, boolean, MediaType)} instead */ - @Deprecated - public static Tuple> convertToMap(BytesReference bytes, boolean ordered, XContentType xContentType) { - if (Objects.isNull(xContentType) == false && xContentType instanceof XContentType == false) { - throw new IllegalArgumentException( - "XContentHelper.convertToMap does not support media type [" + xContentType.getClass().getName() + "]" - ); - } - return (Tuple>) convertToMap(bytes, ordered, (MediaType) xContentType); - } - - /** - * Converts the given bytes into a map that is optionally ordered. The provided {@link XContentType} must be non-null. - */ - public static Tuple> convertToMap( - BytesReference bytes, - boolean ordered, - MediaType xContentType - ) throws OpenSearchParseException { + public static Tuple> convertToMap(BytesReference bytes, boolean ordered, XContentType xContentType) + throws OpenSearchParseException { try { - final MediaType contentType; + final XContentType contentType; InputStream input; Compressor compressor = CompressorFactory.compressor(bytes); if (compressor != null) { @@ -261,7 +243,7 @@ public static String convertToJson(BytesReference bytes, boolean reformatJson, b return convertToJson(bytes, reformatJson, prettyPrint, XContentFactory.xContentType(bytes.toBytesRef().bytes)); } - public static String convertToJson(BytesReference bytes, boolean reformatJson, MediaType xContentType) throws IOException { + public static String convertToJson(BytesReference bytes, boolean reformatJson, XContentType xContentType) throws IOException { return convertToJson(bytes, reformatJson, false, xContentType); } @@ -278,24 +260,10 @@ public static String stripWhitespace(String json) throws IOException { return convertToJson(new BytesArray(json), true, XContentType.JSON); } - /** - * Converts the XContentType to a json string - * - * @deprecated use {@link #convertToJson(BytesReference, boolean, boolean, MediaType)} instead - */ - @Deprecated public static String convertToJson(BytesReference bytes, boolean reformatJson, boolean prettyPrint, XContentType xContentType) throws IOException { - return convertToJson(bytes, reformatJson, prettyPrint, (MediaType) xContentType); - } - - /** - * Converts the given {@link MediaType} to a json string - */ - public static String convertToJson(BytesReference bytes, boolean reformatJson, boolean prettyPrint, MediaType mediaType) - throws IOException { - Objects.requireNonNull(mediaType); - if (mediaType == XContentType.JSON && !reformatJson) { + Objects.requireNonNull(xContentType); + if (xContentType == XContentType.JSON && !reformatJson) { return bytes.utf8ToString(); } @@ -303,7 +271,7 @@ public static String convertToJson(BytesReference bytes, boolean reformatJson, b if (bytes instanceof BytesArray) { final BytesArray array = (BytesArray) bytes; try ( - XContentParser parser = XContentFactory.xContent(mediaType) + XContentParser parser = XContentFactory.xContent(xContentType) .createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, @@ -317,7 +285,7 @@ public static String convertToJson(BytesReference bytes, boolean reformatJson, b } else { try ( InputStream stream = bytes.streamInput(); - XContentParser parser = XContentFactory.xContent(mediaType) + XContentParser parser = XContentFactory.xContent(xContentType) .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, stream) ) { return toJsonString(prettyPrint, parser); @@ -497,10 +465,7 @@ public static BytesReference toXContent(ToXContent toXContent, XContentType xCon * Returns the bytes that represent the XContent output of the provided {@link ToXContent} object, using the provided * {@link XContentType}. Wraps the output into a new anonymous object according to the value returned * by the {@link ToXContent#isFragment()} method returns. - * - * @deprecated use {@link #toXContent(ToXContent, MediaType, Params, boolean)} instead */ - @Deprecated public static BytesReference toXContent(ToXContent toXContent, XContentType xContentType, Params params, boolean humanReadable) throws IOException { try (XContentBuilder builder = XContentBuilder.builder(xContentType.xContent())) { @@ -516,26 +481,6 @@ public static BytesReference toXContent(ToXContent toXContent, XContentType xCon } } - /** - * Returns the bytes that represent the XContent output of the provided {@link ToXContent} object, using the provided - * {@link XContentType}. Wraps the output into a new anonymous object according to the value returned - * by the {@link ToXContent#isFragment()} method returns. - */ - public static BytesReference toXContent(ToXContent toXContent, MediaType mediaType, Params params, boolean humanReadable) - throws IOException { - try (XContentBuilder builder = XContentBuilder.builder(mediaType.xContent())) { - builder.humanReadable(humanReadable); - if (toXContent.isFragment()) { - builder.startObject(); - } - toXContent.toXContent(builder, params); - if (toXContent.isFragment()) { - builder.endObject(); - } - return BytesReference.bytes(builder); - } - } - /** * Guesses the content type based on the provided bytes. * diff --git a/server/src/main/java/org/opensearch/index/reindex/ReindexRequest.java b/server/src/main/java/org/opensearch/index/reindex/ReindexRequest.java index f27e289ba13b5..b444757b85951 100644 --- a/server/src/main/java/org/opensearch/index/reindex/ReindexRequest.java +++ b/server/src/main/java/org/opensearch/index/reindex/ReindexRequest.java @@ -307,7 +307,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.startObject("source"); if (remoteInfo != null) { builder.field("remote", remoteInfo); - builder.rawField("query", remoteInfo.getQuery().streamInput(), RemoteInfo.QUERY_CONTENT_TYPE.mediaType()); + builder.rawField("query", remoteInfo.getQuery().streamInput(), RemoteInfo.QUERY_CONTENT_TYPE.type()); } builder.array("index", getSearchRequest().indices()); getSearchRequest().source().innerToXContent(builder, params); diff --git a/server/src/test/java/org/opensearch/OpenSearchExceptionTests.java b/server/src/test/java/org/opensearch/OpenSearchExceptionTests.java index b3a6fc93ea601..6e328ccef517a 100644 --- a/server/src/test/java/org/opensearch/OpenSearchExceptionTests.java +++ b/server/src/test/java/org/opensearch/OpenSearchExceptionTests.java @@ -742,7 +742,7 @@ public void testThrowableToAndFromXContent() throws IOException { BytesReference throwableBytes = toShuffledXContent((builder, params) -> { OpenSearchException.generateThrowableXContent(builder, params, throwable); return builder; - }, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean()); + }, xContent.type(), ToXContent.EMPTY_PARAMS, randomBoolean()); OpenSearchException parsedException; try (XContentParser parser = createParser(xContent, throwableBytes)) { @@ -774,7 +774,7 @@ public void testUnknownFailureToAndFromXContent() throws IOException { // Prints a null failure using generateFailureXContent() OpenSearchException.generateFailureXContent(builder, params, null, randomBoolean()); return builder; - }, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean()); + }, xContent.type(), ToXContent.EMPTY_PARAMS, randomBoolean()); OpenSearchException parsedFailure; try (XContentParser parser = createParser(xContent, failureBytes)) { @@ -798,7 +798,7 @@ public void testFailureToAndFromXContentWithNoDetails() throws IOException { BytesReference failureBytes = toShuffledXContent((builder, params) -> { OpenSearchException.generateFailureXContent(builder, params, failure, false); return builder; - }, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean()); + }, xContent.type(), ToXContent.EMPTY_PARAMS, randomBoolean()); try (XContentParser parser = createParser(xContent, failureBytes)) { failureBytes = BytesReference.bytes(shuffleXContent(parser, randomBoolean())); @@ -952,7 +952,7 @@ public void testFailureToAndFromXContentWithDetails() throws IOException { BytesReference failureBytes = toShuffledXContent((builder, params) -> { OpenSearchException.generateFailureXContent(builder, params, finalFailure, true); return builder; - }, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean()); + }, xContent.type(), ToXContent.EMPTY_PARAMS, randomBoolean()); try (XContentParser parser = createParser(xContent, failureBytes)) { failureBytes = BytesReference.bytes(shuffleXContent(parser, randomBoolean())); diff --git a/server/src/test/java/org/opensearch/action/search/SearchPhaseExecutionExceptionTests.java b/server/src/test/java/org/opensearch/action/search/SearchPhaseExecutionExceptionTests.java index aad528e9b007e..7731e2d8ede45 100644 --- a/server/src/test/java/org/opensearch/action/search/SearchPhaseExecutionExceptionTests.java +++ b/server/src/test/java/org/opensearch/action/search/SearchPhaseExecutionExceptionTests.java @@ -134,7 +134,7 @@ public void testToAndFromXContent() throws IOException { final String phase = randomFrom("query", "search", "other"); SearchPhaseExecutionException actual = new SearchPhaseExecutionException(phase, "unexpected failures", shardSearchFailures); - BytesReference exceptionBytes = toShuffledXContent(actual, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean()); + BytesReference exceptionBytes = toShuffledXContent(actual, xContent.type(), ToXContent.EMPTY_PARAMS, randomBoolean()); OpenSearchException parsedException; try (XContentParser parser = createParser(xContent, exceptionBytes)) { diff --git a/server/src/test/java/org/opensearch/common/xcontent/BaseXContentTestCase.java b/server/src/test/java/org/opensearch/common/xcontent/BaseXContentTestCase.java index f6324c1232444..f8b0ec2346abb 100644 --- a/server/src/test/java/org/opensearch/common/xcontent/BaseXContentTestCase.java +++ b/server/src/test/java/org/opensearch/common/xcontent/BaseXContentTestCase.java @@ -941,7 +941,7 @@ void doTestRawValue(XContent source) throws Exception { os = new ByteArrayOutputStream(); try (XContentGenerator generator = xcontentType().xContent().createGenerator(os)) { - generator.writeRawValue(new BytesArray(rawData).streamInput(), source.mediaType()); + generator.writeRawValue(new BytesArray(rawData).streamInput(), source.type()); } try ( @@ -966,7 +966,7 @@ public void close() { try (XContentGenerator generator = xcontentType().xContent().createGenerator(os)) { generator.writeStartObject(); generator.writeFieldName("test"); - generator.writeRawValue(new BytesArray(rawData).streamInput(), source.mediaType()); + generator.writeRawValue(new BytesArray(rawData).streamInput(), source.type()); assertFalse("Generator should not have closed the output stream", closed.get()); generator.writeEndObject(); } diff --git a/test/framework/src/main/java/org/opensearch/test/OpenSearchTestCase.java b/test/framework/src/main/java/org/opensearch/test/OpenSearchTestCase.java index 904f30a2edf95..464f43119f02b 100644 --- a/test/framework/src/main/java/org/opensearch/test/OpenSearchTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/OpenSearchTestCase.java @@ -94,7 +94,6 @@ import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.common.util.set.Sets; import org.opensearch.common.xcontent.LoggingDeprecationHandler; -import org.opensearch.common.xcontent.MediaType; import org.opensearch.common.xcontent.NamedXContentRegistry; import org.opensearch.common.xcontent.ToXContent; import org.opensearch.common.xcontent.XContent; @@ -1247,10 +1246,7 @@ public GeohashGenerator() { * Returns the bytes that represent the XContent output of the provided {@link ToXContent} object, using the provided * {@link XContentType}. Wraps the output into a new anonymous object according to the value returned * by the {@link ToXContent#isFragment()} method returns. Shuffles the keys to make sure that parsing never relies on keys ordering. - * - * @deprecated use {@link #toShuffledXContent(ToXContent, MediaType, ToXContent.Params, boolean, String...)} instead */ - @Deprecated protected final BytesReference toShuffledXContent( ToXContent toXContent, XContentType xContentType, @@ -1266,26 +1262,6 @@ protected final BytesReference toShuffledXContent( } } - /** - * Returns the bytes that represent the XContent output of the provided {@link ToXContent} object, using the provided - * {@link XContentType}. Wraps the output into a new anonymous object according to the value returned - * by the {@link ToXContent#isFragment()} method returns. Shuffles the keys to make sure that parsing never relies on keys ordering. - */ - protected final BytesReference toShuffledXContent( - ToXContent toXContent, - MediaType mediaType, - ToXContent.Params params, - boolean humanReadable, - String... exceptFieldNames - ) throws IOException { - BytesReference bytes = XContentHelper.toXContent(toXContent, mediaType, params, humanReadable); - try (XContentParser parser = createParser(mediaType.xContent(), bytes)) { - try (XContentBuilder builder = shuffleXContent(parser, rarely(), exceptFieldNames)) { - return BytesReference.bytes(builder); - } - } - } - /** * Randomly shuffles the fields inside objects in the {@link XContentBuilder} passed in. * Recursively goes through inner objects and also shuffles them. Exceptions for this