Package javax.jms

Examples of javax.jms.BytesMessage


        endpoint.expectedMessageCount(1);

        jmsTemplate.setPubSubDomain(false);
        jmsTemplate.send("test.bytes", new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                BytesMessage bytesMessage = session.createBytesMessage();
                bytesMessage.writeByte((byte) 1);
                bytesMessage.writeByte((byte) 2);
                bytesMessage.writeByte((byte) 3);
                return bytesMessage;
            }
        });

        endpoint.assertIsSatisfied();
View Full Code Here


        if (message instanceof TextMessage) {
            final String text = ((TextMessage)message).getText();
            return NIOConverter.toByteBuffer(text, exchange);
        }
        if (message instanceof BytesMessage) {
            final BytesMessage bmsg = (BytesMessage)message;
            final int len = (int)bmsg.getBodyLength();
            final byte[] data = new byte[len];
            bmsg.readBytes(data, len);
            return NIOConverter.toByteBuffer(data);

        }
        if (message instanceof StreamMessage) {
            final StreamMessage msg = (StreamMessage)message;
View Full Code Here

                throws JMSException;

            void send(JMSEndpoint endpoint, byte[] message, HashMap properties)
                throws Exception
            {
                BytesMessage jmsMessage = m_session.createBytesMessage();
                jmsMessage.writeBytes(message);
                int deliveryMode = extractDeliveryMode(properties);
                int priority = extractPriority(properties);
                long timeToLive = extractTimeToLive(properties);

                if(properties != null && !properties.isEmpty())
View Full Code Here

                        HashMap properties)
                throws Exception
            {
                Destination reply = createTemporaryDestination();
                MessageConsumer subscriber = createConsumer(reply);
                BytesMessage jmsMessage = m_session.createBytesMessage();
                jmsMessage.writeBytes(message);
                jmsMessage.setJMSReplyTo(reply);

                int deliveryMode = extractDeliveryMode(properties);
                int priority = extractPriority(properties);
                long timeToLive = extractTimeToLive(properties);

                if(properties != null && !properties.isEmpty())
                    setProperties(properties, jmsMessage);

                send(endpoint.getDestination(m_session), jmsMessage, deliveryMode,
                     priority, timeToLive);
                BytesMessage response = null;
                try {
                    response = (BytesMessage)subscriber.receive(timeout);
                } catch (ClassCastException cce) {
                    throw new InvokeException
                            ("Error: unexpected message type received - expected BytesMessage");
                }
                byte[] respBytes = null;
                if(response != null)
                {
                    byte[] buffer = new byte[8 * 1024];
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    for(int bytesRead = response.readBytes(buffer);
                        bytesRead != -1; bytesRead = response.readBytes(buffer))
                    {
                        out.write(buffer, 0, bytesRead);
                    }
                    respBytes = out.toByteArray();
                }
View Full Code Here

                throws JMSException;

            void send(JMSEndpoint endpoint, byte[] message, HashMap properties)
                throws JMSException
            {
                BytesMessage jmsMessage = m_session.createBytesMessage();
                jmsMessage.writeBytes(message);
                int deliveryMode = extractDeliveryMode(properties);
                int priority = extractPriority(properties);
                long timeToLive = extractTimeToLive(properties);

                if(properties != null && !properties.isEmpty())
View Full Code Here

                        HashMap properties)
                throws JMSException
            {
                Destination reply = createTemporaryDestination();
                MessageConsumer subscriber = createConsumer(reply);
                BytesMessage jmsMessage = m_session.createBytesMessage();
                jmsMessage.writeBytes(message);
                jmsMessage.setJMSReplyTo(reply);

                int deliveryMode = extractDeliveryMode(properties);
                int priority = extractPriority(properties);
                long timeToLive = extractTimeToLive(properties);

                if(properties != null && !properties.isEmpty())
                    setProperties(properties, jmsMessage);

                send(endpoint.getDestination(m_session), jmsMessage, deliveryMode,
                     priority, timeToLive);
                BytesMessage response = null;
                try {
                    response = (BytesMessage)subscriber.receive(timeout);
                } catch (ClassCastException cce) {
                    throw new InvokeException
                            ("Error: unexpected message type received - expected BytesMessage");
                }
                byte[] respBytes = null;
                if(response != null)
                {
                    byte[] buffer = new byte[8 * 1024];
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    for(int bytesRead = response.readBytes(buffer);
                        bytesRead != -1; bytesRead = response.readBytes(buffer))
                    {
                        out.write(buffer, 0, bytesRead);
                    }
                    respBytes = out.toByteArray();
                }
View Full Code Here

        } else {
            ActiveMQMessage activeMessage = null;

            if (message instanceof BytesMessage) {
                BytesMessage bytesMsg = (BytesMessage)message;
                bytesMsg.reset();
                ActiveMQBytesMessage msg = new ActiveMQBytesMessage();
                msg.setConnection(connection);
                try {
                    for (;;) {
                        // Reads a byte from the message stream until the stream
                        // is empty
                        msg.writeByte(bytesMsg.readByte());
                    }
                } catch (MessageEOFException e) {
                    // if an end of message stream as expected
                } catch (JMSException e) {
                }
View Full Code Here

                message.setText(payload);
            }
            return message;
        }
        case Bytes: {
            BytesMessage message = session.createBytesMessage();
            if (body != null) {
                byte[] payload = context.getTypeConverter().convertTo(byte[].class, exchange, body);
                message.writeBytes(payload);
            }
            return message;
        }
        case Map: {
            MapMessage message = session.createMapMessage();
            if (body != null) {
                Map<?, ?> payload = context.getTypeConverter().convertTo(Map.class, exchange, body);
                populateMapMessage(message, payload, context);
            }
            return message;
        }
        case Object:
            ObjectMessage message = session.createObjectMessage();
            if (body != null) {
                try {
                    Serializable payload = context.getTypeConverter().mandatoryConvertTo(Serializable.class, exchange, body);
                    message.setObject(payload);
                } catch (NoTypeConversionAvailableException e) {
                    // cannot convert to serializable then thrown an exception to avoid sending a null message
                    JMSException cause = new MessageFormatException(e.getMessage());
                    cause.initCause(e);
                    throw cause;
View Full Code Here

        try {
            /**
             * Construct a bytes message object.
             * This is to make sure the utility works across all vendors.
             */
            BytesMessage bmessage = session.createBytesMessage();

            /**
             * This is here to make sure that RI's bad SOAP implementation
             * will get updated for internal buffers.
             */
 
View Full Code Here

    public static SOAPMessage
    SOAPMessageFromJMSMessage(Message message, MessageFactory messageFactory)
                                                throws JAXMException {

        SOAPMessage soapMessage = null;
        BytesMessage bmessage = (BytesMessage) message;

        try {

            //1. construct mime header
            int mimeLength = bmessage.readInt();
            byte[] mbuf = new byte [mimeLength];
            bmessage.readBytes(mbuf, mimeLength);

            ByteArrayInputStream mbin = new ByteArrayInputStream (mbuf);
            ObjectInputStream oi = new ObjectInputStream (mbin);
            Hashtable ht = (Hashtable) oi.readObject();
            MimeHeaders mimeHeaders = hashtableToMime (ht);

            //2. get soap body stream.
            int bodyLength = bmessage.readInt();
            byte[] buf = new byte [bodyLength];
            bmessage.readBytes(buf, bodyLength);

            ByteArrayInputStream bin = new ByteArrayInputStream (buf);

            if ( messageFactory == null ) {
                messageFactory = getMessageFactory ();
View Full Code Here

TOP

Related Classes of javax.jms.BytesMessage

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.