use of org.mule.runtime.api.artifact.Registry in project mule by mulesoft.
the class DefaultApplicationPolicyInstanceTestCase method correctArtifactTypeForPolicies.
@Test
@Issue("MULE-14289")
@Ignore("MULE-14289: The discovered ArtifactConfigurationProcessor is not compatible with the provided mocks.")
public void correctArtifactTypeForPolicies() throws InitialisationException {
MuleContextListener muleContextListener = mock(MuleContextListener.class);
ArgumentCaptor<MuleContext> muleContextCaptor = ArgumentCaptor.forClass(MuleContext.class);
PolicyTemplate policyTemplate = mock(PolicyTemplate.class, RETURNS_DEEP_STUBS);
when(policyTemplate.getArtifactClassLoader().getClassLoader()).thenReturn(this.getClass().getClassLoader());
Application application = mock(Application.class, RETURNS_DEEP_STUBS);
Registry registry = application.getRegistry();
doReturn(of(mockContextWithServices())).when(registry).lookupByType(MuleContext.class);
doReturn(of(mock(ExtensionManager.class))).when(registry).lookupByName(OBJECT_EXTENSION_MANAGER);
PolicyParametrization parameterization = mock(PolicyParametrization.class, RETURNS_DEEP_STUBS);
when(parameterization.getId()).thenReturn("policyId");
DefaultApplicationPolicyInstance applicationPolicyInstance = new DefaultApplicationPolicyInstance(application, policyTemplate, parameterization, mock(ServiceRepository.class), mock(ClassLoaderRepository.class), emptyList(), mock(ExtensionModelLoaderRepository.class), muleContextListener);
applicationPolicyInstance.initialise();
verify(muleContextListener).onCreation(muleContextCaptor.capture());
assertThat(muleContextCaptor.getValue().getArtifactType(), is(POLICY));
}
use of org.mule.runtime.api.artifact.Registry in project mule by mulesoft.
the class DefaultApplicationPolicyInstance method initPolicyContext.
private void initPolicyContext() throws InitialisationException {
ArtifactContextBuilder artifactBuilder = newBuilder().setArtifactType(POLICY).setArtifactProperties(new HashMap<>(parametrization.getParameters())).setArtifactName(parametrization.getId()).setConfigurationFiles(parametrization.getConfig().getAbsolutePath()).setExecutionClassloader(template.getArtifactClassLoader().getClassLoader()).setServiceRepository(serviceRepository).setClassLoaderRepository(classLoaderRepository).setArtifactPlugins(artifactPlugins).setParentArtifact(application).setExtensionManagerFactory(new CompositeArtifactExtensionManagerFactory(application, extensionModelLoaderRepository, artifactPlugins, new DefaultExtensionManagerFactory())).setMuleContextListener(muleContextListener);
artifactBuilder.withServiceConfigurator(customizationService -> {
Registry applicationRegistry = application.getRegistry();
/*
* OBJECT_POLICY_MANAGER_STATE_HANDLER is not proxied as it doesn't implement any lifecycle interfaces (Startable, Stoppable
* or Disposable)
*/
customizationService.overrideDefaultServiceImpl(OBJECT_POLICY_MANAGER_STATE_HANDLER, applicationRegistry.lookupByName(OBJECT_POLICY_MANAGER_STATE_HANDLER).get());
customizationService.overrideDefaultServiceImpl(OBJECT_LOCK_PROVIDER, createLifecycleFilterProxy(applicationRegistry.lookupByName(OBJECT_LOCK_PROVIDER).get()));
customizationService.overrideDefaultServiceImpl(BASE_PERSISTENT_OBJECT_STORE_KEY, createLifecycleFilterProxy(applicationRegistry.lookupByName(BASE_PERSISTENT_OBJECT_STORE_KEY).get()));
customizationService.overrideDefaultServiceImpl(BASE_IN_MEMORY_OBJECT_STORE_KEY, createLifecycleFilterProxy(applicationRegistry.lookupByName(BASE_IN_MEMORY_OBJECT_STORE_KEY).get()));
customizationService.overrideDefaultServiceImpl(OBJECT_TIME_SUPPLIER, createLifecycleFilterProxy(applicationRegistry.lookupByName(OBJECT_TIME_SUPPLIER).get()));
applicationRegistry.lookupByName(CLUSTER_MANAGER_ID).ifPresent(muleClusterManager -> customizationService.registerCustomServiceImpl(CLUSTER_MANAGER_ID, createLifecycleFilterProxy(muleClusterManager)));
});
try {
policyContext = artifactBuilder.build();
enableNotificationListeners(parametrization.getNotificationListeners());
policyContext.getMuleContext().start();
} catch (MuleException e) {
throw new InitialisationException(createStaticMessage("Cannot create artifact context for the policy instance"), e, this);
}
}
use of org.mule.runtime.api.artifact.Registry in project mule by mulesoft.
the class SoapOperationExecutor method execute.
/**
* {@inheritDoc}
*/
@Override
public Publisher<Object> execute(ExecutionContext<OperationModel> context) {
try {
String serviceId = context.getParameter(SERVICE_PARAM);
ForwardingSoapClient connection = (ForwardingSoapClient) connectionResolver.resolve(context).get();
Map<String, String> customHeaders = connection.getCustomHeaders(serviceId, getOperation(context));
SoapRequest request = getRequest(context, customHeaders);
SoapClient soapClient = connection.getSoapClient(serviceId);
SoapResponse response = connection.getExtensionsClientDispatcher(() -> new ExtensionsClientArgumentResolver(registry, policyManager).resolve(context).get()).map(d -> soapClient.consume(request, d)).orElseGet(() -> soapClient.consume(request));
return justOrEmpty(response.getAsResult(streamingHelperArgumentResolver.resolve(context).get()));
} catch (MessageTransformerException | TransformerException e) {
return error(e);
} catch (Exception e) {
return error(soapExceptionEnricher.enrich(e));
} catch (Throwable t) {
return error(wrapFatal(t));
}
}
use of org.mule.runtime.api.artifact.Registry in project mule by mulesoft.
the class MuleArtifactContext method createApplicationComponents.
/**
* Creates te definition for all the objects to be created form the enabled components in the {@code applicationModel}.
*
* @param beanFactory the bean factory in which definition must be created.
* @param applicationModel the artifact application model.
* @param mustBeRoot if the component must be root to be created.
* @return an order list of the created bean names. The order must be respected for the creation of the objects.
*/
protected List<String> createApplicationComponents(DefaultListableBeanFactory beanFactory, ApplicationModel applicationModel, boolean mustBeRoot) {
// This should only be done once at the initial application model creation, called from Spring
List<Pair<ComponentModel, Optional<String>>> objectProvidersByName = lookObjectProvidersComponentModels(applicationModel);
List<String> createdComponentModels = new ArrayList<>();
applicationModel.executeOnEveryMuleComponentTree(cm -> {
SpringComponentModel componentModel = (SpringComponentModel) cm;
if (!mustBeRoot || componentModel.isRoot()) {
if (componentModel.getIdentifier().equals(MULE_IDENTIFIER) || componentModel.getIdentifier().equals(MULE_DOMAIN_IDENTIFIER) || componentModel.getIdentifier().equals(MULE_EE_DOMAIN_IDENTIFIER)) {
return;
}
SpringComponentModel parentComponentModel = componentModel.getParent() != null ? (SpringComponentModel) componentModel.getParent() : (SpringComponentModel) applicationModel.getRootComponentModel();
if (componentModel.isEnabled()) {
if (componentModel.getNameAttribute() != null && componentModel.isRoot()) {
createdComponentModels.add(componentModel.getNameAttribute());
}
beanDefinitionFactory.resolveComponentRecursively(parentComponentModel, componentModel, beanFactory, (resolvedComponentModel, registry) -> {
SpringComponentModel resolvedSpringComponentModel = (SpringComponentModel) resolvedComponentModel;
if (resolvedComponentModel.isRoot()) {
String nameAttribute = resolvedComponentModel.getNameAttribute();
if (resolvedComponentModel.getIdentifier().equals(CONFIGURATION_IDENTIFIER)) {
nameAttribute = OBJECT_MULE_CONFIGURATION;
} else if (nameAttribute == null) {
// This may be a configuration that does not requires a name.
nameAttribute = uniqueValue(resolvedSpringComponentModel.getBeanDefinition().getBeanClassName());
}
registry.registerBeanDefinition(nameAttribute, resolvedSpringComponentModel.getBeanDefinition());
postProcessBeanDefinition(componentModel, registry, nameAttribute);
}
}, null, componentLocator);
} else {
beanDefinitionFactory.resolveComponentRecursively(parentComponentModel, componentModel, beanFactory, null, null, componentLocator);
}
componentLocator.addComponentLocation(cm.getComponentLocation());
}
});
this.objectProviders.addAll(objectProvidersByName.stream().map(pair -> (ConfigurableObjectProvider) pair.getFirst().getObjectInstance()).collect(toList()));
registerObjectFromObjectProviders(beanFactory);
Set<String> alwaysEnabledComponents = dependencyResolver.resolveAlwaysEnabledComponents().stream().map(dependencyNode -> dependencyNode.getComponentName()).collect(toSet());
Set<String> objectProviderNames = objectProvidersByName.stream().map(Pair::getSecond).filter(Optional::isPresent).map(Optional::get).collect(toSet());
// Put object providers first, then always enabled components, then the rest
createdComponentModels.sort(Comparator.comparing(beanName -> {
if (objectProviderNames.contains(beanName)) {
return 1;
} else if (alwaysEnabledComponents.contains(beanName)) {
return 2;
} else {
return 3;
}
}));
return createdComponentModels;
}
use of org.mule.runtime.api.artifact.Registry in project mule by mulesoft.
the class FlowProcessingPhaseTestCase method before.
@Before
public void before() {
when(notificationManager.isNotificationEnabled(any(Class.class))).thenReturn(true);
when(muleContext.getNotificationManager()).thenReturn(notificationManager);
phase.setMuleContext(muleContext);
Registry registry = mock(Registry.class);
when(registry.lookupByName(any())).thenReturn(of(this.flowConstruct));
phase.setRegistry(registry);
ComponentLocation mockComponentLocation = mock(ComponentLocation.class);
when(mockComponentLocation.getRootContainerName()).thenReturn("root");
when(messageSource.getLocation()).thenReturn(mockComponentLocation);
when(mockContext.getTransactionConfig()).thenReturn(empty());
when(mockContext.getMessageSource()).thenReturn(messageSource);
}
Aggregations