3 Replies Latest reply on Dec 7, 2011 12:06 PM by clebert.suconic

    SOS !! Wierd Exception: java.lang.IllegalStateException: Packet hasn't been encoded/decoded yet

    ybhate

      I am getting this exception when i try to send contents of a file as a response to a JMS message. I am using a request-response pattern. A server application initates a request via a JMS message and the other server application listens to this message and synchronously responds with contents from some file. I am using BytesMessage to send the contents of the file. I am using the steps provided in the LargeMessageExample.java file.

       

      Here is the exception trace that i get.

      java.lang.IllegalStateException: Packet hasn't been encoded/decoded yet

          at org.hornetq.core.protocol.core.impl.PacketImpl.getPacketSize(PacketImpl.java:256)

          at org.hornetq.core.client.impl.LargeMessageControllerImpl.setOutputStream(LargeMessageC

          at org.hornetq.core.client.impl.LargeMessageControllerImpl.saveBuffer(LargeMessageContro

          at org.hornetq.core.client.impl.ClientLargeMessageImpl.saveToOutputStream(ClientLargeMes

          at org.hornetq.jms.client.HornetQMessage.saveToOutputStream(HornetQMessage.java:942)

          at org.hornetq.jms.client.HornetQMessage.setObjectProperty(HornetQMessage.java:821)

       

      What does this mean. Is there anyway this can be avoided.

       

      -Thanks

        • 1. Re: SOS !! Wierd Exception: java.lang.IllegalStateException: Packet hasn't been encoded/decoded yet
          clebert.suconic

          What version are you using?

           

          Look at the LargeMessage Example

           

          Post some code showing what you are doing.

          • 2. Re: SOS !! Wierd Exception: java.lang.IllegalStateException: Packet hasn't been encoded/decoded yet
            ybhate

            I am using Hornetq-2.2.5

             

            Providing you some portion of the code. Note that this portion of the code fails only when i get the fileData as part of a response to a JMS request message.

             

            So this is the flow  - only during this flow the code fails and throws exception. Note that all other types of messages are recieved without any problem in the request-respone pattern shown below. The problem is only in the file data transfer.

             

            Server 1 ----- sends JMS message to ----> server 2

             

            Server 2 -----> reads a file ---> put the contents of the file into bytes message as shown below --> responds to the message by setting correlationId-->send the message -----> Server 1

             

            Server 2 --> tried to read the data and put it into a disk file --> throws exception

             

             

            the following code is used to put the file data into the BytesMessage

            ==================================================

            //assume that somewhere in my code above i am getting the file data in the bufferedInputStream.

             

             

             

             

             

             

             

             

             

            BytesMessage bytesMessage = session.createBytesMessage();

            bytesMessage.setObjectProperty("JMS_HQ_InputStream", bufferedInputStream

            );

            bytesMessage.setObjectProperty("ODPAYLOAD", payloadXml);

             

             

            messageId = bytesMessage.getJMSMessageID();

            m = bytesMessage;

             

             

             

            if(properties != null && properties.size() >0)

             

             

             

            msg_payloadUtil.addProperties(m, properties);

             

             

             

             

            m.setJMSCorrelationID(correlationId);

            the following code is used to read the data from the bytesMessage. And this is where it throws exception

            ===========================================================================

             

            private BufferedInputStream getFileData(BytesMessage byteMsg,String fileName)

            {

            BufferedInputStream bufferedInputStream =

            null;

            Calendar calendar = Calendar.getInstance();

            String filePath= PropertiesUtil.getProperty(

            "file.store.path").toString();

            StringBuilder appendFileExt =

             

            if(fileName!=null)

            appendFileExt.append(filePath).append(calendar.getTimeInMillis()).append(

            "-").append(fileName);

             

            else

            appendFileExt.append(filePath).append(calendar.getTimeInMillis());

             

            if(logger.isDebugEnabled())logger.debug("Storing file into temporary area. File name is " + appendFileExt);

             

            try{

            File outputFile =

            new File(appendFileExt.toString());

            FileOutputStream fileOutputStream =

            new FileOutputStream(outputFile);

            BufferedOutputStream bufferedOutput =

            new BufferedOutputStream(fileOutputStream);

             

            if(logger.isDebugEnabled())logger.debug("Size of file data = " + byteMsg.getLongProperty("_HQ_LARGE_SIZE"));

             

            long startTime = System.currentTimeMillis();

            byteMsg.setObjectProperty(

            "JMS_HQ_SaveStream", bufferedOutput); // This is where it throws exception given in my discussion

             

            long endTime = System.currentTimeMillis();

             

            if(logger.isDebugEnabled())logger.debug("Time to write to buffer:->"+(endTime-startTime));

            bufferedInputStream =

            new BufferedInputStream(new FileInputStream(outputFile));

            }

            catch(Exception e){

            e.printStackTrace();

            }

             

            return bufferedInputStream;

             

            }

             

             

             

             

             

             

            new StringBuilder();

            ==================================================

             

            • 3. Re: SOS !! Wierd Exception: java.lang.IllegalStateException: Packet hasn't been encoded/decoded yet
              clebert.suconic

              Did you move to a different message on the caller of getFileData ?

               

              it should always be the current message being received.

               

              You can probably create a sample showing your issue. (use attachments through advanced editor here).