use of org.mule.runtime.policy.api.PolicyPointcutParameters in project mule by mulesoft.
the class DefaultPolicyManager method createOperationPolicy.
@Override
public OperationPolicy createOperationPolicy(Component operation, CoreEvent event, Map<String, Object> operationParameters, OperationExecutionFunction operationExecutionFunction) {
PolicyPointcutParameters operationPointcutParameters = policyPointcutParametersManager.createOperationPointcutParameters(operation, event, operationParameters);
List<Policy> parameterizedPolicies = policyProvider.findOperationParameterizedPolicies(operationPointcutParameters);
if (parameterizedPolicies.isEmpty()) {
return (operationEvent) -> operationExecutionFunction.execute(operationParameters, operationEvent);
}
return new CompositeOperationPolicy(parameterizedPolicies, lookupOperationParametersTransformer(operation.getLocation().getComponentIdentifier().getIdentifier()), operationPolicyProcessorFactory, () -> operationParameters, operationExecutionFunction, streamingManager);
}
use of org.mule.runtime.policy.api.PolicyPointcutParameters in project mule by mulesoft.
the class PolicyPointcutParametersManager method createOperationPointcutParameters.
/**
* Creates {@link PolicyPointcutParameters} for a specific operation. Stored parameters from the source are included in the
* newly created parameters to be able to correlate parameters from both source and operation.
*
* @param operation the operation component to which policies will be applied
* @param event the event which will execute the operation policies
* @param operationParameters a map containing the parameters of the operation
* @return the created {@link PolicyPointcutParameters}
*/
public PolicyPointcutParameters createOperationPointcutParameters(Component operation, CoreEvent event, Map<String, Object> operationParameters) {
ComponentIdentifier operationIdentifier = operation.getLocation().getComponentIdentifier().getIdentifier();
PolicyPointcutParameters sourceParameters = sourceParametersMap.get(event.getContext().getCorrelationId());
OperationPolicyPointcutParametersParameters parameters = new OperationPolicyPointcutParametersParameters(operation, operationParameters, sourceParameters);
Function<OperationPolicyPointcutParametersFactory, PolicyPointcutParameters> creationFunction = factory -> {
try {
return factory.createPolicyPointcutParameters(parameters);
} catch (AbstractMethodError error) {
return factory.createPolicyPointcutParameters(parameters.getOperation(), parameters.getOperationParameters());
}
};
return createPointcutParameters(operation, OperationPolicyPointcutParametersFactory.class, operationPointcutFactories, factory -> factory.supportsOperationIdentifier(operationIdentifier), creationFunction).orElse(new PolicyPointcutParameters(operation, sourceParameters));
}
use of org.mule.runtime.policy.api.PolicyPointcutParameters in project mule by mulesoft.
the class PolicyPointcutParametersManagerTestCase method createOperationParametersWhenOneFactorySupportsIdentifier.
@Test
public void createOperationParametersWhenOneFactorySupportsIdentifier() {
Map<String, Object> operationParameters = new HashMap<>();
PolicyPointcutParameters sourceParameters = parametersManager.createSourcePointcutParameters(component, event);
OperationPolicyPointcutParametersFactory factory = mockOperationFactory(true, sourceParameters);
operationPointcutFactories.add(factory);
sourcePointcutFactories.add(mockSourceFactory(true));
PolicyPointcutParameters parameters = parametersManager.createOperationPointcutParameters(component, event, operationParameters);
assertThat(parameters.getComponent(), is(component));
assertThat(parameters.getSourceParameters(), is(of(sourceParameters)));
verify(factory).supportsOperationIdentifier(identifier);
verify(factory).createPolicyPointcutParameters(any());
}
use of org.mule.runtime.policy.api.PolicyPointcutParameters in project mule by mulesoft.
the class PolicyPointcutParametersManagerTestCase method createOperationParametersFallbacksToDeprecatedMethod.
@Test
public void createOperationParametersFallbacksToDeprecatedMethod() {
Map<String, Object> operationParameters = new HashMap<>();
PolicyPointcutParameters sourceParameters = parametersManager.createSourcePointcutParameters(component, event);
OperationPolicyPointcutParametersFactory factory = mockOperationFactory(true, sourceParameters);
PolicyPointcutParameters parameters = mock(PolicyPointcutParameters.class);
when(factory.createPolicyPointcutParameters(any())).thenThrow(new AbstractMethodError());
when(factory.createPolicyPointcutParameters(component, operationParameters)).thenReturn(parameters);
operationPointcutFactories.add(factory);
PolicyPointcutParameters returnedParameters = parametersManager.createOperationPointcutParameters(component, event, operationParameters);
assertThat(returnedParameters, is(parameters));
verify(factory).supportsOperationIdentifier(identifier);
verify(factory).createPolicyPointcutParameters(any());
verify(factory).createPolicyPointcutParameters(component, operationParameters);
}
use of org.mule.runtime.policy.api.PolicyPointcutParameters in project mule by mulesoft.
the class PolicyPointcutParametersManagerTestCase method createSourceParametersWhenEmptyFactory.
@Test
public void createSourceParametersWhenEmptyFactory() {
PolicyPointcutParameters parameters = parametersManager.createSourcePointcutParameters(component, event);
assertThat(parameters.getComponent(), is(component));
assertThat(parameters.getSourceParameters(), empty());
verify(eventContext).onTerminated(any());
}
Aggregations