Search in sources :

Example 26 with Pair

use of org.mule.runtime.api.util.Pair in project mule by mulesoft.

the class ReflectiveHttpConfigBasedRequester method request.

private Pair<InputStream, Map<String, String>> request(String method, String url, Map<String, String> headers, InputStream body) {
    DefaultOperationParametersBuilder params = builder().configName(configName).addParameter("method", method).addParameter("url", url).addParameter("headers", new MultiMap<>(headers)).addParameter("targetValue", "#[payload]");
    if (body != null) {
        params.addParameter("body", new TypedValue<>(body, INPUT_STREAM));
    }
    try {
        Result<Object, Object> result = client.executeAsync("HTTP", "request", params.build()).get();
        Map<String, String> httpHeaders = getHttpHeaders(result);
        InputStream content = getContent(result);
        return new Pair<>(content, httpHeaders);
    } catch (Exception e) {
        throw new DispatchingException("Could not dispatch soap message using the [" + configName + "] HTTP configuration", e);
    }
}
Also used : MultiMap(org.mule.runtime.api.util.MultiMap) InputStream(java.io.InputStream) InvocationTargetException(java.lang.reflect.InvocationTargetException) DispatchingException(org.mule.runtime.soap.api.exception.DispatchingException) DispatchingException(org.mule.runtime.soap.api.exception.DispatchingException) DefaultOperationParametersBuilder(org.mule.runtime.extension.api.client.DefaultOperationParametersBuilder) Pair(org.mule.runtime.api.util.Pair)

Example 27 with Pair

use of org.mule.runtime.api.util.Pair in project mule by mulesoft.

the class ServerNotificationManagerConfiguratorTestCase method compliantDisabledNotificationByEventClass.

