Search in sources :

Example 1 with JMS_NAMESPACE

use of com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.JMS_NAMESPACE in project mule-migration-assistant by mulesoft.

the class RequestReply method migrateJmsRequestReply.

protected void migrateJmsRequestReply(Element object, MigrationReport report, final Element request, final Element reply, final Optional<Element> requestConnector) {
    getApplicationModel().addNameSpace(JMS_NAMESPACE, "http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd", object.getDocument());
    request.setNamespace(JMS_NAMESPACE);
    request.setName("publish-consume");
    String jmsConfig = migrateJmsConfig(request, report, requestConnector, getApplicationModel());
    migrateOutboundJmsEndpoint(request, report, requestConnector, jmsConfig, getApplicationModel());
    request.detach();
    addElementAfter(request, object);
    object.detach();
    final Element replyTo = request.getChild("message", JMS_NAMESPACE).getChild("reply-to", JMS_NAMESPACE);
    String destination = processAddress(reply, report).map(address -> {
        String path = address.getPath();
        if ("topic".equals(path)) {
            replyTo.setAttribute("destinationType", "TOPIC");
            return address.getPort();
        } else {
            return path;
        }
    }).orElseGet(() -> {
        if (reply.getAttributeValue("queue") != null) {
            return reply.getAttributeValue("queue");
        } else {
            replyTo.setAttribute("destinationType", "TOPIC");
            return reply.getAttributeValue("topic");
        }
    });
    replyTo.setAttribute("destination", destination);
    if (object.getAttribute("timeout") != null) {
        request.addContent(new Element("consume-configuration", JMS_NAMESPACE).setAttribute("maximumWait", object.getAttributeValue("timeout")));
    }
    migrateOutboundEndpointStructure(getApplicationModel(), request, report, true);
    extractInboundChildren(reply, request.getParentElement().indexOf(request) + 2, request.getParentElement(), getApplicationModel());
    addAttributesToInboundProperties(request, getApplicationModel(), report);
}
Also used : AbstractVmEndpoint.resolveVmConector(com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.resolveVmConector) AbstractVmEndpoint.migrateVmConfig(com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.migrateVmConfig) JmsOutboundEndpoint.migrateOutboundJmsEndpoint(com.mulesoft.tools.migration.library.mule.steps.jms.JmsOutboundEndpoint.migrateOutboundJmsEndpoint) VM_NAMESPACE(com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.VM_NAMESPACE) AbstractGlobalEndpointMigratorStep.copyAttributes(com.mulesoft.tools.migration.step.AbstractGlobalEndpointMigratorStep.copyAttributes) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Content(org.jdom2.Content) TransportsUtils.processAddress(com.mulesoft.tools.migration.step.util.TransportsUtils.processAddress) AbstractJmsEndpoint.resolveJmsConnector(com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.resolveJmsConnector) XmlDslUtils.getContainerElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.getContainerElement) VmOutboundEndpoint.migrateOutboundVmEndpoint(com.mulesoft.tools.migration.library.mule.steps.vm.VmOutboundEndpoint.migrateOutboundVmEndpoint) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) JMS_NAMESPACE(com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.JMS_NAMESPACE) Optional(java.util.Optional) AbstractVmEndpoint.getVmConfigName(com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.getVmConfigName) XmlDslUtils.addElementAfter(com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter) Namespace(org.jdom2.Namespace) AbstractJmsEndpoint.addAttributesToInboundProperties(com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.addAttributesToInboundProperties) TransportsUtils.extractInboundChildren(com.mulesoft.tools.migration.step.util.TransportsUtils.extractInboundChildren) TransportsUtils.migrateOutboundEndpointStructure(com.mulesoft.tools.migration.step.util.TransportsUtils.migrateOutboundEndpointStructure) AbstractJmsEndpoint.migrateJmsConfig(com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.migrateJmsConfig) Element(org.jdom2.Element) XmlDslUtils.getContainerElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.getContainerElement) Element(org.jdom2.Element)

Example 2 with JMS_NAMESPACE

