Search in sources :

Example 21 with MigrationReport

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

the class AbstractJmsEndpoint method addConnectionToConfig.

public static void addConnectionToConfig(final Element m4JmsConfig, final Element m3Connector, ApplicationModel appModel, MigrationReport report) {
    Element connection;
    switch(m3Connector.getName()) {
        case "activemq-connector":
            connection = addActiveMqConnection(m4JmsConfig, m3Connector, appModel);
            break;
        case "activemq-xa-connector":
            connection = addActiveMqConnection(m4JmsConfig, m3Connector, appModel);
            Element factoryConfig = connection.getChild("factory-configuration", JMS_NAMESPACE);
            if (factoryConfig == null) {
                factoryConfig = new Element("factory-configuration", JMS_NAMESPACE);
                connection.addContent(factoryConfig);
            }
            factoryConfig.setAttribute("enable-xa", "true");
            break;
        case "connector":
        case "custom-connector":
            report.report("jms.customConnector", m3Connector, m4JmsConfig);
            connection = new Element("generic-connection", JMS_NAMESPACE);
            m4JmsConfig.addContent(connection);
            break;
        case "weblogic-connector":
            report.report("jms.weblogicMqConnector", m3Connector, m4JmsConfig);
            connection = new Element("generic-connection", JMS_NAMESPACE);
            m4JmsConfig.addContent(connection);
            break;
        case "websphere-connector":
            // TODO MMT-202
            report.report("jms.,websphereMqConnector", m3Connector, m4JmsConfig);
            connection = new Element("generic-connection", JMS_NAMESPACE);
            m4JmsConfig.addContent(connection);
            break;
        default:
            connection = new Element("generic-connection", JMS_NAMESPACE);
            m4JmsConfig.addContent(connection);
    }
    String m4Specification = changeDefault("1.0.2b", "1.1", m3Connector.getAttributeValue("specification"));
    if (m4Specification != null && m4Specification.equals("1.0.2b")) {
        connection.setAttribute("specification", "JMS_1_0_2b");
    }
    copyAttributeIfPresent(m3Connector, connection, "username");
    copyAttributeIfPresent(m3Connector, connection, "password");
    copyAttributeIfPresent(m3Connector, connection, "clientId");
    if (m3Connector.getAttribute("connectionFactory-ref") != null) {
        Element defaultCaching = new Element("default-caching", JMS_NAMESPACE);
        Optional<Element> conFactoryOptional = appModel.getNodeOptional("/*/*[@name='" + m3Connector.getAttributeValue("connectionFactory-ref") + "']");
        if (conFactoryOptional.isPresent()) {
            Element connFactory = conFactoryOptional.get();
            copyAttributeIfPresent(connFactory, defaultCaching, "sessionCacheSize");
            copyAttributeIfPresent(connFactory, defaultCaching, "cacheConsumers");
            copyAttributeIfPresent(connFactory, defaultCaching, "cacheProducers");
            connection.addContent(0, new Element("caching-strategy", JMS_NAMESPACE).addContent(defaultCaching));
            connFactory.detach();
        } else {
            report.report("jms.beanConnectionFactory", m3Connector, m4JmsConfig);
        }
    } else {
        connection.addContent(0, new Element("caching-strategy", JMS_NAMESPACE).addContent(new Element("no-caching", JMS_NAMESPACE)));
    }
    if (m3Connector.getAttribute("connectionFactoryJndiName") != null) {
        Element jndiConnFactory = new Element("jndi-connection-factory", JMS_NAMESPACE);
        copyAttributeIfPresent(m3Connector, jndiConnFactory, "connectionFactoryJndiName");
        Element nameResolverBuilder = new Element("name-resolver-builder", JMS_NAMESPACE);
        copyAttributeIfPresent(m3Connector, nameResolverBuilder, "jndiInitialFactory", "jndiInitialContextFactory");
        copyAttributeIfPresent(m3Connector, nameResolverBuilder, "jndiProviderUrl");
        copyAttributeIfPresent(m3Connector, nameResolverBuilder, "jndiProviderUrl");
        processProviderProperties(m3Connector, appModel, nameResolverBuilder);
        Element m3defaultJndiNameResolver = m3Connector.getChild("default-jndi-name-resolver", JMS_NAMESPACE);
        if (m3defaultJndiNameResolver != null) {
            copyAttributeIfPresent(m3defaultJndiNameResolver, nameResolverBuilder, "jndiInitialFactory", "jndiInitialContextFactory");
            copyAttributeIfPresent(m3defaultJndiNameResolver, nameResolverBuilder, "jndiProviderUrl");
            processProviderProperties(m3defaultJndiNameResolver, appModel, nameResolverBuilder);
        }
        Element m3customJndiNameResolver = m3Connector.getChild("custom-jndi-name-resolver", JMS_NAMESPACE);
        if (m3customJndiNameResolver != null) {
            copyAttributeIfPresent(m3customJndiNameResolver.getChildren().stream().filter(p -> "jndiInitialFactory".equals(p.getAttributeValue("key"))).findFirst().get(), nameResolverBuilder, "value", "jndiInitialContextFactory");
            copyAttributeIfPresent(m3customJndiNameResolver.getChildren().stream().filter(p -> "jndiProviderUrl".equals(p.getAttributeValue("key"))).findFirst().get(), nameResolverBuilder, "value", "jndiProviderUrl");
            m3customJndiNameResolver.getChildren("property", CORE_NAMESPACE).forEach(prop -> {
                if ("jndiProviderProperties".equals(prop.getAttributeValue("key"))) {
                    processProviderPropertiesRef(prop.getAttributeValue("value-ref"), appModel, nameResolverBuilder);
                }
            });
        }
        if ("true".equals(m3Connector.getAttributeValue("jndiDestinations"))) {
            if ("true".equals(m3Connector.getAttributeValue("forceJndiDestinations"))) {
                jndiConnFactory.setAttribute("lookupDestination", "ALWAYS");
            } else {
                jndiConnFactory.setAttribute("lookupDestination", "TRY_ALWAYS");
            }
        }
        jndiConnFactory.addContent(nameResolverBuilder);
        Element connFactory = new Element("connection-factory", JMS_NAMESPACE).addContent(jndiConnFactory);
        connection.addContent(connFactory);
    }
}
Also used : System.lineSeparator(java.lang.System.lineSeparator) Optional.of(java.util.Optional.of) StringUtils(org.apache.commons.lang3.StringUtils) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) InboundPropertiesHelper.addAttributesMapping(com.mulesoft.tools.migration.library.mule.steps.core.properties.InboundPropertiesHelper.addAttributesMapping) ExpressionMigrator(com.mulesoft.tools.migration.util.ExpressionMigrator) LinkedHashMap(java.util.LinkedHashMap) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) Map(java.util.Map) Namespace(org.jdom2.Namespace) TransportsUtils.handleServiceOverrides(com.mulesoft.tools.migration.step.util.TransportsUtils.handleServiceOverrides) SPRING_BEANS_NS_URI(com.mulesoft.tools.migration.library.mule.steps.spring.SpringBeans.SPRING_BEANS_NS_URI) XmlDslUtils.setText(com.mulesoft.tools.migration.step.util.XmlDslUtils.setText) PomModelUtils.addSharedLibs(com.mulesoft.tools.migration.project.model.pom.PomModelUtils.addSharedLibs) IOException(java.io.IOException) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) DataWeaveHelper.getMigrationScriptFolder(com.mulesoft.tools.migration.library.mule.steps.core.dw.DataWeaveHelper.getMigrationScriptFolder) DependencyBuilder(com.mulesoft.tools.migration.project.model.pom.Dependency.DependencyBuilder) DataWeaveHelper.library(com.mulesoft.tools.migration.library.mule.steps.core.dw.DataWeaveHelper.library) Dependency(com.mulesoft.tools.migration.project.model.pom.Dependency) XPATH_SELECTOR(com.mulesoft.tools.migration.library.mule.steps.jms.JmsConnector.XPATH_SELECTOR) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) Optional(java.util.Optional) XmlDslUtils.changeDefault(com.mulesoft.tools.migration.step.util.XmlDslUtils.changeDefault) XmlDslUtils.copyAttributeIfPresent(com.mulesoft.tools.migration.step.util.XmlDslUtils.copyAttributeIfPresent) Element(org.jdom2.Element) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) Element(org.jdom2.Element)

