Example usage for javax.jms MapMessage getFloat

List of usage examples for javax.jms MapMessage getFloat

Introduction

In this page you can find the example usage for javax.jms MapMessage getFloat.

Prototype


float getFloat(String name) throws JMSException;

Source Link

Document

Returns the float value with the specified name.

Usage

From source file:org.jbpm.bpel.tutorial.purchase.ejb.InvoiceCallbackMessageBean.java

/**
 * Process the invoice callback message.
 */// ww  w.  j  a v  a  2  s  .c om
public void onMessage(Message message) {
    if (!(message instanceof MapMessage)) {
        log.error("received non-map message: " + message);
        messageContext.setRollbackOnly();
        return;
    }
    try {
        // extract contents
        MapMessage invoiceMessage = (MapMessage) message;
        int orderId = invoiceMessage.getInt("orderId");
        float amount = invoiceMessage.getFloat("amount");

        // populate invoice with contents
        Invoice inv = new Invoice();
        inv.setOrderId(orderId);
        inv.setAmount(amount);

        // send invoice back to requester
        invoiceRequester.sendInvoice(inv);

        log.debug("sent invoice: orderId=" + orderId + ", amount=" + amount);
    } catch (JMSException e) {
        messageContext.setRollbackOnly();
        log.error("could not read invoice message", e);
    } catch (RemoteException e) {
        messageContext.setRollbackOnly();
        log.error("could not send invoice", e);
    }
}

From source file:org.mule.transport.jms.JmsMessageUtilsTestCase.java

/**
 * Tests that is able to convert a Map which only contains simple values into a
 * MapMessage./*from  w w  w  .  ja va 2  s .  com*/
 */
@Test
public void testConvertsValidMapWithSimpleValuesToMapMessage() throws JMSException {
    Session session = mock(Session.class);
    when(session.createMapMessage()).thenReturn(new ActiveMQMapMessage());

    // Creates a test Map with data
    Map data = new HashMap();
    data.put("value1", new Float(4));
    data.put("value2", new byte[] { 1, 2, 3 });
    data.put("value3", "value3");
    data.put("value4", new Double(67.9));
    data.put("value5", true);
    data.put("value6", null);

    Message message = JmsMessageUtils.toMessage(data, session);
    assertTrue(message instanceof MapMessage);

    MapMessage mapMessage = (MapMessage) message;
    assertEquals(new Float(4), mapMessage.getFloat("value1"), 0);
    assertTrue(Arrays.equals(new byte[] { 1, 2, 3 }, mapMessage.getBytes("value2")));
    assertEquals("value3", mapMessage.getString("value3"));
    assertEquals(new Double(67.9), mapMessage.getDouble("value4"), 0);
    assertTrue(mapMessage.getBoolean("value5"));
    assertNull(mapMessage.getObject("value6"));
}