Search in sources :

Example 16 with Pair

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;
}
Also used : MULE_PROPERTY_IDENTIFIER(org.mule.runtime.config.internal.model.ApplicationModel.MULE_PROPERTY_IDENTIFIER) ManagedMap(org.springframework.beans.factory.support.ManagedMap) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) Pair(org.mule.runtime.api.util.Pair) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ManagedMap(org.springframework.beans.factory.support.ManagedMap) Pair(org.mule.runtime.api.util.Pair)

Example 17 with Pair

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);
}
Also used : DisabledNotificationConfig(org.mule.runtime.config.internal.NotificationConfig.DisabledNotificationConfig) NotificationsProvider(org.mule.runtime.core.api.context.notification.NotificationsProvider) Pair(org.mule.runtime.api.util.Pair) Test(org.junit.Test)

Example 18 with Pair

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;
}
Also used : ServiceProvider(org.mule.runtime.api.service.ServiceProvider) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader) LinkedList(java.util.LinkedList) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Pair(org.mule.runtime.api.util.Pair)

Example 19 with Pair

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;
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType) LinkedList(java.util.LinkedList) Pair(org.mule.runtime.api.util.Pair)

Example 20 with Pair

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);
}
Also used : StringUtils.defaultString(org.apache.commons.lang3.StringUtils.defaultString) MuleException(org.mule.runtime.api.exception.MuleException) ExceptionHelper.getRootMuleException(org.mule.runtime.api.exception.ExceptionHelper.getRootMuleException) Pair(org.mule.runtime.api.util.Pair)

Aggregations

Pair (org.mule.runtime.api.util.Pair)35 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)12 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)10 LinkedList (java.util.LinkedList)7 ServiceDiscoverer (org.mule.runtime.module.service.api.discoverer.ServiceDiscoverer)7 List (java.util.List)6 Service (org.mule.runtime.api.service.Service)6 Optional (java.util.Optional)5 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)5 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)5 String.format (java.lang.String.format)4 Set (java.util.Set)4 InOrder (org.mockito.InOrder)4 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)4 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)4 ServiceProvider (org.mule.runtime.api.service.ServiceProvider)4 InputStream (java.io.InputStream)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3