Search in sources :

Example 31 with Attribute

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

the class ApikitErrorHandler method buildOnErrorFromApikitMapping.

private Element buildOnErrorFromApikitMapping(Element mapping) {
    final Namespace rootNamespace = mapping.getDocument().getRootElement().getNamespace();
    final Element newOnError = new Element("on-error-propagate", rootNamespace);
    // Setting type
    final Element exception = mapping.getChild("exception", mapping.getNamespace());
    final Attribute exceptionAttribute = exception.getAttribute("value");
    if (exceptionAttribute != null) {
        final String exceptionClass = exceptionAttribute.getValue();
        final String errorType = getErrorForException(exceptionClass);
        if (errorType != null)
            newOnError.setAttribute("type", errorType);
        else
            newOnError.setAttribute("when", "#[mel:exception.causedBy(" + exceptionClass + ")]");
    }
    // Migrating mapping status code to var
    final String value = mapping.getAttributeValue("statusCode");
    final Element httpStatusVariable = buildSetVariable("httpStatus", value, rootNamespace);
    newOnError.addContent(httpStatusVariable);
    // Copy children to new node
    mapping.getChildren().stream().filter(e -> !e.getNamespace().equals(mapping.getNamespace())).forEach(e -> newOnError.addContent(e.clone()));
    return newOnError;
}
Also used : ApplicationModelUtils.changeNodeName(com.mulesoft.tools.migration.project.model.ApplicationModelUtils.changeNodeName) Attribute(org.jdom2.Attribute) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Namespace(org.jdom2.Namespace) MigrationReport(com.mulesoft.tools.migration.step.category.MigrationReport) Element(org.jdom2.Element) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Namespace(org.jdom2.Namespace)

Example 32 with Attribute

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

the class ApikitHttpListenerMapping method migrateResponse.

private void migrateResponse(Element response, String defaultStatusCode) {
    final Attribute statusCode = response.getAttribute(STATUS_CODE_ATTR_NAME);
    if (statusCode != null) {
        final String currentValue = getExpressionValue(statusCode.getValue());
        final String newValue = "vars.httpStatus default " + (isNullOrEmpty(currentValue) ? defaultStatusCode : currentValue);
        response.setAttribute(STATUS_CODE_ATTR_NAME, buildExpression(newValue));
    } else {
        response.setAttribute(STATUS_CODE_ATTR_NAME, buildExpression("vars.httpStatus default " + defaultStatusCode));
    }
    final Element header = response.getChild("headers", HTTP_NAMESPACE);
    if (header != null) {
        final String headerValue = getExpressionValue(header.getValue());
        final String newHeaderValue = "vars.outboundHeaders default {}" + (isNullOrEmpty(headerValue) ? "" : " ++ " + headerValue);
        header.setText(buildExpression(newHeaderValue));
    } else {
        final Element newHeader = new Element("headers", HTTP_NAMESPACE);
        newHeader.setText(buildExpression("vars.outboundHeaders default {}"));
        response.addContent(newHeader);
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) XmlDslUtils.isTopLevelElement(com.mulesoft.tools.migration.step.util.XmlDslUtils.isTopLevelElement)

Example 33 with Attribute

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

the class XmlDslUtils method addOutboundPropertySetter.

/**
 * Add the compatibility element to convert properties to outbound properties
 *
 * @param propertyName the name of the outbound property
 * @param element the current element that will use the outbound property
 * @param appModel the application model representation
 * @param after the element after the new set-property processor will be added
 */
public static Element addOutboundPropertySetter(String propertyName, Element element, ApplicationModel appModel, Element after) {
    addCompatibilityNamespace(element.getDocument());
    Element setProperty = new Element("set-property", COMPATIBILITY_NAMESPACE);
    setProperty.setAttribute(new Attribute("propertyName", propertyName));
    setProperty.setAttribute(new Attribute("value", "#[vars." + propertyName + "]"));
    addElementAfter(setProperty, after);
    return setProperty;
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 34 with Attribute

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

the class XmlDslUtils method createErrorHandlerParent.

/**
 * Create top level error handler section on configuration file
 *
 * @param element the element to check if it is an error handler top level element
 */
public static void createErrorHandlerParent(Element element) {
    Element parent = element.getParentElement();
    element.detach();
    Element errorHandler = new Element("error-handler");
    errorHandler.setNamespace(CORE_NAMESPACE);
    errorHandler.addContent(element);
    if (element.getAttribute("name") != null) {
        Attribute name = element.getAttribute("name");
        name.detach();
        errorHandler.setAttribute(name);
    }
    parent.addContent(errorHandler);
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 35 with Attribute

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

the class RegexFilter method execute.

@Override
public void execute(Element element, MigrationReport report) throws RuntimeException {
    addValidationsModule(element.getDocument());
    final Attribute attrPattern = element.getAttribute("pattern");
    // Mule 3 filter does something like a 'contains' of the pattern, not an actual regex.
    if (!attrPattern.getValue().endsWith(".*")) {
        attrPattern.setValue(attrPattern.getValue() + ".*");
    }
    if (!attrPattern.getValue().startsWith(".*")) {
        attrPattern.setValue(".*" + attrPattern.getValue());
    }
    attrPattern.setName("regex");
    if (element.getAttribute("value") == null) {
        element.setAttribute("value", "#[payload]");
    }
    element.setName("matches-regex");
    element.setNamespace(VALIDATION_NAMESPACE);
    handleFilter(element);
}
Also used : Attribute(org.jdom2.Attribute)

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