use of org.mule.runtime.api.i18n.I18nMessage 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.i18n.I18nMessage in project mule by mulesoft.
the class AbstractTransformer method transform.
@Override
public Object transform(Object src, Charset enc) throws TransformerException {
Object payload = src;
DataType sourceType;
if (src instanceof Message) {
Message message = (Message) src;
if ((!isSourceDataTypeSupported(DataType.MULE_MESSAGE, true) && !(this instanceof AbstractMessageTransformer))) {
payload = message.getPayload().getValue();
sourceType = message.getPayload().getDataType();
} else {
sourceType = DataType.fromObject(payload);
}
} else {
sourceType = DataType.fromObject(payload);
}
if (!isSourceDataTypeSupported(sourceType)) {
I18nMessage msg = transformOnObjectUnsupportedTypeOfEndpoint(getName(), payload.getClass());
// / FIXME
throw new TransformerException(msg, this);
}
if (logger.isDebugEnabled()) {
logger.debug(format("Applying transformer %s (%s)", getName(), getClass().getName()));
logger.debug(format("Object before transform: %s", StringMessageUtils.toString(payload)));
}
Object result = doTransform(payload, enc);
if (logger.isDebugEnabled()) {
logger.debug(format("Object after transform: %s", StringMessageUtils.toString(result)));
}
checkTransformerReturnClass(this, result);
return result;
}
use of org.mule.runtime.api.i18n.I18nMessage in project mule by mulesoft.
the class AbstractMessageTransformer method transform.
@Override
public final Object transform(Object src, Charset enc, CoreEvent event) throws MessageTransformerException {
DataType sourceType = DataType.fromType(src.getClass());
if (!isSourceDataTypeSupported(sourceType)) {
if (isIgnoreBadInput()) {
logger.debug("Source type is incompatible with this transformer and property 'ignoreBadInput' is set to true, so the transformer chain will continue.");
return src;
} else {
I18nMessage msg = CoreMessages.transformOnObjectUnsupportedTypeOfEndpoint(getName(), src.getClass());
throw new MessageTransformerException(msg, this, event.getMessage());
}
}
if (logger.isDebugEnabled()) {
logger.debug(format("Applying transformer %s (%s)", getName(), getClass().getName()));
logger.debug(format("Object before transform: %s", StringMessageUtils.toString(src)));
}
Message message;
if (src instanceof Message) {
message = (Message) src;
} else // TODO MULE-9342 Clean up transformer vs message transformer confusion
if (src instanceof CoreEvent) {
event = (CoreEvent) src;
message = event.getMessage();
} else if (muleContext.getConfiguration().isAutoWrapMessageAwareTransform()) {
message = of(src);
} else {
if (event == null) {
throw new MessageTransformerException(CoreMessages.noCurrentEventForTransformer(), this, null);
}
message = event.getMessage();
}
Object result;
// TODO MULE-9342 Clean up transformer vs message transformer confusion
if (event == null) {
MuleClientFlowConstruct flowConstruct = new MuleClientFlowConstruct(muleContext);
ComponentLocation location = getLocation() != null ? getLocation() : fromSingleComponent("AbstractMessageTransformer");
event = InternalEvent.builder(create(flowConstruct, location)).message(message).build();
}
result = transformMessage(event, enc);
if (logger.isDebugEnabled()) {
logger.debug(format("Object after transform: %s", StringMessageUtils.toString(result)));
}
result = checkReturnClass(result, event);
return result;
}
use of org.mule.runtime.api.i18n.I18nMessage in project mule by mulesoft.
the class PropertiesUtils method loadProperties.
public static Properties loadProperties(InputStream is) throws IOException {
if (is == null) {
I18nMessage error = CoreMessages.objectIsNull("input stream");
throw new IOException(error.toString());
}
try {
Properties props = new Properties();
props.load(is);
return props;
} finally {
is.close();
}
}
use of org.mule.runtime.api.i18n.I18nMessage in project mule by mulesoft.
the class MuleContainer method shutdown.
/**
* Will shut down the server displaying the cause and time of the shutdown
*
* @param e the exception that caused the shutdown
*/
public void shutdown(Throwable e) throws MuleException {
I18nMessage msg = fatalErrorWhileRunning();
MuleException muleException = getRootMuleException(e);
if (muleException != null) {
logger.error(muleException.getDetailedMessage());
} else {
logger.error(msg.toString() + " " + e.getMessage(), e);
}
List<String> msgs = new ArrayList<>();
msgs.add(msg.getMessage());
Throwable root = getRootException(e);
msgs.add(root.getMessage() + " (" + root.getClass().getName() + ")");
msgs.add(" ");
msgs.add(fatalErrorInShutdown().getMessage());
String shutdownMessage = getBoilerPlate(msgs, '*', 80);
logger.error(shutdownMessage);
doShutdown();
System.exit(1);
}
Aggregations