Example usage for javax.jms ObjectMessage setObject

List of usage examples for javax.jms ObjectMessage setObject

Introduction

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

Prototype


void setObject(Serializable object) throws JMSException;

Source Link

Document

Sets the serializable object containing this message's data.

Usage

From source file:org.yestech.publish.service.JmsQueuePublishProducer.java

@Override
public void send(final IArtifact artifact) {
    jmsTemplate.send(queue, new MessageCreator() {
        public Message createMessage(Session session) throws JMSException {
            ObjectMessage message = session.createObjectMessage();
            message.setObject(artifact);
            return message;
        }/*from  ww w  .ja va 2  s. c o  m*/
    });
}

From source file:org.openadaptor.auxil.connector.jms.DefaultMessageGenerator.java

public Message createMessage(Object messageRecord, Session session) throws JMSException {
    Message msg;// w w w. j ava 2s . com
    if (messageRecord instanceof String) {
        TextMessage textMsg = session.createTextMessage();
        textMsg.setText((String) messageRecord);
        msg = textMsg;
    } else if (messageRecord instanceof Serializable) {
        ObjectMessage objectMsg = session.createObjectMessage();
        objectMsg.setObject((Serializable) messageRecord);
        msg = objectMsg;
    } else {
        // We have not needed more message types in practice.
        // If we do need them in future this is where they go.
        throw new RecordFormatException(
                "Undeliverable record type [" + messageRecord.getClass().getName() + "]");
    }
    setMessageProperties(msg);
    return msg;
}

From source file:org.yestech.publish.service.JmsQueuePublishProducer.java

@Override
public void send(final IFileArtifact artifact) {
    final File inputFile = artifact.getFile();
    if (inputFile == null) {
        throw new RuntimeException("file can't be null for file artifact");
    }/*from w w w.j a  va2 s.c o  m*/
    reset(artifact);
    jmsTemplate.send(queue, new MessageCreator() {
        public Message createMessage(Session session) throws JMSException {
            ObjectMessage message = session.createObjectMessage();
            message.setObject(artifact);
            message.setStringProperty(IPublishConstant.FILE_NAME, inputFile.getName());
            message.setStringProperty(IPublishConstant.URL, url);
            return message;
        }
    });
}

From source file:com.clican.pluto.cluster.jms.SynchronizeServiceJmsImpl.java

public void synchronize(final Message msg) throws SynchronizeException {
    if (log.isDebugEnabled()) {
        log.debug("Send message [" + msg.toString() + "] to topic [" + msg.getName() + "]");
    }//  www .j  a v  a2 s.co m
    Destination destination = destinationMap.get(msg.getName());
    if (destination == null) {
        throw new SynchronizeException(msg);
    }
    try {
        jmsTemplate.send(destination, new MessageCreator() {
            public javax.jms.Message createMessage(Session session) throws JMSException {
                ObjectMessage om = session.createObjectMessage();
                om.setObject(msg);
                return om;
            }
        });
    } catch (JmsException e) {
        // If the <code>JmsException</code> is thrown, we have to invoke the
        // onException method to inform the SimpleConnectionFactory to
        // re-get
        // connection from newer ConnectionFactory which is injected as an
        // target.
        ConnectionFactory cf = jmsTemplate.getConnectionFactory();
        if (cf instanceof ExceptionListener) {
            ((ExceptionListener) cf).onException(new JMSException(e.getMessage()));
        }
        try {
            jmsTemplate.send(destination, new MessageCreator() {
                public javax.jms.Message createMessage(Session session) throws JMSException {
                    ObjectMessage om = session.createObjectMessage();
                    om.setObject(msg);
                    return om;
                }
            });
        } catch (JmsException ex) {
            throw new SynchronizeException(ex, msg);
        }
    }

}

From source file:org.simbasecurity.core.event.EventService.java

private void publish(final SimbaEvent simbaEvent) {
    jmsTemplate.send(this.topic, new MessageCreator() {
        @Override//w w  w .  j a v  a  2  s  .c  o  m
        public Message createMessage(Session session) throws JMSException {
            ObjectMessage message = session.createObjectMessage();
            message.setObject(simbaEvent);
            return message;
        }
    });
}

