Search in sources :

Example 16 with BytesMessage

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);
}
Also used : BytesMessage(javax.jms.BytesMessage)

Example 17 with BytesMessage

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));
}
Also used : BytesMessage(javax.jms.BytesMessage) Date(java.util.Date) Test(org.junit.Test)

Example 18 with BytesMessage

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) BytesMessage(javax.jms.BytesMessage) Test(org.junit.Test)

Example 19 with BytesMessage

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);
}
Also used : BytesMessage(javax.jms.BytesMessage) Source(javax.xml.transform.Source) Test(org.junit.Test)

Example 20 with BytesMessage

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));
}
Also used : BytesMessage(javax.jms.BytesMessage) Result(javax.xml.transform.Result) Test(org.junit.Test)

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