use of org.geotoolkit.swe.xml.v101.Text in project mule-migration-assistant by mulesoft.
the class SmtpOutboundEndpoint method execute.
@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
smtpTransportLib(getApplicationModel());
object.setName("send");
object.setNamespace(EMAIL_NAMESPACE);
Optional<Element> smtpConnector = resolveConnector(object, getApplicationModel());
smtpConnector.ifPresent(c -> {
handleServiceOverrides(c, report);
migrateReconnection(c, object, report);
if (c.getAttribute("toAddresses") != null) {
object.setAttribute("tc", c.getAttributeValue("toAddresses"));
}
if (c.getAttribute("ccAddresses") != null) {
object.setAttribute("cc", c.getAttributeValue("ccAddresses"));
}
if (c.getAttribute("bccAddresses") != null) {
object.setAttribute("bcc", c.getAttributeValue("bccAddresses"));
}
if (c.getAttribute("fromAddress") != null) {
object.setAttribute("fromAddress", c.getAttributeValue("fromAddress"));
}
if (c.getAttribute("replyToAddresses") != null) {
object.setAttribute("replyTo", c.getAttributeValue("replyToAddresses"));
}
if (c.getAttribute("subject") != null) {
object.setAttribute("subject", c.getAttributeValue("subject"));
}
});
getApplicationModel().addNameSpace(EMAIL_NAMESPACE.getPrefix(), EMAIL_NAMESPACE.getURI(), EMAIL_SCHEMA_LOC);
Element m4Config = migrateSmtpConfig(object, report, smtpConnector);
Element connection = getConnection(m4Config);
if (smtpConnector.isPresent() && "gmail-connector".equals(smtpConnector.get().getName())) {
connection.setName("smtps-connection");
connection.addContent(new Element("context", TLS_NAMESPACE).addContent(new Element("trust-store", TLS_NAMESPACE).setAttribute("insecure", "true")));
connection.setAttribute("host", "smtp.gmail.com");
connection.setAttribute("port", "465");
object.removeAttribute("host");
object.removeAttribute("port");
getApplicationModel().addNameSpace(TLS_NAMESPACE.getPrefix(), TLS_NAMESPACE.getURI(), "http://www.mulesoft.org/schema/mule/tls/current/mule-tls.xsd");
report.report("email.gmail", smtpConnector.get(), connection);
} else {
if (object.getAttribute("host") != null) {
object.setAttribute("host", expressionMigrator.migrateExpression(object.getAttributeValue("host"), false, object));
}
copyAttributeIfPresent(object, connection, "host");
copyAttributeIfPresent(object, connection, "port");
processAddress(object, report).ifPresent(address -> {
connection.setAttribute("host", address.getHost());
connection.setAttribute("port", address.getPort());
if (address.getCredentials() != null) {
String[] credsSplit = address.getCredentials().split(":");
connection.setAttribute("user", credsSplit[0]);
connection.setAttribute("password", credsSplit[1]);
}
});
}
copyAttributeIfPresent(object, connection, "user");
copyAttributeIfPresent(object, connection, "password");
if (object.getAttribute("connector-ref") != null) {
object.getAttribute("connector-ref").setName("config-ref");
} else {
object.removeAttribute("name");
object.setAttribute("config-ref", m4Config.getAttributeValue("name"));
}
report.report("email.outbound", object, object);
object.setAttribute("fromAddress", smtpAttributeExpr("#[vars.compatibility_outboundProperties.fromAddress]", object.getAttribute("fromAddress")));
object.setAttribute("subject", smtpAttributeExpr("#[vars.compatibility_outboundProperties.subject]", object.getAttribute("subject")));
object.addContent(new Element("to-addresses", EMAIL_NAMESPACE).addContent(new Element("to-address", EMAIL_NAMESPACE).setAttribute("value", smtpAttributeExpr("#[migration::SmtpTransport::smptToAddress(vars)]", object.getAttribute("to")))));
object.addContent(new Element("cc-addresses", EMAIL_NAMESPACE).addContent(new Element("cc-address", EMAIL_NAMESPACE).setAttribute("value", smtpAttributeExpr("#[migration::SmtpTransport::smptCcAddress(vars)]", object.getAttribute("cc")))));
object.addContent(new Element("bcc-addresses", EMAIL_NAMESPACE).addContent(new Element("bcc-address", EMAIL_NAMESPACE).setAttribute("value", smtpAttributeExpr("#[migration::SmtpTransport::smptBccAddress(vars)]", object.getAttribute("bcc")))));
object.addContent(new Element("reply-to-addresses", EMAIL_NAMESPACE).addContent(new Element("reply-to-address", EMAIL_NAMESPACE).setAttribute("value", smtpAttributeExpr("#[migration::SmtpTransport::smptReplyToAddress(vars)]", object.getAttribute("replyTo")))));
object.addContent(new Element("headers", EMAIL_NAMESPACE).addContent(new Text("#[vars.compatibility_outboundProperties.customHeaders]")));
object.addContent(new Element("body", EMAIL_NAMESPACE).setAttribute("contentType", "#[payload.^mimeType]").addContent(new Element("content", EMAIL_NAMESPACE).addContent(new Text("#[payload]"))));
object.addContent(new Element("attachments", EMAIL_NAMESPACE).addContent(new Text("#[vars filterObject ((value,key) -> ((key as String) startsWith 'att_')) pluck ((value, key, index) -> value)]")));
object.removeAttribute("to");
object.removeAttribute("cc");
object.removeAttribute("bcc");
object.removeAttribute("replyTo");
migrateOutboundEndpointStructure(getApplicationModel(), object, report, false);
}
use of org.geotoolkit.swe.xml.v101.Text in project mule-migration-assistant by mulesoft.
the class AbstractThrottlingTestCase method assertQuotaExceededOnErrorContinueElement.
protected void assertQuotaExceededOnErrorContinueElement(Element onErrorContinueElement, int rateLimitElements, boolean isRateLimit) {
assertThat(onErrorContinueElement, notNullValue());
assertThat(onErrorContinueElement.getName(), is(ON_ERROR_CONTINUE_TAG_NAME));
assertThat(onErrorContinueElement.getNamespace(), is(MULE_4_CORE_NAMESPACE_NO_PREFIX));
assertThat(onErrorContinueElement.getAttributes().size(), is(2));
assertThat(onErrorContinueElement.getAttributeValue(TYPE_ATTR_NAME), is(isRateLimit || rateLimitElements > 1 ? TYPE_ATTR_VALUE_QUOTA_EXCEEDED : TYPE_ATTR_VALUE_THROTTLING));
assertThat(onErrorContinueElement.getAttributeValue(LOG_EXCEPTION_ATTR_NAME), is(FALSE));
assertThat(onErrorContinueElement.getContentSize(), is(1));
Element setResponseElement = onErrorContinueElement.getChild(SET_RESPONSE_TAG_NAME, HTTP_TRANSFORM_NAMESPACE);
assertThat(setResponseElement, notNullValue());
assertThat(setResponseElement.getAttributes().size(), is(1));
assertThat(setResponseElement.getAttributeValue(STATUS_CODE), is(STATUS_CODE_ATTR_VALUE_429));
assertThat(setResponseElement.getContentSize(), is(2));
Element bodyElement = (Element) setResponseElement.getContent(0);
assertThat(bodyElement, notNullValue());
assertThat(bodyElement.getName(), is(BODY_TAG_NAME));
assertThat(bodyElement.getNamespace(), is(HTTP_TRANSFORM_NAMESPACE));
Text dwBodyContent = (Text) bodyElement.getContent(0);
assertThat(dwBodyContent, notNullValue());
assertThat(dwBodyContent.getText(), is(DW_BODY_RESEPONSE_VALUE));
assertHeadersElement((Element) setResponseElement.getContent(1), DW_HEADERS_EXCEPTION_RESPONSE_VALUE);
}
use of org.geotoolkit.swe.xml.v101.Text in project mule-migration-assistant by mulesoft.
the class AbstractThrottlingTestCase method assertHeadersElement.
protected void assertHeadersElement(Element headersElement, String expectedDWResponseValue) {
assertThat(headersElement, notNullValue());
assertThat(headersElement.getName(), is(HEADERS_TAG_NAME));
assertThat(headersElement.getNamespace(), is(HTTP_TRANSFORM_NAMESPACE));
assertThat(headersElement.getContentSize(), is(1));
Text dwHeadersContent = (Text) headersElement.getContent(0);
assertThat(dwHeadersContent, notNullValue());
assertThat(dwHeadersContent.getText(), is(expectedDWResponseValue));
}
use of org.geotoolkit.swe.xml.v101.Text in project mule-migration-assistant by mulesoft.
the class SlaBasedAlgorithmMigrationStepTestCase method assertUnknownApiOnErrorContinueElement.
private void assertUnknownApiOnErrorContinueElement(Element unknownApiOnErrorContinueElement) {
assertThat(unknownApiOnErrorContinueElement, notNullValue());
assertThat(unknownApiOnErrorContinueElement.getName(), is(ON_ERROR_CONTINUE_TAG_NAME));
assertThat(unknownApiOnErrorContinueElement.getNamespace(), is(MULE_4_CORE_NAMESPACE_NO_PREFIX));
assertThat(unknownApiOnErrorContinueElement.getAttributes().size(), is(2));
assertThat(unknownApiOnErrorContinueElement.getAttributeValue(TYPE_ATTR_NAME), is(TYPE_ATTR_VALUE_UNKNOWN_API));
assertThat(unknownApiOnErrorContinueElement.getAttributeValue(LOG_EXCEPTION_ATTR_NAME), is(FALSE));
assertThat(unknownApiOnErrorContinueElement.getContentSize(), is(1));
Element setResponseElement = unknownApiOnErrorContinueElement.getChild(SET_RESPONSE_TAG_NAME, HTTP_TRANSFORM_NAMESPACE);
assertThat(setResponseElement, notNullValue());
assertThat(setResponseElement.getAttributes().size(), is(1));
assertThat(setResponseElement.getAttributeValue(STATUS_CODE), is(STATUS_CODE_ATTR_VALUE_503));
assertThat(setResponseElement.getContentSize(), is(1));
Element bodyElement = (Element) setResponseElement.getContent(0);
assertThat(bodyElement, notNullValue());
assertThat(bodyElement.getName(), is(BODY_TAG_NAME));
assertThat(bodyElement.getNamespace(), is(HTTP_TRANSFORM_NAMESPACE));
Text dwBodyContent = (Text) bodyElement.getContent(0);
assertThat(dwBodyContent, notNullValue());
assertThat(dwBodyContent.getText(), is(DW_BODY_RESEPONSE_VALUE));
}
use of org.geotoolkit.swe.xml.v101.Text in project mule-migration-assistant by mulesoft.
the class SlaBasedAlgorithmMigrationStepTestCase method assertForbiddenClientOnErrorContinueElement.
private void assertForbiddenClientOnErrorContinueElement(Element forbiddenClientOnErrorContinueElement) {
assertThat(forbiddenClientOnErrorContinueElement, notNullValue());
assertThat(forbiddenClientOnErrorContinueElement.getName(), is(ON_ERROR_CONTINUE_TAG_NAME));
assertThat(forbiddenClientOnErrorContinueElement.getNamespace(), is(MULE_4_CORE_NAMESPACE_NO_PREFIX));
assertThat(forbiddenClientOnErrorContinueElement.getAttributes().size(), is(2));
assertThat(forbiddenClientOnErrorContinueElement.getAttributeValue(TYPE_ATTR_NAME), is(TYPE_ATTR_VALUE_FORBIDDEN_CLIENT));
assertThat(forbiddenClientOnErrorContinueElement.getAttributeValue(LOG_EXCEPTION_ATTR_NAME), is(FALSE));
assertThat(forbiddenClientOnErrorContinueElement.getContentSize(), is(1));
Element setResponseElement = forbiddenClientOnErrorContinueElement.getChild(SET_RESPONSE_TAG_NAME, HTTP_TRANSFORM_NAMESPACE);
assertThat(setResponseElement, notNullValue());
assertThat(setResponseElement.getAttributes().size(), is(1));
assertThat(setResponseElement.getAttributeValue(STATUS_CODE), is(STATUS_CODE_ATTR_VALUE_401));
assertThat(setResponseElement.getContentSize(), is(2));
Element bodyElement = (Element) setResponseElement.getContent(0);
assertThat(bodyElement, notNullValue());
assertThat(bodyElement.getName(), is(BODY_TAG_NAME));
assertThat(bodyElement.getNamespace(), is(HTTP_TRANSFORM_NAMESPACE));
Text dwBodyContent = (Text) bodyElement.getContent(0);
assertThat(dwBodyContent, notNullValue());
assertThat(dwBodyContent.getText(), is(DW_BODY_RESEPONSE_VALUE));
assertHeadersElement((Element) setResponseElement.getContent(1), DW_HEADERS_AUTHENTICATE_CLIENT_ID_ENFORCEMENT_RESPONSE_VALUE);
}
Aggregations