Package javax.jms

Examples of javax.jms.StreamMessage


   @Override
   protected void assertEquivalent(final Message m, final int mode, final boolean redelivery) throws JMSException
   {
      super.assertEquivalent(m, mode, redelivery);

      StreamMessage sm = (StreamMessage)m;

      ProxyAssertSupport.assertTrue(sm.readBoolean());

      byte bytes[] = new byte[5];
      sm.readBytes(bytes);
      String s = new String(bytes);
      ProxyAssertSupport.assertEquals("jboss", s);
      ProxyAssertSupport.assertEquals(-1, sm.readBytes(bytes));

      ProxyAssertSupport.assertEquals(sm.readChar(), 'c');
      ProxyAssertSupport.assertEquals(sm.readDouble(), 1.0D, 0.0D);
      ProxyAssertSupport.assertEquals(sm.readFloat(), 2.0F, 0.0F);
      ProxyAssertSupport.assertEquals(sm.readInt(), 3);
      ProxyAssertSupport.assertEquals(sm.readLong(), 4L);
      ProxyAssertSupport.assertEquals(sm.readObject(), "object");
      ProxyAssertSupport.assertEquals(sm.readShort(), (short)5);
      ProxyAssertSupport.assertEquals(sm.readString(), "stringvalue");
   }
View Full Code Here


         mm.setString("s1", "aardvark");

         ObjectMessage om = sessSend.createObjectMessage();
         om.setObject("aardvark");

         StreamMessage sm = sessSend.createStreamMessage();
         sm.writeString("aardvark");

         TextMessage tm = sessSend.createTextMessage("aardvark");

         theProducer.send(m);
         theProducer.send(bm);
         theProducer.send(mm);
         theProducer.send(om);
         theProducer.send(sm);
         theProducer.send(tm);

         theConn.close();

         theOtherConn = JMSTestCase.cf.createConnection();
         theOtherConn.start();

         Session sessReceive = theOtherConn.createSession(false, Session.AUTO_ACKNOWLEDGE);

         MessageConsumer theConsumer = sessReceive.createConsumer(HornetQServerTestCase.queue1);

         Message m2 = theConsumer.receive(1500);

         log.trace("m2 is " + m2);

         ProxyAssertSupport.assertNotNull(m2);

         ProxyAssertSupport.assertEquals("aardvark", m2.getStringProperty("p1"));

         BytesMessage bm2 = (BytesMessage)theConsumer.receive(1500);
         ProxyAssertSupport.assertEquals("aardvark", bm2.readUTF());

         MapMessage mm2 = (MapMessage)theConsumer.receive(1500);
         ProxyAssertSupport.assertEquals("aardvark", mm2.getString("s1"));

         ObjectMessage om2 = (ObjectMessage)theConsumer.receive(1500);
         ProxyAssertSupport.assertEquals("aardvark", (String)om2.getObject());

         StreamMessage sm2 = (StreamMessage)theConsumer.receive(1500);
         ProxyAssertSupport.assertEquals("aardvark", sm2.readString());

         TextMessage tm2 = (TextMessage)theConsumer.receive(1500);
         ProxyAssertSupport.assertEquals("aardvark", tm2.getText());
      }
      finally
View Full Code Here

         MessageConsumer cons = sess.createConsumer(queue);

         conn.start();

         StreamMessage msg = sess.createStreamMessage();
        
         msg.writeInt(1);
         msg.writeInt(2);
         msg.writeInt(3);


         StreamMessage received = (StreamMessage)sendAndConsumeMessage(msg, prod, cons);

         Assert.assertNotNull(received);

         assertEquals(1, received.readObject());
         assertEquals(2, received.readObject());
         assertEquals(3, received.readObject());
        
         try
         {
            received.readObject();
           
            fail("Should throw exception");
         }
         catch (MessageEOFException e)
         {
            //Ok
         }
        
         try
         {
            received.readBoolean();
           
            fail("Should throw exception");
         }
         catch (MessageEOFException e)
         {
            //Ok
         }
        
         try
         {
            received.readByte();
           
            fail("Should throw exception");
         }
         catch (MessageEOFException e)
         {
            //Ok
         }
        
         try
         {
            received.readChar();
           
            fail("Should throw exception");
         }
         catch (MessageEOFException e)
         {
            //Ok
         }
        
         try
         {
            received.readDouble();
           
            fail("Should throw exception");
         }
         catch (MessageEOFException e)
         {
            //Ok
         }
        
         try
         {
            received.readFloat();
           
            fail("Should throw exception");
         }
         catch (MessageEOFException e)
         {
            //Ok
         }
        
         try
         {
            received.readInt();
           
            fail("Should throw exception");
         }
         catch (MessageEOFException e)
         {
            //Ok
         }
        
         try
         {
            received.readLong();
           
            fail("Should throw exception");
         }
         catch (MessageEOFException e)
         {
            //Ok
         }
        
         try
         {
            received.readShort();
           
            fail("Should throw exception");
         }
         catch (MessageEOFException e)
         {
            //Ok
         }
        
         try
         {
            received.readString();
           
            fail("Should throw exception");
         }
         catch (MessageEOFException e)
         {
View Full Code Here

                                                          System.currentTimeMillis(),
                                                          (byte)4,
                                                          1000);
      ClientSession session = new FakeSession(clientMessage);

      StreamMessage foreignStreamMessage = new SimpleJMSStreamMessage();
      foreignStreamMessage.writeByte((byte)1);
      foreignStreamMessage.writeByte((byte)2);
      foreignStreamMessage.writeByte((byte)3);

      HornetQStreamMessage copy = new HornetQStreamMessage(foreignStreamMessage, session);

      MessageHeaderTestBase.ensureEquivalent(foreignStreamMessage, copy);
   }
