Search in sources :

Example 6 with MuleRuntimeException

use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.

the class TemplateOnErrorHandler method createErrorType.

public static ErrorTypeMatcher createErrorType(ErrorTypeRepository errorTypeRepository, String errorTypeNames) {
    if (errorTypeNames == null) {
        return null;
    }
    String[] errorTypeIdentifiers = errorTypeNames.split(",");
    List<ErrorTypeMatcher> matchers = stream(errorTypeIdentifiers).map((identifier) -> {
        String parsedIdentifier = identifier.trim();
        return new SingleErrorTypeMatcher(errorTypeRepository.lookupErrorType(buildFromStringRepresentation(parsedIdentifier)).orElseThrow(() -> new MuleRuntimeException(createStaticMessage("Could not find ErrorType for the given identifier: '%s'", parsedIdentifier))));
    }).collect(toList());
    return new DisjunctiveErrorTypeMatcher(matchers);
}
Also used : ReplyToPropertyRequestReplyReplier(org.mule.runtime.core.privileged.routing.requestreply.ReplyToPropertyRequestReplyReplier) Optional.empty(java.util.Optional.empty) MessageProcessors.newChain(org.mule.runtime.core.privileged.processor.MessageProcessors.newChain) DisjunctiveErrorTypeMatcher(org.mule.runtime.core.api.exception.DisjunctiveErrorTypeMatcher) ComponentIdentifier.buildFromStringRepresentation(org.mule.runtime.api.component.ComponentIdentifier.buildFromStringRepresentation) Exceptions.unwrap(org.mule.runtime.core.api.rx.Exceptions.unwrap) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) Processor(org.mule.runtime.core.api.processor.Processor) Function(java.util.function.Function) PROCESS_START(org.mule.runtime.api.notification.ErrorHandlerNotification.PROCESS_START) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ConfigurationComponentLocator(org.mule.runtime.api.component.location.ConfigurationComponentLocator) ErrorHandlerNotification(org.mule.runtime.api.notification.ErrorHandlerNotification) MuleContext(org.mule.runtime.core.api.MuleContext) MuleException(org.mule.runtime.api.exception.MuleException) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher) Mono.from(reactor.core.publisher.Mono.from) Mono.just(reactor.core.publisher.Mono.just) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) InternalMessage(org.mule.runtime.core.internal.message.InternalMessage) DefaultExceptionPayload(org.mule.runtime.core.internal.message.DefaultExceptionPayload) ComponentAnnotations.updateRootContainerName(org.mule.runtime.core.internal.component.ComponentAnnotations.updateRootContainerName) Optional.ofNullable(java.util.Optional.ofNullable) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) NullExceptionHandler(org.mule.runtime.core.api.exception.NullExceptionHandler) EnrichedNotificationInfo.createInfo(org.mule.runtime.api.notification.EnrichedNotificationInfo.createInfo) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) NoExtend(org.mule.api.annotation.NoExtend) TransactionCoordination(org.mule.runtime.core.api.transaction.TransactionCoordination) ProcessingStrategy(org.mule.runtime.core.api.processor.strategy.ProcessingStrategy) ErrorTypeMatcher(org.mule.runtime.core.api.exception.ErrorTypeMatcher) MessageProcessorChain(org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) MessageProcessors.processWithChildContext(org.mule.runtime.core.privileged.processor.MessageProcessors.processWithChildContext) PROCESS_END(org.mule.runtime.api.notification.ErrorHandlerNotification.PROCESS_END) Optional(java.util.Optional) TRUE(java.lang.Boolean.TRUE) Arrays.stream(java.util.Arrays.stream) MessageProcessors.getProcessingStrategy(org.mule.runtime.core.privileged.processor.MessageProcessors.getProcessingStrategy) DisjunctiveErrorTypeMatcher(org.mule.runtime.core.api.exception.DisjunctiveErrorTypeMatcher) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher) ErrorTypeMatcher(org.mule.runtime.core.api.exception.ErrorTypeMatcher) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) DisjunctiveErrorTypeMatcher(org.mule.runtime.core.api.exception.DisjunctiveErrorTypeMatcher) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher)

Example 7 with MuleRuntimeException

use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.

the class DeployableMavenClassLoaderModelLoader method exportSharedLibrariesResourcesAndPackages.

