Package javax.jms

Examples of javax.jms.StreamMessage


     * @return
     * @throws JMSException
     */
    protected StreamMessage createStreamMessage () throws JMSException
    {
        StreamMessage ret = null;
        ret = getDestination ().createStreamMessage ();
        return ret;
    }
View Full Code Here


   *
   * @return
   */
  public StreamMessage createStreamMessage() throws JMSException
  {
      StreamMessage ret = null;

      try {
          if ( session == null )
              refresh ();
          ret = session.createStreamMessage ();
View Full Code Here

            ObjectMessage m = createObjectMessage ();
            Serializable content = ((ObjectMessage) message).getObject ();
            m.setObject ( content );
            ret = m;
        } else if ( message instanceof StreamMessage ) {
            StreamMessage m = createStreamMessage ();
            StreamMessage src = (StreamMessage) message;
            Object lastRead = null;
            do {
                lastRead = null;
                try {
                    lastRead = src.readObject ();
                    if ( lastRead != null ) {
                        m.writeObject ( lastRead );
                        // System.out.println ( "Copied object: " + lastRead );
                        // System.out.println ( "to message: " + m );
                    }
                } catch ( MessageEOFException noMoreData ) {
                }
            } while ( lastRead != null );

            ret = m;
        } else if ( message instanceof BytesMessage ) {
            BytesMessage m = createBytesMessage ();
            BytesMessage src = (BytesMessage) message;
            final int LEN = 100;
            byte[] buf = new byte[LEN];
            int bytesRead = src.readBytes ( buf );
            while ( bytesRead >= 0 ) {
                m.writeBytes ( buf, 0, bytesRead );
                bytesRead = src.readBytes ( buf );
            }

            ret = m;
        } else {
            // no known subinterface of Message
View Full Code Here

        MessageProducer mandatoryProducer = producerSession.createProducer(queue);

        // Third test - should be routed
        _logger.info("Sending isBound message");
        StreamMessage msg = producerSession.createStreamMessage();

        msg.setStringProperty("F1000", "1");

        msg.writeByte((byte) 42);

        mandatoryProducer.send(msg);

        _logger.info("Starting consumer connection");
        con.start();

        StreamMessage msg2 = (StreamMessage) consumer.receive(2000);
        assertNotNull(msg2);

        msg2.readByte();
        try
        {
            msg2.readByte();
            fail("Expected exception not thrown");
        }
        catch (Exception e)
        {
            assertTrue("Expected MessageEOFException: " + e, e instanceof MessageEOFException);
View Full Code Here

        consumer.setMessageListener(new MessageListener()
            {

                public void onMessage(Message message)
                {
                    final StreamMessage sm = (StreamMessage) message;
                    try
                    {
                        sm.clearBody();
                        // it is legal to extend a stream message's content
                        sm.writeString("dfgjshfslfjshflsjfdlsjfhdsljkfhdsljkfhsd");
                    }
                    catch (Throwable t)
                    {
                        listenerCaughtException.set(t);
                    }
                    finally
                    {
                        awaitMessages.countDown();
                    }
                }
            });

        Connection con2 = (AMQConnection) getConnection("guest", "guest");
        AMQSession producerSession = (AMQSession) con2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        MessageProducer producer = producerSession.createProducer(queue);
        con.start();
        StreamMessage sm = producerSession.createStreamMessage();
        sm.writeInt(42);
        producer.send(sm);

        // Allow up to five seconds for the message to arrive with the consumer
        final boolean completed = awaitMessages.await(5, TimeUnit.SECONDS);
        assertTrue("Message did not arrive with consumer within a reasonable time", completed);
View Full Code Here

        return message;
    }

    public static StreamMessage newStreamMessage(Session session, int size) throws JMSException
    {
        StreamMessage message = session.createStreamMessage();
        message.writeString(createMessagePayload(size));
        return message;
    }
View Full Code Here

        MessageProducer mandatoryProducer = producerSession.createProducer(queue);

        // Third test - should be routed
        _logger.info("Sending isBound message");
        StreamMessage msg = producerSession.createStreamMessage();

        msg.setStringProperty("F1000", "1");

        msg.writeByte((byte) 42);

        mandatoryProducer.send(msg);

        _logger.info("Starting consumer connection");
        con.start();

        StreamMessage msg2 = (StreamMessage) consumer.receive(2000);
        assertNotNull(msg2);

        msg2.readByte();
        try
        {
            msg2.readByte();
            fail("Expected exception not thrown");
        }
        catch (Exception e)
        {
            assertTrue("Expected MessageEOFException: " + e, e instanceof MessageEOFException);
View Full Code Here

        consumer.setMessageListener(new MessageListener()
            {

                public void onMessage(Message message)
                {
                    final StreamMessage sm = (StreamMessage) message;
                    try
                    {
                        sm.clearBody();
                        // it is legal to extend a stream message's content
                        sm.writeString("dfgjshfslfjshflsjfdlsjfhdsljkfhdsljkfhsd");
                    }
                    catch (Throwable t)
                    {
                        listenerCaughtException.set(t);
                    }
                    finally
                    {
                        awaitMessages.countDown();
                    }
                }
            });

        Connection con2 = (AMQConnection) getConnection("guest", "guest");
        AMQSession producerSession = (AMQSession) con2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        MessageProducer producer = producerSession.createProducer(queue);
        con.start();
        StreamMessage sm = producerSession.createStreamMessage();
        sm.writeInt(42);
        producer.send(sm);

        // Allow up to five seconds for the message to arrive with the consumer
        final boolean completed = awaitMessages.await(5, TimeUnit.SECONDS);
        assertTrue("Message did not arrive with consumer within a reasonable time", completed);
View Full Code Here

        setMessageProperties(message);
    }

    public MessageConverter(AMQSession session, StreamMessage message) throws JMSException
    {
        StreamMessage nativeMessage = session.createStreamMessage();

        try
        {
            message.reset();
            while (true)
            {
                nativeMessage.writeObject(message.readObject());
            }
        }
        catch (MessageEOFException e)
        {
            // we're at the end so don't mind the exception
View Full Code Here

        return message;
    }

    public static StreamMessage newStreamMessage(Session session, int size) throws JMSException
    {
        StreamMessage message = session.createStreamMessage();
        message.writeString(createMessagePayload(size));
        return message;
    }
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.