0
votes

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.

1
Mmmh, that's a first. Are you sure the two messages waiting in the queue are different? Or is there a risk that the custom-transformer maintains state and replays the first message twice? - David Dossot
ya...i am sure that these two messages are different. I think custom-transform is replaying the message twice. Can it be a solution if i delay the message by some seconds which i am getting from queue? if it is, then please suggest me how can i do this. - user3675877
No, introducing a delay is not a solution. Can you share the code of the custom transformer? - David Dossot
i attached the custom class in question itself. Please check out in the question. - user3675877
What actually happening is, rather than going for the whole flow for each soap message, wmq is fetching soap message in less time as compared to the time taken by flow to execute. - user3675877

1 Answers

0
votes

There are many many issues with your approach:

  • The main one that probably causes the issue is that the file that is written has always the same name so you'll get concurrent writes and all sorts of nastiness that can happen with that. Mule is a highly concurrent environment: you need to code accordingly.
  • This transformer is doing way too much: a transformer should only transform data.
  • Properties are loaded each time instead of injecting them from the Spring config.
  • Custom Java-based file writing code is done instead of using a file:outbound-endpoint.
  • The call to InterchangeablePriority should probably be done in a component. If thread safe, create this object only one with a Spring bean and use it in a component.
  • It's hard to understand the intent around timeOut.
  • Cosmetics: ProvinceName => provinceName (Java coding standards).