private void exportSharedLibrariesResourcesAndPackages(File applicationFolder, ClassLoaderModelBuilder classLoaderModelBuilder, Set<BundleDependency> dependencies) {
    Model model = loadPomModel(applicationFolder);
    Build build = model.getBuild();
    if (build != null) {
        List<Plugin> plugins = build.getPlugins();
        if (plugins != null) {
            Optional<Plugin> packagingPluginOptional = plugins.stream().filter(plugin -> plugin.getArtifactId().equals(MULE_MAVEN_PLUGIN_ARTIFACT_ID) && plugin.getGroupId().equals(MULE_MAVEN_PLUGIN_GROUP_ID)).findFirst();
            packagingPluginOptional.ifPresent(packagingPlugin -> {
                Object configuration = packagingPlugin.getConfiguration();
                if (configuration != null) {
                    Xpp3Dom sharedLibrariesDom = ((Xpp3Dom) configuration).getChild("sharedLibraries");
                    if (sharedLibrariesDom != null) {
                        Xpp3Dom[] sharedLibraries = sharedLibrariesDom.getChildren("sharedLibrary");
                        if (sharedLibraries != null) {
                            FileJarExplorer fileJarExplorer = new FileJarExplorer();
                            for (Xpp3Dom sharedLibrary : sharedLibraries) {
                                String groupId = getSharedLibraryAttribute(applicationFolder, sharedLibrary, "groupId");
                                String artifactId = getSharedLibraryAttribute(applicationFolder, sharedLibrary, "artifactId");
                                Optional<BundleDependency> bundleDependencyOptional = dependencies.stream().filter(bundleDependency -> bundleDependency.getDescriptor().getArtifactId().equals(artifactId) && bundleDependency.getDescriptor().getGroupId().equals(groupId)).findFirst();
                                bundleDependencyOptional.map(bundleDependency -> {
                                    JarInfo jarInfo = fileJarExplorer.explore(bundleDependency.getBundleUri());
                                    classLoaderModelBuilder.exportingPackages(jarInfo.getPackages());
                                    classLoaderModelBuilder.exportingResources(jarInfo.getResources());
                                    return bundleDependency;
                                }).orElseThrow(() -> new MuleRuntimeException(I18nMessageFactory.createStaticMessage(format("Dependency %s:%s could not be found within the artifact %s. It must be declared within the maven dependencies of the artifact.", groupId, artifactId, applicationFolder.getName()))));
                            }
                        }
                    }
                }
            });
        }
    }
}
Also used : FileJarExplorer(org.mule.runtime.module.artifact.internal.util.FileJarExplorer) LoggerFactory(org.slf4j.LoggerFactory) BundleDescriptor(org.mule.runtime.module.artifact.api.descriptor.BundleDescriptor) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) Build(org.apache.maven.model.Build) MULE_MAVEN_PLUGIN_ARTIFACT_ID(org.mule.runtime.module.artifact.api.classloader.MuleMavenPlugin.MULE_MAVEN_PLUGIN_ARTIFACT_ID) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) Map(java.util.Map) Preconditions.checkState(org.mule.runtime.api.util.Preconditions.checkState) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) DOMAIN(org.mule.runtime.core.api.config.bootstrap.ArtifactType.DOMAIN) POLICY(org.mule.runtime.core.api.config.bootstrap.ArtifactType.POLICY) MULE_LOADER_ID(org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.MULE_LOADER_ID) MavenClient(org.mule.maven.client.api.MavenClient) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) INCLUDE_TEST_DEPENDENCIES(org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.INCLUDE_TEST_DEPENDENCIES) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) AbstractMavenClassLoaderModelLoader(org.mule.runtime.module.deployment.impl.internal.maven.AbstractMavenClassLoaderModelLoader) Set(java.util.Set) LocalRepositorySupplierFactory(org.mule.maven.client.api.LocalRepositorySupplierFactory) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) String.format(java.lang.String.format) File(java.io.File) I18nMessageFactory(org.mule.runtime.api.i18n.I18nMessageFactory) ArtifactType(org.mule.runtime.core.api.config.bootstrap.ArtifactType) List(java.util.List) Plugin(org.apache.maven.model.Plugin) APP(org.mule.runtime.core.api.config.bootstrap.ArtifactType.APP) MULE_MAVEN_PLUGIN_GROUP_ID(org.mule.runtime.module.artifact.api.classloader.MuleMavenPlugin.MULE_MAVEN_PLUGIN_GROUP_ID) MavenUtils.getPomModelFolder(org.mule.runtime.module.deployment.impl.internal.maven.MavenUtils.getPomModelFolder) Optional(java.util.Optional) ClassLoaderModelBuilder(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel.ClassLoaderModelBuilder) JarInfo(org.mule.runtime.module.artifact.internal.util.JarInfo) Model(org.apache.maven.model.Model) FileJarExplorer(org.mule.runtime.module.artifact.internal.util.FileJarExplorer) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) BundleDependency(org.mule.runtime.module.artifact.api.descriptor.BundleDependency) JarInfo(org.mule.runtime.module.artifact.internal.util.JarInfo) Build(org.apache.maven.model.Build) ClassLoaderModel(org.mule.runtime.module.artifact.api.descriptor.ClassLoaderModel) Model(org.apache.maven.model.Model) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Plugin(org.apache.maven.model.Plugin)

