ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » General IBM MQ Support » Message Broker v5 Custom Node Problem

Post new topic  Reply to topic
 Message Broker v5 Custom Node Problem « View previous topic :: View next topic » 
Author Message
Mirage
PostPosted: Mon Mar 13, 2006 1:46 pm    Post subject: Message Broker v5 Custom Node Problem Reply with quote

Apprentice

Joined: 30 Nov 2004
Posts: 44
Location: IL

We are using a custom node to read the data off of the local file system. As a recommendation from IBM, we are using clearMessage() in the custom node to release the resources used by the custom node. When executing this code, it seems as though the flow is failing somewhere after the custom node, but when an error occurs, the processing is backed out and the code takes the catch branch in message broker. Here is our custom code, the error message we see is at the bottom.

TIA -Nick

Code:
import com.ibm.broker.plugin.*;
import com.svharbor.udt.util.Base64;
import java.io.*;
import java.util.Date;

public class FileRead extends MbNode implements MbNodeInterface {

   private String logFileName;
   private String readMode;
   private String workingDir;
   private String archiveDir;
   private boolean logFlag;

   public FileRead() throws MbException {
      createInputTerminal("IN");
      createOutputTerminal("OUT");
      createOutputTerminal("ERROR");
   }

   public static String getNodeName() {
      return "FileReadNode";
   }

   public String getLogFileName() {
      return logFileName;
   }

   public void setLogFileName(String s) {
      logFileName = s;
   }

   public String getReadMode() {
      return readMode;
   }

   public void setReadMode(String s) {
      readMode = s;
   }

   public String getWorkingDir() {
      return workingDir;
   }

   public void setWorkingDir(String s) {
      workingDir = s;
   }

   public String getArchiveDir() {
      return archiveDir;
   }

   public void setArchiveDir(String s) {
      archiveDir = s;
   }

