Search in sources :

Example 46 with MuleRuntimeException

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;
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Example 47 with MuleRuntimeException

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;
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException)

Example 48 with MuleRuntimeException

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;
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) MuleServiceModelBuilder(org.mule.runtime.api.deployment.meta.MuleServiceModel.MuleServiceModelBuilder) FileWriter(java.io.FileWriter) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) IOException(java.io.IOException) MuleServiceModelJsonSerializer(org.mule.runtime.api.deployment.persistence.MuleServiceModelJsonSerializer) File(java.io.File)

Example 49 with MuleRuntimeException

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")));
}
Also used : XmlApplicationParser(org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationParser) XmlApplicationServiceRegistry(org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationServiceRegistry) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Document(org.w3c.dom.Document) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry)

Example 50 with MuleRuntimeException

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());
}
Also used : ErrorType(org.mule.runtime.api.message.ErrorType) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier)

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