Example 8 with MuleRuntimeException

use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.

the class ApplicationPolicyDeploymentTestCase method appliesApplicationPolicyDuplicatingPluginOnDomain.

@Test
public void appliesApplicationPolicyDuplicatingPluginOnDomain() throws Exception {
    addPackedDomainFromBuilder(exceptionThrowingPluginImportingDomain);
    policyManager.registerPolicyTemplate(exceptionThrowingPluginImportingPolicyFileBuilder.getArtifactFile());
    ApplicationFileBuilder applicationFileBuilder = createExtensionApplicationWithServices(APP_WITH_EXTENSION_PLUGIN_CONFIG, helloExtensionV1Plugin).dependingOn(exceptionThrowingPluginImportingDomain);
    addPackedAppFromBuilder(applicationFileBuilder);
    startDeployment();
    assertApplicationDeploymentSuccess(applicationDeploymentListener, applicationFileBuilder.getId());
    policyManager.addPolicy(applicationFileBuilder.getId(), exceptionThrowingPluginImportingPolicyFileBuilder.getArtifactId(), new PolicyParametrization(EXCEPTION_POLICY_NAME, s -> true, 1, emptyMap(), getResourceFile("/exceptionThrowingPolicy.xml"), emptyList()));
    try {
        executeApplicationFlow("main");
        fail("Flow execution was expected to throw an exception");
    } catch (MuleRuntimeException expected) {
        assertThat(expected.getCause().getCause().getClass().getName(), is(equalTo("org.exception.CustomException")));
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) ArtifactPluginFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder) Matchers.hasItems(org.hamcrest.Matchers.hasItems) PollingProber(org.mule.tck.probe.PollingProber) Collections.singletonList(java.util.Collections.singletonList) BEFORE_NEXT(org.mule.runtime.api.notification.PolicyNotification.BEFORE_NEXT) PROCESS_END(org.mule.runtime.api.notification.PolicyNotification.PROCESS_END) TestPolicyProcessor.policyParametrization(org.mule.runtime.module.deployment.internal.TestPolicyProcessor.policyParametrization) Arrays.asList(java.util.Arrays.asList) Is.is(org.hamcrest.core.Is.is) AbstractSecurityProvider(org.mule.runtime.core.api.security.AbstractSecurityProvider) Assert.fail(org.junit.Assert.fail) PolicyFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.PolicyFileBuilder) JUnitProbe(org.mule.tck.probe.JUnitProbe) AFTER_NEXT(org.mule.runtime.api.notification.PolicyNotification.AFTER_NEXT) PolicyPointcut(org.mule.runtime.core.api.policy.PolicyPointcut) MulePluginModel(org.mule.runtime.api.deployment.meta.MulePluginModel) EXPORTED_RESOURCE_PROPERTY(org.mule.runtime.container.internal.ClasspathModuleDiscoverer.EXPORTED_RESOURCE_PROPERTY) MULE_LOADER_ID(org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.MULE_LOADER_ID) Collections.emptyList(java.util.Collections.emptyList) PolicyNotification(org.mule.runtime.api.notification.PolicyNotification) PolicyNotificationListener(org.mule.runtime.api.notification.PolicyNotificationListener) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ApplicationFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder) CompilerUtils(org.mule.tck.util.CompilerUtils) PolicyRegistrationException(org.mule.runtime.deployment.model.api.policy.PolicyRegistrationException) JAVA_LOADER_ID(org.mule.runtime.module.extension.api.loader.java.DefaultJavaExtensionModelLoader.JAVA_LOADER_ID) List(java.util.List) Matchers.equalTo(org.hamcrest.Matchers.equalTo) MULE(org.mule.runtime.api.deployment.meta.Product.MULE) PROCESS_START(org.mule.runtime.api.notification.PolicyNotification.PROCESS_START) MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) EXPORTED_RESOURCES(org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.EXPORTED_RESOURCES) BeforeClass(org.junit.BeforeClass) MulePolicyModel(org.mule.runtime.api.deployment.meta.MulePolicyModel) ArrayList(java.util.ArrayList) PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID(org.mule.runtime.module.deployment.impl.internal.policy.PropertiesBundleDescriptorLoader.PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Collections.singletonMap(java.util.Collections.singletonMap) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TestPolicyProcessor.invocationCount(org.mule.runtime.module.deployment.internal.TestPolicyProcessor.invocationCount) Collections.emptyMap(java.util.Collections.emptyMap) SecurityException(org.mule.runtime.api.security.SecurityException) XmlExtensionModelLoader(org.mule.runtime.extension.api.loader.xml.XmlExtensionModelLoader) PolicyParametrization(org.mule.runtime.core.api.policy.PolicyParametrization) JarFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.JarFileBuilder) Test(org.junit.Test) File(java.io.File) BOOTSTRAP_PROPERTIES(org.mule.runtime.core.internal.config.bootstrap.ClassLoaderRegistryBootstrapDiscoverer.BOOTSTRAP_PROPERTIES) Authentication(org.mule.runtime.api.security.Authentication) EXPORTED_PACKAGES(org.mule.runtime.deployment.model.api.artifact.ArtifactDescriptorConstants.EXPORTED_PACKAGES) RESOURCE_XML(org.mule.runtime.extension.api.loader.xml.XmlExtensionModelLoader.RESOURCE_XML) MuleArtifactLoaderDescriptorBuilder(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder) Product(org.mule.runtime.api.deployment.meta.Product) ApplicationFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) PolicyParametrization(org.mule.runtime.core.api.policy.PolicyParametrization) Test(org.junit.Test)

