use of org.apache.camel.component.rabbitmq.testbeans.TestSerializableObject in project camel by apache.
the class RabbitMQInOutIntTest method serializeTest.
@Test
public void serializeTest() throws InterruptedException, IOException {
TestSerializableObject foo = new TestSerializableObject();
foo.setName("foobar");
TestSerializableObject reply = template.requestBodyAndHeader("direct:rabbitMQ", foo, RabbitMQConstants.EXCHANGE_NAME, EXCHANGE, TestSerializableObject.class);
assertEquals("foobar", reply.getName());
assertEquals("foobar", reply.getDescription());
}
use of org.apache.camel.component.rabbitmq.testbeans.TestSerializableObject in project camel by apache.
the class RabbitMQInOutIntTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:rabbitMQ").id("producingRoute").setHeader("routeHeader", simple("routeHeader")).inOut(rabbitMQEndpoint);
from(rabbitMQEndpoint).id("consumingRoute").log("Receiving message").process(new Processor() {
public void process(Exchange exchange) throws Exception {
if (exchange.getIn().getBody(TestSerializableObject.class) != null) {
TestSerializableObject foo = exchange.getIn().getBody(TestSerializableObject.class);
foo.setDescription("foobar");
} else if (exchange.getIn().getBody(TestPartiallySerializableObject.class) != null) {
TestPartiallySerializableObject foo = exchange.getIn().getBody(TestPartiallySerializableObject.class);
foo.setNonSerializableObject(new TestNonSerializableObject());
foo.setDescription("foobar");
} else if (exchange.getIn().getBody(String.class) != null) {
if (exchange.getIn().getBody(String.class).contains("header")) {
assertEquals(exchange.getIn().getHeader("String"), "String");
assertEquals(exchange.getIn().getHeader("routeHeader"), "routeHeader");
}
if (exchange.getIn().getBody(String.class).contains("Exception")) {
throw new IllegalArgumentException("Boom");
}
if (exchange.getIn().getBody(String.class).contains("TimeOut")) {
Thread.sleep(TIMEOUT_MS * 2);
}
exchange.getIn().setBody(exchange.getIn().getBody(String.class) + " response");
}
}
});
from("direct:rabbitMQNoAutoAck").id("producingRouteNoAutoAck").setHeader("routeHeader", simple("routeHeader")).inOut(noAutoAckEndpoint);
from(noAutoAckEndpoint).id("consumingRouteNoAutoAck").to(resultEndpoint).throwException(new IllegalStateException("test exception"));
}
};
}
use of org.apache.camel.component.rabbitmq.testbeans.TestSerializableObject in project camel by apache.
the class RabbitMQInOutIntTest method testSerializableObject.
@Test
public void testSerializableObject() throws IOException {
TestSerializableObject foo = new TestSerializableObject();
foo.setName("foobar");
byte[] body = null;
try (ByteArrayOutputStream b = new ByteArrayOutputStream();
ObjectOutputStream o = new ObjectOutputStream(b)) {
o.writeObject(foo);
body = b.toByteArray();
}
TestSerializableObject newFoo = null;
try (InputStream b = new ByteArrayInputStream(body);
ObjectInputStream o = new ObjectInputStream(b)) {
newFoo = (TestSerializableObject) o.readObject();
} catch (IOException | ClassNotFoundException e) {
}
assertEquals(foo.getName(), newFoo.getName());
}
use of org.apache.camel.component.rabbitmq.testbeans.TestSerializableObject in project camel by apache.
the class RabbitMQInOutIntTest method headerTest.
@Test
public void headerTest() throws InterruptedException, IOException {
Map<String, Object> headers = new HashMap<String, Object>();
TestSerializableObject testObject = new TestSerializableObject();
testObject.setName("header");
headers.put("String", "String");
headers.put("Boolean", new Boolean(false));
// This will blow up the connection if not removed before sending the message
headers.put("TestObject1", testObject);
// This will blow up the connection if not removed before sending the message
headers.put("class", testObject.getClass());
// This will mess up de-serialization if not removed before sending the message
headers.put("CamelSerialize", true);
// populate a map and an arrayList
Map<Object, Object> tmpMap = new HashMap<Object, Object>();
List<String> tmpList = new ArrayList<String>();
for (int i = 0; i < 3; i++) {
String name = "header" + i;
tmpList.add(name);
tmpMap.put(name, name);
}
// This will blow up the connection if not removed before sending the message
headers.put("arrayList", tmpList);
// This will blow up the connection if not removed before sending the message
headers.put("map", tmpMap);
String reply = template.requestBodyAndHeaders("direct:rabbitMQ", "header", headers, String.class);
assertEquals("header response", reply);
}
Aggregations