Search in sources :

Example 1 with MigrationReport

use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.

the class OAuth2ProviderConfig method migrateAuthorizationConfig.

private void migrateAuthorizationConfig(Element element, MigrationReport report) {
    final Element authorizationConfig = new Element("authorization-config", OAUTH2_PROVIDER_NAMESPACE);
    if (element.getAttributeValue("loginPage") != null) {
        authorizationConfig.setAttribute("loginPage", element.getAttributeValue("loginPage"));
        element.removeAttribute("loginPage");
    }
    final String path = element.getAttributeValue("authorizationEndpointPath");
    if (path != null) {
        authorizationConfig.setAttribute("path", path.startsWith("/") ? path : "/" + path);
        element.removeAttribute("authorizationEndpointPath");
    }
    if (element.getAttributeValue("authorizationCodeStore-ref") != null) {
        getApplicationModel().getNodeOptional("//*[namespace-uri() = '" + SPRING_BEANS_NS_URI + "' and local-name() = 'bean' and @name='" + element.getAttributeValue("authorizationCodeStore-ref") + "']").ifPresent(b -> {
            authorizationConfig.setAttribute("authorizationCodeStore", b.getAttributes().stream().filter(att -> "objectStore-ref".equals(att.getName())).map(att -> att.getValue()).findFirst().get());
        });
        element.removeAttribute("authorizationCodeStore-ref");
        if (element.getAttributeValue("authorizationTtlSeconds") != null) {
            report.report("oauth2Provider.authorizationTtl", element, authorizationConfig);
            element.removeAttribute("authorizationTtlSeconds");
        }
    }
    element.addContent(authorizationConfig);
}
Also used : HTTP_NAMESPACE_URI(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTP_NAMESPACE_URI) SPRING_BEANS_NS_URI(com.mulesoft.tools.migration.library.mule.steps.spring.SpringBeans.SPRING_BEANS_NS_URI) HttpInboundEndpoint.extractListenerConfig(com.mulesoft.tools.migration.library.mule.steps.http.HttpInboundEndpoint.extractListenerConfig) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors.joining(java.util.stream.Collectors.joining) Collections.singletonList(java.util.Collections.singletonList) HTTPS_NAMESPACE_URI(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTPS_NAMESPACE_URI) HttpsInboundEndpoint.handleHttpsListenerConfig(com.mulesoft.tools.migration.library.mule.steps.http.HttpsInboundEndpoint.handleHttpsListenerConfig) HTTP_NAMESPACE(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTP_NAMESPACE) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) HTTPS_NAMESPACE(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTPS_NAMESPACE) XmlDslUtils.addElementAfter(com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter) Namespace(org.jdom2.Namespace) Namespace.getNamespace(org.jdom2.Namespace.getNamespace) Arrays.stream(java.util.Arrays.stream) Element(org.jdom2.Element) Element(org.jdom2.Element)

Example 2 with MigrationReport

use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.

the class VmOutboundEndpoint method migrateOutboundVmEndpoint.

public static void migrateOutboundVmEndpoint(Element object, MigrationReport report, Optional<Element> connector, String configName, Element vmConfig) {
    String path = processAddress(object, report).map(address -> address.getPath()).orElseGet(() -> obtainPath(object));
    addQueue(VM_NAMESPACE, connector, vmConfig, path);
    if (object.getAttribute("responseTimeout") != null) {
        object.setAttribute("timeout", object.getAttributeValue("responseTimeout"));
        object.setAttribute("timeoutUnit", "MILLISECONDS");
        object.removeAttribute("responseTimeout");
    }
    object.setAttribute("config-ref", configName);
    object.setAttribute("queueName", path);
    object.removeAttribute("path");
    object.removeAttribute("name");
    object.removeAttribute("mimeType");
    object.removeAttribute("disableTransportTransformer");
    Element content = buildContent(VM_NAMESPACE);
    object.addContent(content);
    report.report("vm.sessionVars", content, content);
}
Also used : TransportsUtils.processAddress(com.mulesoft.tools.migration.step.util.TransportsUtils.processAddress) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) CORE_EE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_EE_NAMESPACE) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) Optional(java.util.Optional) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) TransportsUtils.migrateOutboundEndpointStructure(com.mulesoft.tools.migration.step.util.TransportsUtils.migrateOutboundEndpointStructure) Element(org.jdom2.Element) Element(org.jdom2.Element)

