Search in sources :

Example 76 with MuleRuntimeException

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

the class AbstractQueueTxJournalEntry method write.

public void write(DataOutputStream outputStream, MuleContext muleContext) {
    try {
        serializeTxId(outputStream);
        outputStream.write(operation);
        if (isCheckpointOperation(operation)) {
            outputStream.flush();
            return;
        }
        outputStream.write(queueName.length());
        outputStream.write(queueName.getBytes());
        byte[] serializedValue = muleContext.getObjectSerializer().getInternalProtocol().serialize(value);
        outputStream.writeInt(serializedValue.length);
        outputStream.write(serializedValue);
        outputStream.flush();
    } catch (IOException e) {
        throw new MuleRuntimeException(e);
    }
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) IOException(java.io.IOException)

Example 77 with MuleRuntimeException

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

the class MuleObjectStoreManager method doCreateObjectStore.

private <T extends ObjectStore<?>> T doCreateObjectStore(String name, ObjectStoreSettings settings) {
    final ObjectStore<? extends Serializable> baseStore = getBaseStore(settings);
    T store;
    try {
        store = getPartitionFromBaseObjectStore(baseStore, name);
    } catch (Exception e) {
        throw new MuleRuntimeException(createStaticMessage("Found exception trying to create Object Store of name " + name), e);
    }
    if (settings.getExpirationInterval() > 0 && (settings.getMaxEntries().isPresent() || settings.getEntryTTL().isPresent())) {
        store = getMonitorablePartition(name, baseStore, store, settings);
    }
    return store;
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) NoSuchElementException(java.util.NoSuchElementException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException)

Example 78 with MuleRuntimeException

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

the class AbstractMessageProcessorChain method initialise.

@Override
public void initialise() throws InitialisationException {
    processorInterceptorManager.getInterceptorFactories().stream().forEach(interceptorFactory -> {
        ReactiveInterceptorAdapter reactiveInterceptorAdapter = new ReactiveInterceptorAdapter(interceptorFactory);
        try {
            muleContext.getInjector().inject(reactiveInterceptorAdapter);
        } catch (MuleException e) {
            throw new MuleRuntimeException(e);
        }
        additionalInterceptors.add(0, reactiveInterceptorAdapter);
    });
    processorInterceptorManager.getInterceptorFactories().stream().forEach(interceptorFactory -> {
        ReactiveAroundInterceptorAdapter reactiveInterceptorAdapter = new ReactiveAroundInterceptorAdapter(interceptorFactory);
        try {
            muleContext.getInjector().inject(reactiveInterceptorAdapter);
        } catch (MuleException e) {
            throw new MuleRuntimeException(e);
        }
        additionalInterceptors.add(0, reactiveInterceptorAdapter);
    });
    initialiseIfNeeded(getMessageProcessorsForLifecycle(), muleContext);
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ReactiveInterceptorAdapter(org.mule.runtime.core.internal.processor.interceptor.ReactiveInterceptorAdapter) ReactiveAroundInterceptorAdapter(org.mule.runtime.core.internal.processor.interceptor.ReactiveAroundInterceptorAdapter) MuleException(org.mule.runtime.api.exception.MuleException)

Example 79 with MuleRuntimeException

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

the class AnnotatedObjectInvocationHandler method removeDynamicAnnotations.

/**
 * Returns a newly built object containing the state of the given {@code annotated} object, but without any of its annotations.
 * <p>
 * This is useful when trying to use the base object in some scenarios where the object is introspected, to avoid the
 * dynamically added stuff to interfere with that introspection.
 * <p>
 * Note that there is no consistent state kept between the {@code annotated} and the returned objects. After calling this
 * method, the {@code annotated} object should be discarded (unless it is immutable, which wouldn't cause any problems)
 *
 * @param annotated the object to remove dynamic stuff from
 * @return a newly built object.
 */
public static <T, A> T removeDynamicAnnotations(A annotated) {
    if (annotated instanceof DynamicallyComponent) {
        Class<?> baseClass = annotated.getClass().getSuperclass();
        Map<String, Field> fieldsByName = new HashMap<>();
        Class<?> currentClass = baseClass;
        while (currentClass != Object.class) {
            Field[] targetFields = currentClass.getDeclaredFields();
            for (Field field : targetFields) {
                if (!isStatic(field.getModifiers()) && !fieldsByName.containsKey(field.getName())) {
                    fieldsByName.put(field.getName(), field);
                }
            }
            currentClass = currentClass.getSuperclass();
        }
        try {
            T base = (T) baseClass.newInstance();
            for (Field field : fieldsByName.values()) {
                boolean acc = field.isAccessible();
                field.setAccessible(true);
                try {
                    field.set(base, field.get(annotated));
                } finally {
                    field.setAccessible(acc);
                }
            }
            return base;
        } catch (Exception e) {
            throw new MuleRuntimeException(e);
        }
    } else {
        return (T) annotated;
    }
}
Also used : Field(java.lang.reflect.Field) HashMap(java.util.HashMap) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) DynamicallyComponent(org.mule.runtime.core.internal.component.DynamicallyComponent) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException)

Example 80 with MuleRuntimeException

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

the class AbstractDependencyFileBuilder method getArtifactPomFile.

public File getArtifactPomFile() {
    if (artifactPomFile == null) {
        checkArgument(!isEmpty(artifactId), "Filename cannot be empty");
        final File tempFile = new File(getTempFolder(), artifactId + ".pom");
        tempFile.deleteOnExit();
        Model model = new Model();
        model.setGroupId(getGroupId());
        model.setArtifactId(getArtifactId());
        model.setVersion(getVersion());
        model.setModelVersion("4.0.0");
        if (!sharedLibraries.isEmpty()) {
            model.setBuild(new Build());
            model.getBuild().setPlugins(singletonList(createMuleMavenPlugin()));
        }
        for (AbstractDependencyFileBuilder fileBuilderDependency : dependencies) {
            model.addDependency(fileBuilderDependency.getAsMavenDependency());
        }
        artifactPomFile = new File(tempFile.getAbsolutePath());
        try (FileOutputStream fileOutputStream = new FileOutputStream(artifactPomFile)) {
            new MavenXpp3Writer().write(fileOutputStream, model);
        } catch (IOException e) {
            throw new MuleRuntimeException(e);
        }
    }
    return artifactPomFile;
}
Also used : Build(org.apache.maven.model.Build) FileOutputStream(java.io.FileOutputStream) Model(org.apache.maven.model.Model) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) IOException(java.io.IOException) File(java.io.File) MavenXpp3Writer(org.apache.maven.model.io.xpp3.MavenXpp3Writer)

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