Examples of StreamMessage


Examples of javax.jms.StreamMessage

        MessageConsumer consumer = session.createConsumer(destination);
        MessageProducer producer = session.createProducer(destination);

        // Send the message.
        {
            StreamMessage message = session.createStreamMessage();
            message.writeString("This is a test to see how it works.");
            producer.send(message);
        }

        // Check the message.
        {
            StreamMessage message = (StreamMessage)consumer.receive(1000);
            assertNotNull(message);

            // Invalid conversion should throw exception and not move the stream
            // position.
            try {
                message.readByte();
                fail("Should have received NumberFormatException");
            } catch (NumberFormatException e) {
            }

            assertEquals("This is a test to see how it works.", message.readString());

            // Invalid conversion should throw exception and not move the stream
            // position.
            try {
                message.readByte();
                fail("Should have received MessageEOFException");
            } catch (MessageEOFException e) {
            }
        }
        assertNull(consumer.receiveNoWait());
View Full Code Here

Examples of javax.jms.StreamMessage

      QueueReceiver qr = s_rec.createReceiver(q);
      /* Create a sender for sending messages */
      QueueSender qsender = s_send.createSender(q);
      qsender.setDisableMessageTimestamp(false);
      /* create a text message for sending */
      StreamMessage msg = s_send.createStreamMessage();
      /* and write values into it */
      msg.writeByte((byte)0);
      msg.writeBoolean(true);
      msg.writeChar('c');
      msg.writeDouble(1.11d);
      msg.writeFloat(1.1f);
      msg.writeInt(1);
      msg.writeShort((short)1);
      msg.writeString(TEXT);

      /* Send the message */
      qsender.send(msg);
      /* Commit the sending session */
      s_send.commit();
      /* Receive the message */
      msg = (StreamMessage) qr.receiveNoWait();
     
      Assert.assertNotNull("message recieved", msg);
      /* Commit the session to clear the queue */
      s_rec.commit();
      /* Check, that the text of the message is still the same */
     
      Assert.assertEquals("byte", msg.readByte(), (byte) 0);
      Assert.assertEquals("boolean", msg.readBoolean(), true);
      Assert.assertEquals("char", msg.readChar(), 'c');
      Assert.assertEquals("double", msg.readDouble(), 1.11d, 0);
      Assert.assertEquals("float", msg.readFloat(), 1.1f, 0);
      Assert.assertEquals("int", msg.readInt(), 1);
      Assert.assertEquals("short", msg.readShort(), (short) 1);
      Assert.assertEquals("string", msg.readString(), TEXT);
     
    } finally {
      try {
        s_rec.close();
      } catch (Exception ex) {
View Full Code Here

Examples of javax.jms.StreamMessage

        MessageConsumer consumer = session.createConsumer(destination);
        MessageProducer producer = session.createProducer(destination);

        // Send the message.
        {
            StreamMessage message = session.createStreamMessage();
            message.writeString("This is a test to see how it works.");
            producer.send(message);
        }
       
        // Check the message.
        {
            StreamMessage message = (StreamMessage) consumer.receive(1000);
            assertNotNull(message);
           
            // Invalid conversion should throw exception and not move the stream position.
            try {
                message.readByte();
                fail("Should have received NumberFormatException");
            } catch (NumberFormatException e) {
            }
           
            assertEquals("This is a test to see how it works.", message.readString() );
   
            // Invalid conversion should throw exception and not move the stream position.
            try {
                message.readByte();
                fail("Should have received MessageEOFException");
            } catch (MessageEOFException e) {
            }
        }
        assertNull(consumer.receiveNoWait());
View Full Code Here

Examples of javax.jms.StreamMessage

                msg.setConnection(connection);
                msg.setObject(objMsg.getObject());
                msg.storeContent();
                activeMessage = msg;
            } else if (message instanceof StreamMessage) {
                StreamMessage streamMessage = (StreamMessage) message;
                streamMessage.reset();
                ActiveMQStreamMessage msg = new ActiveMQStreamMessage();
                msg.setConnection(connection);
                Object obj = null;

                try {
                    while ((obj = streamMessage.readObject()) != null) {
                        msg.writeObject(obj);
                    }
                } catch (MessageEOFException e) {
                    // if an end of message stream as expected
                } catch (JMSException e) {
View Full Code Here

Examples of javax.jms.StreamMessage

      assertTrue("BigInteger == BigInteger2", data2.equals(data));
   }
   public void testStreamMessage() throws Exception
   {
      log.info("+++ testStreamMessage");
      StreamMessage sent = session.createStreamMessage();
      sent.writeBoolean(true);
      sent.writeByte((byte) 1);
      byte[] testBytes = "Bytes".getBytes();
      sent.writeBytes(testBytes);
      sent.writeChar('c');
      sent.writeShort((short) 31415);
      sent.writeInt(314159);
      sent.writeLong(3141592653589793238L);
      sent.writeDouble(3.1415926535897932384626433832795);
      sent.writeFloat(3.141f);
      sent.writeObject("31415926535897932384626433832795");
      sent.writeString("31415926535897932384626433832795");

      StreamMessage recv = (StreamMessage) sendRecMsg(sent);
      log.debug("recv: "+recv);
      assertTrue("Boolean == true", recv.readBoolean() == true);
      assertTrue("Byte == 1", recv.readByte() == 1);
      // Quirky spec behavior requires a read past the end of the byte[] field
      byte[] bytes = new byte[testBytes.length];
      recv.readBytes(bytes);
      assertTrue(recv.readBytes(bytes) < 0);
      assertTrue("Bytes == Bytes[]",
         Arrays.equals(bytes, testBytes));
      char c = recv.readChar();
      assertTrue("Char == c", c == 'c');
      assertTrue("Short == 314159", recv.readShort() == 31415);
      assertTrue("Int == 314159", recv.readInt() == 314159);
      assertTrue("Long == 3141592653589793238L",
         recv.readLong() == 3141592653589793238L);
      assertTrue("Double == 3.1415926535897932384626433832795",
         recv.readDouble() == 3.1415926535897932384626433832795);
      assertTrue("Float == true", recv.readFloat() == 3.141f);
      assertTrue("Object == 31415926535897932384626433832795",
         recv.readObject().equals("31415926535897932384626433832795"));
      assertTrue("String == 31415926535897932384626433832795",
         recv.readString().equals("31415926535897932384626433832795"));
   }
View Full Code Here

Examples of javax.jms.StreamMessage

   }
  
   public void testSMBodyReadable() throws Exception
   {
      byte bValue = 123;
      StreamMessage sm = queueProducerSession.createStreamMessage();
      sm.writeByte(bValue);
      sm.setStringProperty("COM_SUN_JMS_TESTNAME",
                                    "xMessageEOFExceptionQTestforStreamMessage");
      queueProducer.send(sm);

      StreamMessage received = (StreamMessage)queueConsumer.receive(3000);
      received.readByte();
   }
View Full Code Here

Examples of javax.jms.StreamMessage

   }

   public void testStreamMessage() throws Exception
   {
      StreamMessage m = queueProducerSession.createStreamMessage();

      //Some arbitrary values
      boolean myBool = true;
      byte myByte = -111;
      short myShort = 15321;
      int myInt = 0x71ab6c80;
      long myLong = 0x20bf1e3fb6fa31dfL;
      float myFloat = Float.MAX_VALUE - 23465;
      double myDouble = Double.MAX_VALUE - 72387633;
      String myString = "abcdef&^*&!^ghijkl\uD5E2\uCAC7\uD2BB\uB7DD\uB7C7\uB3A3\uBCE4\uB5A5";
      char myChar = 'q';
      byte[] myBytes = new byte[]
      {-23, 114, -126, -12, 74, 87};

      m.writeBoolean(myBool);
      m.writeByte(myByte);
      m.writeShort(myShort);
      m.writeChar(myChar);
      m.writeInt(myInt);
      m.writeLong(myLong);
      m.writeFloat(myFloat);
      m.writeDouble(myDouble);
      m.writeString(myString);
      m.writeBytes(myBytes);
      m.writeBytes(myBytes, 2, 3);



      m.writeObject(new Boolean(myBool));
      m.writeObject(new Byte(myByte));
      m.writeObject(new Short(myShort));
      m.writeObject(new Integer(myInt));
      m.writeObject(new Long(myLong));
      m.writeObject(new Float(myFloat));
      m.writeObject(new Double(myDouble));
      m.writeObject(myString);
      m.writeObject(myBytes);

      try
      {
         m.writeObject(new Object());
         fail();
      }
      catch (MessageFormatException e)
      {
      }

      //Reading should not be possible when message is read-write
      try
      {
         m.readBoolean();
         fail();
      }
      catch (javax.jms.MessageNotReadableException e)
      {
      }
      try
      {
         m.readShort();
         fail();
      }
      catch (javax.jms.MessageNotReadableException e)
      {
      }
      try
      {
         m.readChar();
         fail();
      }
      catch (javax.jms.MessageNotReadableException e)
      {
      }
      try
      {
         m.readInt();
         fail();
      }
      catch (javax.jms.MessageNotReadableException e)
      {
      }
      try
      {
         m.readLong();
         fail();
      }
      catch (javax.jms.MessageNotReadableException e)
      {
      }
      try
      {
         m.readFloat();
         fail();
      }
      catch (javax.jms.MessageNotReadableException e)
      {
      }
      try
      {
         m.readDouble();
         fail();
      }
      catch (javax.jms.MessageNotReadableException e)
      {
      }
      try
      {
         byte[] bytes = new byte[333];
         m.readBytes(bytes);
         fail();
      }
      catch (javax.jms.MessageNotReadableException e)
      {
      }

      queueProducer.send(queue, m);

      StreamMessage m2 = (StreamMessage) queueConsumer.receive(2000);

      assertEquals(myBool, m2.readBoolean());
      assertEquals(myByte, m2.readByte());
      assertEquals(myShort, m2.readShort());
      assertEquals(myChar, m2.readChar());
      assertEquals(myInt, m2.readInt());
      assertEquals(myLong, m2.readLong());
      assertEquals(myFloat, m2.readFloat(), 0);
      assertEquals(myDouble, m2.readDouble(), 0);
      assertEquals(myString, m2.readString());

      byte[] bytes = new byte[6];
      int ret = m2.readBytes(bytes);
      assertEquals(6, ret);

      assertByteArraysEqual(myBytes, bytes);

      ret = m2.readBytes(bytes);
      assertEquals(-1, ret);

      byte[] bytes2 = new byte[3];
      ret = m2.readBytes(bytes2);

      assertEquals(3, ret);

      assertEquals(myBytes[2], bytes2[0]);
      assertEquals(myBytes[3], bytes2[1]);
      assertEquals(myBytes[4], bytes2[2]);

      ret = m2.readBytes(bytes2);
      assertEquals(-1, ret);

      assertEquals(myBool, m2.readBoolean());
      assertEquals(myByte, m2.readByte());
      assertEquals(myShort, m2.readShort());
      assertEquals(myInt, m2.readInt());
      assertEquals(myLong, m2.readLong());
      assertEquals(myFloat, m2.readFloat(), 0);
      assertEquals(myDouble, m2.readDouble(), 0);
      assertEquals(myString, m2.readString());

      bytes = new byte[6];
      ret = m2.readBytes(bytes);
      assertEquals(6, ret);
      assertByteArraysEqual(myBytes, bytes);

      ret = m2.readBytes(bytes);
      assertEquals(-1, ret);

      //Try and read past the end of the stream
      try
      {
         m2.readBoolean();
         fail();
      }
      catch (MessageEOFException e)
      {
      }

      try
      {
         m2.readByte();
         fail();
      }
      catch (MessageEOFException e)
      {
      }

      try
      {
         m2.readChar();
         fail();
      }
      catch (MessageEOFException e)
      {
      }

      try
      {
         m2.readDouble();
         fail();
      }
      catch (MessageEOFException e)
      {
      }

      try
      {
         m2.readFloat();
         fail();
      }
      catch (MessageEOFException e)
      {
      }

      try
      {
         m2.readInt();
         fail();
      }
      catch (MessageEOFException e)
      {
      }

      try
      {
         m2.readLong();
         fail();
      }
      catch (MessageEOFException e)
      {
      }

      try
      {
         m2.readShort();
         fail();
      }
      catch (MessageEOFException e)
      {
      }

      //Message should not be writable in read-only mode
      try
      {
         m2.writeBoolean(myBool);
         fail();
      }
      catch (javax.jms.MessageNotWriteableException e)
      {
      }
      try
      {
         m2.writeByte(myByte);
         fail();
      }
      catch (javax.jms.MessageNotWriteableException e)
      {
      }
      try
      {
         m2.writeShort(myShort);
         fail();
      }
      catch (javax.jms.MessageNotWriteableException e)
      {
      }
      try
      {
         m2.writeChar(myChar);
         fail();
      }
      catch (javax.jms.MessageNotWriteableException e)
      {
      }

      try
      {
         m2.writeInt(myInt);
         fail();
      }
      catch (javax.jms.MessageNotWriteableException e)
      {
      }
      try
      {
         m2.writeLong(myLong);
         fail();
      }
      catch (javax.jms.MessageNotWriteableException e)
      {
      }
      try
      {
         m2.writeFloat(myFloat);
         fail();
      }
      catch (javax.jms.MessageNotWriteableException e)
      {
      }
      try
      {
         m2.writeDouble(myDouble);
         fail();
      }
      catch (javax.jms.MessageNotWriteableException e)
      {
      }

      try
      {
         m2.writeBytes(myBytes);
         fail();
      }
      catch (javax.jms.MessageNotWriteableException e)
      {
      }

      try
      {
         m2.writeObject(myString);
         fail();
      }
      catch (javax.jms.MessageNotWriteableException e)
      {
      }

      m2.reset();

      // check we go back to the beginning
      assertEquals(myBool, m2.readBoolean());
      assertEquals(myByte, m2.readByte());
      assertEquals(myShort, m2.readShort());
      assertEquals(myChar, m2.readChar());
      assertEquals(myInt, m2.readInt());
      assertEquals(myLong, m2.readLong());
      assertEquals(myFloat, m2.readFloat(), 0);
      assertEquals(myDouble, m2.readDouble(), 0);
      assertEquals(myString, m2.readString());

      m2.clearBody();

      try
      {
         //Should now be write only
         m2.readBoolean();
         fail();
      }
      catch (MessageNotReadableException e)
      {
      }

      m2.writeBoolean(myBool);

      m2.reset();

      assertEquals(myBool, m2.readBoolean());
      try
      {
         m2.readBoolean();
         fail();
      }
      catch (MessageEOFException e)
      {
      }
View Full Code Here

Examples of javax.jms.StreamMessage

      super.tearDown();
   }

   public void testNullValue() throws Exception
   {
      StreamMessage m = session.createStreamMessage();

      m.writeString(null);

      queueProd.send(m);

      conn.start();

      StreamMessage rm = (StreamMessage)queueCons.receive();

      assertNull(rm.readString());
   }