use of com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.JMS_NAMESPACE in project mule-migration-assistant by mulesoft.

the class QuartzInboundEndpoint method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    if (object.removeAttribute("repeatCount")) {
        report.report("quartz.repeatCount", object, object);
    }
    object.setName("scheduler");
    object.setNamespace(CORE_NAMESPACE);
    addMigrationAttributeToElement(object, new Attribute("isMessageSource", "true"));
    String configName = object.getAttributeValue("connector-ref");
    Optional<Element> config;
    if (configName != null) {
        config = getApplicationModel().getNodeOptional("/*/*[namespace-uri() = '" + QUARTZ_NS_URI + "' and local-name() = 'connector' and @name = '" + configName + "']");
    } else {
        config = getApplicationModel().getNodeOptional("/*/*[namespace-uri() = '" + QUARTZ_NS_URI + "' and local-name() = 'connector']");
    }
    config.ifPresent(cfg -> {
        Element receiverThreadingProfile = cfg.getChild("receiver-threading-profile", CORE_NAMESPACE);
        if (receiverThreadingProfile != null) {
            if (receiverThreadingProfile.getAttribute("maxThreadsActive") != null) {
                getContainerElement(object).setAttribute("maxConcurrency", receiverThreadingProfile.getAttributeValue("maxThreadsActive"));
            }
        }
    });
    Element schedulingStrategy = new Element("scheduling-strategy", CORE_NAMESPACE);
    Element fixedFrequecy = null;
    Element cron = null;
    if (object.getAttribute("repeatInterval") != null) {
        if (fixedFrequecy == null) {
            fixedFrequecy = new Element("fixed-frequency", CORE_NAMESPACE);
            schedulingStrategy.addContent(fixedFrequecy);
        }
        fixedFrequecy.setAttribute("frequency", object.getAttributeValue("repeatInterval"));
        object.removeAttribute("repeatInterval");
    }
    if (object.getAttribute("startDelay") != null) {
        if (fixedFrequecy == null) {
            fixedFrequecy = new Element("fixed-frequency", CORE_NAMESPACE);
            schedulingStrategy.addContent(fixedFrequecy);
        }
        fixedFrequecy.setAttribute("startDelay", object.getAttributeValue("startDelay"));
        object.removeAttribute("startDelay");
    }
    if (object.getAttribute("cronExpression") != null) {
        if (cron == null) {
            cron = new Element("cron", CORE_NAMESPACE);
            schedulingStrategy.addContent(cron);
        }
        cron.setAttribute("expression", object.getAttributeValue("cronExpression"));
        object.removeAttribute("cronExpression");
    }
    if (object.getAttribute("cronTimeZone") != null) {
        if (cron == null) {
            cron = new Element("cron", CORE_NAMESPACE);
            schedulingStrategy.addContent(cron);
        }
        cron.setAttribute("timeZone", object.getAttributeValue("cronTimeZone"));
        object.removeAttribute("cronTimeZone");
    }
    Element eventGeneratorJob = object.getChild("event-generator-job", QUARTZ_NS);
    if (eventGeneratorJob != null) {
        String payload = eventGeneratorJob.getChildText("payload", QUARTZ_NS);
        if (payload != null) {
            addElementAfter(new Element("set-payload", CORE_NAMESPACE).setAttribute("value", payload), object);
        }
    }
    Element endpointPollingJob = object.getChild("endpoint-polling-job", QUARTZ_NS);
    if (endpointPollingJob != null) {
        Element jobEndpoint = endpointPollingJob.getChild("job-endpoint", QUARTZ_NS);
        addMigrationAttributeToElement(jobEndpoint, new Attribute("isPolledConsumer", "true"));
        if (JobEndpointMigrableConnector.JMS.equals(resolveEndpointConnector(jobEndpoint))) {
            handleGlobalEndpointsRefs(jobEndpoint);
            final Optional<Element> jobEndpointConnector = resolveJmsConnector(jobEndpoint, getApplicationModel());
            jobEndpointConnector.ifPresent(c -> jobEndpoint.setAttribute("connector-ref", c.getAttributeValue("name")));
            getApplicationModel().addNameSpace(JMS_NAMESPACE, "http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd", object.getDocument());
            jobEndpoint.setNamespace(JMS_NAMESPACE);
            jobEndpoint.setName("consume");
            String jmsConfig = migrateJmsConfig(jobEndpoint, report, jobEndpointConnector, getApplicationModel());
            migrateOutboundJmsEndpoint(jobEndpoint, report, jobEndpointConnector, jmsConfig, getApplicationModel());
            jobEndpoint.detach();
            addElementAfter(jobEndpoint, object);
            if (object.getAttribute("timeout") != null) {
                jobEndpoint.addContent(new Element("consume-configuration", JMS_NAMESPACE).setAttribute("maximumWait", object.getAttributeValue("timeout")));
            }
            migrateOutboundEndpointStructure(getApplicationModel(), jobEndpoint, report, true);
            extractInboundChildren(jobEndpoint, jobEndpoint.getParentElement().indexOf(jobEndpoint) + 2, jobEndpoint.getParentElement(), getApplicationModel());
            addAttributesToInboundProperties(jobEndpoint, getApplicationModel(), report);
            object.addContent(schedulingStrategy);
        } else if (JobEndpointMigrableConnector.VM.equals(resolveEndpointConnector(jobEndpoint))) {
            handleGlobalEndpointsRefs(jobEndpoint);
            final Optional<Element> jobEndpointConnector = resolveVmConector(jobEndpoint, getApplicationModel());
            jobEndpointConnector.ifPresent(c -> jobEndpoint.setAttribute("connector-ref", c.getAttributeValue("name")));
            getApplicationModel().addNameSpace(VM_NAMESPACE, "http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd", object.getDocument());
            jobEndpoint.setNamespace(VM_NAMESPACE);
            jobEndpoint.setName("consume");
            final String vmConfigName = getVmConfigName(object, jobEndpointConnector);
            Element vmConfig = migrateVmConfig(object, jobEndpointConnector, vmConfigName, getApplicationModel());
            migrateVmEndpointConsumer(jobEndpoint, report, jobEndpointConnector, vmConfigName, vmConfig);
            jobEndpoint.detach();
            addElementAfter(jobEndpoint, object);
            if (object.getAttribute("timeout") != null) {
                jobEndpoint.setAttribute("timeout", object.getAttributeValue("timeout"));
                jobEndpoint.setAttribute("timeoutUnit", "MILLISECONDS");
                object.removeAttribute("timeout");
            }
            migrateOutboundEndpointStructure(getApplicationModel(), jobEndpoint, report, true, true);
            extractInboundChildren(jobEndpoint, jobEndpoint.getParentElement().indexOf(jobEndpoint) + 2, jobEndpoint.getParentElement(), getApplicationModel());
            object.addContent(schedulingStrategy);
        } else if (JobEndpointMigrableConnector.POLLING.equals(resolveEndpointConnector(jobEndpoint))) {
            // This handles a Mule 4 connector source that is a polling source
            jobEndpoint.setName("inbound-endpoint");
            jobEndpoint.setNamespace(CORE_NAMESPACE);
            jobEndpoint.detach();
            addElementBefore(jobEndpoint, object);
            jobEndpoint.addContent(schedulingStrategy);
            object.detach();
        } else {
            object.addContent(schedulingStrategy);
            report.report("quartz.unsupportedSource", jobEndpoint, object);
        }
    } else {
        object.addContent(schedulingStrategy);
    }
    object.removeAttribute("connector-ref");
    object.removeAttribute("name");
    object.removeAttribute("jobName");
    object.removeContent(new ElementFilter(QUARTZ_NS));
}
Also used : XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) ElementFilter(org.jdom2.filter.ElementFilter) AbstractGlobalEndpointMigratorStep.copyAttributes(com.mulesoft.tools.migration.step.AbstractGlobalEndpointMigratorStep.copyAttributes) XmlDslUtils.addElementBefore(com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementBefore) CORE_NAMESPACE(com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE) JMS_NAMESPACE(com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.JMS_NAMESPACE) AbstractVmEndpoint.getVmConfigName(com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.getVmConfigName) XmlDslUtils.addElementAfter(com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter) Namespace(org.jdom2.Namespace) Namespace.getNamespace(org.jdom2.Namespace.getNamespace) VmOutboundEndpoint.migrateVmEndpointConsumer(com.mulesoft.tools.migration.library.mule.steps.vm.VmOutboundEndpoint.migrateVmEndpointConsumer) AbstractJmsEndpoint.addAttributesToInboundProperties(com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.addAttributesToInboundProperties) TransportsUtils.extractInboundChildren(com.mulesoft.tools.migration.step.util.TransportsUtils.extractInboundChildren) TransportsUtils.migrateOutboundEndpointStructure(com.mulesoft.tools.migration.step.util.TransportsUtils.migrateOutboundEndpointStructure) AbstractJmsEndpoint.migrateJmsConfig(com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.migrateJmsConfig) AbstractVmEndpoint.resolveVmConector(com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.resolveVmConector) AbstractVmEndpoint.migrateVmConfig(com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.migrateVmConfig) JmsOutboundEndpoint.migrateOutboundJmsEndpoint(com.mulesoft.tools.migration.library.mule.steps.jms.JmsOutboundEndpoint.migrateOutboundJmsEndpoint) VM_NAMESPACE(com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.VM_NAMESPACE) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) AbstractJmsEndpoint.resolveJmsConnector(com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.resolveJmsConnector) Attribute(org.jdom2.Attribute) XmlDslUtils.getContainerElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.getContainerElement) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) Optional(java.util.Optional) Element(org.jdom2.Element) Optional(java.util.Optional) 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) ElementFilter(org.jdom2.filter.ElementFilter)

