Skip to content

Commit

Permalink
refactor XContent.type to XContent.mediaType
Browse files Browse the repository at this point in the history
Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
  • Loading branch information
nknize committed Feb 8, 2023
1 parent 986a83d commit 6978118
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,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 ByteArrayEntity(source, createContentType(xContent.type())));
request.setEntity(new ByteArrayEntity(source, createContentType(xContent.mediaType())));
return request;
}

Expand Down Expand Up @@ -555,7 +555,7 @@ static Request multiSearchTemplate(MultiSearchTemplateRequest multiSearchTemplat

XContent xContent = REQUEST_BODY_CONTENT_TYPE.xContent();
byte[] source = MultiSearchTemplateRequest.writeMultiLineFormat(multiSearchTemplateRequest, xContent);
request.setEntity(new ByteArrayEntity(source, createContentType(xContent.type())));
request.setEntity(new ByteArrayEntity(source, createContentType(xContent.mediaType())));
return request;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public interface XContent {
/**
* The type this content handles and produces.
*/
MediaType type();
MediaType mediaType();

byte streamSeparator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static XContentBuilder contentBuilder() throws IOException {
private CborXContent() {}

@Override
public MediaType type() {
public MediaType mediaType() {
return XContentType.CBOR;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static XContentBuilder contentBuilder() throws IOException {
private JsonXContent() {}

@Override
public MediaType type() {
public MediaType mediaType() {
return XContentType.JSON;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static XContentBuilder contentBuilder() throws IOException {
private SmileXContent() {}

@Override
public MediaType type() {
public MediaType mediaType() {
return XContentType.SMILE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static XContentBuilder contentBuilder() throws IOException {
private YamlXContent() {}

@Override
public MediaType type() {
public MediaType mediaType() {
return XContentType.YAML;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,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(), (XContentType) RemoteInfo.QUERY_CONTENT_TYPE.type());
builder.rawField("query", remoteInfo.getQuery().streamInput(), (XContentType) RemoteInfo.QUERY_CONTENT_TYPE.mediaType());
}
builder.array("index", getSearchRequest().indices());
getSearchRequest().source().innerToXContent(builder, params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ public void testThrowableToAndFromXContent() throws IOException {
BytesReference throwableBytes = toShuffledXContent((builder, params) -> {
OpenSearchException.generateThrowableXContent(builder, params, throwable);
return builder;
}, xContent.type(), ToXContent.EMPTY_PARAMS, randomBoolean());
}, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean());

OpenSearchException parsedException;
try (XContentParser parser = createParser(xContent, throwableBytes)) {
Expand Down Expand Up @@ -774,7 +774,7 @@ public void testUnknownFailureToAndFromXContent() throws IOException {
// Prints a null failure using generateFailureXContent()
OpenSearchException.generateFailureXContent(builder, params, null, randomBoolean());
return builder;
}, xContent.type(), ToXContent.EMPTY_PARAMS, randomBoolean());
}, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean());

OpenSearchException parsedFailure;
try (XContentParser parser = createParser(xContent, failureBytes)) {
Expand All @@ -798,7 +798,7 @@ public void testFailureToAndFromXContentWithNoDetails() throws IOException {
BytesReference failureBytes = toShuffledXContent((builder, params) -> {
OpenSearchException.generateFailureXContent(builder, params, failure, false);
return builder;
}, xContent.type(), ToXContent.EMPTY_PARAMS, randomBoolean());
}, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean());

try (XContentParser parser = createParser(xContent, failureBytes)) {
failureBytes = BytesReference.bytes(shuffleXContent(parser, randomBoolean()));
Expand Down Expand Up @@ -952,7 +952,7 @@ public void testFailureToAndFromXContentWithDetails() throws IOException {
BytesReference failureBytes = toShuffledXContent((builder, params) -> {
OpenSearchException.generateFailureXContent(builder, params, finalFailure, true);
return builder;
}, xContent.type(), ToXContent.EMPTY_PARAMS, randomBoolean());
}, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean());

try (XContentParser parser = createParser(xContent, failureBytes)) {
failureBytes = BytesReference.bytes(shuffleXContent(parser, randomBoolean()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.type(), ToXContent.EMPTY_PARAMS, randomBoolean());
BytesReference exceptionBytes = toShuffledXContent(actual, xContent.mediaType(), ToXContent.EMPTY_PARAMS, randomBoolean());

OpenSearchException parsedException;
try (XContentParser parser = createParser(xContent, exceptionBytes)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.type());
generator.writeRawValue(new BytesArray(rawData).streamInput(), source.mediaType());
}

try (
Expand All @@ -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.type());
generator.writeRawValue(new BytesArray(rawData).streamInput(), source.mediaType());
assertFalse("Generator should not have closed the output stream", closed.get());
generator.writeEndObject();
}
Expand Down

0 comments on commit 6978118

Please sign in to comment.