Example 22 with MigrationReport

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

the class AbstractJmsEndpoint method migrateJmsConfig.

public static String migrateJmsConfig(Element object, MigrationReport report, Optional<Element> connector, ApplicationModel appModel) {
    String configName = connector.map(conn -> conn.getAttributeValue("name")).orElse((object.getAttribute("name") != null ? object.getAttributeValue("name") : (object.getAttribute("ref") != null ? object.getAttributeValue("ref") : "")).replaceAll("\\\\", "_") + "JmsConfig");
    Optional<Element> config = appModel.getNodeOptional("*/*[namespace-uri()='" + JMS_NAMESPACE_URI + "' and local-name()='config' and @name='" + configName + "']");
    config.orElseGet(() -> {
        final Element jmsCfg = new Element("config", JMS_NAMESPACE);
        jmsCfg.setAttribute("name", configName);
        connector.ifPresent(conn -> {
            handleServiceOverrides(conn, report);
            addConnectionToConfig(jmsCfg, conn, appModel, report);
        });
        addTopLevelElement(jmsCfg, connector.map(c -> c.getDocument()).orElse(object.getDocument()));
        return jmsCfg;
    });
    return configName;
}
Also used : System.lineSeparator(java.lang.System.lineSeparator) Optional.of(java.util.Optional.of) StringUtils(org.apache.commons.lang3.StringUtils) ApplicationModel(com.mulesoft.tools.migration.project.model.ApplicationModel) InboundPropertiesHelper.addAttributesMapping(com.mulesoft.tools.migration.library.mule.steps.core.properties.InboundPropertiesHelper.addAttributesMapping) ExpressionMigrator(com.mulesoft.tools.migration.util.ExpressionMigrator) LinkedHashMap(java.util.LinkedHashMap) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) Map(java.util.Map) Namespace(org.jdom2.Namespace) TransportsUtils.handleServiceOverrides(com.mulesoft.tools.migration.step.util.TransportsUtils.handleServiceOverrides) SPRING_BEANS_NS_URI(com.mulesoft.tools.migration.library.mule.steps.spring.SpringBeans.SPRING_BEANS_NS_URI) XmlDslUtils.setText(com.mulesoft.tools.migration.step.util.XmlDslUtils.setText) PomModelUtils.addSharedLibs(com.mulesoft.tools.migration.project.model.pom.PomModelUtils.addSharedLibs) IOException(java.io.IOException) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) DataWeaveHelper.getMigrationScriptFolder(com.mulesoft.tools.migration.library.mule.steps.core.dw.DataWeaveHelper.getMigrationScriptFolder) DependencyBuilder(com.mulesoft.tools.migration.project.model.pom.Dependency.DependencyBuilder) DataWeaveHelper.library(com.mulesoft.tools.migration.library.mule.steps.core.dw.DataWeaveHelper.library) Dependency(com.mulesoft.tools.migration.project.model.pom.Dependency) XPATH_SELECTOR(com.mulesoft.tools.migration.library.mule.steps.jms.JmsConnector.XPATH_SELECTOR) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) Optional(java.util.Optional) XmlDslUtils.changeDefault(com.mulesoft.tools.migration.step.util.XmlDslUtils.changeDefault) XmlDslUtils.copyAttributeIfPresent(com.mulesoft.tools.migration.step.util.XmlDslUtils.copyAttributeIfPresent) Element(org.jdom2.Element) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) Element(org.jdom2.Element)

