use of com.mindbright.security.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;
}
use of com.mindbright.security.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);
}
}
use of com.mindbright.security.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;
}
use of com.mindbright.security.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);
}
use of com.mindbright.security.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);
}
Aggregations