Package org.apache.activemq.util.xstream

Examples of org.apache.activemq.util.xstream.SamplePojo


        MessageProducer producer = producerSession.createProducer(destination);

        Message message;
        ObjectMessage objectMessage;
        TextMessage textMessage;
        SamplePojo body;
        Object object;
        String text;

        // Send a text message
        String xmlText = "<org.apache.activemq.util.xstream.SamplePojo>"
            + "<name>James</name>"
            + "<city>London</city>"
            + "</org.apache.activemq.util.xstream.SamplePojo>";

        TextMessage txtRequest = producerSession.createTextMessage(xmlText);
        producer.send(txtRequest);

        // lets consume it as a text message
        message = adaptiveConsumer.receive(timeout);
        assertNotNull("Should have received a message!", message);
        assertTrue("Should be a TextMessage but was: " + message, message instanceof TextMessage);
        textMessage = (TextMessage)message;
        text = textMessage.getText();
        assertTrue("Text should be non-empty!", text != null && text.length() > 0);

        // lets consume it as an object message
        message = origConsumer.receive(timeout);
        assertNotNull("Should have received a message!", message);
        assertTrue("Should be an ObjectMessage but was: " + message, message instanceof ObjectMessage);
        objectMessage = (ObjectMessage)message;
        object = objectMessage.getObject();
        assertTrue("object payload of wrong type: " + object, object instanceof SamplePojo);
        body = (SamplePojo)object;
        assertEquals("name", "James", body.getName());
        assertEquals("city", "London", body.getCity());

        // Send object message
        ObjectMessage objRequest = producerSession.createObjectMessage(new SamplePojo("James", "London"));
        producer.send(objRequest);

        // lets consume it as an object message
        message = adaptiveConsumer.receive(timeout);
        assertNotNull("Should have received a message!", message);
        assertTrue("Should be an ObjectMessage but was: " + message, message instanceof ObjectMessage);
        objectMessage = (ObjectMessage)message;
        object = objectMessage.getObject();
        assertTrue("object payload of wrong type: " + object, object instanceof SamplePojo);
        body = (SamplePojo)object;
        assertEquals("name", "James", body.getName());
        assertEquals("city", "London", body.getCity());

        // lets consume it as a text message
        message = origConsumer.receive(timeout);
        assertNotNull("Should have received a message!", message);
        assertTrue("Should be a TextMessage but was: " + message, message instanceof TextMessage);
View Full Code Here

TOP

Related Classes of org.apache.activemq.util.xstream.SamplePojo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.