View Full Code Here

Examples of javax.jms.StreamMessage

   protected void prepareMessage(Message m) throws JMSException
   {
      super.prepareMessage(m);

      StreamMessage sm = (StreamMessage)m;

      sm.writeBoolean(true);
      sm.writeByte((byte)3);
      sm.writeBytes(new byte[] {(byte)4, (byte)5, (byte)6});
      sm.writeChar((char)7);
      sm.writeDouble(8.0);
      sm.writeFloat(9.0f);
      sm.writeInt(10);
      sm.writeLong(11l);
      sm.writeObject("this is an object");
      sm.writeShort((short)12);
      sm.writeString("this is a String");
   }
View Full Code Here

Examples of javax.jms.StreamMessage

   protected void assertEquivalent(Message m, int mode) throws JMSException
   {
      super.assertEquivalent(m, mode);

      StreamMessage sm = (StreamMessage)m;

      sm.reset();

      assertEquals(true, sm.readBoolean());
      assertEquals((byte)3, sm.readByte());
      byte[] bytes = new byte[3];
      sm.readBytes(bytes);
      assertEquals((byte)4, bytes[0]);
      assertEquals((byte)5, bytes[1]);
      assertEquals((byte)6, bytes[2]);
      assertEquals(-1, sm.readBytes(bytes));
      assertEquals((char)7, sm.readChar());
      assertEquals(new Double(8.0), new Double(sm.readDouble()));
      assertEquals(new Float(9.0), new Float(sm.readFloat()));
      assertEquals(10, sm.readInt());
      assertEquals(11l, sm.readLong());
      assertEquals("this is an object", sm.readObject());
      assertEquals((short)12, sm.readShort());
      assertEquals("this is a String", sm.readString());
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.