From e40420bddb736c59063aa7bf10db48fd875ae09e Mon Sep 17 00:00:00 2001 From: Owais Kazi Date: Wed, 26 Jul 2023 03:13:55 -0700 Subject: [PATCH] Changed XContentType from MediaType (#912) --- .../sdk/sample/helloworld/rest/RestHelloAction.java | 7 ++++--- .../java/org/opensearch/sdk/rest/TestSDKRestRequest.java | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/opensearch/sdk/sample/helloworld/rest/RestHelloAction.java b/src/main/java/org/opensearch/sdk/sample/helloworld/rest/RestHelloAction.java index 46722bc5..122245b3 100644 --- a/src/main/java/org/opensearch/sdk/sample/helloworld/rest/RestHelloAction.java +++ b/src/main/java/org/opensearch/sdk/sample/helloworld/rest/RestHelloAction.java @@ -11,6 +11,7 @@ import org.opensearch.OpenSearchParseException; import org.opensearch.core.common.bytes.BytesReference; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; @@ -100,11 +101,11 @@ public List routes() { private Function handlePostRequest = (request) -> { if (request.hasContent()) { String adjective = ""; - XContentType contentType = request.getXContentType(); - if (contentType == null) { + MediaType mediaType = request.getMediaType(); + if (mediaType == null) { // Plain text adjective = request.content().utf8ToString(); - } else if (contentType.equals(XContentType.JSON)) { + } else if (mediaType.equals(XContentType.JSON)) { try { adjective = request.contentParser().mapStrings().get("adjective"); } catch (IOException | OpenSearchParseException e) { diff --git a/src/test/java/org/opensearch/sdk/rest/TestSDKRestRequest.java b/src/test/java/org/opensearch/sdk/rest/TestSDKRestRequest.java index 16b33ef2..9135958d 100644 --- a/src/test/java/org/opensearch/sdk/rest/TestSDKRestRequest.java +++ b/src/test/java/org/opensearch/sdk/rest/TestSDKRestRequest.java @@ -56,7 +56,7 @@ public void testSDKRestRequestMethods() throws IOException { assertEquals(expectedPath, sdkRestRequest.path()); assertEquals(expectedParams, sdkRestRequest.params()); assertEquals(expectedHeaders, sdkRestRequest.getHeaders()); - assertEquals(exptectedXContentType, sdkRestRequest.getXContentType()); + assertEquals(exptectedXContentType, sdkRestRequest.getMediaType()); assertEquals(expectedContent, sdkRestRequest.content()); Map source = sdkRestRequest.contentParser().mapStrings();