use of org.mule.runtime.api.component.Component in project mule by mulesoft.
the class ComponentInvocationHandlerTestCase method implementsAnnotated.
@Test
public void implementsAnnotated() throws Exception {
Component annotated = addAnnotationsToClass(ImplementsAnnotated.class).newInstance();
assertThat(annotated.getAnnotations(), is(nullValue()));
}
use of org.mule.runtime.api.component.Component in project mule by mulesoft.
the class ComponentInvocationHandlerTestCase method differentClassLoader.
@Test
public void differentClassLoader() throws Exception {
ClassLoader childCl = createDelegatorClassLoader();
Class<Component> annotatedClass = addAnnotationsToClass(childCl.loadClass(Delegator.class.getName()));
assertThat(annotatedClass.getClassLoader(), instanceOf(CompositeClassLoader.class));
}
use of org.mule.runtime.api.component.Component in project mule by mulesoft.
the class LookupFunction method call.
@Override
public Object call(Object[] parameters, BindingContext context) {
String flowName = (String) parameters[0];
Object payload = parameters[1];
Location componentLocation = Location.builder().globalName(flowName).build();
Component component = componentLocator.find(componentLocation).orElseThrow(() -> new IllegalArgumentException(format("There is no component named '%s'.", flowName)));
if (component instanceof Flow) {
try {
Message incomingMessage = lookupValue(context, MESSAGE, Message.builder().nullValue().build());
Map<String, ?> incomingVariables = lookupValue(context, VARS, EMPTY_MAP);
Error incomingError = lookupValue(context, ERROR, null);
Message message = Message.builder(incomingMessage).value(payload).mediaType(APPLICATION_JAVA).build();
CoreEvent event = CoreEvent.builder(PrivilegedEvent.getCurrentEvent().getContext()).variables(incomingVariables).error(incomingError).message(message).build();
return ((ExecutableComponent) component).execute(event).get().getMessage().getPayload();
} catch (ExecutionException e) {
ComponentExecutionException componentExecutionException = (ComponentExecutionException) e.getCause();
Error error = componentExecutionException.getEvent().getError().get();
throw new MuleRuntimeException(createStaticMessage(format("Flow '%s' has failed with error '%s' (%s)", flowName, error.getErrorType(), error.getDescription())), error.getCause());
} catch (InterruptedException e) {
throw new MuleRuntimeException(e);
}
} else {
throw new IllegalArgumentException(format("Component '%s' is not a flow.", flowName));
}
}
use of org.mule.runtime.api.component.Component in project mule by mulesoft.
the class DefaultPolicyManager method createSourcePolicyInstance.
@Override
public SourcePolicy createSourcePolicyInstance(Component source, CoreEvent sourceEvent, Processor flowExecutionProcessor, MessageSourceResponseParametersProcessor messageSourceResponseParametersProcessor) {
PolicyPointcutParameters sourcePointcutParameters = policyPointcutParametersManager.createSourcePointcutParameters(source, sourceEvent);
List<Policy> parameterizedPolicies = policyProvider.findSourceParameterizedPolicies(sourcePointcutParameters);
if (parameterizedPolicies.isEmpty()) {
return event -> from(process(event, flowExecutionProcessor)).defaultIfEmpty(CoreEvent.builder(sourceEvent).message(of(null)).build()).<Either<SourcePolicyFailureResult, SourcePolicySuccessResult>>map(flowExecutionResult -> right(new SourcePolicySuccessResult(flowExecutionResult, () -> messageSourceResponseParametersProcessor.getSuccessfulExecutionResponseParametersFunction().apply(flowExecutionResult), messageSourceResponseParametersProcessor))).onErrorResume(Exception.class, e -> {
MessagingException messagingException = e instanceof MessagingException ? (MessagingException) e : new MessagingException(event, e, (Component) flowExecutionProcessor);
return just(Either.left(new SourcePolicyFailureResult(messagingException, () -> messageSourceResponseParametersProcessor.getFailedExecutionResponseParametersFunction().apply(messagingException.getEvent()))));
});
}
return new CompositeSourcePolicy(parameterizedPolicies, lookupSourceParametersTransformer(source.getLocation().getComponentIdentifier().getIdentifier()), sourcePolicyProcessorFactory, flowExecutionProcessor, messageSourceResponseParametersProcessor);
}
use of org.mule.runtime.api.component.Component in project mule by mulesoft.
the class PolicyPointcutParametersManager method createSourcePointcutParameters.
/**
* Creates {@link PolicyPointcutParameters} for a specific source. The created parameters is also stored so it can be used in
* case a matching policy also defines an operation part.
*
* @param source the source component to which policies will be applied
* @param event the event which will execute the source policies
* @return the created {@link PolicyPointcutParameters}
*/
public PolicyPointcutParameters createSourcePointcutParameters(Component source, CoreEvent event) {
ComponentIdentifier sourceIdentifier = source.getLocation().getComponentIdentifier().getIdentifier();
PolicyPointcutParameters sourcePointcutParameters = createPointcutParameters(source, SourcePolicyPointcutParametersFactory.class, sourcePointcutFactories, factory -> factory.supportsSourceIdentifier(sourceIdentifier), factory -> factory.createPolicyPointcutParameters(source, event.getMessage().getAttributes())).orElse(new PolicyPointcutParameters(source));
String correlationId = event.getContext().getCorrelationId();
sourceParametersMap.put(correlationId, sourcePointcutParameters);
((BaseEventContext) event.getContext()).getRootContext().onTerminated((e, t) -> sourceParametersMap.remove(correlationId));
return sourcePointcutParameters;
}
Aggregations