0
我正在嘗試創建一個簡單的mule應用程序,它讀取磁盤上文件的名稱和內容並將其顯示在Web瀏覽器上。表達式的執行失敗。 (org.mule.api.expression.ExpressionRuntimeException)。消息有效負載的類型爲:字符串
我的流程如下HTTP - > JAVA變壓器 - SETPAYLOAD - HTTP
我的Java變壓器代碼包括以下
public class ReadFile extends AbstractMessageTransformer {
/**
* loads the content of the file specified in the parameter
*
* @param filename
* the name of the file
* @return the content of the file
*/
public String readFile(String filename) {
File file;
file = new File("O:\\test.txt");
StringBuilder builder = new StringBuilder();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String line = null;
while ((line = reader.readLine()) != null)
builder.append(line);
} catch (IOException e) {
e.printStackTrace();
} finally {
closeQuietly(reader);
}
return builder.toString();
}
public String getFileName(MuleMessage message) {
Path p = Paths.get("O:\\Test.txt");
String file = p.getFileName().toString();
return file;
}
public String setPayload(MuleMessage message, String outputEncoding) {
String payload1 = "#[ReadFile]";
return payload1;
}
private void closeQuietly(Closeable c) {
if (c != null) {
try {
c.close();
} catch (IOException ignored) {
}
}
}
@Override
public Object transformMessage(MuleMessage message, String outputEncoding)
throws TransformerException {
String filename = getFileName(message);
String content = readFile(filename);
setPayload(message, content);
return message;
}
}
我得到表達ReadFile的失敗的錯誤執行。 (org.mule.api.expression.ExpressionRuntimeException)
。消息有效負載的類型爲:String
並且不知道爲什麼?