use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.
the class LifecycleUtils method initialiseIfNeeded.
/**
* The same as {@link #initialiseIfNeeded(Object)}, only that before checking for {@code object} being {@link Initialisable}, it
* uses the given {@code muleContext} to perform further initialization.
* <p>
* It checks if the {@code object} implements {@link MuleContextAware}, in which case it will invoke
* {@link MuleContextAware#setMuleContext(MuleContext)} with the given {@code muleContext}.
* <p>
* Also depending on the value of the {@code inject} argument, it will perform dependency injection on the {@code object}
*
* @param object the object you're trying to initialise
* @param inject whether it should perform dependency injection on the {@code object} before actually initialising it
* @param muleContext a {@link MuleContext}
* @throws InitialisationException
* @throws IllegalArgumentException if {@code MuleContext} is {@code null}
*/
public static void initialiseIfNeeded(Object object, boolean inject, MuleContext muleContext) throws InitialisationException {
checkArgument(muleContext != null, "muleContext cannot be null");
object = unwrap(object);
if (object == null) {
return;
}
if (object instanceof MuleContextAware) {
((MuleContextAware) object).setMuleContext(muleContext);
}
if (inject) {
try {
muleContext.getInjector().inject(object);
} catch (MuleException e) {
I18nMessage message = createStaticMessage(format("Found exception trying to inject object of type '%s' on initialising phase", object.getClass().getName()));
if (object instanceof Initialisable) {
throw new InitialisationException(message, e, (Initialisable) object);
}
throw new MuleRuntimeException(message, e);
}
}
initialiseIfNeeded(object);
}
use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.
the class SecurityFilterMessageProcessor method initialise.
@Override
public void initialise() throws InitialisationException {
try {
muleContext.getInjector().inject(filter);
initialiseIfNeeded(filter, muleContext);
} catch (MuleException e) {
throw new InitialisationException(e, this);
}
}
use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.
the class IdempotentRedeliveryPolicy method process.
@Override
public CoreEvent process(CoreEvent event) throws MuleException {
Optional<Exception> exceptionSeen = empty();
String messageId = null;
try {
messageId = getIdForEvent(event);
} catch (ExpressionRuntimeException e) {
logger.warn("The message cannot be processed because the digest could not be generated. Either make the payload serializable or use an expression.");
return null;
} catch (Exception ex) {
exceptionSeen = of(ex);
}
Lock lock = lockFactory.createLock(idrId + "-" + messageId);
lock.lock();
try {
RedeliveryCounter counter = findCounter(messageId);
if (exceptionSeen.isPresent()) {
throw new MessageRedeliveredException(messageId, counter.counter.get(), maxRedeliveryCount, exceptionSeen.get());
} else if (counter != null && counter.counter.get() > maxRedeliveryCount) {
throw new MessageRedeliveredException(messageId, counter.errors, counter.counter.get(), maxRedeliveryCount);
}
try {
CoreEvent returnEvent = processNext(CoreEvent.builder(DefaultEventContext.child((BaseEventContext) event.getContext(), empty()), event).build());
counter = findCounter(messageId);
if (counter != null) {
resetCounter(messageId);
}
return returnEvent;
} catch (Exception ex) {
if (ex instanceof MessagingException) {
incrementCounter(messageId, (MessagingException) ex);
throw ex;
} else {
MessagingException me = createMessagingException(event, ex, this);
incrementCounter(messageId, me);
throw ex;
}
}
} finally {
lock.unlock();
}
}
use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.
the class AbstractOutboundRouter method process.
@Override
public CoreEvent process(final CoreEvent event) throws MuleException {
ExecutionTemplate<CoreEvent> executionTemplate = createTransactionalExecutionTemplate(muleContext, getTransactionConfig());
ExecutionCallback<CoreEvent> processingCallback = () -> {
try {
return route(event);
} catch (RoutingException e1) {
throw e1;
} catch (Exception e2) {
throw new RoutingException(AbstractOutboundRouter.this, e2);
}
};
try {
return executionTemplate.execute(processingCallback);
} catch (MuleException e) {
throw e;
} catch (Exception e) {
throw new DefaultMuleException(e);
}
}
use of org.mule.runtime.api.exception.MuleException in project mule by mulesoft.
the class DefaultMuleApplication method stop.
@Override
public void stop() {
if (this.artifactContext == null || !this.artifactContext.getMuleContext().getLifecycleManager().isDirectTransition(Stoppable.PHASE_NAME)) {
return;
}
if (this.artifactContext == null) {
withContextClassLoader(null, () -> {
// app never started, maybe due to a previous error
if (logger.isInfoEnabled()) {
logger.info(format("Stopping app '%s' with no mule context", descriptor.getName()));
}
});
status = ApplicationStatus.STOPPED;
return;
}
artifactContext.getMuleContext().getLifecycleManager().checkPhase(Stoppable.PHASE_NAME);
try {
withContextClassLoader(null, () -> {
if (logger.isInfoEnabled()) {
logger.info(miniSplash(format("Stopping app '%s'", descriptor.getName())));
}
});
this.artifactContext.getMuleContext().stop();
} catch (MuleException e) {
throw new DeploymentStopException(createStaticMessage(format("Error stopping application '%s'", descriptor.getName())), e);
}
}
Aggregations