Skip to content

Commit 7be4d20

Browse files
cwperkspeternied
authored andcommitted
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> (cherry picked from commit bae002b)
1 parent 87990cd commit 7be4d20

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
@@ -107,6 +107,7 @@
107107
import org.opensearch.common.collect.Tuple;
108108
import org.opensearch.common.settings.Settings;
109109
import org.opensearch.common.unit.TimeValue;
110+
import org.opensearch.common.xcontent.MediaType;
110111
import org.opensearch.common.xcontent.NamedXContentRegistry;
111112
import org.opensearch.common.xcontent.XContentBuilder;
112113
import org.opensearch.common.xcontent.XContentFactory;
@@ -937,11 +938,11 @@ private static boolean retrieveFile(final RestHighLevelClient restHighLevelClien
937938
return false;
938939
}
939940

940-
private static BytesReference readXContent(final String content, final XContentType xContentType) throws IOException {
941+
private static BytesReference readXContent(final String content, final MediaType mediaType) throws IOException {
941942
BytesReference retVal;
942943
XContentParser parser = null;
943944
try {
944-
parser = XContentFactory.xContent(xContentType).createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, content);
945+
parser = XContentFactory.xContent(mediaType).createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, content);
945946
parser.nextToken();
946947
final XContentBuilder builder = XContentFactory.jsonBuilder();
947948
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)