Example 9 with MuleRuntimeException

use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.

the class ExtensionDefinitionParser method parseCollectionParameter.

/**
 * Registers a definition for a {@link ParameterModel} which represents an {@link ArrayType}
 *
 * @param key               the key that the parsed value should have on the parsed parameter's map
 * @param name              the parameter's name
 * @param arrayType         the parameter's {@link ArrayType}
 * @param defaultValue      the parameter's default value
 * @param expressionSupport the parameter's {@link ExpressionSupport}
 * @param required          whether the parameter is required
 */
protected void parseCollectionParameter(String key, String name, ArrayType arrayType, Object defaultValue, ExpressionSupport expressionSupport, boolean required, DslElementSyntax parameterDsl, Set<ModelProperty> modelProperties) {
    parseAttributeParameter(key, name, arrayType, defaultValue, expressionSupport, required, modelProperties);
    Class<?> collectionType = ExtensionMetadataTypeUtils.getType(arrayType).orElse(null);
    if (Set.class.equals(collectionType)) {
        collectionType = HashSet.class;
    } else if (Collection.class.equals(collectionType) || Iterable.class.equals(collectionType) || collectionType == null) {
        collectionType = List.class;
    }
    final String collectionElementName = parameterDsl.getElementName();
    addParameter(getChildKey(key), fromChildConfiguration(collectionType).withWrapperIdentifier(collectionElementName));
    addDefinition(baseDefinitionBuilder.withIdentifier(collectionElementName).withTypeDefinition(fromType(collectionType)).build());
    Optional<DslElementSyntax> collectionItemDsl = parameterDsl.getGeneric(arrayType.getType());
    if (parameterDsl.supportsChildDeclaration() && collectionItemDsl.isPresent()) {
        String itemIdentifier = collectionItemDsl.get().getElementName();
        String itemNamespace = collectionItemDsl.get().getPrefix();
        arrayType.getType().accept(new BasicTypeMetadataVisitor() {

            private void addBasicTypeDefinition(MetadataType metadataType) {
                Builder itemDefinitionBuilder = baseDefinitionBuilder.withIdentifier(itemIdentifier).withNamespace(itemNamespace).withTypeDefinition(fromType(ExtensionMetadataTypeUtils.getType(metadataType).orElse(Object.class))).withTypeConverter(value -> resolverOf(name, metadataType, value, getDefaultValue(metadataType).orElse(null), getExpressionSupport(metadataType), false, emptySet()));
                addDefinition(itemDefinitionBuilder.build());
            }

            @Override
            protected void visitBasicType(MetadataType metadataType) {
                addBasicTypeDefinition(metadataType);
            }

            @Override
            public void visitDate(DateType dateType) {
                addBasicTypeDefinition(dateType);
            }

            @Override
            public void visitDateTime(DateTimeType dateTimeType) {
                addBasicTypeDefinition(dateTimeType);
            }

            @Override
            public void visitObject(ObjectType objectType) {
                if (isMap(objectType)) {
                    return;
                }
                DslElementSyntax itemDsl = collectionItemDsl.get();
                if ((itemDsl.supportsTopLevelDeclaration() || itemDsl.supportsChildDeclaration()) && !parsingContext.isRegistered(itemDsl.getElementName(), itemDsl.getPrefix())) {
                    try {
                        parsingContext.registerObjectType(itemDsl.getElementName(), itemDsl.getPrefix(), objectType);
                        new ObjectTypeParameterParser(baseDefinitionBuilder, objectType, getContextClassLoader(), dslResolver, parsingContext).parse().forEach(definition -> addDefinition(definition));
                    } catch (ConfigurationException e) {
                        throw new MuleRuntimeException(createStaticMessage("Could not create parser for collection complex type"), e);
                    }
                }
            }
        });
    }
}
Also used : InfrastructureTypeMapping.getNameMap(org.mule.runtime.module.extension.internal.loader.java.type.InfrastructureTypeMapping.getNameMap) ExpressionBasedParameterResolverValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionBasedParameterResolverValueResolver) StaticValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StaticValueResolver) KeyAttributeDefinitionPair(org.mule.runtime.dsl.api.component.KeyAttributeDefinitionPair) InfrastructureParameterModelProperty(org.mule.runtime.extension.api.property.InfrastructureParameterModelProperty) BEHAVIOUR(org.mule.runtime.api.meta.model.parameter.ParameterRole.BEHAVIOUR) ParameterRole(org.mule.runtime.api.meta.model.parameter.ParameterRole) DateTimeType(org.mule.metadata.api.model.DateTimeType) RequiredParameterValueResolverWrapper(org.mule.runtime.module.extension.internal.runtime.resolver.RequiredParameterValueResolverWrapper) Builder.fromSimpleParameter(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromSimpleParameter) QueryParameterModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.QueryParameterModelProperty) Instant.ofEpochMilli(java.time.Instant.ofEpochMilli) ArrayType(org.mule.metadata.api.model.ArrayType) Map(java.util.Map) NestableElementModelVisitor(org.mule.runtime.api.meta.model.nested.NestableElementModelVisitor) ExpressionTypedValueValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionTypedValueValueResolver) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) ModelProperty(org.mule.runtime.api.meta.model.ModelProperty) NestableElementModel(org.mule.runtime.api.meta.model.nested.NestableElementModel) ExtensionModelUtils.isContent(org.mule.runtime.extension.api.util.ExtensionModelUtils.isContent) SchedulingStrategyParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.SchedulingStrategyParsingDelegate) ExtensionMetadataTypeUtils.isMap(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.isMap) IntrospectionUtils.isTargetParameter(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.isTargetParameter) ObjectType(org.mule.metadata.api.model.ObjectType) ParameterGroupDescriptor(org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor) Set(java.util.Set) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) DateType(org.mule.metadata.api.model.DateType) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) ZoneId(java.time.ZoneId) ComponentBuildingDefinition(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition) DefaultValueResolverParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.DefaultValueResolverParsingDelegate) DateTimeParseException(java.time.format.DateTimeParseException) ObjectFieldType(org.mule.metadata.api.model.ObjectFieldType) StringType(org.mule.metadata.api.model.StringType) MetadataType(org.mule.metadata.api.model.MetadataType) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) IntrospectionUtils.getContainerName(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getContainerName) ParameterResolverValueResolverWrapper(org.mule.runtime.module.extension.internal.runtime.resolver.ParameterResolverValueResolverWrapper) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) StackedTypesModelProperty.getStackedTypesModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.stackabletypes.StackedTypesModelProperty.getStackedTypesModelProperty) NativeQueryParameterValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.NativeQueryParameterValueResolver) MetadataTypeUtils.getDefaultValue(org.mule.metadata.api.utils.MetadataTypeUtils.getDefaultValue) ExtensionsTypeLoaderFactory(org.mule.runtime.extension.api.declaration.type.ExtensionsTypeLoaderFactory) StackedTypesModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.stackabletypes.StackedTypesModelProperty) LocalDateTime(java.time.LocalDateTime) Builder.fromChildMapConfiguration(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromChildMapConfiguration) VALUE_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.VALUE_ATTRIBUTE_NAME) Supplier(java.util.function.Supplier) ObjectTypeParameterParser(org.mule.runtime.module.extension.internal.config.dsl.parameter.ObjectTypeParameterParser) ArrayList(java.util.ArrayList) TypeSafeValueResolverWrapper(org.mule.runtime.module.extension.internal.runtime.resolver.TypeSafeValueResolverWrapper) LinkedHashMap(java.util.LinkedHashMap) Calendar(java.util.Calendar) ExtensionMetadataTypeUtils.getExpressionSupport(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.getExpressionSupport) TypedInlineParameterGroupParser(org.mule.runtime.module.extension.internal.config.dsl.parameter.TypedInlineParameterGroupParser) MediaTypeValueResolverParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.MediaTypeValueResolverParsingDelegate) ConversionService(org.springframework.core.convert.ConversionService) TypeDefinition.fromType(org.mule.runtime.dsl.api.component.TypeDefinition.fromType) MuleExtensionUtils.isExpression(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.isExpression) ParameterizedModel(org.mule.runtime.api.meta.model.parameter.ParameterizedModel) ValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) ParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.ParsingDelegate) Builder.fromMultipleDefinitions(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromMultipleDefinitions) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) Reference(org.mule.runtime.api.util.Reference) DefaultObjectParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.DefaultObjectParsingDelegate) NOT_SUPPORTED(org.mule.runtime.api.meta.ExpressionSupport.NOT_SUPPORTED) JavaTypeUtils.getType(org.mule.metadata.java.api.utils.JavaTypeUtils.getType) ExtensionMetadataTypeUtils.getId(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.getId) TemplateParser(org.mule.runtime.core.privileged.util.TemplateParser) IntrospectionUtils.getMemberName(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getMemberName) Date(java.util.Date) Builder.fromChildConfiguration(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromChildConfiguration) TypeConverter(org.mule.runtime.dsl.api.component.TypeConverter) IntrospectionUtils.isLiteral(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.isLiteral) TypeDefinition.fromMapEntryType(org.mule.runtime.dsl.api.component.TypeDefinition.fromMapEntryType) ProcessorChainValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ProcessorChainValueResolver) IntrospectionUtils.isTypedValue(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.isTypedValue) TypedValueValueResolverWrapper(org.mule.runtime.module.extension.internal.runtime.resolver.TypedValueValueResolverWrapper) PoolingProfile(org.mule.runtime.api.config.PoolingProfile) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) Builder.fromChildCollectionConfiguration(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromChildCollectionConfiguration) ISODateTimeFormat(org.joda.time.format.ISODateTimeFormat) ObjectParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.ObjectParsingDelegate) Collection(java.util.Collection) REQUIRED(org.mule.runtime.api.meta.ExpressionSupport.REQUIRED) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Instant(java.time.Instant) String.format(java.lang.String.format) NestedRouteModel(org.mule.runtime.api.meta.model.nested.NestedRouteModel) List(java.util.List) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Builder(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder) CharsetValueResolverParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.CharsetValueResolverParsingDelegate) TlsContextFactory(org.mule.runtime.api.tls.TlsContextFactory) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) RetryPolicyTemplate(org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate) TypeSafeExpressionValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.TypeSafeExpressionValueResolver) KeyAttributeDefinitionPair.newBuilder(org.mule.runtime.dsl.api.component.KeyAttributeDefinitionPair.newBuilder) Builder.fromSimpleReferenceParameter(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromSimpleReferenceParameter) HashMap(java.util.HashMap) Processor(org.mule.runtime.core.api.processor.Processor) Builder.fromFixedValue(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromFixedValue) ConcurrentMap(java.util.concurrent.ConcurrentMap) ValueResolverParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.ValueResolverParsingDelegate) HashSet(java.util.HashSet) ExtensionMetadataTypeUtils.isFlattenedParameterGroup(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.isFlattenedParameterGroup) ImmutableList(com.google.common.collect.ImmutableList) Literal(org.mule.runtime.extension.api.runtime.parameter.Literal) BasicTypeMetadataVisitor(org.mule.metadata.api.visitor.BasicTypeMetadataVisitor) ParameterGroupModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty) ExclusiveOptionalModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ExclusiveOptionalModelProperty) Collections.emptyMap(java.util.Collections.emptyMap) Collections.emptySet(java.util.Collections.emptySet) NameUtils.hyphenize(org.mule.runtime.extension.api.util.NameUtils.hyphenize) IntrospectionUtils.isParameterResolver(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.isParameterResolver) ExpressionSupport(org.mule.runtime.api.meta.ExpressionSupport) NestedChainModel(org.mule.runtime.api.meta.model.nested.NestedChainModel) DateTime(org.joda.time.DateTime) AttributeDefinition(org.mule.runtime.dsl.api.component.AttributeDefinition) AnonymousInlineParameterGroupParser(org.mule.runtime.module.extension.internal.config.dsl.parameter.AnonymousInlineParameterGroupParser) Collectors.toList(java.util.stream.Collectors.toList) ExtensionMetadataTypeUtils(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils) RouteComponentParser(org.mule.runtime.module.extension.internal.config.dsl.construct.RouteComponentParser) FixedTypeParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.FixedTypeParsingDelegate) NestedComponentModel(org.mule.runtime.api.meta.model.nested.NestedComponentModel) TopLevelParameterObjectFactory(org.mule.runtime.module.extension.internal.config.dsl.parameter.TopLevelParameterObjectFactory) ImplementingTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty) StaticLiteralValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StaticLiteralValueResolver) ObjectTypeParameterParser(org.mule.runtime.module.extension.internal.config.dsl.parameter.ObjectTypeParameterParser) Builder(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder) KeyAttributeDefinitionPair.newBuilder(org.mule.runtime.dsl.api.component.KeyAttributeDefinitionPair.newBuilder) MetadataType(org.mule.metadata.api.model.MetadataType) BasicTypeMetadataVisitor(org.mule.metadata.api.visitor.BasicTypeMetadataVisitor) ObjectType(org.mule.metadata.api.model.ObjectType) DateTimeType(org.mule.metadata.api.model.DateTimeType) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) DateType(org.mule.metadata.api.model.DateType)