   public void evaluate(
      MbMessageAssembly mbmessageassembly,
      MbInputTerminal mbinputterminal)
      throws MbException {
      PrintWriter logger = null;
      FileUtility fileUtil = new FileUtility();
      boolean flag = false;
      long l = 0L;
      String s = "";
      String s1 = "";
      String s2 = "OUT";
      String s3 = "ERROR";
      byte abyte0[] = null;
      MbMessage mbmessage = new MbMessage(mbmessageassembly.getMessage());
      MbMessageAssembly mbmessageassembly1 =
         new MbMessageAssembly(mbmessageassembly, mbmessage);
      MbElement mbelement = mbmessageassembly1.getMessage().getRootElement();
      setAttribute("firstParserClassName", "XML");
      MbElement mbelement1 =
         mbelement.getFirstElementByPath("/XML/FileStructure");
      MbElement mbelement2 =
         mbelement.getFirstElementByPath("/XML/FileStructure/FileName");
      try {
         if (logFileName != null) {
            logFlag = true;
            logger = new PrintWriter(new FileWriter(logFileName));
         } else {
            logFlag = false;
         }
         if (logFlag) {
            logger.println(
               "************************************************************");
            logger.println(
               "FileRead Node processing started at " + new Date());
            logger.println("ReadMode " + readMode);
            logger.flush();
         }
         String s7 = (String) mbelement2.getValue();
         if (logFlag) {
            logger.println(
               "FileName along with the path from the message is " + s7);
            logger.flush();
         }
         File file = new File(s7);
         if (file.isDirectory()) {
            if (logFlag) {
               logger.println("Given path is not a file");
               logger.flush();
            }
            throw new Exception("Given path is not a file");
         }
         if (!file.exists()) {
            if (logFlag) {
               logger.println("Given file " + s7 + " does not exist");
               logger.flush();
            }
            throw new Exception("Given file " + s7 + " does not exist");
         }
         Object obj = "";
         String s4 = "";
         String s5 = "";
         String s6 = "";
         String s9 = "";
         String s10 = "";
         int i = s7.lastIndexOf(File.separator);
         obj = s7.substring(i + 1, s7.length());
         s4 = s7.substring(0, i);
         int j = ((String) obj).lastIndexOf(".");
         s5 = ((String) obj).substring(j + 1, ((String) obj).length());
         s6 = ((String) obj).substring(0, j);
         File file1;
         try {
            if (workingDir.length() > 0 && archiveDir.length() > 0) {
               logger.println("WorkingDir: " + workingDir);
               logger.flush();
               logger.println("ArchiveDir: " + archiveDir);
               logger.flush();
               logger.println("Length:WorkingDir: " + workingDir.length());
               logger.flush();
               logger.println("Length:ArchiveDir: " + archiveDir.length());
               logger.flush();
               s9 =
                  workingDir
                     + File.separator
                     + s6
                     + "_"
                     + fileUtil.getDateAsString()
                     + "."
                     + s5;
               s10 =
                  archiveDir
                     + File.separator
                     + s6
                     + "_"
                     + fileUtil.getDateAsString()
                     + "."
                     + s5;
               if (logFlag) {
                  logger.println("Incoming Event File Path " + s4);
                  logger.flush();
                  logger.println("FileName WithoutPath " + obj);
                  logger.flush();
                  logger.println("File Extension " + s5);
                  logger.flush();
                  logger.println("FileName Without Extension " + s6);
                  logger.flush();
                  logger.println("Working File " + s9);
                  logger.flush();
                  logger.println("Archive File " + s10);
                  logger.flush();
                  logger.println("Moving the file to Working Directory");
                  logger.flush();
               }
               boolean flag1 = fileUtil.moveFile(s7, s9);
               if (logFlag) {
                  logger.println(
                     "File Move to Working dir's result is " + flag1);
                  logger.flush();
               }
               if (!flag1) {
                  if (logFlag) {
                     logger.println(
                        "Cannot move file from " + s7 + " to " + s9);
                     logger.flush();
                  }
                  throw new Exception(
                     "Cannot move file from " + s7 + " to " + s9);
               }
               flag1 = false;
               if (logFlag) {
                  logger.println(
                     "Reading the file from "
                        + s9
                        + " in "
                        + readMode
                        + " mode");
                  logger.flush();
               }
               file1 = new File(s9);
            } else {
               if (logFlag) {
                  logger.println(
                     "Reading the file from "
                        + s9
                        + " in "
                        + readMode
                        + " mode");
                  logger.flush();
               }
               file1 = new File(s7);
            }
         } catch (Exception e) {
            boolean flag1 = false;
            file1 = new File(s7);
            logger.println(
               "Working Directory and Archive  not mentioned in the Properties");
            logger.flush();
         }
         long l1 = file1.length();
         if (readMode.equalsIgnoreCase("ASCII")) {
            s = fileUtil.readAsciiFile(file1);
         } else if (readMode.equalsIgnoreCase("BINARY")) {
            abyte0 = fileUtil.readBinaryFile(file1);
         } else if (readMode.equalsIgnoreCase("BASE64")) {
            abyte0 = fileUtil.readBinaryFile(file1);
            s1 = Base64.encodeBytes(abyte0);
         } else {
            throw new Exception("Unsupported mode in readMode property. Should be ASCII or BINARY or BASE64 ");
         }
         if (logFlag) {
            logger.println("Size of the file is " + l1);
            logger.flush();
         }
         try {
            if (workingDir.length() > 0 && archiveDir.length() > 0) {
               boolean flag2 = fileUtil.moveFile(s9, s10);
               if (logFlag) {
                  logger.println(
                     "File Move to Archive dir's result is " + flag2);
                  logger.flush();
               }
               if (!flag2) {
                  if (logFlag) {
                     logger.println(
                        "Cannot move file from " + s9 + " to " + s10);
                     logger.flush();
                  }
                  throw new Exception(
                     "Cannot move file from " + s9 + " to " + s10);
               }
            }
         } catch (Exception exception1) {
         }
         if (logFlag) {
            logger.println(
               "Creating a Child element 'FileSize' and setting the value to "
                  + l1);
            logger.flush();
         }
         MbElement mbelement3 =
            mbelement1.createElementAsFirstChild(
               0x1000000,
               "FileSize",
               (new Long(l1)).toString());
         if (logFlag) {
            logger.println(
               "Creating a Child element 'FileContent' and setting the file's content as Array");
            logger.flush();
         }
         if (readMode.equalsIgnoreCase("ASCII")) {
            obj =
               mbelement1.createElementAsLastChild(
                  0x1000000,
                  "FileContent",
                  s);
         } else if (readMode.equalsIgnoreCase("BASE64")) {
            obj =
               mbelement1.createElementAsLastChild(
                  0x1000000,
                  "FileContent",
                  s1);
         } else if (readMode.equalsIgnoreCase("BINARY")) {
            obj =
               mbelement1.createElementAsLastChild(
                  0x1000000,
                  "FileContent",
                  abyte0);
         }
         if (logFlag) {
            logger.println("Adding timestamp to 'FileName'");
            logger.flush();
         }
         obj =
            s4
               + File.separator
               + s6
               + "_"
               + fileUtil.getDateAsString()
               + "."
               + s5;
         if (logFlag) {
            logger.println("Changing the value from " + s7 + " to " + obj);
            logger.flush();
         }
         mbelement2.setValue(obj);
         logger.flush();

         MbOutputTerminal mboutputterminal = getOutputTerminal(s2);
         mboutputterminal.propagate(mbmessageassembly1);

      } catch (Exception exception) {
         String s8 = exception.getMessage();
         if (logFlag) {
            logger.println("In Exception block " + exception);
            logger.println(s8);
            logger.flush();
            logger.close();
         }
         Object aobj[] = new Object[0];
         throw new MbRecoverableException("", "", "", s8, "", aobj);
      } finally {
         //RAGHU: Feb1, 2006. Moved the propagate up and added the clearMessage()
         if (logFlag) {
            logger.println("Clearing the MBMessage");
            logger.flush();
         }
         mbmessage.clearMessage();
         if (logFlag) {
            logger.println("Cleared the MBMessage");
            logger.flush();
         }
      }
      //logger.close();
      //RAGHU: March 09, 2006. Moved the propagate down --commented 3/10/06 by Nick
      //MbOutputTerminal mboutputterminal = getOutputTerminal(s2);
      //mboutputterminal.propagate(mbmessageassembly1);
   }

   public void onDelete() {
   }
}


Here is the complete error we are experiencing from this:

RunTimeErrorText:Caught exception and rethrowing. Unhandled exception in plugin method. com.ibm.broker.plugin.MbRecoverableException. FileRead.java. 316. [BIPv500:2230]BIP2230E: Error detected whilst processing a message in node '{0}'.

The message broker detected an error whilst processing a message in node '{0}'. An exception has been thrown to cut short the processing of the message.

See the following messages for details of the error. : Caught exception and rethrowing.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General IBM MQ Support » Message Broker v5 Custom Node Problem
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.