View Full Code Here

   }

   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

   }

   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());
         ProxyAssertSupport.fail();
      }
      catch (MessageFormatException e)
      {
      }

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

      queueProducer.send(HornetQServerTestCase.queue1, m);

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

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

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

      assertByteArraysEqual(myBytes, bytes);

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

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

      ProxyAssertSupport.assertEquals(3, ret);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      m2.reset();

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

      m2.clearBody();

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

      m2.writeBoolean(myBool);

      m2.reset();

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

      super.tearDown();
   }

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

      m.writeString(null);

      queueProd.send(m);

      conn.start();

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

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

   @Override
   protected void prepareMessage(final 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

   @Override
   protected void assertEquivalent(final Message m, final int mode, final boolean redelivery) throws JMSException
   {
      super.assertEquivalent(m, mode, redelivery);

      StreamMessage sm = (StreamMessage)m;

      sm.reset();

      ProxyAssertSupport.assertEquals(true, sm.readBoolean());
      ProxyAssertSupport.assertEquals((byte)3, sm.readByte());
      byte[] bytes = new byte[3];
      sm.readBytes(bytes);
      ProxyAssertSupport.assertEquals((byte)4, bytes[0]);
      ProxyAssertSupport.assertEquals((byte)5, bytes[1]);
      ProxyAssertSupport.assertEquals((byte)6, bytes[2]);
      ProxyAssertSupport.assertEquals(-1, sm.readBytes(bytes));
      ProxyAssertSupport.assertEquals((char)7, sm.readChar());
      ProxyAssertSupport.assertEquals(new Double(8.0), new Double(sm.readDouble()));
      ProxyAssertSupport.assertEquals(new Float(9.0), new Float(sm.readFloat()));
      ProxyAssertSupport.assertEquals(10, sm.readInt());
      ProxyAssertSupport.assertEquals(11l, sm.readLong());
      ProxyAssertSupport.assertEquals("this is an object", sm.readObject());
      ProxyAssertSupport.assertEquals((short)12, sm.readShort());
      ProxyAssertSupport.assertEquals("this is a String", sm.readString());
   }
View Full Code Here

        data.add(new Double("7"));
        data.add(new String("8"));
        data.add(null);
        data.add(new byte[] {9, 10});

        StreamMessage result = (StreamMessage) JmsMessageUtils.toMessage(data, session);

        // Resets so it's readable
        result.reset();
        assertEquals(Boolean.TRUE, result.readObject());
        assertEquals(new Byte("1"), result.readObject());
        assertEquals(new Short("2"), result.readObject());
        assertEquals(new Character('3'), result.readObject());
        assertEquals(new Integer("4"), result.readObject());
        // can't write Longs: https://issues.apache.org/activemq/browse/AMQ-1965
        // assertEquals(new Long("5"), result.readObject());
        assertEquals(new Float("6"), result.readObject());
        assertEquals(new Double("7"), result.readObject());
        assertEquals(new String("8"), result.readObject());
        assertNull(result.readObject());
        assertTrue(Arrays.equals(new byte[] {9, 10}, (byte[]) result.readObject()));
    }
View Full Code Here

TOP

Related Classes of javax.jms.StreamMessage

Copyright © 2018 www.massapicom. 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.