From source file:nl.han.dare2date.jms.JMSPublisher.java

public ObjectMessage createObjectMessage(Serializable item) {
    if (topicPublisher == null) {
        throw new RuntimeException("Not connected");
    }/*from  w  w  w . j a  v  a2  s . c om*/

    try {
        ObjectMessage msg = session.createObjectMessage();
        msg.setObject(item);
        return msg;
    } catch (JMSException e) {
        logger.error("Can't create object message", e);
        return null;
    }
}

From source file:com.cws.esolutions.agent.mq.MQMessageHandler.java

public void onMessage(final Message message) {
    final String methodName = MQMessageHandler.CNAME + "#onMessage(final Message message)";

    if (DEBUG) {//from  ww w.  j  a va 2s  .  c  o m
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Message: {}", message);
    }

    final Session session = agentBean.getSession();
    final MessageProducer producer = agentBean.getProducer();
    final Destination destination = MQMessageHandler.agentBean.getResponseQueue();

    if (DEBUG) {
        DEBUGGER.debug("Session: {}", session);
        DEBUGGER.debug("MessageProducer: {}", producer);
        DEBUGGER.debug("Destination: {}", destination);
    }

    try {
        ObjectMessage mqMessage = (ObjectMessage) message;

        if (DEBUG) {
            DEBUGGER.debug("mqMessage: {}", mqMessage);
        }

        if ((StringUtils.equals(MQMessageHandler.serverConfig.getRequestQueue(),
                MQMessageHandler.serverConfig.getResponseQueue()))
                && (mqMessage.getObject() instanceof AgentResponse)) {
            return;
        }

        AgentRequest agentRequest = (AgentRequest) mqMessage.getObject();

        if (DEBUG) {
            DEBUGGER.debug("agentRequest: {}", agentRequest);
        }

        mqMessage.acknowledge();

        AgentResponse agentResponse = MQMessageHandler.processor.processRequest(agentRequest);

        if (DEBUG) {
            DEBUGGER.debug("AgentResponse: {}", agentResponse);
        }

        ObjectMessage oMessage = session.createObjectMessage(true);
        oMessage.setObject(agentResponse);
        oMessage.setJMSCorrelationID(message.getJMSCorrelationID());

        if (DEBUG) {
            DEBUGGER.debug("ObjectMessage: {}", oMessage);
        }

        producer.send(destination, oMessage);
    } catch (JMSException jx) {
        ERROR_RECORDER.error(jx.getMessage(), jx);
    } catch (AgentException ax) {
        ERROR_RECORDER.error(ax.getMessage(), ax);
    }
}

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

public void exchangeSent(final ExchangeEvent event) {
    jmsTemplate.send(new MessageCreator() {

        public Message createMessage(Session session) throws JMSException {
            createConfigNodeForNamespace(event.getExchange());
            ObjectMessage message = session.createObjectMessage();
            message.setObjectProperty(EVENT, Event.Sent.name());
            message.setObject((Serializable) getSerializer(event.getExchange().getService().getNamespaceURI())
                    .serialize(event.getExchange()));
            return message;
        }/*from   w  ww . ja va  2s . c  o m*/

    });
}

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

public void exchangeAccepted(final ExchangeEvent event) {
    jmsTemplate.send(new MessageCreator() {

        public Message createMessage(Session session) throws JMSException {
            createConfigNodeForNamespace(event.getExchange());
            ObjectMessage message = session.createObjectMessage();
            message.setStringProperty(EVENT, Event.Accepted.name());
            message.setObject((Serializable) getSerializer(event.getExchange().getService().getNamespaceURI())
                    .serialize(event.getExchange()));
            return message;
        }/* www.j  a v  a2 s  . c  o m*/

    });
}

From source file:com.datatorrent.lib.io.jms.JMSObjectInputOperatorTest.java

private void createObjectMsgs(int numMessages) throws Exception {
    ObjectMessage message = testMeta.session.createObjectMessage();
    message.setObject("Test for Object Messages");
    for (int i = 0; i < numMessages; i++) {
        testMeta.producer.send(message);
    }//from   ww  w.j  ava  2 s . c  om
}