use of com.mulesoft.tools.migration.library.tools.mel.MelCompatibilityResolver in project mule-migration-assistant by mulesoft.
the class HttpConnectorRequester method execute.
@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
httpRequesterLib(getApplicationModel());
final Namespace httpNamespace = Namespace.getNamespace("http", HTTP_NAMESPACE_URI);
object.setNamespace(httpNamespace);
if (object.getAttribute("port") != null) {
report.report("http.port", object, object, object.getAttributeValue("port"));
object.removeAttribute("port");
}
if (object.getAttribute("host") != null) {
report.report("http.host", object, object, object.getAttributeValue("host"));
object.removeAttribute("host");
}
if (object.getAttribute("parseResponse") != null) {
report.report("http.parseResponse", object, object, object.getAttributeValue("parseResponse"));
object.removeAttribute("parseResponse");
}
migrateExpression(object.getAttribute("path"), getExpressionMigrator());
migrateExpression(object.getAttribute("method"), getExpressionMigrator());
migrateExpression(object.getAttribute("followRedirects"), getExpressionMigrator());
migrateOperationStructure(getApplicationModel(), object, report, true, getExpressionMigrator(), new MelCompatibilityResolver());
addAttributesToInboundProperties(object, getApplicationModel(), report);
object.getChildren().forEach(c -> {
if (HTTP_NAMESPACE_URI.equals(c.getNamespaceURI())) {
executeChild(c, report, httpNamespace);
}
});
if (object.getChild("request-builder", httpNamespace) == null) {
object.addContent(new Element("request-builder", httpNamespace).addContent(compatibilityHeaders(httpNamespace)));
}
if (object.getAttribute("source") != null) {
if (!"#[payload]".equals(object.getAttributeValue("source"))) {
object.addContent(setText(new Element("body", httpNamespace), getExpressionMigrator().wrap(getExpressionMigrator().migrateExpression(object.getAttributeValue("source"), true, object))));
}
object.removeAttribute("source");
}
Element requestBuilder = object.getChild("request-builder", httpNamespace);
if (requestBuilder != null) {
object.removeContent(requestBuilder);
Builder<Content> listBuilder = ImmutableList.<Content>builder();
listBuilder.addAll(requestBuilder.getContent().stream().filter(c -> c instanceof Element && ("header".equals(((Element) c).getName()) || "headers".equals(((Element) c).getName()))).collect(toList()));
listBuilder.addAll(requestBuilder.getContent().stream().filter(c -> c instanceof Element && ("uri-param".equals(((Element) c).getName()) || "uri-params".equals(((Element) c).getName()))).collect(toList()));
listBuilder.addAll(requestBuilder.getContent().stream().filter(c -> c instanceof Element && ("query-param".equals(((Element) c).getName()) || "query-params".equals(((Element) c).getName()))).collect(toList()));
List<Content> builderContent = listBuilder.build();
requestBuilder.setContent(emptyList());
object.addContent(builderContent);
}
Element responseValidator = null;
Element successValidator = object.getChild("success-status-code-validator", httpNamespace);
if (successValidator != null) {
object.removeContent(successValidator);
responseValidator = new Element("response-validator", httpNamespace);
object.addContent(responseValidator);
responseValidator.addContent(successValidator);
}
Element failureValidator = object.getChild("failure-status-code-validator", httpNamespace);
if (failureValidator != null) {
object.removeContent(failureValidator);
if (responseValidator == null) {
responseValidator = new Element("response-validator", httpNamespace);
object.addContent(responseValidator);
}
responseValidator.addContent(failureValidator);
}
}
Aggregations