Example 10 with MuleRuntimeException

use of org.mule.runtime.api.exception.MuleRuntimeException in project mule by mulesoft.

the class BaseExtensionResourcesGeneratorAnnotationProcessor method process.

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    log("Starting Resources generator for Extensions");
    ResourcesGenerator generator = new AnnotationProcessorResourceGenerator(fetchResourceFactories(), processingEnv);
    try {
        getExtension(roundEnv).ifPresent(extensionElement -> {
            if (!shouldProcess(extensionElement, processingEnv)) {
                return;
            }
            Optional<Class<Object>> annotatedClass = processor.classFor(extensionElement, processingEnv);
            ExtensionElement extension = toExtensionElement(extensionElement, processingEnv);
            ClassLoader classLoader = annotatedClass.map(Class::getClassLoader).orElseGet(ExtensionModel.class::getClassLoader);
            withContextClassLoader(classLoader, () -> {
                ExtensionModel extensionModel = parseExtension(extensionElement, extension, roundEnv, classLoader);
                generator.generateFor(extensionModel);
            });
        });
        return false;
    } catch (MuleRuntimeException e) {
        Optional<IllegalModelDefinitionException> exception = extractOfType(e, IllegalModelDefinitionException.class);
        if (exception.isPresent()) {
            throw exception.get();
        }
        processingEnv.getMessager().printMessage(ERROR, format("%s\n%s", e.getMessage(), getStackTrace(e)));
        throw e;
    }
}
Also used : IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) Optional(java.util.Optional) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ResourcesGenerator(org.mule.runtime.extension.api.resources.ResourcesGenerator) ExtensionElement(org.mule.runtime.module.extension.api.loader.java.type.ExtensionElement) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader)

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