简体   繁体   中英

mule message.getInvocationProperty cannot be resolved from within Java method

I'm trying to access a mule flowVar from within a Java class:

In the mule processor: flowVars.rootFilePath="c:\\test"

From within the mule processor, I'm calling the java method renameFile(oldFile, newFile) :

package com.rename;

import java.io.File; import org.mule.api.MuleMessage;

public class FileRename {

public String renameFile(String oldFile, String newFile) {
    File file1 = new File(message.getInvocationProperty("rootFilePath") + oldFile);
    File file2 = new File(message.getInvocationProperty("rootFilePath") + newFile);
    file1.renameTo(file2);
    return "Renaming " + oldFile + " to: " + newFile;
}

}

However, I'm receiving the error " message cannot be resolved". What am I missing here? Your help is very much appreciated!

Why can't you use onCall Method to do this?

You can use below code as a sample to access message.

public class MyComponent implements Callable {
 @Override
    public Object onCall(MuleEventContext eventContext) throws Exception {
     String oldFile = eventContext.getMessage().getProperty('');
      return "Renaming " + oldFile + " to: " + newFile;";
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM