Click here to Skip to main content
15,885,216 members
Articles / Programming Languages / Java
Tip/Trick

Mule ESB: Creating a Simple Synchronous File Reader

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
28 Aug 2016CPOL 9.3K  
Creating a simple Synchronous File Reader

In this tip, I will show you how to create a very simple Synchronous File Reader inside your Mule flow.

You just need to add these lines of code in your Java component class, which will enable you to read a File in between the flow.

I hope this helps!

Java
package org.rahul.util;

import java.io.File;

import org.mule.api.MuleEventContext;
import org.mule.api.lifecycle.Callable;

public class SynchronousFileReader implements Callable{

public File getFileContent(String fileLocation)
{
File file = new File(fileLocation);
return file;
}

@Override
public Object onCall(MuleEventContext eventContext) throws Exception {

String filepath = eventContext.getMessage().getInvocationProperty("filepath");
File file = getFileContent(filepath);
return file;
}
}

Sample Usage:

XML
<component class="org.rahul.util.SynchronousFileReader" 
doc:name="Java"/>
        <!-- File as Binary -->
        <file:file-to-byte-array-transformer doc:name="File to Byte Array" 
        mimeType="binary/octet-stream"/>

Use transformers like File-to-String or File-to-Byte-Array Transformer according to your requirement, after using this Java component.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --