use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class AutoConfigurationBuilder method autoConfigure.
protected void autoConfigure(MuleContext muleContext, ConfigResource[] resources) throws ConfigurationException {
Map<String, List<ConfigResource>> configsMap = new LinkedHashMap<String, List<ConfigResource>>();
for (ConfigResource resource : resources) {
String configExtension = substringAfterLast(resource.getUrl().getPath(), ".");
List<ConfigResource> configs = configsMap.get(configExtension);
if (configs == null) {
configs = new ArrayList<ConfigResource>();
configsMap.put(configExtension, configs);
}
configs.add(resource);
}
try {
Properties props = loadProperties(getResource("configuration-builders.properties", this.getClass()).openStream());
for (Map.Entry<String, List<ConfigResource>> e : configsMap.entrySet()) {
String extension = e.getKey();
List<ConfigResource> configs = e.getValue();
String className = (String) props.get(extension);
if (className == null || !ClassUtils.isClassOnPath(className, this.getClass())) {
throw new ConfigurationException(configurationBuilderNoMatching(createConfigResourcesString()));
}
ConfigurationBuilder cb = (ConfigurationBuilder) ClassUtils.instantiateClass(className, new Object[] { configs.stream().map(ConfigResource::getResourceName).toArray(String[]::new), getArtifactProperties(), artifactType });
if (parentContext != null && cb instanceof ParentMuleContextAwareConfigurationBuilder) {
((ParentMuleContextAwareConfigurationBuilder) cb).setParentContext(parentContext);
} else if (parentContext != null) {
throw new MuleRuntimeException(createStaticMessage(format("ConfigurationBuilder %s does not support domain context", cb.getClass().getCanonicalName())));
}
cb.configure(muleContext);
}
} catch (ConfigurationException e) {
throw e;
} catch (Exception e) {
throw new ConfigurationException(e);
}
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class PropertiesUtils method loadAllProperties.
/**
* Load all properties files in the classpath with the given properties file name.
*/
public static Properties loadAllProperties(String fileName, ClassLoader classLoader) {
Properties p = new Properties();
List<URL> resourcesUrl = new ArrayList<>();
Enumeration<URL> resources;
try {
resources = classLoader.getResources(fileName);
while (resources.hasMoreElements()) {
resourcesUrl.add(resources.nextElement());
}
Collections.sort(resourcesUrl, (url, url1) -> {
if ("file".equals(url.getProtocol())) {
return 1;
}
return -1;
});
for (URL resourceUrl : resourcesUrl) {
InputStream in = resourceUrl.openStream();
p.load(in);
in.close();
}
} catch (IOException e) {
throw new MuleRuntimeException(CoreMessages.createStaticMessage("Failed to load resource: " + fileName), e);
}
return p;
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class StringMessageUtils method getBoilerPlate.
public static String getBoilerPlate(List<String> messages, char c, int maxlength) {
int size;
StringBuilder buf = new StringBuilder(messages.size() * maxlength);
int trimLength = maxlength - (c == ' ' ? 2 : 4);
for (int i = 0; i < messages.size(); i++) {
size = messages.get(i).toString().length();
if (size > trimLength) {
String temp = messages.get(i).toString();
int k = i;
int x;
int len;
messages.remove(i);
while (temp.length() > 0) {
len = (trimLength <= temp.length() ? trimLength : temp.length());
String msg = temp.substring(0, len);
x = msg.indexOf(lineSeparator());
if (x > -1) {
msg = msg.substring(0, x);
len = x + 1;
} else {
x = msg.lastIndexOf(' ');
if (x > -1 && len == trimLength) {
msg = msg.substring(0, x);
len = x + 1;
}
}
if (msg.startsWith(" ")) {
msg = msg.substring(1);
}
temp = temp.substring(len);
messages.add(k, msg);
k++;
}
}
}
buf.append(lineSeparator());
if (c != ' ') {
buf.append(StringUtils.repeat(c, maxlength));
}
for (int i = 0; i < messages.size(); i++) {
buf.append(lineSeparator());
if (c != ' ') {
buf.append(c);
}
buf.append(" ");
buf.append(messages.get(i));
String osEncoding = Charset.defaultCharset().name();
int padding;
try {
padding = trimLength - messages.get(i).toString().getBytes(osEncoding).length;
} catch (UnsupportedEncodingException ueex) {
throw new MuleRuntimeException(failedToConvertStringUsingEncoding(osEncoding), ueex);
}
if (padding > 0) {
buf.append(StringUtils.repeat(' ', padding));
}
buf.append(' ');
if (c != ' ') {
buf.append(c);
}
}
buf.append(lineSeparator());
if (c != ' ') {
buf.append(StringUtils.repeat(c, maxlength));
}
return buf.toString();
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class AbstractAggregator method initEventGroupsObjectStore.
protected void initEventGroupsObjectStore() throws InitialisationException {
try {
if (eventGroupsObjectStore == null) {
// TODO: Delete ProvidedObjectStoreWrapper if not needed when moving this to compatibility
eventGroupsObjectStore = new ProvidedPartitionableObjectStoreWrapper(null, internalEventsGroupsObjectStoreSupplier());
}
eventGroupsObjectStore.open(storePrefix + ".expiredAndDispatchedGroups");
eventGroupsObjectStore.open(storePrefix + ".eventGroups");
} catch (MuleRuntimeException | ObjectStoreException e) {
throw new InitialisationException(e, this);
}
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class MuleObjectStoreManager method getMonitorablePartition.
@SuppressWarnings({ "rawtypes", "unchecked" })
private <T extends ObjectStore<? extends Serializable>> T getMonitorablePartition(String name, ObjectStore baseStore, T store, ObjectStoreSettings settings) {
if (baseStore instanceof PartitionableExpirableObjectStore) {
Scheduler scheduler = schedulerService.customScheduler(muleContext.getSchedulerBaseConfig().withName("ObjectStoreManager-Monitor-" + name).withMaxConcurrentTasks(1));
scheduler.scheduleWithFixedDelay(new Monitor(name, (PartitionableExpirableObjectStore) baseStore, settings.getEntryTTL().orElse(0L), settings.getMaxEntries().orElse(UNBOUNDED)), 0, settings.getExpirationInterval(), MILLISECONDS);
expirationSchedulers.put(name, scheduler);
return store;
} else {
MonitoredObjectStoreWrapper monObjectStore;
// or putting an uninitialised ObjectStore
synchronized (this) {
monObjectStore = new MonitoredObjectStoreWrapper(store, settings);
monObjectStore.setMuleContext(muleContext);
try {
monObjectStore.initialise();
} catch (InitialisationException e) {
throw new MuleRuntimeException(e);
}
}
return (T) monObjectStore;
}
}
Aggregations