Aggregations

JMS_NAMESPACE (com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.JMS_NAMESPACE)2 AbstractJmsEndpoint.addAttributesToInboundProperties (com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.addAttributesToInboundProperties)2 AbstractJmsEndpoint.migrateJmsConfig (com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.migrateJmsConfig)2 AbstractJmsEndpoint.resolveJmsConnector (com.mulesoft.tools.migration.library.mule.steps.jms.AbstractJmsEndpoint.resolveJmsConnector)2 JmsOutboundEndpoint.migrateOutboundJmsEndpoint (com.mulesoft.tools.migration.library.mule.steps.jms.JmsOutboundEndpoint.migrateOutboundJmsEndpoint)2 VM_NAMESPACE (com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.VM_NAMESPACE)2 AbstractVmEndpoint.getVmConfigName (com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.getVmConfigName)2 AbstractVmEndpoint.migrateVmConfig (com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.migrateVmConfig)2 AbstractVmEndpoint.resolveVmConector (com.mulesoft.tools.migration.library.mule.steps.vm.AbstractVmEndpoint.resolveVmConector)2 AbstractApplicationModelMigrationStep (com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep)2 AbstractGlobalEndpointMigratorStep.copyAttributes (com.mulesoft.tools.migration.step.AbstractGlobalEndpointMigratorStep.copyAttributes)2 MigrationReport (com.mulesoft.tools.migration.step.category.MigrationReport)2 TransportsUtils.extractInboundChildren (com.mulesoft.tools.migration.step.util.TransportsUtils.extractInboundChildren)2 TransportsUtils.migrateOutboundEndpointStructure (com.mulesoft.tools.migration.step.util.TransportsUtils.migrateOutboundEndpointStructure)2 CORE_NAMESPACE (com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE)2 XmlDslUtils.addElementAfter (com.mulesoft.tools.migration.step.util.XmlDslUtils.addElementAfter)2 XmlDslUtils.getContainerElement (com.mulesoft.tools.migration.step.util.XmlDslUtils.getContainerElement)2 Optional (java.util.Optional)2 Element (org.jdom2.Element)2 Namespace (org.jdom2.Namespace)2