use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class LoggerContextCache method getLoggerContext.
LoggerContext getLoggerContext(final ClassLoader classLoader) {
LoggerContext ctx;
try {
final int key = computeKey(classLoader);
// If possible, avoid using Guava cache since the callable puts unwanted pressure on the garbage collector.
ctx = builtContexts.get(key);
if (ctx == null) {
synchronized (this) {
ctx = builtContexts.get(key);
if (ctx == null) {
ctx = doGetLoggerContext(classLoader, key);
}
}
}
} catch (ExecutionException e) {
throw new MuleRuntimeException(createStaticMessage("Could not init logger context "), e);
}
if (ctx.getState() == LifeCycle.State.INITIALIZED) {
synchronized (this) {
if (ctx.getState() == LifeCycle.State.INITIALIZED) {
ctx.start();
}
}
}
return ctx;
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class ModuleDelegatingEntityResolver method overrideSystemIdForCompatibility.
private String overrideSystemIdForCompatibility(String publicId, String systemId) throws SAXException, IOException {
if (systemId.equals(CORE_XSD)) {
Boolean useDeprecated = muleEntityResolver.resolveEntity(publicId, CORE_DEPRECATED_XSD) != null;
Boolean usingCompatibility = muleEntityResolver.resolveEntity(publicId, COMPATIBILITY_XSD) != null;
Boolean runningTests = isRunningTests(new Throwable().getStackTrace());
if (useDeprecated && (usingCompatibility || runningTests)) {
return CORE_DEPRECATED_XSD;
} else {
return CORE_CURRENT_XSD;
}
} else if (systemId.equals(TEST_XSD)) {
Boolean runningTests = isRunningTests(new Throwable().getStackTrace());
if (!runningTests && generateFromExtensions(publicId, systemId) == null) {
String message = "Internal runtime mule-test.xsd can't be used in real applications";
throw new MuleRuntimeException(createStaticMessage(message));
}
}
return systemId;
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class ServiceFileBuilder method createServiceJsonDescriptorFile.
private File createServiceJsonDescriptorFile() {
File serviceDescriptor = new File(getTempFolder(), getArtifactId() + "service.json");
serviceDescriptor.deleteOnExit();
MuleServiceModelBuilder serviceModelBuilder = new MuleServiceModelBuilder();
serviceModelBuilder.setName(getArtifactId()).setMinMuleVersion("4.0.0").setRequiredProduct(MULE);
serviceModelBuilder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
serviceModelBuilder.withBundleDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
serviceModelBuilder.withServiceProviderClassName(serviceProviderClassName);
String serviceDescriptorContent = new MuleServiceModelJsonSerializer().serialize(serviceModelBuilder.build());
try (FileWriter fileWriter = new FileWriter(serviceDescriptor)) {
fileWriter.write(serviceDescriptorContent);
} catch (IOException e) {
throw new MuleRuntimeException(e);
}
return serviceDescriptor;
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class DefaultXmlArtifactDeclarationLoader method loadArtifactConfig.
private ConfigLine loadArtifactConfig(String name, InputStream resource) {
checkArgument(resource != null, "The given application was not found as resource");
Document document = noValidationDocumentLoader().loadDocument(context.getExtensions(), name, resource);
return new XmlApplicationParser(new XmlApplicationServiceRegistry(new SpiServiceRegistry(), context), resolveContextArtifactPluginClassLoaders()).parse(document.getDocumentElement()).orElseThrow(() -> new MuleRuntimeException(createStaticMessage("Could not load load a Configuration from the given resource")));
}
use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.
the class BeanDefinitionFactory method resolveErrorType.
private ErrorType resolveErrorType(String representation) {
int separator = representation.indexOf(":");
String namespace;
String identifier;
if (separator > 0) {
namespace = representation.substring(0, separator).toUpperCase();
identifier = representation.substring(separator + 1).toUpperCase();
} else {
namespace = CORE_ERROR_NS;
identifier = representation.toUpperCase();
}
ComponentIdentifier errorIdentifier = ComponentIdentifier.builder().namespace(namespace).name(identifier).build();
if (CORE_ERROR_NS.equals(namespace)) {
return errorTypeRepository.lookupErrorType(errorIdentifier).orElseThrow(() -> new MuleRuntimeException(createStaticMessage(format("There's no MULE error named '%s'.", identifier))));
} else if (errorTypeRepository.getErrorNamespaces().contains(namespace) && !syntheticErrorNamespaces.contains(namespace)) {
throw new MuleRuntimeException(createStaticMessage(format("Cannot use error type '%s:%s': namespace already exists.", namespace, identifier)));
} else if (syntheticErrorNamespaces.contains(namespace)) {
Optional<ErrorType> optionalErrorType = errorTypeRepository.lookupErrorType(errorIdentifier);
if (optionalErrorType.isPresent()) {
return optionalErrorType.get();
}
} else {
syntheticErrorNamespaces.add(namespace);
}
return errorTypeRepository.addErrorType(errorIdentifier, errorTypeRepository.getAnyErrorType());
}
Aggregations