Example 3 with MigrationReport

use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.

the class HttpTransformers method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    if ("request-wildcard-filter".equals(object.getName())) {
        addValidationDependency(getApplicationModel().getPomModel().get());
        addValidationNamespace(object.getDocument());
        Element wildcardFilterTryScope = new Element("try", CORE_NAMESPACE);
        Element matchValidator = new Element("matches-regex", VALIDATION_NAMESPACE);
        String regex;
        Element parent = object.getParentElement();
        if ("not-filter".equals(parent.getName()) && parent.getNamespace().equals(CORE_NAMESPACE)) {
            addElementAfter(wildcardFilterTryScope, object.getParentElement());
            object.getParentElement().detach();
            regex = "^(?!" + object.getAttributeValue("pattern").replaceAll("\\*", ".*") + ").*$";
        } else {
            regex = "^" + object.getAttributeValue("pattern").replaceAll("\\*", ".*") + "$";
            addElementAfter(wildcardFilterTryScope, object);
            object.detach();
        }
        matchValidator.setAttribute("value", "#[message.attributes.requestPath]");
        matchValidator.setAttribute("regex", regex);
        matchValidator.removeAttribute("pattern");
        wildcardFilterTryScope.addContent(matchValidator);
        wildcardFilterTryScope.addContent(new Element("error-handler", CORE_NAMESPACE).addContent(new Element("on-error-propagate", CORE_NAMESPACE).addContent(new Element("set-variable", CORE_NAMESPACE).setAttribute("variableName", "statusCode").setAttribute("value", "406")).setAttribute("type", "MULE:VALIDATION")));
    } else if ("body-to-parameter-map-transformer".equals(object.getName())) {
        Element bodyToParamMap = new Element("set-payload", CORE_NAMESPACE).setAttribute("value", "#[output application/java --- payload]");
        if (object.getParentElement() == object.getDocument().getRootElement()) {
            getApplicationModel().getNodes("//mule:transformer[@ref='" + object.getAttributeValue("name") + "']").forEach(t -> {
                addElementAfter(bodyToParamMap, t);
                t.detach();
            });
        } else {
            addElementAfter(bodyToParamMap, object);
        }
        object.detach();
    } else {
        if (object.getAttribute("name") != null) {
            getApplicationModel().getNodes("//mule:transformer[@ref = '" + object.getAttributeValue("name") + "']").forEach(t -> t.detach());
        }
        object.detach();
    }
}
Also used : HTTP_NAMESPACE_URI(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTP_NAMESPACE_URI) ExpressionMigrator(com.mulesoft.tools.migration.util.ExpressionMigrator) ValidationMigration.addValidationNamespace(com.mulesoft.tools.migration.library.mule.steps.validation.ValidationMigration.addValidationNamespace) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) ValidationPomContribution.addValidationDependency(com.mulesoft.tools.migration.library.mule.steps.validation.ValidationPomContribution.addValidationDependency) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) XmlDslUtils.addElementAfter(com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter) VALIDATION_NAMESPACE(com.mulesoft.tools.migration.library.mule.steps.validation.ValidationMigration.VALIDATION_NAMESPACE) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Element(org.jdom2.Element) Element(org.jdom2.Element)

Example 4 with MigrationReport

use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.

