Package javax.jms

Examples of javax.jms.StreamMessage


            bmsg.readBytes(data,len);
            return NIOConverter.toByteBuffer(data);
           
        }
        if (message instanceof StreamMessage) {
            final StreamMessage msg = (StreamMessage)message;
            final ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
            final DataOutputStream dataOut = new DataOutputStream(bytesOut);
            try {
                while (true) {
                    final Object obj = msg.readObject();
                    writeData(dataOut,obj);
                }
            }catch(MessageEOFException e) {
                //we have no other way of knowing the end of the message
            }
            dataOut.close();
            return NIOConverter.toByteBuffer(bytesOut.toByteArray());
        }
        if (message instanceof MapMessage) {
            final MapMessage msg = (MapMessage)message;
            final ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
            final DataOutputStream dataOut = new DataOutputStream(bytesOut);
            for (final Enumeration en = msg.getMapNames(); en.hasMoreElements();) {
                final Object obj = msg.getObject(en.nextElement().toString());
                writeData(dataOut,obj);
            }
            dataOut.close();
            return NIOConverter.toByteBuffer(bytesOut.toByteArray());
        }
View Full Code Here


      System.out.println(key + " => " + m.getObject(key));
    }
  }
  else if (args[0].equals("-s")) {
    System.out.println("Receiving as StreamMessage");
          StreamMessage m = (StreamMessage)consumer.receive();
          System.out.println(m);
    System.out.println("==========================================");
    System.out.println("Printing stream contents:");
    try {
      while(true)
        System.out.println(m.readObject());
    }
    catch (MessageEOFException e) {
      // DONE
    }
  }
View Full Code Here

    }

    public void testCreateStreamMessage() throws Exception
    {
        AMQSession_0_10 session = createAMQSession_0_10();
        StreamMessage m = session.createStreamMessage();
        assertTrue("Legacy Stream message encoding should be the default" + m.getClass(),!(m instanceof AMQPEncodedListMessage));
    }
View Full Code Here

    public void testStreamMessage() throws JMSException, IOException
    {
        //Create Sample Message using UUIDs
        UUID test = UUID.randomUUID();

        StreamMessage testMessage = _session.createStreamMessage();

        byte[] testBytes = convertToBytes(test);

        testMessage.writeBytes(testBytes);

        sendAndTest(testMessage, testBytes);
    }
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

                    TextMessage textMsg = (TextMessage) message;
                    bodyMessage.setHeader(JMS_MESSAGE_TYPE, JmsMessageType.Text);
                    bodyMessage.setBody(textMsg.getText());
                    break;
                case Stream:
                    StreamMessage streamMessage = (StreamMessage) message;
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    int next = streamMessage.readByte();
                    while (next > -1) {
                        baos.write(next);
                        next = streamMessage.readByte();
                    }
                    baos.flush();
                    bodyMessage.setHeader(JMS_MESSAGE_TYPE, JmsMessageType.Bytes);
                    bodyMessage.setBody(baos.toByteArray());
                    break;
View Full Code Here

         } else if (jmsMessage instanceof ObjectMessage) {
             ObjectMessage sourceObj = ObjectMessage.class.cast(jmsMessage);
             syMessage.setContent(sourceObj.getObject());
            
        } else if (jmsMessage instanceof StreamMessage) {
            StreamMessage sourceStream = StreamMessage.class.cast(jmsMessage);
            syMessage.setContent(sourceStream);
           
        } else if (jmsMessage instanceof TextMessage) {
            TextMessage sourceText = TextMessage.class.cast(jmsMessage);
            syMessage.setContent(sourceText.getText());
View Full Code Here

        } else if (jmsMessage instanceof BytesMessage) {
            BytesMessage msg = BytesMessage.class.cast(jmsMessage);
            msg.writeBytes(syMessage.getContent(byte[].class));

        } else if (jmsMessage instanceof StreamMessage) {
            StreamMessage msg = StreamMessage.class.cast(jmsMessage);
            byte[] buffer = new byte[8192];
            int size = 0;
            if (syMessage.getContent() instanceof StreamMessage) {
                // in case the StreamMessage is passed through from JMS inbound
                StreamMessage sm = syMessage.getContent(StreamMessage.class);
                while ((size = sm.readBytes(buffer)) > 0) {
                    msg.writeBytes(buffer, 0, size);
                }
            } else {
                InputStream is = syMessage.getContent(InputStream.class);
                while ((size = is.read(buffer)) > 0) {
View Full Code Here

        assertNull(op.get(MESSAGE_CONTENT_MAP));
    }

    @Test
    public void testExtractStreamMessageTypeAttributes() throws JMSException {
        StreamMessage objectMessage = mock(StreamMessage.class);

        Operation op = new Operation();

        extractMessageTypeAttributes(op, objectMessage);
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.