This is the part of my xml in Mule. >
<flow name="CatalogueFlow_BC" doc:name="CatalogueFlow_BC">
< wmq:inbound-endpoint queue="${wmq.queue.nameCT_BC}" connector-ref="WMQ" doc:name="WMQ"/>
< object-to-string-transformer doc:name="File Mapping"/>
< custom-transformer class="catalogue.ServiceController_BC" doc:name="Java"/>
<logger message="******************Entered Catalogue SOAP File with Province Name BC is Processed*********" level="INFO" category="Audit_LogCAT" doc:name="CAT Logger"/>
<catch-exception-strategy doc:name="Catch Exception Strategy">
logger message="*******************************Entered Catalogue SOAP File with Province Name BC is having error: #[exception.causeException]****************" level="INFO" category="Audit_LogCAT" doc:name="CAT Exception Logger"/>
/catch-exception-strategy>
</flow>
My java code is converting the coming SOAP message from queue into text file. it is designed in such a way that 2 SOAp message will make 1 text file with 2 SOAP records. The issue is, when i am running my mule flow, and putting the message one by one in the queue, everything is fine. But if I directly put 2 message in the queue i.e. first I put 2 message in the queue and then run my flow, it is taking only first SOAP and after java transformation, the result of First SOAP is printing 2 times in the text file.
public class IPController_BC extends AbstractMessageTransformer{
TimeOut timeOut = TimeOut.getInstance();
@SuppressWarnings({ "unused" })
public Object transformMessage(MuleMessage message, String outputEncoding)throws TransformerException {
String flagGetPayload = null;
String intermediateFile = null;
String invoiceFile = null;
try {
// Get the payload from the mule message and store in the flagGetPayload
flagGetPayload= (String) message.getPayload();
try{
Properties prop = new Properties();
prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("path_config.properties"));
intermediateFile = prop.getProperty("INTERMEDIATEIP_LOCATION");
invoiceFile=prop.getProperty("INVOICEIP_LOCATION");
} catch (IOException e1) {
// TODO Auto-generated catch block
logger.error("IOException",e1);
}
//WRITING MESSAGE INTO A FILE FROM flagGetPayload
File file = new File(intermediateFile+"/soap.xml");
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(flagGetPayload);
bw.close();
//
String ProvinceName="BC";
InterchangeablePriority ip=new InterchangeablePriority();
System.out.println("start operation");
ip.startOperationIP(ProvinceName);
//ip.deleteFile();
}
catch (Exception e) {
logger.error("Exception",e);
}
File folder = new File(invoiceFile);
File[] listOfFiles = folder.listFiles();
for (File file : listOfFiles){
}
String file = null;
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
file= listOfFiles[i].getAbsolutePath();
} else if (listOfFiles[i].isDirectory()) {
}
}
return file;
}
public TimeOut setTimer() {
timeOut.schedule(30);
return timeOut;
}
}
This is the attached java class. Inside this java class, some more functions are being called.
custom-transformermaintains state and replays the first message twice? - David Dossot