Search in sources :

Example 46 with ObjectMessage

use of javax.jms.ObjectMessage in project tomee by apache.

the class MdbConnectionFactoryTests method test02_directRpc.

public void test02_directRpc() throws Exception {
    final Connection connection = createConnection();
    Session session = null;
    MessageProducer producer = null;
    MessageConsumer consumer = null;
    try {
        // create request
        final Map<String, Object> request = new TreeMap<String, Object>();
        request.put("method", "businessMethod(java.lang.String)");
        request.put("args", new Object[] { "cheese" });
        // initialize session
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        final Destination requestQueue = session.createQueue("BasicMdb");
        final Destination responseQueue = session.createTemporaryQueue();
        // Create a request messages
        final ObjectMessage requestMessage = session.createObjectMessage();
        requestMessage.setJMSReplyTo(responseQueue);
        requestMessage.setObject((Serializable) request);
        // Send the request message
        producer = session.createProducer(requestQueue);
        producer.send(requestMessage);
        //            System.out.println("\n" + "***************************************\n" +
        //                    "Sent request message: " + requestMessage + "\n" +
        //                    "         request map: " + request + "\n" +
        //                    "            to queue: " + requestQueue + "\n" +
        //                    "***************************************\n\n");
        // create consumer
        consumer = session.createConsumer(responseQueue);
        //            System.out.println("\n" + "***************************************\n" +
        //                    "Listening for response at : " + responseQueue + "\n" +
        //                    "***************************************\n\n");
        // wait for response mesage
        final Message message = consumer.receive(1000);
        // verify message
        assertNotNull("Did not get a response message", message);
        assertTrue("Response message is not an ObjectMessage", message instanceof ObjectMessage);
        final ObjectMessage responseMessage = (ObjectMessage) message;
        final Serializable object = responseMessage.getObject();
        assertNotNull("Response ObjectMessage contains a null object");
        assertTrue("Response ObjectMessage does not contain an instance of Map", object instanceof Map);
        final Map response = (Map) object;
        // process results
        if (response.containsKey("exception")) {
            throw (Exception) response.get("return");
        }
        final String returnValue = (String) response.get("return");
        assertEquals("eseehc", returnValue);
    } finally {
        MdbUtil.close(producer);
        MdbUtil.close(session);
        MdbUtil.close(connection);
    }
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) Serializable(java.io.Serializable) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) TreeMap(java.util.TreeMap) ObjectMessage(javax.jms.ObjectMessage) MessageProducer(javax.jms.MessageProducer) TreeMap(java.util.TreeMap) Map(java.util.Map) Session(javax.jms.Session)

Example 47 with ObjectMessage

use of javax.jms.ObjectMessage in project simba-os by cegeka.

the class RefreshCacheEventListenerTest method onMessage_AuthorizationChanged.

@Test
public void onMessage_AuthorizationChanged() throws Exception {
    SimbaEvent event = new SimbaEvent(SimbaEventType.AUTHORIZATION_CHANGED, null);
    ObjectMessage message = mock(ObjectMessage.class);
    when(message.getObject()).thenReturn(event);
    listener.onMessage(message);
    verify(service).invalidate();
}
Also used : ObjectMessage(javax.jms.ObjectMessage) SimbaEvent(org.simbasecurity.common.event.SimbaEvent) Test(org.junit.Test)

Aggregations

ObjectMessage (javax.jms.ObjectMessage)47 Message (javax.jms.Message)20 Test (org.junit.Test)18 JMSException (javax.jms.JMSException)16 Session (javax.jms.Session)15 TextMessage (javax.jms.TextMessage)11 Serializable (java.io.Serializable)10 Destination (javax.jms.Destination)9 Map (java.util.Map)8 BytesMessage (javax.jms.BytesMessage)8 MapMessage (javax.jms.MapMessage)8 MessageProducer (javax.jms.MessageProducer)7 TreeMap (java.util.TreeMap)6 MessageConsumer (javax.jms.MessageConsumer)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 Event (models.ChatRoom.Event)4 Connection (javax.jms.Connection)3 QueueConnection (javax.jms.QueueConnection)3 QueueSession (javax.jms.QueueSession)3 StreamMessage (javax.jms.StreamMessage)3