@Test
public void compliantDisabledNotificationByEventClass() 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.setEventClass(CompliantNotification.class);
    configurator.setDisabledNotifications(singletonList(disableNotificationConfig));
    configurator.initialise();
    verify(notificationManager).disableType(CompliantNotification.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 28 with Pair

use of org.mule.runtime.api.util.Pair in project mule by mulesoft.

the class ServerNotificationManagerConfiguratorTestCase method compliantDisabledNotificationByEventName.

@Test
public void compliantDisabledNotificationByEventName() 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.setEventName("test:COMPLIANT");
    configurator.setDisabledNotifications(singletonList(disableNotificationConfig));
    configurator.initialise();
    verify(notificationManager).disableType(CompliantNotification.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 29 with Pair

use of org.mule.runtime.api.util.Pair in project mule by mulesoft.

the class MuleArtifactContext method recursivelyResolveConfigFiles.

private List<ConfigFile> recursivelyResolveConfigFiles(List<Pair<String, InputStream>> configFilesToResolve, List<ConfigFile> alreadyResolvedConfigFiles) {
    DefaultConfigurationPropertiesResolver propertyResolver = new DefaultConfigurationPropertiesResolver(empty(), new EnvironmentPropertiesConfigurationProvider());
    ImmutableList.Builder<ConfigFile> resolvedConfigFilesBuilder = ImmutableList.<ConfigFile>builder().addAll(alreadyResolvedConfigFiles);
    configFilesToResolve.stream().filter(fileNameInputStreamPair -> !alreadyResolvedConfigFiles.stream().anyMatch(configFile -> configFile.getFilename().equals(fileNameInputStreamPair.getFirst()))).forEach(fileNameInputStreamPair -> {
        Document document = xmlConfigurationDocumentLoader.loadDocument(muleContext.getExtensionManager() == null ? emptySet() : muleContext.getExtensionManager().getExtensions(), fileNameInputStreamPair.getFirst(), fileNameInputStreamPair.getSecond());
        ConfigLine mainConfigLine = xmlApplicationParser.parse(document.getDocumentElement()).get();
        ConfigFile configFile = new ConfigFile(fileNameInputStreamPair.getFirst(), asList(mainConfigLine));
        resolvedConfigFilesBuilder.add(configFile);
        try {
            fileNameInputStreamPair.getSecond().close();
        } catch (IOException e) {
            throw new MuleRuntimeException(e);
        }
    });
    ImmutableSet.Builder<String> importedFiles = ImmutableSet.builder();
    for (ConfigFile configFile : resolvedConfigFilesBuilder.build()) {
        List<ConfigLine> rootConfigLines = configFile.getConfigLines();
        ConfigLine muleRootElementConfigLine = rootConfigLines.get(0);
        importedFiles.addAll(muleRootElementConfigLine.getChildren().stream().filter(configLine -> configLine.getNamespace().equals(CORE_PREFIX) && configLine.getIdentifier().equals(IMPORT_ELEMENT)).map(configLine -> {
            SimpleConfigAttribute fileConfigAttribute = configLine.getConfigAttributes().get("file");
            if (fileConfigAttribute == null) {
                throw new RuntimeConfigurationException(createStaticMessage(format("<import> does not have a file attribute defined. At file '%s', at line %s", configFile.getFilename(), configLine.getLineNumber())));
            }
            return fileConfigAttribute.getValue();
        }).map(value -> (String) propertyResolver.resolveValue(value)).filter(fileName -> !alreadyResolvedConfigFiles.stream().anyMatch(solvedConfigFile -> solvedConfigFile.getFilename().equals(fileName))).collect(toList()));
    }
    Set<String> importedConfigurationFiles = importedFiles.build();
    if (importedConfigurationFiles.isEmpty()) {
        return resolvedConfigFilesBuilder.build();
    }
    List<Pair<String, InputStream>> newConfigFilesToResolved = importedConfigurationFiles.stream().map(importedFileName -> {
        InputStream resourceAsStream = muleContext.getExecutionClassLoader().getResourceAsStream(importedFileName);
        if (resourceAsStream == null) {
            throw new RuntimeConfigurationException(createStaticMessage(format("Could not find imported resource '%s'", importedFileName)));
        }
        return (Pair<String, InputStream>) new Pair(importedFileName, resourceAsStream);
    }).collect(toList());
    return recursivelyResolveConfigFiles(newConfigFilesToResolved, resolvedConfigFilesBuilder.build());
}
Also used : ClassLoaderResourceProvider(org.mule.runtime.config.internal.dsl.model.ClassLoaderResourceProvider) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) SimpleConfigAttribute(org.mule.runtime.config.api.dsl.processor.SimpleConfigAttribute) Optional.of(java.util.Optional.of) Thread.currentThread(java.lang.Thread.currentThread) ContextAnnotationAutowireCandidateResolver(org.springframework.context.annotation.ContextAnnotationAutowireCandidateResolver) ByteArrayResource(org.springframework.core.io.ByteArrayResource) MuleInjectorProcessor(org.mule.runtime.config.internal.processor.MuleInjectorProcessor) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) BeanDefinitionFactory(org.mule.runtime.config.internal.dsl.spring.BeanDefinitionFactory) Arrays.asList(java.util.Arrays.asList) Document(org.w3c.dom.Document) Map(java.util.Map) MULE_EE_DOMAIN_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.MULE_EE_DOMAIN_IDENTIFIER) PostRegistrationActionsPostProcessor(org.mule.runtime.config.internal.processor.PostRegistrationActionsPostProcessor) ComponentBuildingDefinitionUtils.registerComponentBuildingDefinitions(org.mule.runtime.config.internal.util.ComponentBuildingDefinitionUtils.registerComponentBuildingDefinitions) Resource(org.springframework.core.io.Resource) ConfigurableObjectProvider(org.mule.runtime.api.ioc.ConfigurableObjectProvider) Set(java.util.Set) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME(org.springframework.context.annotation.AnnotationConfigUtils.CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME) ComponentLocatorCreatePostProcessor(org.mule.runtime.config.internal.processor.ComponentLocatorCreatePostProcessor) SpringComponentModel(org.mule.runtime.config.internal.dsl.model.SpringComponentModel) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Optional.empty(java.util.Optional.empty) MulePropertyEditorRegistrar(org.mule.runtime.config.internal.editors.MulePropertyEditorRegistrar) BeanDefinitionBuilder.genericBeanDefinition(org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) TransformerResolver(org.mule.runtime.core.internal.registry.TransformerResolver) DefaultRegistry(org.mule.runtime.core.internal.registry.DefaultRegistry) ArrayList(java.util.ArrayList) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) MULE_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.MULE_IDENTIFIER) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues) Component(org.mule.runtime.api.component.Component) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) XmlConfigurationDocumentLoader.noValidationDocumentLoader(org.mule.runtime.config.api.XmlConfigurationDocumentLoader.noValidationDocumentLoader) Registry(org.mule.runtime.api.artifact.Registry) ConfigurationDependencyResolver(org.mule.runtime.config.internal.dsl.model.ConfigurationDependencyResolver) ConfigFile(org.mule.runtime.config.api.dsl.processor.ConfigFile) REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME(org.springframework.context.annotation.AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME) LaxInstantiationStrategyWrapper(org.mule.runtime.config.internal.util.LaxInstantiationStrategyWrapper) ManagedMap(org.springframework.beans.factory.support.ManagedMap) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) ComponentModelHelper.updateAnnotationValue(org.mule.runtime.config.internal.dsl.spring.ComponentModelHelper.updateAnnotationValue) ApplicationModel(org.mule.runtime.config.internal.model.ApplicationModel) IOException(java.io.IOException) BeansException(org.springframework.beans.BeansException) ArtifactConfig(org.mule.runtime.config.api.dsl.processor.ArtifactConfig) GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) LifecycleUtils.disposeIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.disposeIfNeeded) SPRING_SINGLETON_OBJECT(org.mule.runtime.config.internal.dsl.spring.BeanDefinitionFactory.SPRING_SINGLETON_OBJECT) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) ResourceProvider(org.mule.runtime.config.api.dsl.model.ResourceProvider) CglibSubclassingInstantiationStrategy(org.springframework.beans.factory.support.CglibSubclassingInstantiationStrategy) LoggerFactory(org.slf4j.LoggerFactory) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) ManagedList(org.springframework.beans.factory.support.ManagedList) XmlApplicationParser(org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationParser) OBJECT_REGISTRY(org.mule.runtime.core.api.config.MuleProperties.OBJECT_REGISTRY) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) Preconditions.checkState(org.mule.runtime.api.util.Preconditions.checkState) ServiceRegistry(org.mule.runtime.core.api.registry.ServiceRegistry) Pair(org.mule.runtime.api.util.Pair) DOMAIN(org.mule.runtime.core.api.config.bootstrap.ArtifactType.DOMAIN) Collectors.toSet(java.util.stream.Collectors.toSet) XmlConfigurationDocumentLoader(org.mule.runtime.config.api.XmlConfigurationDocumentLoader) EnvironmentPropertiesConfigurationProvider(org.mule.runtime.config.internal.dsl.model.config.EnvironmentPropertiesConfigurationProvider) MULE_DOMAIN_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.MULE_DOMAIN_IDENTIFIER) POLICY(org.mule.runtime.core.api.config.bootstrap.ArtifactType.POLICY) ImmutableSet(com.google.common.collect.ImmutableSet) IMPORT_ELEMENT(org.mule.runtime.config.api.dsl.CoreDslConstants.IMPORT_ELEMENT) ObjectProvider(org.mule.runtime.api.ioc.ObjectProvider) OBJECT_MULE_CONTEXT(org.mule.runtime.core.api.config.MuleProperties.OBJECT_MULE_CONTEXT) String.format(java.lang.String.format) AbstractRefreshableConfigApplicationContext(org.springframework.context.support.AbstractRefreshableConfigApplicationContext) BeanPostProcessor(org.springframework.beans.factory.config.BeanPostProcessor) List(java.util.List) APP(org.mule.runtime.core.api.config.bootstrap.ArtifactType.APP) AutoIdUtils.uniqueValue(org.mule.runtime.config.internal.parsers.generic.AutoIdUtils.uniqueValue) Optional(java.util.Optional) OBJECT_MULE_CONFIGURATION(org.mule.runtime.core.api.config.MuleProperties.OBJECT_MULE_CONFIGURATION) MuleRegistryHelper(org.mule.runtime.core.internal.registry.MuleRegistryHelper) Converter(org.mule.runtime.core.api.transformer.Converter) ComponentBuildingDefinitionRegistry(org.mule.runtime.config.api.dsl.model.ComponentBuildingDefinitionRegistry) UrlResource(org.springframework.core.io.UrlResource) ConfigurationProperties(org.mule.runtime.api.component.ConfigurationProperties) MuleContext(org.mule.runtime.core.api.MuleContext) ImmutableList(com.google.common.collect.ImmutableList) ArtifactDeclaration(org.mule.runtime.app.declaration.api.ArtifactDeclaration) XmlApplicationServiceRegistry(org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationServiceRegistry) DiscardedOptionalBeanPostProcessor(org.mule.runtime.config.internal.processor.DiscardedOptionalBeanPostProcessor) RuntimeConfigurationException(org.mule.runtime.config.internal.dsl.model.config.RuntimeConfigurationException) ConfigLine(org.mule.runtime.config.api.dsl.processor.ConfigLine) IOUtils(org.mule.runtime.core.api.util.IOUtils) ROOT_CONTAINER_NAME_KEY(org.mule.runtime.api.component.AbstractComponent.ROOT_CONTAINER_NAME_KEY) Logger(org.slf4j.Logger) Collections.emptySet(java.util.Collections.emptySet) Optional.ofNullable(java.util.Optional.ofNullable) PropertyValue(org.springframework.beans.PropertyValue) ConfigResource(org.mule.runtime.core.api.config.ConfigResource) DefaultConfigurationPropertiesResolver(org.mule.runtime.config.internal.dsl.model.config.DefaultConfigurationPropertiesResolver) XmlConfigurationDocumentLoader.schemaValidatingDocumentLoader(org.mule.runtime.config.api.XmlConfigurationDocumentLoader.schemaValidatingDocumentLoader) LifecycleStatePostProcessor(org.mule.runtime.config.internal.processor.LifecycleStatePostProcessor) Collectors.toList(java.util.stream.Collectors.toList) ArtifactType(org.mule.runtime.core.api.config.bootstrap.ArtifactType) ConfigurationClassPostProcessor(org.springframework.context.annotation.ConfigurationClassPostProcessor) ExtensionManager(org.mule.runtime.core.api.extension.ExtensionManager) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) RequiredAnnotationBeanPostProcessor(org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) CONFIGURATION_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.CONFIGURATION_IDENTIFIER) Comparator(java.util.Comparator) InputStream(java.io.InputStream) SimpleConfigAttribute(org.mule.runtime.config.api.dsl.processor.SimpleConfigAttribute) ConfigFile(org.mule.runtime.config.api.dsl.processor.ConfigFile) ImmutableList(com.google.common.collect.ImmutableList) InputStream(java.io.InputStream) ConfigLine(org.mule.runtime.config.api.dsl.processor.ConfigLine) IOException(java.io.IOException) Document(org.w3c.dom.Document) EnvironmentPropertiesConfigurationProvider(org.mule.runtime.config.internal.dsl.model.config.EnvironmentPropertiesConfigurationProvider) ImmutableSet(com.google.common.collect.ImmutableSet) RuntimeConfigurationException(org.mule.runtime.config.internal.dsl.model.config.RuntimeConfigurationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) DefaultConfigurationPropertiesResolver(org.mule.runtime.config.internal.dsl.model.config.DefaultConfigurationPropertiesResolver) Pair(org.mule.runtime.api.util.Pair)

