Search in sources :

Example 11 with Attribute

use of com.github.zhenwei.core.asn1.x509.Attribute in project mule-migration-assistant by mulesoft.

the class SftpInboundEndpoint method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    object.setName("listener");
    object.setNamespace(SFTP_NAMESPACE);
    addMigrationAttributeToElement(object, new Attribute("isMessageSource", "true"));
    String configName = object.getAttributeValue("connector-ref");
    Optional<Element> config;
    if (configName != null) {
        config = getApplicationModel().getNodeOptional("/*/*[namespace-uri() = '" + SFTP_NS_URI + "' and local-name() = 'config' and @name = '" + configName + "']");
    } else {
        config = getApplicationModel().getNodeOptional("/*/*[namespace-uri() = '" + SFTP_NS_URI + "' and local-name() = 'config']");
    }
    Element sftpConfig = migrateSftpConfig(object, configName, config, report);
    Element connection = sftpConfig.getChild("connection", SFTP_NAMESPACE);
    addAttributesToInboundProperties(object, report);
    Element redelivery = object.getChild("idempotent-redelivery-policy", CORE_NAMESPACE);
    if (redelivery != null) {
        redelivery.setName("redelivery-policy");
        Attribute exprAttr = redelivery.getAttribute("idExpression");
        if (exprAttr != null) {
            // TODO MMT-128
            exprAttr.setValue(exprAttr.getValue().replaceAll("#\\[header\\:inbound\\:originalFilename\\]", "#[attributes.name]"));
            if (getExpressionMigrator().isWrapped(exprAttr.getValue())) {
                exprAttr.setValue(getExpressionMigrator().wrap(getExpressionMigrator().migrateExpression(exprAttr.getValue(), true, object)));
            }
        }
        migrateRedeliveryPolicyChildren(redelivery, report);
    }
    migrateSchedulingStrategy(object, OptionalInt.of(1000));
    if (object.getAttribute("sizeCheckWaitTime") != null && !"0".equals(object.getAttributeValue("sizeCheckWaitTime"))) {
        String sizeCheckWaitTime = object.getAttributeValue("sizeCheckWaitTime");
        object.setAttribute("timeBetweenSizeCheck", sizeCheckWaitTime);
        object.removeAttribute("sizeCheckWaitTime");
    } else if (object.getAttribute("fileAge") != null && !"0".equals(object.getAttributeValue("fileAge"))) {
        String fileAge = object.getAttributeValue("fileAge");
        object.setAttribute("timeBetweenSizeCheck", fileAge);
        object.removeAttribute("fileAge");
    }
    if (object.getAttribute("tempDir") != null || object.getAttribute("useTempFileTimestampSuffix") != null) {
        report.report("sftp.tempDir", object, object);
        object.removeAttribute("tempDir");
        object.removeAttribute("useTempFileTimestampSuffix");
    }
    doExecute(object, report);
    migrateFileFilters(object, report, SFTP_NAMESPACE, getApplicationModel());
    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("username", credsSplit[0]);
            if (credsSplit.length > 1) {
                connection.setAttribute("password", credsSplit[1]);
            }
        }
        object.setAttribute("path", address.getPath() != null ? resolveDirectory(address.getPath()) : "/");
    });
    copyAttributeIfPresent(object, connection, "host");
    copyAttributeIfPresent(object, connection, "port");
    copyAttributeIfPresent(object, connection, "user", "username");
    copyAttributeIfPresent(object, connection, "password");
    Attribute pathAttr = object.getAttribute("path");
    if (pathAttr != null) {
        pathAttr.setName("directory");
    }
    if (object.getAttribute("connector-ref") != null) {
        object.getAttribute("connector-ref").setName("config-ref");
    } else {
        object.setAttribute("config-ref", sftpConfig.getAttributeValue("name"));
    }
    object.removeAttribute("name");
    copyAttributeIfPresent(object, connection, "identityFile");
    copyAttributeIfPresent(object, connection, "passphrase");
    if (object.getAttribute("knownHostsFile") != null && connection.getAttribute("knownHostsFile") == null) {
        copyAttributeIfPresent(object, connection, "knownHostsFile");
    }
    object.removeAttribute("knownHostsFile");
    if (object.getAttribute("archiveDir") != null) {
        String fileArchiveConfigName = sftpConfig.getAttributeValue("name") + "Archive";
        addTopLevelElement(new Element("config", FILE_NAMESPACE).setAttribute("name", fileArchiveConfigName).addContent(new Element("connection", FILE_NAMESPACE).setAttribute("workingDir", object.getAttributeValue("archiveDir"))), object.getDocument());
        object.getParentElement().addContent(3, new Element("write", FILE_NAMESPACE).setAttribute("config-ref", fileArchiveConfigName).setAttribute("path", "#[attributes.name]"));
        object.removeAttribute("archiveDir");
        object.removeAttribute("archiveTempReceivingDir");
        object.removeAttribute("archiveTempSendingDir");
    }
    if (object.getAttribute("responseTimeout") != null) {
        copyAttributeIfPresent(object, connection, "responseTimeout", "connectionTimeout");
        connection.setAttribute("connectionTimeoutUnit", "MILLISECONDS");
    }
    if (object.getAttribute("exchange-pattern") != null) {
        object.removeAttribute("exchange-pattern");
    }
}
Also used : Attribute(org.jdom2.Attribute) 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 12 with Attribute

