Skip to content

Commit

Permalink
Changed XContentType from MediaType (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
owaiskazi19 authored Jul 26, 2023
1 parent ec7c4a6 commit e40420b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -100,11 +101,11 @@ public List<NamedRoute> routes() {
private Function<RestRequest, RestResponse> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> source = sdkRestRequest.contentParser().mapStrings();
Expand Down

0 comments on commit e40420b

Please sign in to comment.