Example usage for javax.jms ObjectMessage getObject

List of usage examples for javax.jms ObjectMessage getObject

Introduction

In this page you can find the example usage for javax.jms ObjectMessage getObject.

Prototype


Serializable getObject() throws JMSException;

Source Link

Document

Gets the serializable object containing this message's data.

Usage

From source file:nz.net.orcon.kanban.automation.JmsEventListener.java

@Override
public void onMessage(Message message) {
    ObjectMessage objectMessage = (ObjectMessage) message;
    try {/*from  w  w  w . j  av  a 2s  .c  om*/
        Serializable body = objectMessage.getObject();
        if (body instanceof CardHolder) {
            CardHolder cardHolder = (CardHolder) body;
            automationEngine.examine(cardHolder);
        } else if (body instanceof Notification) {
            Notification notification = (Notification) body;
            automationEngine.executeActions(notification);
        } else if (body instanceof BoardRule) {
            BoardRule timerNotification = (BoardRule) body;
            automationEngine.executeActions(timerNotification);
        } else {
            logger.warn("JMS Message Contained Invalid Body");
        }
    } catch (Exception e) {
        logger.error("JMS Exception on Event Reception", e);
    }
}

From source file:org.dataminx.dts.ws.jms.DtsWsMessageConverter.java

/**
 * Extracts the given JMS Message payload and returns it as an object.
 *
 * @param message the incoming JMS message
 * @return the message payload as an {@link Object}
 * @throws JMSException if the incoming message is not of a supported
 *         message type/*from   w w w . java  2  s  .  c  om*/
 */
private Object extractMessagePayload(final Message message) throws JMSException {
    final Object payload;
    if (message instanceof TextMessage) {
        final TextMessage textMessage = (TextMessage) message;
        payload = textMessage.getText();
    } else if (message instanceof ObjectMessage) {
        final ObjectMessage objectMessage = (ObjectMessage) message;
        payload = objectMessage.getObject();
    } else if (message instanceof BytesMessage) {
        final BytesMessage bytesMessage = (BytesMessage) message;
        final byte[] bytes = new byte[(int) bytesMessage.getBodyLength()];
        bytesMessage.readBytes(bytes);
        final ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        payload = new StreamSource(bis);
    } else {
        throw new MessageConversionException("Invalid message type...");
    }
    return payload;
}

From source file:com.thoughtworks.go.server.messaging.activemq.JMSMessageListenerAdapter.java

protected boolean runImpl() {
    try {/*w  w  w. j a v a 2s  . c om*/
        Message message = consumer.receive();
        if (message == null) {
            LOG.debug("Message consumer was closed.");
            return true;
        }

        ObjectMessage omessage = (ObjectMessage) message;
        listener.onMessage((GoMessage) omessage.getObject());

    } catch (JMSException e) {
        LOG.warn("Error reciving message. Message receiving will continue despite this error.", e);
    } catch (Exception e) {
        LOG.error("Exception thrown in message handling by listener " + listener, e);
    }
    return false;
}

From source file:com.espertech.esperio.jms.JMSDefaultAnyMessageUnmarshaller.java

public EventBean unmarshal(EventAdapterService eventAdapterService, Message message) throws EPException {
    try {/*from   w w  w .j  a  va  2 s  .  c o m*/
        if (message instanceof ObjectMessage) {
            ObjectMessage objmsg = (ObjectMessage) message;
            Serializable obj = objmsg.getObject();
            return eventAdapterService.adapterForBean(obj);
        } else if (message instanceof MapMessage) {
            Map<String, Object> properties = new HashMap<String, Object>();
            MapMessage mapMsg = (MapMessage) message;
            Enumeration en = mapMsg.getMapNames();
            while (en.hasMoreElements()) {
                String property = (String) en.nextElement();
                Object mapObject = mapMsg.getObject(property);
                properties.put(property, mapObject);
            }

            // Get event type property
            Object typeProperty = properties.get(InputAdapter.ESPERIO_MAP_EVENT_TYPE);
            if (typeProperty == null) {
                log.warn(".unmarshal Failed to unmarshal map message, expected type property not found: '"
                        + InputAdapter.ESPERIO_MAP_EVENT_TYPE + "'");
                return null;
            }

            // Get event type
            String name = typeProperty.toString();
            EventType eventType = eventAdapterService.getExistsTypeByName(name);
            if (eventType == null) {
                log.warn(".unmarshal Failed to unmarshal map message, event type name '" + name
                        + "' is not a known type");
                return null;
            }

            return eventAdapterService.adapterForTypedMap(properties, eventType);
        } else {
            String error = ".unmarshal Failed to unmarshal message of JMS type: " + message.getJMSType();
            log.error(error);
            throw new EPException(error);
        }
    } catch (JMSException ex) {
        throw new EPException("Error unmarshalling message", ex);
    }
}

