use of com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE 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);
}
}
use of com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_NAMESPACE 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);
}
}
use of com.mulesoft.tools.migration.step.util.XmlDslUtils.CORE_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));
}
Aggregations