Search in sources :

Example 1 with TestSerializableObject

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());
}
Also used : TestSerializableObject(org.apache.camel.component.rabbitmq.testbeans.TestSerializableObject) Test(org.junit.Test)

Example 2 with TestSerializableObject

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"));
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) TestSerializableObject(org.apache.camel.component.rabbitmq.testbeans.TestSerializableObject) Processor(org.apache.camel.Processor) TestPartiallySerializableObject(org.apache.camel.component.rabbitmq.testbeans.TestPartiallySerializableObject) RouteBuilder(org.apache.camel.builder.RouteBuilder) TestNonSerializableObject(org.apache.camel.component.rabbitmq.testbeans.TestNonSerializableObject) CamelExecutionException(org.apache.camel.CamelExecutionException) IOException(java.io.IOException)

Example 3 with TestSerializableObject

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());
}
Also used : TestSerializableObject(org.apache.camel.component.rabbitmq.testbeans.TestSerializableObject) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 4 with TestSerializableObject

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);
}
Also used : TestSerializableObject(org.apache.camel.component.rabbitmq.testbeans.TestSerializableObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TestSerializableObject(org.apache.camel.component.rabbitmq.testbeans.TestSerializableObject) TestNonSerializableObject(org.apache.camel.component.rabbitmq.testbeans.TestNonSerializableObject) TestPartiallySerializableObject(org.apache.camel.component.rabbitmq.testbeans.TestPartiallySerializableObject) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Aggregations

TestSerializableObject (org.apache.camel.component.rabbitmq.testbeans.TestSerializableObject)4 Test (org.junit.Test)3 IOException (java.io.IOException)2 TestNonSerializableObject (org.apache.camel.component.rabbitmq.testbeans.TestNonSerializableObject)2 TestPartiallySerializableObject (org.apache.camel.component.rabbitmq.testbeans.TestPartiallySerializableObject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 CamelExecutionException (org.apache.camel.CamelExecutionException)1 Endpoint (org.apache.camel.Endpoint)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1