XML Marshal/ Unmarshal error when using Castor /Web Logic


EJB programming & troubleshooting: XML Marshal/ Unmarshal error when using Castor /Web Logic

  1. We are using Castor library for reading and writing to Xml files. Given a xml schema, castor generates Java objects based on the schema. The client code is entirely unaware of any xml api (SAX, DOM or otherwise)

    We are reading and writing to Xml files from our EJBS. The XML file is used to pass arguments from one EJB to another. We write to a XML file , close the file from EJB A and call EJB B. When EJB B tries to read the xml file, the read failes. This happens when EJB A and EJB B are on different machine. We are using a common file share on the UNIX boxes to read/write the xml file.. The problem doesnot occur when we have the two EJB's on the same machine .

    Our constraints are, we cannot pass the Castor Object itself as argument from EJBA - EJB B. We cannot move to database due to time constraints.

    To overcome the read failure, we have the following code which seems to work most of the time, but not all the time. Any suggestions on how to resolve this issue .

    Code Snippet

     public static synchronized void marshallRTIX(REPORT oRtix, String sFileName)
                            throws IOException
            FileWriter oWriter = new FileWriter(sFileName);
         public static synchronized REPORT unmarshallRTIX(String sFileName)
                                throws IOException
                appLog.debug(null,"UNATD","BCKEND",null," Umarshalling the Rtix file : " + sFileName);
                FileReader oReader = new FileReader(sFileName);
         int iLoopCount = 0;
                //Loop through 'FILE_HANDLE_ITERATOR' no of times to get a handle of file
                for (iLoopCount = 0; iLoopCount < FILE_HANDLE_ITERATOR; ++ iLoopCount){
         if (!oReader.ready()){
         catch(InterruptedException e){
         appLog.debug(null,"UNATD","BCKEND",null, "File handle got after " + iLoopCount * 100 + " milliseconds");
         //Unmarshalling the file
         REPORT oRtix = (REPORT) REPORT.unmarshalREPORT(oReader);
         return oRtix;
         } catch(Exception e){
         // If no handle is got throw an marshal error.
         throw new MarshalException();
  2. Can you post what the exception is?

    theres a lot of possible issues with the code as its written

     Are u using the same file for communication all the time? if you are, how are u ensuring the 2 EJBs arent reading at writing at the same time, which is probably causing your error. unless theres only ever 1 thread operating.. given that the methods are marked as synchronized it looks like you have a few threads running.

    If you are not, then u must be passing the file name as a parameter to the other EJB. In that case, you would be better off just using the marshall method in the castor generated objects to generate your XML string and pass the XML as a String parameter to EJB B. Its just as easy and will work a lot better than hacking about swapping files. To do this just use a StringWriter rather than a FileWriter