use of org.mule.runtime.api.util.Pair in project mule by mulesoft.
the class PropertyComponentUtils method getPropertyValueFromPropertyComponent.
/**
* Creates a {@link Pair} from a generic property/ies component in the configuration.
*
* @param propertyComponentModel the component model for spring:property, spring:properties or property.
* @return a {@code PropertyValue} with the parsed content of the component.
*/
public static Pair<String, Object> getPropertyValueFromPropertyComponent(ComponentModel propertyComponentModel) {
Pair<String, Object> propertyValue;
String refKey = getReferenceAttributeName(propertyComponentModel.getIdentifier());
String nameKey = getNameAttributeName(propertyComponentModel.getIdentifier());
if (propertyComponentModel.getInnerComponents().isEmpty()) {
Object value;
if (propertyComponentModel.getParameters().containsKey(refKey)) {
value = new RuntimeBeanReference(propertyComponentModel.getParameters().get(refKey));
} else {
value = propertyComponentModel.getParameters().get(VALUE_PARAMETER_NAME);
}
if (!propertyComponentModel.getParameters().containsKey(nameKey)) {
propertyValue = new Pair<>(PROPERTY_NAME_PROPERTY_ATTRIBUTE, new RuntimeBeanReference(propertyComponentModel.getParameters().get("ref")));
} else {
propertyValue = new Pair<>(propertyComponentModel.getParameters().get(nameKey), value);
}
} else if (propertyComponentModel.getInnerComponents().get(0).getIdentifier().getName().equals("map")) {
ComponentModel springMap = propertyComponentModel.getInnerComponents().get(0);
ManagedMap<String, Object> propertiesMap = new ManagedMap<>();
springMap.getInnerComponents().stream().forEach(mapEntry -> {
Object value;
if (mapEntry.getParameters().containsKey(VALUE_PARAMETER_NAME)) {
value = mapEntry.getParameters().get(VALUE_PARAMETER_NAME);
} else {
value = new RuntimeBeanReference(mapEntry.getParameters().get(REFERENCE_MULE_PROPERTY_ATTRIBUTE));
}
propertiesMap.put(mapEntry.getParameters().get(PROPERTY_NAME_MULE_PROPERTY_ATTRIBUTE), value);
});
propertyValue = new Pair<>(propertyComponentModel.getNameAttribute(), propertiesMap);
} else {
throw new MuleRuntimeException(createStaticMessage("Unrecognized property model identifier: " + propertyComponentModel.getInnerComponents().get(0).getIdentifier()));
}
return propertyValue;
}
use of org.mule.runtime.api.util.Pair in project mule by mulesoft.
the class ServerNotificationManagerConfiguratorTestCase method compliantDisabledNotificationByInterface.
@Test
public void compliantDisabledNotificationByInterface() throws InitialisationException {
doReturn(singletonList((NotificationsProvider) () -> singletonMap("test:COMPLIANT", new Pair(CompliantNotification.class, CompliantNotificationListener.class)))).when(registry).lookupAllByType(NotificationsProvider.class);
final DisabledNotificationConfig disableNotificationConfig = new DisabledNotificationConfig();
disableNotificationConfig.setInterfaceClass(CompliantNotificationListener.class);
configurator.setDisabledNotifications(singletonList(disableNotificationConfig));
configurator.initialise();
verify(notificationManager).disableInterface(CompliantNotificationListener.class);
}
use of org.mule.runtime.api.util.Pair in project mule by mulesoft.
the class IsolatedServiceProviderDiscoverer method discover.
@Override
public List<Pair<ArtifactClassLoader, ServiceProvider>> discover() throws ServiceResolutionError {
List<Pair<ArtifactClassLoader, ServiceProvider>> serviceProviders = new LinkedList<>();
for (Object serviceArtifactClassLoader : serviceArtifactClassLoaders) {
try {
final ServiceProvider serviceProvider;
String artifactName = (String) serviceArtifactClassLoader.getClass().getMethod("getArtifactId").invoke(serviceArtifactClassLoader);
ClassLoader classLoader = (ClassLoader) serviceArtifactClassLoader.getClass().getMethod("getClassLoader").invoke(serviceArtifactClassLoader);
serviceProvider = instantiateServiceProvider(classLoader, artifactName);
// TODO MULE-12254 - Remove null which is needed in order to avoid class cast exceptions
serviceProviders.add(new Pair(null, serviceProvider));
} catch (Exception e) {
throw new IllegalStateException("Couldn't discover service from class loader: " + serviceArtifactClassLoader, e);
}
}
return serviceProviders;
}
use of org.mule.runtime.api.util.Pair in project mule by mulesoft.
the class MessagingExceptionResolver method collectErrors.
private List<Pair<Throwable, ErrorType>> collectErrors(Component obj, MessagingException me, ErrorTypeLocator locator) {
List<Pair<Throwable, ErrorType>> errors = new LinkedList<>();
getExceptionsAsList(me).forEach(e -> {
ErrorType type = errorTypeFromException(obj, locator, e);
if (!isUnknownMuleError(type) && !isCriticalMuleError(type)) {
errors.add(new Pair<>(e, type));
}
});
return errors;
}
use of org.mule.runtime.api.util.Pair in project mule by mulesoft.
the class AbstractExceptionListener method resolveExceptionAndMessageToLog.
protected Pair<MuleException, String> resolveExceptionAndMessageToLog(Throwable t) {
MuleException muleException = getRootMuleException(t);
String logMessage = null;
if (muleException != null) {
if (!isVerboseExceptions() && t instanceof EventProcessingException && ((EventProcessingException) t).getEvent().getError().map(e -> CORE_NAMESPACE_NAME.equals(e.getErrorType().getNamespace()) && UNKNOWN_ERROR_IDENTIFIER.equals(e.getErrorType().getIdentifier())).orElse(false)) {
logMessage = ((MuleException) sanitize(muleException)).getVerboseMessage();
} else {
logMessage = muleException.getDetailedMessage();
}
}
return new Pair<>(muleException, logMessage);
}
Aggregations