the class JmsInboundEndpoint method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    jmsTransportLib(getApplicationModel());
    addMigrationAttributeToElement(object, new Attribute("isMessageSource", "true"));
    Element tx = object.getChild("transaction", JMS_NAMESPACE);
    while (tx != null) {
        String txAction = mapTransactionalAction(tx.getAttributeValue("action"), report, tx, object);
        object.setAttribute("transactionalAction", txAction);
        object.removeChild("transaction", JMS_NAMESPACE);
        tx = object.getChild("transaction", JMS_NAMESPACE);
    }
    while (object.getChild("xa-transaction", CORE_NAMESPACE) != null) {
        Element xaTx = object.getChild("xa-transaction", CORE_NAMESPACE);
        String txAction = mapTransactionalAction(xaTx.getAttributeValue("action"), report, xaTx, object);
        object.setAttribute("transactionalAction", txAction);
        object.setAttribute("transactionType", "XA");
        object.removeChild("xa-transaction", CORE_NAMESPACE);
    }
    while (object.getChild("multi-transaction", CORE_EE_NAMESPACE) != null) {
        Element multiTx = object.getChild("multi-transaction", CORE_EE_NAMESPACE);
        String txAction = mapTransactionalAction(multiTx.getAttributeValue("action"), report, multiTx, object);
        object.setAttribute("transactionalAction", txAction);
        object.removeChild("multi-transaction", CORE_EE_NAMESPACE);
    }
    getApplicationModel().addNameSpace(JMS_NAMESPACE, "http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd", object.getDocument());
    object.setNamespace(JMS_NAMESPACE);
    object.setName("listener");
    Optional<Element> connector = resolveJmsConnector(object, getApplicationModel());
    String configName = migrateJmsConfig(object, report, connector, getApplicationModel());
    connector.ifPresent(m3c -> {
        migrateReconnect(m3c, object, report, object);
        if (m3c.getAttributeValue("acknowledgementMode") != null) {
            switch(m3c.getAttributeValue("acknowledgementMode")) {
                case "CLIENT_ACKNOWLEDGE":
                    object.setAttribute("ackMode", "MANUAL");
                    break;
                case "DUPS_OK_ACKNOWLEDGE":
                    object.setAttribute("ackMode", "DUPS_OK");
                    break;
                default:
            }
        }
        if (m3c.getAttributeValue("numberOfConsumers") != null) {
            object.setAttribute("numberOfConsumers", m3c.getAttributeValue("numberOfConsumers"));
        }
        handleConnectorChildElements(m3c, getApplicationModel().getNode("*/*[namespace-uri()='" + JMS_NAMESPACE_URI + "' and local-name()='config' and @name='" + configName + "']"), new Element("connection", CORE_NAMESPACE), report);
    });
    String destination = processAddress(object, report).map(address -> {
        String path = address.getPath();
        if ("topic".equals(path)) {
            configureTopicListener(object, JMS_NAMESPACE, connector);
            return address.getPort();
        } else {
            return path;
        }
    }).orElseGet(() -> {
        if (object.getAttributeValue("queue") != null) {
            return object.getAttributeValue("queue");
        } else {
            configureTopicListener(object, JMS_NAMESPACE, connector);
            return object.getAttributeValue("topic");
        }
    });
    if (object.getAttribute("exchange-pattern") == null || object.getAttributeValue("exchange-pattern").equals("request-response")) {
        Element outboundBuilder = new Element("response", JMS_NAMESPACE);
        outboundBuilder.addContent(compatibilityProperties(getApplicationModel()));
        outboundBuilder.setAttribute("correlationId", "#[migration::JmsTransport::jmsCorrelationId(correlationId, vars)]");
        report.report("jms.propertiesListener", object, object);
        connector.ifPresent(m3c -> {
            if (m3c.getAttributeValue("persistentDelivery") != null) {
                outboundBuilder.setAttribute("persistentDelivery", m3c.getAttributeValue("persistentDelivery"));
            }
        });
        object.addContent(outboundBuilder);
    }
    if (object.getChild("selector", JMS_NAMESPACE) != null) {
        object.setAttribute("selector", object.getChild("selector", JMS_NAMESPACE).getAttributeValue("expression"));
        object.removeChild("selector", JMS_NAMESPACE);
    }
    object.setAttribute("config-ref", configName);
    if (destination != null) {
        object.setAttribute("destination", destination);
    }
    object.removeAttribute("queue");
    object.removeAttribute("topic");
    object.removeAttribute("name");
    object.removeAttribute("responseTimeout");
    // TODO
    object.removeAttribute("xaPollingTimeout");
    if (object.getAttribute("exchange-pattern") == null || object.getAttributeValue("exchange-pattern").equals("request-response")) {
        migrateInboundEndpointStructure(getApplicationModel(), object, report, true);
    } else {
        migrateInboundEndpointStructure(getApplicationModel(), object, report, false);
    }
    addAttributesToInboundProperties(object, getApplicationModel(), report);
}
Also used : XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) CORE_EE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_EE_NAMESPACE) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) TransportsUtils.processAddress(com.mulesoft.tools.migration.step.util.TransportsUtils.processAddress) Attribute(org.jdom2.Attribute) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) TransportsUtils.handleConnectorChildElements(com.mulesoft.tools.migration.step.util.TransportsUtils.handleConnectorChildElements) TransportsUtils.migrateInboundEndpointStructure(com.mulesoft.tools.migration.step.util.TransportsUtils.migrateInboundEndpointStructure) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) Optional(java.util.Optional) Namespace(org.jdom2.Namespace) XmlDslUtils.copyAttributeIfPresent(com.mulesoft.tools.migration.step.util.XmlDslUtils.copyAttributeIfPresent) XmlDslUtils.migrateReconnect(com.mulesoft.tools.migration.step.util.XmlDslUtils.migrateReconnect) Element(org.jdom2.Element) Attribute(org.jdom2.Attribute) XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) Element(org.jdom2.Element)

