diff --git a/src/main/java/org/opensearch/flowframework/model/Template.java b/src/main/java/org/opensearch/flowframework/model/Template.java index f4a8b1958..3f42c225e 100644 --- a/src/main/java/org/opensearch/flowframework/model/Template.java +++ b/src/main/java/org/opensearch/flowframework/model/Template.java @@ -260,9 +260,9 @@ public void writeTo(StreamOutput output) throws IOException { } /** - * Parse raw json content into a Template instance. + * Parse raw xContent into a Template instance. * - * @param parser json based content parser + * @param parser xContent based content parser * @return an instance of the template * @throws IOException if content can't be parsed correctly */ diff --git a/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java b/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java index 5d8aed031..e254b66f7 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java @@ -18,6 +18,7 @@ import org.opensearch.core.rest.RestStatus; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; +import org.opensearch.core.xcontent.XContentParser; import org.opensearch.flowframework.common.FlowFrameworkFeatureEnabledSetting; import org.opensearch.flowframework.exception.FlowFrameworkException; import org.opensearch.flowframework.model.Template; @@ -30,6 +31,7 @@ import java.util.List; import java.util.Locale; +import static org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken; import static org.opensearch.flowframework.common.CommonValue.DRY_RUN; import static org.opensearch.flowframework.common.CommonValue.PROVISION_WORKFLOW; import static org.opensearch.flowframework.common.CommonValue.WORKFLOW_ID; @@ -89,7 +91,9 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli ); } try { - Template template = Template.parse(request.content().utf8ToString()); + XContentParser parser = request.contentParser(); + ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser); + Template template = Template.parse(parser); boolean dryRun = request.paramAsBoolean(DRY_RUN, false); boolean provision = request.paramAsBoolean(PROVISION_WORKFLOW, false);