use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class MVELExpressionLanguage method evaluate.
@Override
public TypedValue evaluate(String expression, CoreEvent event, CoreEvent.Builder eventBuilder, ComponentLocation componentLocation, BindingContext bindingContext) {
expression = removeExpressionMarker(expression);
Map<String, Object> bindingMap = bindingContext.identifiers().stream().collect(toMap(id -> id, id -> bindingContext.lookup(id).get().getValue()));
final Object value = evaluateUntyped(expression, (PrivilegedEvent) event, (PrivilegedEvent.Builder) eventBuilder, componentLocation, bindingMap);
if (value instanceof TypedValue) {
return (TypedValue) value;
} else {
final Serializable compiledExpression = expressionExecutor.getCompiledExpression(expression);
DataType dataType = event != null ? dataTypeResolver.resolve(value, (PrivilegedEvent) event, compiledExpression) : OBJECT;
return new TypedValue(value, dataType);
}
}
use of org.mule.runtime.core.api.event.CoreEvent 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.core.api.event.CoreEvent in project mule by mulesoft.
the class OperationPolicyProcessor method apply.
@Override
public Publisher<CoreEvent> apply(Publisher<CoreEvent> publisher) {
return from(publisher).cast(PrivilegedEvent.class).flatMap(operationEvent -> {
PolicyStateId policyStateId = new PolicyStateId(operationEvent.getContext().getCorrelationId(), policy.getPolicyId());
Optional<CoreEvent> latestPolicyState = policyStateHandler.getLatestState(policyStateId);
PrivilegedEvent variablesProviderEvent = (PrivilegedEvent) latestPolicyState.orElseGet(() -> PrivilegedEvent.builder(operationEvent.getContext()).message(of(null)).build());
policyStateHandler.updateState(policyStateId, variablesProviderEvent);
PrivilegedEvent policyEvent = policyEventConverter.createEvent(operationEvent, variablesProviderEvent);
Processor operationCall = buildOperationExecutionWithPolicyFunction(nextProcessor, operationEvent, policyStateId);
policyStateHandler.updateNextOperation(policyStateId.getExecutionIdentifier(), operationCall);
return executePolicyChain(operationEvent, policyStateId, policyEvent);
});
}
use of org.mule.runtime.core.api.event.CoreEvent in project mule by mulesoft.
the class PolicyNextActionMessageProcessor method apply.
@Override
public Publisher<CoreEvent> apply(Publisher<CoreEvent> publisher) {
return from(publisher).doOnNext(coreEvent -> logExecuteNextEvent("Before execute-next", coreEvent.getContext(), coreEvent.getMessage(), this.muleContext.getConfiguration().getId())).flatMap(event -> {
Processor nextOperation = policyStateHandler.retrieveNextOperation(event.getContext().getCorrelationId());
if (nextOperation == null) {
return error(new MuleRuntimeException(createStaticMessage("There's no next operation configured for event context id " + event.getContext().getCorrelationId())));
}
popBeforeNextFlowFlowStackElement().accept(event);
notificationHelper.notification(BEFORE_NEXT).accept(event);
return from(processWithChildContext(event, nextOperation, ofNullable(getLocation()))).doOnSuccessOrError(notificationHelper.successOrErrorNotification(AFTER_NEXT).andThen((ev, t) -> pushAfterNextFlowStackElement().accept(event))).onErrorResume(MessagingException.class, t -> {
PolicyStateId policyStateId = new PolicyStateId(event.getContext().getCorrelationId(), muleContext.getConfiguration().getId());
policyStateHandler.getLatestState(policyStateId).ifPresent(latestStateEvent -> t.setProcessedEvent(policyEventConverter.createEvent((PrivilegedEvent) t.getEvent(), (PrivilegedEvent) latestStateEvent)));
// Given we've used child context to ensure AFTER_NEXT notifications are fired at exactly the right time we need
// to propagate the error to parent context manually.
((BaseEventContext) event.getContext()).error(resolveMessagingException(t.getFailingComponent(), muleContext).apply(t));
return empty();
}).doOnNext(coreEvent -> logExecuteNextEvent("After execute-next", coreEvent.getContext(), coreEvent.getMessage(), this.muleContext.getConfiguration().getId()));
});
}
use of org.mule.runtime.core.api.event.CoreEvent 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));
}
Aggregations