Examples of BytesMessage


Examples of javax.jms.BytesMessage

         theProducer.setDeliveryMode(DeliveryMode.PERSISTENT);

         Message m = sessSend.createMessage();
         m.setStringProperty("p1", "aardvark");

         BytesMessage bm = sessSend.createBytesMessage();
         bm.writeObject("aardvark");

         MapMessage mm = sessSend.createMapMessage();
         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);
View Full Code Here

Examples of javax.jms.BytesMessage

   }

   public void sendMessage(byte[] data, String propertyName, String propertyValue, Destination destination) throws Exception
   {
      MessageProducer producer = session.createProducer(destination);
      BytesMessage message = session.createBytesMessage();
      message.setStringProperty(propertyName, propertyValue);
      message.writeBytes(data);
      producer.send(message);
   }
View Full Code Here

Examples of javax.jms.BytesMessage

         MessageProducer prod = sess.createProducer(HornetQServerTestCase.queue1);
         prod.setDeliveryMode(DeliveryMode.PERSISTENT);

         for (int i = 0; i < 1; i++)
         {
            BytesMessage bm = sess.createBytesMessage();

            bm.writeBytes(bytes);

            prod.send(bm);
         }

         conn.close();

         stop();

         startNoDelete();

         // HornetQ server restart implies new ConnectionFactory lookup
         deployAndLookupAdministeredObjects();

         conn = JMSTestCase.cf.createConnection();
         sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
         conn.start();
         MessageConsumer cons = sess.createConsumer(HornetQServerTestCase.queue1);
         for (int i = 0; i < 1; i++)
         {
            BytesMessage bm = (BytesMessage)cons.receive(3000);

            ProxyAssertSupport.assertNotNull(bm);

            byte[] bytes2 = new byte[bytes.length];

            bm.readBytes(bytes2);

            for (int j = 0; j < bytes.length; j++)
            {
               ProxyAssertSupport.assertEquals(bytes[j], bytes2[j]);
            }
View Full Code Here

Examples of javax.jms.BytesMessage

         subscriber1 = session.createDurableSubscriber(topic1, "subscriber-1");
         subscriber2 = session.createDurableSubscriber(topic1, "subscriber-2");

         // -----------------(Step1) Publish Messages to make Paging Files. --------------------
         System.out.println("---------- Send messages. ----------");
         BytesMessage bytesMessage = session.createBytesMessage();
         bytesMessage.writeBytes(new byte[JMSPagingFileDeleteTest.MESSAGE_SIZE]);
         for (int i = 0; i < JMSPagingFileDeleteTest.MESSAGE_NUM; i++)
         {
            producer.send(bytesMessage);
         }
         System.out.println("Sent " + JMSPagingFileDeleteTest.MESSAGE_NUM + " messages.");

         pagingStore = server.getPagingManager().getPageStore(new SimpleString("jms.topic.topic1"));
         printPageStoreInfo(pagingStore);

         assertTrue(pagingStore.isPaging());

         connection.start();

         // -----------------(Step2) Restart the server. --------------------------------------
         stopAndStartServer(); // If try this test without restarting server, please comment out this line;

         // -----------------(Step3) Subscribe to all the messages from the topic.--------------
         System.out.println("---------- Receive all messages. ----------");
         for (int i = 0; i < JMSPagingFileDeleteTest.MESSAGE_NUM; i++)
         {
            Message message1 = subscriber1.receive(JMSPagingFileDeleteTest.RECEIVE_TIMEOUT);
            assertNotNull(message1);
            Message message2 = subscriber2.receive(JMSPagingFileDeleteTest.RECEIVE_TIMEOUT);
            assertNotNull(message2);
         }

         pagingStore = server.getPagingManager().getPageStore(new SimpleString("jms.topic.topic1"));
         long timeout = System.currentTimeMillis() + 5000;
         while (timeout > System.currentTimeMillis() && pagingStore.isPaging())
         {
            Thread.sleep(100);
         }
         assertFalse(pagingStore.isPaging());
        
         printPageStoreInfo(pagingStore);

         assertEquals(0, pagingStore.getAddressSize());
         // assertEquals(1, pagingStore.getNumberOfPages()); //I expected number of the page is 1, but It was not.
         assertFalse(pagingStore.isPaging()); // I expected IsPaging is false, but It was true.
         // If the server is not restart, this test pass.

         // -----------------(Step4) Publish a message. the message is stored in the paging file.
         producer = session.createProducer(topic1);
         bytesMessage = session.createBytesMessage();
         bytesMessage.writeBytes(new byte[JMSPagingFileDeleteTest.MESSAGE_SIZE]);
         producer.send(bytesMessage);

         printPageStoreInfo(pagingStore);
        
         timeout = System.currentTimeMillis() + 10000;
View Full Code Here

Examples of javax.jms.BytesMessage

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

      BytesMessage bm = (BytesMessage)m;

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

Examples of javax.jms.BytesMessage

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

      BytesMessage bm = (BytesMessage)m;

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

Examples of javax.jms.BytesMessage

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

      BytesMessage foreignBytesMessage = new SimpleJMSBytesMessage();
      for (int i = 0; i < 20; i++)
      {
         foreignBytesMessage.writeByte((byte)i);
      }

      HornetQBytesMessage copy = new HornetQBytesMessage(foreignBytesMessage, session);

      foreignBytesMessage.reset();
      copy.reset();

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

Examples of javax.jms.BytesMessage

      received.readByte();
   }

   public void testBytesMessage() throws Exception
   {
      BytesMessage m = queueProducerSession.createBytesMessage();

      // 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";
      log.trace("String is length:" + myString.length());
      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.writeUTF(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)
      {
         // OK
      }

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

      queueProducer.send(HornetQServerTestCase.queue1, m);

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

      ProxyAssertSupport.assertNotNull(m2);

      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.readUTF());

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

      assertByteArraysEqual(myBytes, bytes);

      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]);

      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.readUTF());

      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)
      {
         // OK
      }

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

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

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

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

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

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

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

      try
      {
         m2.readUnsignedByte();
         ProxyAssertSupport.fail();
      }
      catch (MessageEOFException e)
      {
         // OK
      }

      try
      {
         m2.readUnsignedShort();
         ProxyAssertSupport.fail();
      }
      catch (MessageEOFException e)
      {
         // OK
      }

      try
      {
         m2.readUTF();
         ProxyAssertSupport.fail();
      }
      catch (MessageEOFException e)
      {
         // OK
      }

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

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

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

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

      long bodyLength = m2.getBodyLength();

      ProxyAssertSupport.assertEquals(161, bodyLength);

      m2.reset();

      // test the unsigned reads

      m2.readBoolean();
      int unsignedByte = m2.readUnsignedByte();

      ProxyAssertSupport.assertEquals((int)(myByte & 0xFF), unsignedByte);

      int unsignedShort = m2.readUnsignedShort();

      ProxyAssertSupport.assertEquals((int)(myShort & 0xFFFF), unsignedShort);

      m2.clearBody();

      try
      {
         m2.getBodyLength();
         ProxyAssertSupport.fail();
      }
      catch (MessageNotReadableException e)
      {
         // OK
      }

      m2.reset();

      ProxyAssertSupport.assertEquals(0, m2.getBodyLength());

      // Test that changing the received message doesn't affect the sent message
      m.reset();
      ProxyAssertSupport.assertEquals(161, m.getBodyLength());

