Skip to content

Instantly share code, notes, and snippets.

View mariomartinezricston's full-sized avatar

mariomartinezricston

View GitHub Profile
@Override
public void onNotification(MuleContextNotification notification) {
if (notification.getAction() == MuleContextNotification.CONTEXT_STARTED) {
logger.info("Context Started");
final Runnable startFlow=createParalelStart(notification);
new Thread(startFlow).start();
}
}
private Runnable createParalelStart(final MuleContextNotification notification) {
final Runnable callFlow = new Runnable() {
public void run() {
try
{
Thread.sleep(4000);
logger.info("Starting up process in 4 second");
executeFlow(notification);
}
@mariomartinezricston
mariomartinezricston / FlowInvokerContextListener.java
Last active September 20, 2016 13:53
FlowInvoker executeFlow
private void executeFlow(final MuleContextNotification notification) throws MuleException {
DefaultMuleMessage message=new DefaultMuleMessage(notification,context);
MuleClient client=context.getClient();
client.send("vm://startup", message);
}
@mariomartinezricston
mariomartinezricston / FlowInvokerContextListener.java
Created September 20, 2016 11:58
FlowInvokerContextListener
public class FlowInvokerContextListener implements MuleContextNotificationListener<MuleContextNotification> {
@Inject
private MuleContext context;
private static final Logger logger = Logger.getLogger(FlowInvokerContextListener.class);
<configuration doc:name="Configuration">
<expression-language>
<global-functions>
def dayOfTheMonth(date){
import java.util.Calendar;
import java.text.SimpleDateFormat;
cal = Calendar.getInstance();
sdf = new SimpleDateFormat('yyyyMMdd');
<flow name="usingTransformerAnnotation">
<http:listener config-ref="HTTP_Listener_Configuration" path="/transformerAnnotation" doc:name="HTTP" allowedMethods="GET"/>
<set-payload value="#['Annotated Max!']" doc:name="Set Payload"/>
<component class="javacall.AnimalTransformerAnnotation" doc:name="Java"/>
<object-to-string-transformer doc:name="Object to String"/>
</flow>
@ContainsTransformerMethods
public class AnimalTransformerAnnotation {
@Transformer
public Animal returnAnimal(@Payload String name){
return new Animal(name);
}
}
<flow name="usingTransformer">
<http:listener config-ref="HTTP_Listener_Configuration" path="/transformer" allowedMethods="GET" doc:name="HTTP"/>
<set-variable variableName="flowVarName" value="#['Max the Mule']" doc:name="Variable"/>
<custom-transformer returnClass="model.Animal" class="javacall.AnimalTransformer" doc:name="Java"/>
<object-to-string-transformer doc:name="Object to String"/>
</flow>
public class AnimalTransformer extends AbstractMessageTransformer{
public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException {
String flowVarName = message.getProperty("flowVarName", PropertyScope.INVOCATION);
Animal animal=new Animal(flowVarName);
return animal;
}
}
<flow name="usingCustomMessageProcessor">
<http:listener config-ref="HTTP_Listener_Configuration" path="/customMessage" doc:name="HTTP" allowedMethods="GET"/>
<custom-processor class="javacall.MessageProcessorCall" doc:name="Custom Processor"/>
<object-to-string-transformer doc:name="Object to String"/>
</flow>