Search in sources :

Example 21 with BytesMessage

use of javax.jms.BytesMessage in project spring-framework by spring-projects.

the class SimpleMessageConverter method createMessageForByteArray.

/**
	 * Create a JMS BytesMessage for the given byte array.
	 * @param bytes the byyte array to convert
	 * @param session current JMS session
	 * @return the resulting message
	 * @throws JMSException if thrown by JMS methods
	 * @see javax.jms.Session#createBytesMessage
	 */
protected BytesMessage createMessageForByteArray(byte[] bytes, Session session) throws JMSException {
    BytesMessage message = session.createBytesMessage();
    message.writeBytes(bytes);
    return message;
}
Also used : BytesMessage(javax.jms.BytesMessage)

Example 22 with BytesMessage

use of javax.jms.BytesMessage in project ats-framework by Axway.

the class JmsMessageVerification method getBodyHash.

private byte[] getBodyHash(final String algorithm) {
    isNotNull();
    MessageDigest digest;
    try {
        digest = MessageDigest.getInstance(algorithm);
    } catch (final NoSuchAlgorithmException e) {
        throw new JmsMessageException("Failed to load " + algorithm + " algorithm: " + e);
    }
    try {
        if (actualMessage instanceof TextMessage) {
            digest.update(((TextMessage) actualMessage).getText().getBytes());
        } else if (actualMessage instanceof BytesMessage) {
            final BytesMessage m = (BytesMessage) actualMessage;
            final byte[] tmp = new byte[2048];
            int r;
            while ((r = m.readBytes(tmp)) >= 0) {
                if (r != 0) {
                    digest.update(tmp, 0, r);
                }
            }
        } else if (actualMessage instanceof StreamMessage) {
            final StreamMessage m = (StreamMessage) actualMessage;
            final byte[] tmp = new byte[2048];
            int r;
            while ((r = m.readBytes(tmp)) >= 0) {
                if (r != 0) {
                    digest.update(tmp, 0, r);
                }
            }
        } else {
            throw new JmsMessageException("Cannot determind content hash for message type : " + actualMessage.getClass());
        }
    } catch (final JMSException e) {
        throw new JmsMessageException("Failed to determine message " + algorithm + " hash", e);
    }
    return digest.digest();
}
Also used : JmsMessageException(com.axway.ats.action.exceptions.JmsMessageException) BytesMessage(javax.jms.BytesMessage) StreamMessage(javax.jms.StreamMessage) JMSException(javax.jms.JMSException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest) TextMessage(javax.jms.TextMessage)

Example 23 with BytesMessage

use of javax.jms.BytesMessage in project ats-framework by Axway.

the class JmsClient method doSendBinaryMessage.

// Send and close session
private void doSendBinaryMessage(final Session session, final Destination destination, final byte[] bytes, final Map<String, ?> properties) throws JMSException {
    try {
        BytesMessage message = session.createBytesMessage();
        message.writeBytes(bytes);
        if (properties != null) {
            // Tested with: ActiveMQ
            for (final Entry<String, ?> property : properties.entrySet()) {
                message.setObjectProperty(property.getKey(), property.getValue());
            }
        }
        final MessageProducer producer = session.createProducer(destination);
        producer.send(message);
    } finally {
        releaseSession(false);
    }
}
Also used : BytesMessage(javax.jms.BytesMessage) MessageProducer(javax.jms.MessageProducer)

Example 24 with BytesMessage

use of javax.jms.BytesMessage in project jmeter by apache.

the class Publisher method publish.

public Message publish(byte[] bytes, String destinationName, Map<String, Object> properties, int deliveryMode, int priority, long expiration) throws JMSException, NamingException {
    BytesMessage msg = session.createBytesMessage();
    msg.writeBytes(bytes);
    return setPropertiesAndSend(destinationName, properties, msg, deliveryMode, priority, expiration);
}
Also used : BytesMessage(javax.jms.BytesMessage)

Example 25 with BytesMessage

use of javax.jms.BytesMessage in project tomee by apache.

the class JMSProducerImpl method send.

@Override
public JMSProducer send(final Destination destination, final byte[] body) {
    final BytesMessage message = wrap(context.createBytesMessage());
    if (body != null) {
        try {
            message.writeBytes(body);
        } catch (final JMSException e) {
            throw new MessageFormatRuntimeException(e.getMessage());
        }
    }
    send(destination, message);
    return this;
}
Also used : BytesMessage(javax.jms.BytesMessage) JMSException(javax.jms.JMSException) MessageFormatRuntimeException(javax.jms.MessageFormatRuntimeException)

Aggregations

BytesMessage (javax.jms.BytesMessage)25 JMSException (javax.jms.JMSException)10 TextMessage (javax.jms.TextMessage)9 MapMessage (javax.jms.MapMessage)8 ObjectMessage (javax.jms.ObjectMessage)7 Test (org.junit.Test)7 StreamMessage (javax.jms.StreamMessage)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Map (java.util.Map)3 Message (javax.jms.Message)3 MessageFormatException (javax.jms.MessageFormatException)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Serializable (java.io.Serializable)2 Enumeration (java.util.Enumeration)2 HashMap (java.util.HashMap)2 Session (javax.jms.Session)2 NoTypeConversionAvailableException (org.apache.camel.NoTypeConversionAvailableException)2 RuntimeCamelException (org.apache.camel.RuntimeCamelException)2 DefaultExchangeHolder (org.apache.camel.impl.DefaultExchangeHolder)2