View Full Code Here

Examples of javax.jms.BytesMessage

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

      BytesMessage byteMsg = (BytesMessage)m;

      StringBuffer sb = new StringBuffer();
      byte[] buffer = new byte[1024];
      int n = byteMsg.readBytes(buffer);
      while (n != -1)
      {
         sb.append(new String(buffer, 0, n));
         n = byteMsg.readBytes(buffer);
      }
      ProxyAssertSupport.assertEquals("HornetQ", sb.toString());
   }
View Full Code Here

Examples of javax.jms.BytesMessage

                jmsException.setLinkedException(e);
                throw jmsException;
            }
        }
        if (body instanceof byte[]) {
            BytesMessage result = session.createBytesMessage();
            result.writeBytes((byte[])body);
            return result;
        }
        if (body instanceof Map) {
            MapMessage result = session.createMapMessage();
            Map<?, ?> map = (Map<?, ?>)body;
            try {
                populateMapMessage(result, map, context);
                return result;
            } catch (JMSException e) {
                // if MapMessage creation failed then fall back to Object Message
                LOG.warn("Can not populate MapMessage will fall back to ObjectMessage, cause by: " + e.getMessage());
            }
        }
        if (body instanceof String) {
            return session.createTextMessage((String)body);
        }
        if (body instanceof File || body instanceof Reader || body instanceof InputStream || body instanceof ByteBuffer) {
            BytesMessage result = session.createBytesMessage();
            byte[] bytes = context.getTypeConverter().convertTo(byte[].class, body);
            result.writeBytes(bytes);
            return result;
        }
        if (body instanceof Serializable) {
            return session.createObjectMessage((Serializable)body);
        }
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.