Search in sources :

Example 61 with MuleRuntimeException

use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.

the class IsolatedClassLoaderFactory method getLibraryPackages.

private JarInfo getLibraryPackages(List<URL> libraries) {
    Set<String> packages = new HashSet<>();
    Set<String> resources = new HashSet<>();
    final JarExplorer jarExplorer = new FileJarExplorer();
    for (URL library : libraries) {
        try {
            JarInfo jarInfo = jarExplorer.explore(library.toURI());
            packages.addAll(jarInfo.getPackages());
            resources.addAll(jarInfo.getResources());
        } catch (URISyntaxException e) {
            throw new MuleRuntimeException(e);
        }
    }
    return new JarInfo(packages, resources);
}
Also used : JarExplorer(org.mule.runtime.module.artifact.internal.util.JarExplorer) FileJarExplorer(org.mule.runtime.module.artifact.internal.util.FileJarExplorer) FileJarExplorer(org.mule.runtime.module.artifact.internal.util.FileJarExplorer) JarInfo(org.mule.runtime.module.artifact.internal.util.JarInfo) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL) HashSet(java.util.HashSet)

Example 62 with MuleRuntimeException

use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.

the class ZipUtils method compress.

/**
 * Compress a set of resource files into a ZIP file
 *
 * @param targetFile file that will contain the zipped files
 * @param resources resources to compress
 * @throws UncheckedIOException in case of any error processing the files
 */
public static void compress(File targetFile, ZipResource[] resources) {
    try (ZipOutputStream out = new ZipOutputStream(new FileOutputStream(targetFile))) {
        for (ZipResource zipResource : resources) {
            URL resourceUrl = ClassUtils.getResource(zipResource.file, ZipUtils.class);
            if (resourceUrl == null) {
                resourceUrl = new File(zipResource.file).toURI().toURL();
            }
            try (FileInputStream in = new FileInputStream(new File(resourceUrl.toURI()))) {
                out.putNextEntry(new ZipEntry(zipResource.alias == null ? zipResource.file : zipResource.alias));
                byte[] buffer = new byte[1024];
                int count;
                while ((count = in.read(buffer)) > 0) {
                    out.write(buffer, 0, count);
                }
            } catch (URISyntaxException e) {
                throw new MuleRuntimeException(e);
            }
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) UncheckedIOException(java.io.UncheckedIOException) URISyntaxException(java.net.URISyntaxException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) URL(java.net.URL) FileInputStream(java.io.FileInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) File(java.io.File)

Example 63 with MuleRuntimeException

use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.

the class MuleContextUtils method mockContextWithServices.

/**
 * Creates and configures a mock {@link MuleContext} to return testing services implementations.
 *
 * @return the created {@code muleContext}.
 */
public static MuleContextWithRegistries mockContextWithServices() {
    final MuleContextWithRegistries muleContext = mockMuleContext();
    SchedulerService schedulerService = spy(new SimpleUnitTestSupportSchedulerService());
    when(muleContext.getSchedulerService()).thenReturn(schedulerService);
    ErrorTypeRepository errorTypeRepository = mock(ErrorTypeRepository.class);
    when(muleContext.getErrorTypeRepository()).thenReturn(errorTypeRepository);
    when(errorTypeRepository.getErrorType(any(ComponentIdentifier.class))).thenReturn(of(mock(ErrorType.class)));
    final MuleRegistry registry = muleContext.getRegistry();
    NotificationListenerRegistry notificationListenerRegistry = mock(NotificationListenerRegistry.class);
    ConfigurationProperties configProps = mock(ConfigurationProperties.class);
    when(configProps.resolveBooleanProperty(any())).thenReturn(empty());
    ConfigurationComponentLocator configurationComponentLocator = mock(ConfigurationComponentLocator.class);
    when(configurationComponentLocator.find(any(Location.class))).thenReturn(empty());
    when(configurationComponentLocator.find(any(ComponentIdentifier.class))).thenReturn(emptyList());
    try {
        when(registry.lookupObject(NotificationListenerRegistry.class)).thenReturn(notificationListenerRegistry);
        Map<Class, Object> injectableObjects = new HashMap<>();
        injectableObjects.put(MuleContext.class, muleContext);
        injectableObjects.put(SchedulerService.class, schedulerService);
        injectableObjects.put(ErrorTypeRepository.class, errorTypeRepository);
        injectableObjects.put(ExtendedExpressionManager.class, muleContext.getExpressionManager());
        injectableObjects.put(StreamingManager.class, muleContext.getRegistry().lookupObject(StreamingManager.class));
        injectableObjects.put(ObjectStoreManager.class, muleContext.getRegistry().lookupObject(OBJECT_STORE_MANAGER));
        injectableObjects.put(NotificationDispatcher.class, muleContext.getRegistry().lookupObject(NotificationDispatcher.class));
        injectableObjects.put(NotificationListenerRegistry.class, notificationListenerRegistry);
        injectableObjects.put(ConfigurationComponentLocator.class, configurationComponentLocator);
        injectableObjects.put(ConfigurationProperties.class, configProps);
        // Ensure injection of consistent mock objects
        when(muleContext.getInjector()).thenReturn(new MocksInjector(injectableObjects));
    } catch (RegistrationException e1) {
        throw new MuleRuntimeException(e1);
    }
    return muleContext;
}
Also used : RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) SimpleUnitTestSupportSchedulerService(org.mule.tck.SimpleUnitTestSupportSchedulerService) SchedulerService(org.mule.runtime.api.scheduler.SchedulerService) HashMap(java.util.HashMap) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) NotificationDispatcher(org.mule.runtime.api.notification.NotificationDispatcher) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) ConfigurationProperties(org.mule.runtime.api.component.ConfigurationProperties) ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) StreamingManager(org.mule.runtime.core.api.streaming.StreamingManager) NotificationListenerRegistry(org.mule.runtime.api.notification.NotificationListenerRegistry) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ConfigurationComponentLocator(org.mule.runtime.api.component.location.ConfigurationComponentLocator) SimpleUnitTestSupportSchedulerService(org.mule.tck.SimpleUnitTestSupportSchedulerService) Location(org.mule.runtime.api.component.location.Location)

Example 64 with MuleRuntimeException

use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.

the class MVELExpressionLanguageTestCase method createEvent.

protected PrivilegedEvent createEvent(String payload, DataType dataType, Object attributes, DataType attributesDataType) {
    InternalMessage message = mock(InternalMessage.class);
    when(message.getPayload()).thenReturn(new TypedValue<>(payload, dataType));
    when(message.getAttributes()).thenReturn(new TypedValue<>(attributes, attributesDataType));
    try {
        return this.<PrivilegedEvent.Builder>getEventBuilder().message(message).build();
    } catch (MuleException e) {
        throw new MuleRuntimeException(e);
    }
}
Also used : InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleException(org.mule.runtime.api.exception.MuleException)

Example 65 with MuleRuntimeException

use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.

the class SingleResourceTransactionFactoryManager method getTransactionFactoryFor.

public TransactionFactory getTransactionFactoryFor(Class type) {
    TransactionFactory transactionFactory = transactionFactoriesCache.get(type);
    if (transactionFactory == null) {
        for (Class transactionResourceType : transactionFactories.keySet()) {
            if (transactionResourceType.isAssignableFrom(type)) {
                transactionFactory = transactionFactories.get(transactionResourceType);
                this.transactionFactoriesCache.put(type, transactionFactory);
                break;
            }
        }
    }
    if (transactionFactory == null) {
        throw new MuleRuntimeException(CoreMessages.createStaticMessage(String.format("No %s for transactional resource %s", TransactionFactory.class.getName(), type.getName())));
    }
    return transactionFactory;
}
Also used : TransactionFactory(org.mule.runtime.core.api.transaction.TransactionFactory) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException)

Aggregations

MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)123 IOException (java.io.IOException)22 List (java.util.List)22 MuleException (org.mule.runtime.api.exception.MuleException)22 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)22 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)22 Map (java.util.Map)20 Optional (java.util.Optional)20 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)18 ArrayList (java.util.ArrayList)17 String.format (java.lang.String.format)16 File (java.io.File)15 HashMap (java.util.HashMap)15 HashSet (java.util.HashSet)13 Set (java.util.Set)13 Collectors.toList (java.util.stream.Collectors.toList)12 ConfigurationException (org.mule.runtime.core.api.config.ConfigurationException)12 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)10 Collections.emptyMap (java.util.Collections.emptyMap)9 Optional.empty (java.util.Optional.empty)9