Skip to content

Commit bae002b

Browse files
cwperkspeternied
andauthored
Update usage of XContentFactory.xContent (#2433)
* Switch from XContentType to MediaType Signed-off-by: Craig Perkins <cwperx@amazon.com> Signed-off-by: Peter Nied <petern@amazon.com> Co-authored-by: Peter Nied <petern@amazon.com>
1 parent d676716 commit bae002b

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/main/java/org/opensearch/security/support/ConfigHelper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.opensearch.action.support.WriteRequest.RefreshPolicy;
4242
import org.opensearch.client.Client;
4343
import org.opensearch.common.bytes.BytesReference;
44+
import org.opensearch.common.xcontent.MediaType;
4445
import org.opensearch.common.xcontent.NamedXContentRegistry;
4546
import org.opensearch.common.xcontent.XContentBuilder;
4647
import org.opensearch.common.xcontent.XContentFactory;
@@ -116,11 +117,11 @@ public static String createEmptySdcYaml(CType cType, int configVersion) throws E
116117
return DefaultObjectMapper.YAML_MAPPER.writeValueAsString(createEmptySdc(cType, configVersion));
117118
}
118119

119-
public static BytesReference readXContent(final Reader reader, final XContentType xContentType) throws IOException {
120+
public static BytesReference readXContent(final Reader reader, final MediaType mediaType) throws IOException {
120121
BytesReference retVal;
121122
XContentParser parser = null;
122123
try {
123-
parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, reader);
124+
parser = XContentFactory.xContent(mediaType).createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, reader);
124125
parser.nextToken();
125126
final XContentBuilder builder = XContentFactory.jsonBuilder();
126127
builder.copyCurrentStructure(parser);

src/main/java/org/opensearch/security/tools/SecurityAdmin.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
import org.opensearch.common.collect.Tuple;
115115
import org.opensearch.common.settings.Settings;
116116
import org.opensearch.common.unit.TimeValue;
117+
import org.opensearch.common.xcontent.MediaType;
117118
import org.opensearch.common.xcontent.NamedXContentRegistry;
118119
import org.opensearch.common.xcontent.XContentBuilder;
119120
import org.opensearch.common.xcontent.XContentFactory;
@@ -945,11 +946,11 @@ private static boolean retrieveFile(final RestHighLevelClient restHighLevelClien
945946
return false;
946947
}
947948

948-
private static BytesReference readXContent(final String content, final XContentType xContentType) throws IOException {
949+
private static BytesReference readXContent(final String content, final MediaType mediaType) throws IOException {
949950
BytesReference retVal;
950951
XContentParser parser = null;
951952
try {
952-
parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, content);
953+
parser = XContentFactory.xContent(mediaType).createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, content);
953954
parser.nextToken();
954955
final XContentBuilder builder = XContentFactory.jsonBuilder();
955956
builder.copyCurrentStructure(parser);

src/test/java/org/opensearch/security/auditlog/sink/KafkaSinkTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void after() {
5454
public void testKafka() throws Exception {
5555
String configYml = FileHelper.loadFile("auditlog/endpoints/sink/configuration_kafka.yml");
5656
configYml = configYml.replace("_RPLC_BOOTSTRAP_SERVERS_",embeddedKafka.getEmbeddedKafka().getBrokersAsString());
57-
Settings.Builder settingsBuilder = Settings.builder().loadFromSource(configYml, YamlXContent.yamlXContent.type());
57+
Settings.Builder settingsBuilder = Settings.builder().loadFromSource(configYml, YamlXContent.yamlXContent.mediaType());
5858
try(KafkaConsumer<Long, String> consumer = createConsumer()) {
5959
consumer.subscribe(Arrays.asList("compliance"));
6060

0 commit comments

Comments
 (0)