Is there an easy way to configure a Flow to read a single file from the classpath one time? I don\'t need to poll for a file. I just need to read a known file and set its co
I am trying to throw Java class transformer so you can use the following
note : the path is the direct package that contain the file you want to read am store the path inside mule variable and then read the file content and stor its value into Payload
.
public class PayloadFileReader extends AbstractMessageTransformer {
public Object transformMessage(MuleMessage message, String outputEncoding)
throws TransformerException {
String result = "";
try {
result = readFileTest(message.getInvocationProperty("path")
.toString());
} catch (Exception e) {
e.printStackTrace();
}
message.setPayload(result);
return message;
}
public String readFileTest(String path) throws FileNotFoundException,
IOException, Exception {
ClassLoader classLoader = getClass().getClassLoader();
"+classLoader.getResource("samples/v3/addVal-request.sample").getFile());
File file = new File(classLoader.getResource(path).getFile());
FileReader fileReader = new FileReader(file);
BufferedReader bufferReader = null;
StringBuilder stringBuffer = new StringBuilder();
String line;
try {
bufferReader = new BufferedReader(fileReader);
while ((line = bufferReader.readLine()) != null) {
stringBuffer.append(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bufferReader != null) {
try {
bufferReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return stringBuffer.toString();
}