use of com.github.zhenwei.core.asn1.x509.Attribute in project mule-migration-assistant by mulesoft.

the class AbstractSpringMigratorStep method moveNamespacesDeclarations.

protected void moveNamespacesDeclarations(Document muleDocument, Element movedElement, Document springDocument) {
    Set<Namespace> declaredNamespaces = doGetNamespacesDeclarationsRecursively(movedElement);
    Attribute schemaLocationAttribute = muleDocument.getRootElement().getAttribute("schemaLocation", muleDocument.getRootElement().getNamespace("xsi"));
    if (schemaLocationAttribute != null) {
        Map<String, String> locations = new HashMap<>();
        String[] splitLocations = stream(schemaLocationAttribute.getValue().split("\\s")).filter(s -> !StringUtils.isEmpty(s)).toArray(String[]::new);
        for (int i = 0; i < splitLocations.length; i += 2) {
            locations.put(splitLocations[i], splitLocations[i + 1]);
        }
        for (Namespace namespace : declaredNamespaces) {
            if (!StringUtils.isEmpty(namespace.getURI()) && locations.containsKey(namespace.getURI())) {
                getApplicationModel().addNameSpace(namespace, fixSpringSchemaLocationVersion(locations.get(namespace.getURI())), springDocument.getDocument());
            }
        }
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) File(java.io.File) TreeSet(java.util.TreeSet) Document(org.jdom2.Document) Attribute(org.jdom2.Attribute) JDOMException(org.jdom2.JDOMException) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) AbstractApplicationModelMigrationStep(com.mulesoft.tools.migration.step.AbstractApplicationModelMigrationStep) Paths(java.nio.file.Paths) MigrationStepException(com.mulesoft.tools.migration.exception.MigrationStepException) Map(java.util.Map) Entry(java.util.Map.Entry) Namespace(org.jdom2.Namespace) Namespace.getNamespace(org.jdom2.Namespace.getNamespace) StringUtils.substring(org.apache.commons.lang3.StringUtils.substring) Arrays.stream(java.util.Arrays.stream) Path(java.nio.file.Path) Element(org.jdom2.Element) Attribute(org.jdom2.Attribute) HashMap(java.util.HashMap) Namespace(org.jdom2.Namespace) Namespace.getNamespace(org.jdom2.Namespace.getNamespace)

Example 13 with Attribute

use of com.github.zhenwei.core.asn1.x509.Attribute in project mule-migration-assistant by mulesoft.

the class ExpiredFilter method execute.

@Override
public void execute(Element element, MigrationReport report) throws RuntimeException {
    addValidationNamespace(element.getDocument());
    addValidationDependency(getApplicationModel().getPomModel().get());
    element.setName("is-not-elapsed");
    element.setNamespace(VALIDATION_NAMESPACE);
    migrateExpression(element.getAttribute("dateTime"), getExpressionMigrator());
    element.getAttribute("dateTime").setName("since");
    final Attribute expiresInAttr = element.getAttribute("expiresIn");
    if (expiresInAttr != null) {
        expiresInAttr.setValue(expiresInAttr.getValue());
        expiresInAttr.setName("time");
    } else {
        element.setAttribute("time", "30000");
    }
    element.setAttribute("timeUnit", "MILLISECONDS");
    handleFilter(element);
}
Also used : Attribute(org.jdom2.Attribute)

Example 14 with Attribute

use of com.github.zhenwei.core.asn1.x509.Attribute in project mule-migration-assistant by mulesoft.

the class HttpConnectorRequestConfig method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    object.setNamespace(HTTP_NAMESPACE);
    if ("request-config".equals(object.getName())) {
        final Element requestConnection = new Element("request-connection", HTTP_NAMESPACE);
        copyAttributeIfPresent(object, requestConnection, "protocol");
        copyExpressionAttributeIfPresent(object, requestConnection, "host", "host", true);
        copyExpressionAttributeIfPresent(object, requestConnection, "port", "port", true);
        copyAttributeIfPresent(object, requestConnection, "usePersistentConnections");
        copyAttributeIfPresent(object, requestConnection, "maxConnections");
        copyAttributeIfPresent(object, requestConnection, "connectionIdleTimeout");
        copyAttributeIfPresent(object, requestConnection, "streamResponse");
        copyAttributeIfPresent(object, requestConnection, "responseBufferSize");
        copyAttributeIfPresent(object, requestConnection, "tlsContext-ref", "tlsContext");
        copyAttributeIfPresent(object, requestConnection, "clientSocketProperties-ref", "clientSocketProperties");
        copyAttributeIfPresent(object, requestConnection, "proxy-ref", "proxyConfig");
        object.addContent(requestConnection);
        for (Attribute attribute : object.getAttributes()) {
            if ("basePath".equals(attribute.getName()) || "followRedirects".equals(attribute.getName()) || "sendBodyMode".equals(attribute.getName()) || "requestStreamingMode".equals(attribute.getName()) || "responseTimeout".equals(attribute.getName())) {
                attribute.setValue(getExpressionMigrator().migrateExpression(attribute.getValue(), true, object));
            }
        }
    }
    object.getChildren().forEach(c -> {
        if (HTTP_NAMESPACE_URI.equals(c.getNamespaceURI())) {
            execute(c, report);
        } else if (TLS_NAMESPACE_URI.equals(c.getNamespaceURI()) && "context".equals(c.getName())) {
            final Element requestConnection = c.getParentElement().getChild("request-connection", HTTP_NAMESPACE);
            c.detach();
            requestConnection.addContent(c);
        } else if (TCP_NAMESPACE_URI.equals(c.getNamespaceURI()) && "client-socket-properties".equals(c.getName())) {
            final Element clientSocketPropsContainer = new Element("client-socket-properties", HTTP_NAMESPACE);
            final Element requestConnection = c.getParentElement().getChild("request-connection", HTTP_NAMESPACE);
            c.detach();
            clientSocketPropsContainer.addContent(c);
            requestConnection.addContent(clientSocketPropsContainer);
        }
    });
    if ("basic-authentication".equals(object.getName()) || "digest-authentication".equals(object.getName()) || "ntlm-authentication".equals(object.getName())) {
        final Element authentication = new Element("authentication", HTTP_NAMESPACE);
        final Element requestConnection = object.getParentElement().getChild("request-connection", HTTP_NAMESPACE);
        object.detach();
        authentication.addContent(object);
        requestConnection.addContent(authentication);
        for (Attribute attribute : object.getAttributes()) {
            XmlDslUtils.migrateExpression(attribute, getExpressionMigrator());
        }
    }
    if (("proxy".equals(object.getName()) || "ntlm-proxy".equals(object.getName())) && "request-config".equals(object.getParentElement().getName())) {
        final Element proxyConfig = new Element("proxy-config", HTTP_NAMESPACE);
        final Element requestConnection = object.getParentElement().getChild("request-connection", HTTP_NAMESPACE);
        object.detach();
        proxyConfig.addContent(object);
        requestConnection.addContent(proxyConfig);
    }
    if ("raml-api-configuration".equals(object.getName())) {
        report.report("http.restConnect", object, object.getParentElement());
        object.detach();
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 15 with Attribute

use of com.github.zhenwei.core.asn1.x509.Attribute in project mule-migration-assistant by mulesoft.

the class HttpInboundEndpoint method execute.

@Override
public void execute(Element object, MigrationReport report) throws RuntimeException {
    httpListenerLib(getApplicationModel());
    object.setNamespace(HTTP_NAMESPACE);
    object.setName("listener");
    addMigrationAttributeToElement(object, new Attribute("isMessageSource", "true"));
    String flowName = getContainerElement(object).getAttributeValue("name");
    String configName = ((object.getAttribute("name") != null ? object.getAttributeValue("name") : (object.getAttribute("ref") != null ? object.getAttributeValue("ref") : flowName)).replaceAll("\\\\", "_") + "ListenerConfig");
    processAddress(object, report).ifPresent(address -> {
        extractListenerConfig(getApplicationModel(), object, () -> getConnector(object.getAttributeValue("connector-ref")), HTTP_NAMESPACE, configName, address.getHost(), address.getPort());
        if (address.getPath() != null) {
            if (address.getPath().endsWith("*")) {
                object.setAttribute("path", address.getPath());
            } else {
                object.setAttribute("path", address.getPath().endsWith("/") ? address.getPath() + "*" : address.getPath() + "/*");
            }
        }
    });
    if (object.getAttribute("host") != null && object.getAttribute("port") != null) {
        extractListenerConfig(getApplicationModel(), object, () -> getConnector(object.getAttributeValue("connector-ref")), HTTP_NAMESPACE, configName, object.getAttributeValue("host"), object.getAttributeValue("port"));
        object.removeAttribute("host");
        object.removeAttribute("port");
    }
    if (object.getAttribute("connector-ref") != null) {
        Element connector = getConnector(object.getAttributeValue("connector-ref"));
        handleConnector(connector, object, report);
        object.removeAttribute("connector-ref");
    } else {
        getDefaultConnector().ifPresent(connector -> {
            handleConnector(connector, object, report);
        });
    }
    if (object.getAttribute("method") != null) {
        object.getAttribute("method").setName("allowedMethods");
    }
    if (object.getAttribute("path") == null) {
        object.setAttribute("path", "/*");
    } else {
        String path = object.getAttributeValue("path");
        if (!path.endsWith("*")) {
            object.setAttribute("path", path.endsWith("/") ? path + "*" : path + "/*");
        }
    }
    getApplicationModel().getNodes("/*/mule:flow[@name='" + flowName + "']/*[namespace-uri()='" + HTTP_NAMESPACE_URI + "' and local-name()='response-builder']").forEach(rb -> {
        handleReferencedResponseBuilder(rb, getApplicationModel(), HTTP_NAMESPACE);
        Element response = getResponse(object, HTTP_NAMESPACE);
        handleResponseBuilder(object, response, rb, HTTP_NAMESPACE);
        copyAttributeIfPresent(rb, response, "statusCode");
        copyAttributeIfPresent(rb, response, "reasonPhrase");
        if (response.getAttribute("statusCode") == null) {
            response.setAttribute("statusCode", "#[migration::HttpListener::httpListenerResponseSuccessStatusCode(vars)]");
            report.report("http.statusCode", response, response);
        }
        // if (rb.getAttribute("disablePropertiesAsHeaders") == null
        // || "false".equals(rb.getAttributeValue("disablePropertiesAsHeaders"))) {
        response.addContent(compatibilityHeaders(getApplicationModel(), HTTP_NAMESPACE));
    // }
    });
    getApplicationModel().getNodes("/*/mule:flow[@name='" + flowName + "']/*[namespace-uri()='" + HTTP_NAMESPACE_URI + "' and local-name()='error-response-builder']").forEach(rb -> {
        handleReferencedResponseBuilder(rb, getApplicationModel(), HTTP_NAMESPACE);
        Element errorResponse = getErrorResponse(object, HTTP_NAMESPACE);
        handleResponseBuilder(object, errorResponse, rb, HTTP_NAMESPACE);
        copyAttributeIfPresent(rb, errorResponse, "statusCode");
        copyAttributeIfPresent(rb, errorResponse, "reasonPhrase");
        if (errorResponse.getAttribute("statusCode") == null) {
            errorResponse.setAttribute("statusCode", "#[vars.statusCode default migration::HttpListener::httpListenerResponseErrorStatusCode(vars)]");
            report.report("http.statusCode", errorResponse, errorResponse);
        }
        // if (rb.getAttribute("disablePropertiesAsHeaders") == null
        // || "false".equals(rb.getAttributeValue("disablePropertiesAsHeaders"))) {
        errorResponse.addContent(compatibilityHeaders(getApplicationModel(), HTTP_NAMESPACE));
    // }
    });
    if (object.getAttribute("contentType") != null) {
        Element response = getResponse(object, HTTP_NAMESPACE);
        response.addContent(new Element("header", HTTP_NAMESPACE).setAttribute("headerName", "Content-Type").setAttribute("value", object.getAttributeValue("contentType")));
        response.setAttribute("statusCode", "#[migration::HttpListener::httpListenerResponseSuccessStatusCode(vars)]");
        report.report("http.statusCode", response, response);
        // if (rb.getAttribute("disablePropertiesAsHeaders") == null
        // || "false".equals(rb.getAttributeValue("disablePropertiesAsHeaders"))) {
        response.addContent(compatibilityHeaders(getApplicationModel(), HTTP_NAMESPACE));
        object.removeAttribute("contentType");
    }
    Element response = object.getChild("response", HTTP_NAMESPACE);
    if (response == null) {
        response = getResponse(object, HTTP_NAMESPACE);
        response.setAttribute("statusCode", "#[migration::HttpListener::httpListenerResponseSuccessStatusCode(vars)]");
        report.report("http.statusCode", response, response);
        // if (rb.getAttribute("disablePropertiesAsHeaders") == null
        // || "false".equals(rb.getAttributeValue("disablePropertiesAsHeaders"))) {
        response.addContent(compatibilityHeaders(getApplicationModel(), HTTP_NAMESPACE));
    // }
    }
    Element errorResponse = object.getChild("error-response", HTTP_NAMESPACE);
    if (errorResponse == null) {
        errorResponse = getErrorResponse(object, HTTP_NAMESPACE);
        errorResponse.setAttribute("statusCode", "#[vars.statusCode default migration::HttpListener::httpListenerResponseErrorStatusCode(vars)]");
        report.report("http.statusCode", errorResponse, errorResponse, "Avoid using an outbound property to determine the status code.");
        // if (rb.getAttribute("disablePropertiesAsHeaders") == null
        // || "false".equals(rb.getAttributeValue("disablePropertiesAsHeaders"))) {
        errorResponse.addContent(compatibilityHeaders(getApplicationModel(), HTTP_NAMESPACE));
    // }
    }
    migrateInboundEndpointStructure(getApplicationModel(), object, report, true);
    addAttributesToInboundProperties(object, getApplicationModel(), report);
    // Replicates logic from org.mule.transport.http.HttpMuleMessageFactory#extractPayloadFromHttpRequest
    Element checkPayload = new Element("choice", CORE_NAMESPACE).addContent(new Element("when", CORE_NAMESPACE).setAttribute("expression", "#[message.attributes.headers['Transfer-Encoding'] == null and (message.attributes.headers['Content-Length'] as Number default 0) == 0]").addContent(new Element("set-payload", CORE_NAMESPACE).setAttribute("value", "#[message.attributes.requestUri]")));
    addElementAfter(checkPayload, object);
    report.report("http.checkPayload", checkPayload, checkPayload);
    if (object.getAttribute("name") != null) {
        object.removeAttribute("name");
    }
    if (object.getAttribute("ref") != null) {
        object.removeAttribute("ref");
    }
}
Also used : Attribute(org.jdom2.Attribute) XmlDslUtils.addMigrationAttributeToElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addMigrationAttributeToElement) XmlDslUtils.addTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.addTopLevelElement) XmlDslUtils.getContainerElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.getContainerElement) Element(org.jdom2.Element)

Aggregations

Attribute (org.jdom2.Attribute)316 Element (org.jdom2.Element)210 IOException (java.io.IOException)98 ArrayList (java.util.ArrayList)75 Attribute (ucar.nc2.Attribute)65 List (java.util.List)46 Document (org.jdom2.Document)43 Variable (ucar.nc2.Variable)39 HashMap (java.util.HashMap)26 Extensions (org.bouncycastle.asn1.x509.Extensions)26 X509Certificate (java.security.cert.X509Certificate)24 Namespace (org.jdom2.Namespace)24 File (java.io.File)23 Attribute (org.bouncycastle.asn1.pkcs.Attribute)21 GeneralName (org.bouncycastle.asn1.x509.GeneralName)21 Array (ucar.ma2.Array)21 Test (org.junit.Test)20 GeneralNames (org.bouncycastle.asn1.x509.GeneralNames)19 Dimension (ucar.nc2.Dimension)19 Map (java.util.Map)17