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;
}
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();
}
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);
}
}
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);
}
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;
}
Aggregations