Example 23 with MigrationReport

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

the class Pop3InboundEndpoint method migratePop3Config.

public Element migratePop3Config(Element object, MigrationReport report, Optional<Element> connector) {
    String configName = connector.map(conn -> conn.getAttributeValue("name")).orElse((object.getAttribute("name") != null ? object.getAttributeValue("name") : (object.getAttribute("ref") != null ? object.getAttributeValue("ref") : "")).replaceAll("\\\\", "_") + "Pop3Config");
    Optional<Element> config = getApplicationModel().getNodeOptional("*/*[namespace-uri() = '" + EMAIL_NAMESPACE.getURI() + "' and local-name() = 'pop3-config' and @name='" + configName + "']");
    return config.orElseGet(() -> {
        final Element imapCfg = new Element("pop3-config", EMAIL_NAMESPACE);
        imapCfg.setAttribute("name", configName);
        Element connection = createConnection();
        imapCfg.addContent(connection);
        addTopLevelElement(imapCfg, connector.map(c -> c.getDocument()).orElse(object.getDocument()));
        return imapCfg;
    });
}
Also used : TransportsUtils.migrateSchedulingStrategy(com.mulesoft.tools.migration.step.util.TransportsUtils.migrateSchedulingStrategy) XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) OptionalInt(java.util.OptionalInt) TransportsUtils.processAddress(com.mulesoft.tools.migration.step.util.TransportsUtils.processAddress) ExpressionMigrator(com.mulesoft.tools.migration.util.ExpressionMigrator) Attribute(org.jdom2.Attribute) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) Optional(java.util.Optional) TransportsUtils.handleServiceOverrides(com.mulesoft.tools.migration.step.util.TransportsUtils.handleServiceOverrides) XmlDslUtils.migrateReconnection(com.mulesoft.tools.migration.step.util.XmlDslUtils.migrateReconnection) XmlDslUtils.copyAttributeIfPresent(com.mulesoft.tools.migration.step.util.XmlDslUtils.copyAttributeIfPresent) Element(org.jdom2.Element) XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) Element(org.jdom2.Element)

