use of javax.jms.BytesMessage in project meteo by pierre.
the class AMQSession method createMessage.
protected Message createMessage(final Object event) throws JMSException {
final String eventStr = event.toString();
if (useBytesMessage.get()) {
final BytesMessage msg = session.createBytesMessage();
msg.writeBytes(eventStr.getBytes(UTF8));
return msg;
}
return session.createTextMessage(eventStr);
}
use of javax.jms.BytesMessage in project spring-framework by spring-projects.
the class MappingJackson2MessageConverterTests method toBytesMessage.
@Test
public void toBytesMessage() throws Exception {
BytesMessage bytesMessageMock = mock(BytesMessage.class);
Date toBeMarshalled = new Date();
given(sessionMock.createBytesMessage()).willReturn(bytesMessageMock);
converter.toMessage(toBeMarshalled, sessionMock);
verify(bytesMessageMock).setStringProperty("__encoding__", "UTF-8");
verify(bytesMessageMock).setStringProperty("__typeid__", Date.class.getName());
verify(bytesMessageMock).writeBytes(isA(byte[].class));
}
use of javax.jms.BytesMessage in project spring-framework by spring-projects.
the class MappingJackson2MessageConverterTests method fromBytesMessage.
@Test
public void fromBytesMessage() throws Exception {
BytesMessage bytesMessageMock = mock(BytesMessage.class);
Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar");
byte[] bytes = "{\"foo\":\"bar\"}".getBytes();
final ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes);
given(bytesMessageMock.getStringProperty("__typeid__")).willReturn(Object.class.getName());
given(bytesMessageMock.propertyExists("__encoding__")).willReturn(false);
given(bytesMessageMock.getBodyLength()).willReturn(new Long(bytes.length));
given(bytesMessageMock.readBytes(any(byte[].class))).willAnswer(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
return byteStream.read((byte[]) invocation.getArguments()[0]);
}
});
Object result = converter.fromMessage(bytesMessageMock);
assertEquals("Invalid result", result, unmarshalled);
}
use of javax.jms.BytesMessage in project spring-framework by spring-projects.
the class MarshallingMessageConverterTests method fromBytesMessage.
@Test
public void fromBytesMessage() throws Exception {
BytesMessage bytesMessageMock = mock(BytesMessage.class);
Object unmarshalled = new Object();
given(bytesMessageMock.getBodyLength()).willReturn(10L);
given(bytesMessageMock.readBytes(isA(byte[].class))).willReturn(0);
given(unmarshallerMock.unmarshal(isA(Source.class))).willReturn(unmarshalled);
Object result = converter.fromMessage(bytesMessageMock);
assertEquals("Invalid result", result, unmarshalled);
}
use of javax.jms.BytesMessage in project spring-framework by spring-projects.
the class MarshallingMessageConverterTests method toBytesMessage.
@Test
public void toBytesMessage() throws Exception {
BytesMessage bytesMessageMock = mock(BytesMessage.class);
Object toBeMarshalled = new Object();
given(sessionMock.createBytesMessage()).willReturn(bytesMessageMock);
converter.toMessage(toBeMarshalled, sessionMock);
verify(marshallerMock).marshal(eq(toBeMarshalled), isA(Result.class));
verify(bytesMessageMock).writeBytes(isA(byte[].class));
}
Aggregations