Example 30 with Pair

use of org.mule.runtime.api.util.Pair in project mule by mulesoft.

the class MuleArtifactContext method resolveArtifactConfig.

private ArtifactConfig resolveArtifactConfig() throws IOException {
    ArtifactConfig.Builder applicationConfigBuilder = new ArtifactConfig.Builder();
    applicationConfigBuilder.setArtifactProperties(this.artifactProperties);
    List<Pair<String, InputStream>> initialConfigFiles = new ArrayList<>();
    for (ConfigResource artifactConfigResource : artifactConfigResources) {
        initialConfigFiles.add(new Pair<>(artifactConfigResource.getResourceName(), artifactConfigResource.getInputStream()));
    }
    List<ConfigFile> configFiles = new ArrayList<>();
    recursivelyResolveConfigFiles(initialConfigFiles, configFiles).forEach(applicationConfigBuilder::addConfigFile);
    applicationConfigBuilder.setApplicationName(muleContext.getConfiguration().getId());
    return applicationConfigBuilder.build();
}
Also used : ConfigFile(org.mule.runtime.config.api.dsl.processor.ConfigFile) ArtifactConfig(org.mule.runtime.config.api.dsl.processor.ArtifactConfig) ArrayList(java.util.ArrayList) ConfigResource(org.mule.runtime.core.api.config.ConfigResource) 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