From source file:messagebean.MessageBean.java

@Override
public void onMessage(Message message) {
    ObjectMessage objectMessage = null;
    try {//from  w ww . j a  v  a2  s . co  m
        objectMessage = (ObjectMessage) message;
        String jsn = (String) objectMessage.getObject();

        DItem item = jsnToDitem(jsn);
        if (item == null) {
            return;
        }
        entityBean.addData(item);
    } catch (Exception ex) {
        logError(ex);
        mdctx.setRollbackOnly();
    }
}

From source file:org.yestech.notify.service.JmsQueueNotificationConsumer.java

public void onMessage(Message message) {
    if (message instanceof ObjectMessage) {
        ObjectMessage objMessage = (ObjectMessage) message;
        INotificationJob job = null;// ww w. ja  v a2 s  .c o m
        try {
            job = (INotificationJob) objMessage.getObject();
            recieve(job);
        } catch (JMSException e) {
            logger.error(e.getMessage(), e);
        }
    }
}

From source file:nz.net.orcon.kanban.controllers.BoardsCache.java

@Override
public void onMessage(Message message) {
    try {/*from w  w  w . jav a 2s .  c  om*/
        ObjectMessage objectMessage = (ObjectMessage) message;
        PhaseChange change = (PhaseChange) objectMessage.getObject();
        actualIncrementCardCount(change);
    } catch (Exception e) {
        logger.error("JMS Exception on Phase Change Reception ", e);
    }
}

From source file:nz.net.orcon.kanban.automation.IdGeneratorReceiver.java

/**
 * This onMessage overrides the SyncReceive method which notifies the registered SyncMessage Object.
 * If this is the Primary Server it will send a IdResponse with a new ID.
 */// w  ww  .j  a  va 2 s .c  om
@Override
public void onMessage(Message message) {

    // See if this is a IdRequest - If So Process it.
    ObjectMessage objectMessage = (ObjectMessage) message;
    try {
        Serializable body = objectMessage.getObject();
        if (body instanceof Coup) {
            Coup coup = (Coup) body;
            if (!coup.isPutdown() && !coup.getRequestId().equals(clusterManager.getServerId())) {
                if (clusterManager.isLeader()) {
                    putDown((Coup) body);
                } else {
                    if (coup.getCoupTime() > clusterManager.getStartTime()) {
                        putDown(coup);
                    }
                }
            }
        }

        if (clusterManager.isLeader() && body instanceof IdRequest) {
            sendNewId((IdRequest) body);
        }
    } catch (Exception e) {
        // Do Something
    } finally {
        super.onMessage(message);
    }
}

From source file:nz.net.orcon.kanban.automation.CacheManager.java

@Override
public void onMessage(Message message) {

    try {/*  ww w.j  a  v  a 2  s . c  o  m*/
        ObjectMessage objectMessage = (ObjectMessage) message;
        CacheInvalidationInstruction instruction = (CacheInvalidationInstruction) objectMessage.getObject();

        if (logger.isDebugEnabled()) {
            logger.debug("Cache Invalidation Instruction: " + instruction.getCacheType() + " "
                    + instruction.getId());
        }

        Cache<?> cache = cacheList.get(instruction.getCacheType().toString());
        cache.invalidate(instruction.getId());

        if (instruction.getCacheType().equals("BOARD")) {
            timerManager.loadTimersForBoard(instruction.getId());
        }
    } catch (Exception e) {
        logger.error("JMS Exception on Cache Invalidation Reception ", e);
    }

}

From source file:org.apache.servicemix.audit.async.AbstractJmsExchangeListener.java

public void afterPropertiesSet() throws Exception {
    if (factory == null) {
        throw new IllegalStateException(
                "Unable to initialize JMS ExchangeListener -- no ConnectionFactory set");
    }// w  w w  .  ja  v  a 2  s  .  c o  m
    container = new DefaultMessageListenerContainer();
    container.setConnectionFactory(factory);
    container.setDestinationName(getDestinationName());
    container.setMessageListener(new MessageListener() {

        @SuppressWarnings("unchecked")
        public void onMessage(Message message) {
            ObjectMessage om = (ObjectMessage) message;
            try {
                T object = (T) om.getObject();
                switch (Event.valueOf(om.getStringProperty(EVENT))) {
                case Sent:
                    onSent(object);
                case Accepted:
                    onAccepted(object);
                }
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }

    });
    container.afterPropertiesSet();
    container.setConcurrentConsumers(10);
    container.start();

    jmsTemplate = new JmsTemplate(factory);
    jmsTemplate.setDefaultDestinationName(getDestinationName());
}