6 Replies Latest reply on Jul 3, 2003 10:13 AM by Adrian Brock

    java.io.OptionalDataException

    delboypass Newbie

      Im trying to build a standalone client that can read the messages off a queue as objects and then convert them to messages and send them to a queue.

      My problem is that when im trying to read a message off the queue as an object I get the above error: java.io.OptionalDataException.

      Here is the method im using:

      public Object readObject(String sFileName){
      Object obj =null;

      try {
      FileInputStream fileI = new FileInputStream(sFileName);
      ObjectInputStream input = new ObjectInputStream(fileI);
      obj = input.readObject();
      input.close() ;
      }

      And here is the stack trace:

      [transfer] java.io.OptionalDataException
      [transfer] at java.io.ObjectInputStream.readObject(ObjectInputStream.java:280)
      [transfer] at java.io.ObjectInputStream.readObject(ObjectInputStream.java:231)


      What my question is:
      is there a way to read a message off the queue outside of the JBoss application eitehr as objects or messages. I have the message title if it helps:
      [transfer] ID%0589-1057068463363502487.-9223372036853748214


        • 1. Re: java.io.OptionalDataException
          Adrian Brock Master

          I don't see any JMS code in your example.

          Regards,
          Adrian

          • 2. Re: java.io.OptionalDataException
            delboypass Newbie

            I wasnt planning to use JMS code at this stage.
            In the previous message i said i wanted to read in a message as an object as I thought a JMS message would be a serialised object and written out as such but looks as though it is not written out as a serialised object but something else.
            I was just wanting to read in a message from outside the JBoss Application server.

            We have been having problems restarting the JBoss application server when the queues start to hold above 20,000 messages.The persistence manager takes about 15 minutes to load and the queue takes about 15 minutes as well to initiate. This means that this standalone client will be able to transfer the messages without having to load up the application server first so the application server can start up without anuy messages present in hte queue.

            What would the code be to read in a JMS Message from a file.
            (Remember that without the JBoss application server running that my queue isnt in JNDI so dont have connectionfactory ect)

            If The message isnt a serialised object, then what is it and what is the implementation in JBoss for writing and reading messages (this is what I need to mimic) otherwise how do I change the persistence manager to not take so long on start up.

            With our messages we do not need priority, just any message from hte queue will do so no ordering required.

            • 3. Re: java.io.OptionalDataException
              Adrian Brock Master

              Assuming you are using the file persistent manager,
              there is a long and a byte in front of the message.
              The long is the internal messageid, the byte is the
              type of message (Map, Stream, Text, etc).

              Regards,
              Adrian

              • 4. Re: java.io.OptionalDataException
                delboypass Newbie

                adrian, is there any code that allows me to read in a message object without using JMS.

                I how do I get past the long and the byte to get to the message??

                • 5. Re: java.io.OptionalDataException
                  delboypass Newbie

                  try {
                  FileInputStream fileI = new FileInputStream(sFileName);
                  ObjectInputStream input = new ObjectInputStream(fileI);
                  long longtemp = input.readLong();
                  System.out.println("long: "+longtemp);
                  byte bytetemp = input.readByte();
                  System.out.println("byte: "+bytetemp);
                  obj = input.readObject();
                  input.close() ;
                  }
                  catch (Exception ex) {

                  Adrian, I have read the long and then the byte but reading the object still throws the java.io.optionalDataException???

                  Any ideas?

                  • 6. Re: java.io.OptionalDataException
                    Adrian Brock Master

                    If you just want to serialize/deseriaize a message
                    the read/writeObject is the correct way.

                    Internally jboss does some other tricks for message
                    pooling that means they are not directly serialized.
                    For the exact protocol look at the source for persistence
                    manager you are using.

                    Regards,
                    Adrian