Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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