Example 5 with MigrationReport

use of com.mulesoft.tools.migration.step.category.MigrationReport in project mule-migration-assistant by mulesoft.

the class JmsOutboundEndpoint method migrateOutboundJmsEndpoint.

public static void migrateOutboundJmsEndpoint(Element object, MigrationReport report, Optional<Element> connector, String configName, ApplicationModel appModel) {
    String destination = processAddress(object, report).map(address -> {
        String path = address.getPath();
        if ("topic".equals(path)) {
            configureTopicPublisher(object);
            return address.getPort();
        } else {
            return path;
        }
    }).orElseGet(() -> {
        if (object.getAttributeValue("queue") != null) {
            return object.getAttributeValue("queue");
        } else {
            configureTopicPublisher(object);
            return object.getAttributeValue("topic");
        }
    });
    report.report("jms.propertiesPublish", object, object);
    Element outboundBuilder = new Element("message", JMS_NAMESPACE);
    Attribute migrationReplyTo = object.getAttribute("reply-to", Namespace.getNamespace("migration", "migration"));
    if (migrationReplyTo != null) {
        if (migrationReplyTo.getValue().startsWith("TOPIC:")) {
            outboundBuilder.addContent(new Element("reply-to", JMS_NAMESPACE).setAttribute("destination", migrationReplyTo.getValue()).setAttribute("destinationType", "TOPIC"));
        } else {
            outboundBuilder.addContent(new Element("reply-to", JMS_NAMESPACE).setAttribute("destination", migrationReplyTo.getValue()));
        }
        migrationReplyTo.detach();
    } else {
        outboundBuilder.addContent(new Element("reply-to", JMS_NAMESPACE).setAttribute("destination", "#[migration::JmsTransport::jmsPublishReplyTo(vars)]"));
    }
    outboundBuilder.addContent(compatibilityProperties(appModel));
    outboundBuilder.setAttribute("correlationId", "#[migration::JmsTransport::jmsCorrelationId(correlationId, vars)]");
    object.setAttribute("sendCorrelationId", "#[migration::JmsTransport::jmsSendCorrelationId(vars)]");
    object.addContent(outboundBuilder);
    connector.ifPresent(m3c -> {
        if (m3c.getAttributeValue("persistentDelivery") != null) {
            object.setAttribute("persistentDelivery", m3c.getAttributeValue("persistentDelivery"));
        }
        // This logic comes from JmsMessageDispatcher#dispatchMessage in Mule 3
        if ("true".equals(m3c.getAttributeValue("honorQosHeaders"))) {
            report.report("jms.inboundProperties", m3c, object);
            String defaultDeliveryMode = "true".equals(m3c.getAttributeValue("persistentDelivery")) ? "2" : "1";
            object.setAttribute("persistentDelivery", "#[(vars.compatibility_inboundProperties.JMSDeliveryMode default " + defaultDeliveryMode + ") == 2]");
            object.setAttribute("priority", "#[vars.compatibility_inboundProperties.JMSPriority default 4]");
        }
        handleConnectorChildElements(m3c, appModel.getNode("*/*[namespace-uri()='" + JMS_NAMESPACE_URI + "' and local-name()='config' and @name='" + configName + "']"), new Element("connection", CORE_NAMESPACE), report);
    });
    if (object.getAttribute("responseTimeout") != null) {
        object.addContent(new Element("consume-configuration", JMS_NAMESPACE).setAttribute("maximumWait", object.getAttributeValue("responseTimeout")));
    }
    object.removeAttribute("responseTimeout");
    object.setAttribute("config-ref", configName);
    if (destination != null) {
        object.setAttribute("destination", destination);
    }
    object.removeAttribute("queue");
    object.removeAttribute("topic");
    object.removeAttribute("name");
    object.removeAttribute("exchange-pattern");
}
Also used : TransportsUtils.processAddress(com.mulesoft.tools.migration.step.util.TransportsUtils.processAddress) Attribute(org.jdom2.Attribute) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) TransportsUtils.handleConnectorChildElements(com.mulesoft.tools.migration.step.util.TransportsUtils.handleConnectorChildElements) CORE_EE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_EE_NAMESPACE) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) Optional(java.util.Optional) Namespace(org.jdom2.Namespace) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) TransportsUtils.migrateOutboundEndpointStructure(com.mulesoft.tools.migration.step.util.TransportsUtils.migrateOutboundEndpointStructure) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) Element(org.jdom2.Element) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Aggregations

MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)33 Element (org.jdom2.Element)28 Optional (java.util.Optional)16 Namespace (org.jdom2.Namespace)16 CORE_NAMESPACE (com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE)13 List (java.util.List)13 ExpressionMigratorAware (com.mulesoft.tools.migration.step.ExpressionMigratorAware)12 ExpressionMigrator (com.mulesoft.tools.migration.util.ExpressionMigrator)12 Attribute (org.jdom2.Attribute)12 ApplicationModel (com.mulesoft.tools.migration.project.model.ApplicationModel)11 AbstractApplicationModelMigrationStep (com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep)11 TransportsUtils.processAddress (com.mulesoft.tools.migration.step.util.TransportsUtils.processAddress)10 XmlDslUtils.copyAttributeIfPresent (com.mulesoft.tools.migration.step.util.XmlDslUtils.copyAttributeIfPresent)9 XmlDslUtils.addElementAfter (com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter)8 Collectors.toList (java.util.stream.Collectors.toList)8 XmlDslUtils.addTopLevelElement (com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement)7 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)6 TransportsUtils.migrateOutboundEndpointStructure (com.mulesoft.tools.migration.step.util.TransportsUtils.migrateOutboundEndpointStructure)6 XmlDslUtils.addMigrationAttributeToElement (com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement)6 StringUtils (org.apache.commons.lang3.StringUtils)6