Example 24 with MigrationReport

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

the class VmInboundEndpoint method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    addMigrationAttributeToElement(object, new Attribute("isMessageSource", "true"));
    Element tx = object.getChild("transaction", VM_NAMESPACE);
    while (tx != null) {
        String txAction = mapTransactionalAction(tx.getAttributeValue("action"), report, tx, object);
        object.setAttribute("transactionalAction", txAction);
        if (!"NONE".equals(txAction)) {
            if (object.getChild("redelivery-policy", CORE_NAMESPACE) == null) {
                object.addContent(new Element("redelivery-policy", CORE_NAMESPACE));
            }
        }
        object.removeChild("transaction", VM_NAMESPACE);
        tx = object.getChild("transaction", VM_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");
        if (!"NONE".equals(txAction)) {
            if (object.getChild("redelivery-policy", CORE_NAMESPACE) == null) {
                object.addContent(new Element("redelivery-policy", CORE_NAMESPACE));
            }
        }
        if ("true".equals(xaTx.getAttributeValue("interactWithExternal"))) {
            report.report("vm.externalTx", xaTx, object);
        }
        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);
        if (!"NONE".equals(txAction)) {
            if (object.getChild("redelivery-policy", CORE_NAMESPACE) == null) {
                object.addContent(new Element("redelivery-policy", CORE_NAMESPACE));
            }
        }
        object.removeChild("multi-transaction", CORE_EE_NAMESPACE);
    }
    getApplicationModel().addNameSpace(VM_NAMESPACE, "http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd", object.getDocument());
    object.setNamespace(VM_NAMESPACE);
    object.setName("listener");
    Optional<Element> connector = resolveVmConector(object, getApplicationModel());
    String configName = getVmConfigName(object, connector);
    Element vmConfig = migrateVmConfig(object, connector, configName, getApplicationModel());
    String path = processAddress(object, report).map(address -> address.getPath()).orElseGet(() -> obtainPath(object));
    addQueue(VM_NAMESPACE, connector, vmConfig, path);
    connector.ifPresent(conn -> {
        handleServiceOverrides(conn, report);
        Integer consumers = null;
        if (conn.getAttribute("numberOfConcurrentTransactedReceivers") != null) {
            consumers = parseInt(conn.getAttributeValue("numberOfConcurrentTransactedReceivers"));
        } else if (conn.getChild("receiver-threading-profile", CORE_NAMESPACE) != null && conn.getChild("receiver-threading-profile", CORE_NAMESPACE).getAttribute("maxThreadsActive") != null) {
            consumers = parseInt(conn.getChild("receiver-threading-profile", CORE_NAMESPACE).getAttributeValue("maxThreadsActive"));
        }
        if (consumers != null) {
            getContainerElement(object).setAttribute("maxConcurrency", "" + consumers);
            object.setAttribute("numberOfConsumers", "" + consumers);
        }
        handleConnectorChildElements(conn, vmConfig, new Element("connection", CORE_NAMESPACE), report);
    });
    if (object.getAttribute("mimeType") != null) {
        Element setMimeType = new Element("set-payload", CORE_NAMESPACE).setAttribute("value", "#[output " + object.getAttributeValue("mimeType") + " --- payload]");
        addElementAfter(setMimeType, object);
        object.removeAttribute("mimeType");
    }
    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("disableTransportTransformer");
    Element content = buildContent(VM_NAMESPACE);
    object.addContent(new Element("response", VM_NAMESPACE).addContent(content));
    report.report("vm.sessionVars", content, content);
    if (object.getAttribute("exchange-pattern") == null || object.getAttributeValue("exchange-pattern").equals("one-way")) {
        migrateInboundEndpointStructure(getApplicationModel(), object, report, false, true);
    } else {
        migrateInboundEndpointStructure(getApplicationModel(), object, report, true, true);
    }
}
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) Integer.parseInt(java.lang.Integer.parseInt) 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) XmlDslUtils.getContainerElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.getContainerElement) 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) XmlDslUtils.addElementAfter(com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter) TransportsUtils.handleServiceOverrides(com.mulesoft.tools.migration.step.util.TransportsUtils.handleServiceOverrides) Element(org.jdom2.Element) Attribute(org.jdom2.Attribute) XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) XmlDslUtils.getContainerElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.getContainerElement) Element(org.jdom2.Element)

Example 25 with MigrationReport

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

the class WsConsumerConfig method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    Namespace wscNamespace = Namespace.getNamespace("wsc", "http://www.mulesoft.org/schema/mule/wsc");
    getApplicationModel().addNameSpace(wscNamespace.getPrefix(), wscNamespace.getURI(), "http://www.mulesoft.org/schema/mule/wsc/current/mule-wsc.xsd");
    object.setNamespace(wscNamespace);
    object.setName("config");
    Element connection = new Element("connection", wscNamespace);
    copyAttributeIfPresent(object, connection, "service");
    object.removeAttribute("service");
    copyAttributeIfPresent(object, connection, "port");
    object.removeAttribute("port");
    copyAttributeIfPresent(object, connection, "wsdlLocation");
    migrateExpression(connection.getAttribute("wsdlLocation"), expressionMigrator);
    object.removeAttribute("wsdlLocation");
    copyAttributeIfPresent(object, connection, "serviceAddress", "address");
    migrateExpression(connection.getAttribute("address"), expressionMigrator);
    object.removeAttribute("serviceAddress");
    // TODO useConnectorToRetrieveWsdl?
    if (object.getAttribute("useConnectorToRetrieveWsdl") != null) {
        report.report("wsc.wsdl", object, object);
        object.removeAttribute("useConnectorToRetrieveWsdl");
    }
    if (object.getAttribute("connectorConfig") != null) {
        connection.addContent(new Element("custom-transport-configuration", wscNamespace).addContent(new Element("http-transport-configuration", wscNamespace).setAttribute("requesterConfig", object.getAttributeValue("connectorConfig"))));
        object.removeAttribute("connectorConfig");
    } else if (object.getAttribute("connector-ref") != null) {
        String transportConnectorName = object.getAttributeValue("connector-ref");
        final Element requestConfig = new Element("request-config", HTTP_NAMESPACE).setAttribute("name", transportConnectorName);
        final Element requestConnection = new Element("request-connection", HTTP_NAMESPACE);
        requestConfig.addContent(requestConnection);
        addTopLevelElement(requestConfig, object.getDocument());
        String address = connection.getAttributeValue("address");
        processAddress(connection, report).ifPresent(a -> {
            requestConnection.setAttribute("host", getExpressionMigrator().migrateExpression(a.getHost(), true, object));
            if (a.getPort() != null) {
                requestConnection.setAttribute("port", getExpressionMigrator().migrateExpression(a.getPort(), true, object));
            }
            requestConnection.setAttribute("protocol", "HTTP");
        });
        connection.setAttribute("address", address);
        Element connector = getApplicationModel().getNode("/*/*[namespace-uri()='" + HTTP_NAMESPACE_URI + "' and local-name()='connector' and @name='" + transportConnectorName + "']");
        if (connector != null) {
            handleConnector(connector, requestConnection, report, wscNamespace, getApplicationModel());
        } else {
            connector = getApplicationModel().getNode("/*/*[namespace-uri()='" + HTTPS_NAMESPACE_URI + "' and local-name()='connector' and @name='" + transportConnectorName + "']");
            if (connector != null) {
                handleConnector(connector, requestConnection, report, wscNamespace, getApplicationModel());
                migrate(requestConnection, of(connector), report, getApplicationModel(), "tls-client");
            }
        }
        connection.addContent(new Element("custom-transport-configuration", wscNamespace).addContent(new Element("http-transport-configuration", wscNamespace).setAttribute("requesterConfig", transportConnectorName)));
        object.removeAttribute("connector-ref");
    } else {
        // If the protocol is not http, lookup the appropriate connector
        // only https/jms transports supported
        String address = connection.getAttributeValue("address");
        processAddress(connection, report).ifPresent(a -> {
            if ("https".equals(a.getProtocol())) {
                List<Element> connectors = getApplicationModel().getNodes("/*/*[namespace-uri()='" + HTTPS_NAMESPACE_URI + "' and local-name()='connector']");
                if (connectors.isEmpty()) {
                    return;
                }
                Element connector = connectors.iterator().next();
                final Element requestConfig = new Element("request-config", HTTP_NAMESPACE).setAttribute("name", connector.getAttributeValue("name"));
                final Element requestConnection = new Element("request-connection", HTTP_NAMESPACE);
                requestConfig.addContent(requestConnection);
                addTopLevelElement(requestConfig, connector.getDocument());
                requestConnection.setAttribute("host", getExpressionMigrator().migrateExpression(a.getHost(), true, object));
                if (a.getPort() != null) {
                    requestConnection.setAttribute("port", getExpressionMigrator().migrateExpression(a.getPort(), true, object));
                }
                requestConnection.setAttribute("protocol", "HTTPS");
                handleConnector(connector, requestConnection, report, wscNamespace, getApplicationModel());
                migrate(requestConnection, of(connector), report, getApplicationModel(), "tls-client");
                connection.addContent(new Element("custom-transport-configuration", wscNamespace).addContent(new Element("http-transport-configuration", wscNamespace).setAttribute("requesterConfig", connector.getAttributeValue("name"))));
                object.removeAttribute("connector-ref");
            } else if ("jms".equals(a.getProtocol())) {
            // TODO MMT-24
            } else {
                report.report("wsc.unsupportedProtocol", object, object);
            }
        });
        connection.setAttribute("address", address);
    }
    object.addContent(connection);
    Namespace ws3Namespace = Namespace.getNamespace("ws", WS_NAMESPACE_URI);
    if (object.getChild("security", ws3Namespace) != null) {
        Namespace tlsNamespace = Namespace.getNamespace("tls", TLS_NAMESPACE_URI);
        Element security = object.getChild("security", ws3Namespace);
        security.setName("web-service-security");
        security.setNamespace(wscNamespace);
        security.detach();
        connection.addContent(security);
        if (security.getChild("wss-sign", ws3Namespace) != null) {
            Element sign = security.getChild("wss-sign", ws3Namespace);
            sign.setName("sign-security-strategy");
            sign.setNamespace(wscNamespace);
            String tlsContextName = sign.getAttributeValue("tlsContext-ref");
            sign.removeAttribute("tlsContext-ref");
            // TODO signatureKeyIdentifier?
            Element tlsContext = getApplicationModel().getNode("/*/*[namespace-uri()='" + TLS_NAMESPACE_URI + "' and local-name()='context' and @name='" + tlsContextName + "']");
            Element keyStoreConfig = new Element("key-store-configuration", wscNamespace);
            Element keyStore = tlsContext.getChild("key-store", tlsNamespace);
            copyAttributeIfPresent(keyStore, keyStoreConfig, "path", "keyStorePath", false);
            copyAttributeIfPresent(keyStore, keyStoreConfig, "keyPassword", false);
            copyAttributeIfPresent(keyStore, keyStoreConfig, "password", false);
            copyAttributeIfPresent(keyStore, keyStoreConfig, "alias", false);
            copyAttributeIfPresent(keyStore, keyStoreConfig, "type", false);
            sign.addContent(keyStoreConfig);
            if (!getApplicationModel().getNodeOptional("//*[@tlsContext-ref='" + tlsContextName + "']").isPresent()) {
                tlsContext.detach();
            }
            sign.detach();
            security.addContent(sign);
        }
        if (security.getChild("wss-verify-signature", ws3Namespace) != null) {
            Element verifySignature = security.getChild("wss-verify-signature", ws3Namespace);
            verifySignature.setName("verify-signature-security-strategy");
            verifySignature.setNamespace(wscNamespace);
            String tlsContextName = verifySignature.getAttributeValue("tlsContext-ref");
            verifySignature.removeAttribute("tlsContext-ref");
            Element tlsContext = getApplicationModel().getNode("/*/*[namespace-uri()='" + TLS_NAMESPACE_URI + "' and local-name()='context' and @name='" + tlsContextName + "']");
            Element keyStoreConfig = new Element("trust-store-configuration", wscNamespace);
            Element trustStore = tlsContext.getChild("trust-store", tlsNamespace);
            copyAttributeIfPresent(trustStore, keyStoreConfig, "path", "trustStorePath", false);
            copyAttributeIfPresent(trustStore, keyStoreConfig, "password", false);
            copyAttributeIfPresent(trustStore, keyStoreConfig, "alias", false);
            copyAttributeIfPresent(trustStore, keyStoreConfig, "type", false);
            verifySignature.addContent(keyStoreConfig);
            if (!getApplicationModel().getNodeOptional("//*[@tlsContext-ref='" + tlsContextName + "']").isPresent()) {
                tlsContext.detach();
            }
            verifySignature.detach();
            security.addContent(verifySignature);
        }
        if (security.getChild("wss-username-token", ws3Namespace) != null) {
            Element userNameToken = security.getChild("wss-username-token", ws3Namespace);
            userNameToken.setName("username-token-security-strategy");
            userNameToken.setNamespace(wscNamespace);
            userNameToken.detach();
            security.addContent(userNameToken);
        }
        if (security.getChild("wss-timestamp", ws3Namespace) != null) {
            Element timestamp = security.getChild("wss-timestamp", ws3Namespace);
            // TODO checkResponseTimestamp?
            timestamp.setName("timestamp-security-strategy");
            timestamp.setNamespace(wscNamespace);
            timestamp.getAttribute("expires").setName("timeToLive");
            timestamp.detach();
            security.addContent(timestamp);
        }
        if (security.getChild("wss-decrypt", ws3Namespace) != null) {
            Element decrypt = security.getChild("wss-decrypt", ws3Namespace);
            decrypt.setName("decrypt-security-strategy");
            decrypt.setNamespace(wscNamespace);
            String tlsContextName = decrypt.getAttributeValue("tlsContext-ref");
            decrypt.removeAttribute("tlsContext-ref");
            Element tlsContext = getApplicationModel().getNode("/*/*[namespace-uri()='" + TLS_NAMESPACE_URI + "' and local-name()='context' and @name='" + tlsContextName + "']");
            Element keyStoreConfig = new Element("key-store-configuration", wscNamespace);
            Element keyStore = tlsContext.getChild("key-store", tlsNamespace);
            copyAttributeIfPresent(keyStore, keyStoreConfig, "path", "keyStorePath", false);
            copyAttributeIfPresent(keyStore, keyStoreConfig, "keyPassword", false);
            copyAttributeIfPresent(keyStore, keyStoreConfig, "password", false);
            copyAttributeIfPresent(keyStore, keyStoreConfig, "alias", false);
            copyAttributeIfPresent(keyStore, keyStoreConfig, "type", false);
            decrypt.addContent(keyStoreConfig);
            if (decrypt.getAttribute("alias") != null) {
                keyStoreConfig.setAttribute("alias", decrypt.getAttributeValue("alias"));
                decrypt.removeAttribute("alias");
            }
            if (!getApplicationModel().getNodeOptional("//*[@tlsContext-ref='" + tlsContextName + "']").isPresent()) {
                tlsContext.detach();
            }
            decrypt.detach();
            security.addContent(decrypt);
        }
        if (security.getChild("wss-encrypt", ws3Namespace) != null) {
            Element encrypt = security.getChild("wss-encrypt", ws3Namespace);
            encrypt.setName("encrypt-security-strategy");
            encrypt.setNamespace(wscNamespace);
            String tlsContextName = encrypt.getAttributeValue("tlsContext-ref");
            encrypt.removeAttribute("tlsContext-ref");
            Element tlsContext = getApplicationModel().getNode("/*/*[namespace-uri()='" + TLS_NAMESPACE_URI + "' and local-name()='context' and @name='" + tlsContextName + "']");
            Element keyStoreConfig = new Element("key-store-configuration", wscNamespace);
            Element trustStore = tlsContext.getChild("trust-store", tlsNamespace);
            copyAttributeIfPresent(trustStore, keyStoreConfig, "path", "keyStorePath", false);
            copyAttributeIfPresent(trustStore, keyStoreConfig, "password", false);
            copyAttributeIfPresent(trustStore, keyStoreConfig, "alias", false);
            copyAttributeIfPresent(trustStore, keyStoreConfig, "type", false);
            encrypt.addContent(keyStoreConfig);
            if (encrypt.getAttribute("alias") != null) {
                keyStoreConfig.setAttribute("alias", encrypt.getAttributeValue("alias"));
                encrypt.removeAttribute("alias");
            }
            if (!getApplicationModel().getNodeOptional("//*[@tlsContext-ref='" + tlsContextName + "']").isPresent()) {
                tlsContext.detach();
            }
            encrypt.detach();
            security.addContent(encrypt);
        }
    }
}
Also used : HTTP_NAMESPACE_URI(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTP_NAMESPACE_URI) TLS_NAMESPACE_URI(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.TLS_NAMESPACE_URI) HttpsOutboundEndpoint.migrate(com.mulesoft.tools.migration.library.mule.steps.http.HttpsOutboundEndpoint.migrate) Optional.of(java.util.Optional.of) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) HTTPS_NAMESPACE_URI(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTPS_NAMESPACE_URI) TransportsUtils.processAddress(com.mulesoft.tools.migration.step.util.TransportsUtils.processAddress) ExpressionMigrator(com.mulesoft.tools.migration.util.ExpressionMigrator) WS_NAMESPACE_URI(com.mulesoft.tools.migration.library.mule.steps.wsc.WsConsumer.WS_NAMESPACE_URI) HTTP_NAMESPACE(com.mulesoft.tools.migration.library.mule.steps.http.AbstractHttpConnectorMigrationStep.HTTP_NAMESPACE) List(java.util.List) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) ExpressionMigratorAware(com.mulesoft.tools.migration.step.ExpressionMigratorAware) Namespace(org.jdom2.Namespace) XmlDslUtils.migrateExpression(com.mulesoft.tools.migration.step.util.XmlDslUtils.migrateExpression) HttpOutboundEndpoint.handleConnector(com.mulesoft.tools.migration.library.mule.steps.http.HttpOutboundEndpoint.handleConnector) XmlDslUtils.copyAttributeIfPresent(com.mulesoft.tools.migration.step.util.XmlDslUtils.copyAttributeIfPresent) Element(org.jdom2.Element) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) Element(org.jdom2.Element) List(java.util.List) Namespace(org.jdom2.Namespace)

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