List of usage examples for javax.jms ObjectMessage setObject
void setObject(Serializable object) throws JMSException;
From source file:eu.learnpad.simulator.mon.manager.ResponseDispatcher.java
public static void sendResponse(ComplexEventResponse response, String enablerName, String answerTopic) { try {//from w ww.j a v a 2 s . co m publicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); connectionTopic = publishSession.createTopic(answerTopic); tPub = publishSession.createPublisher(connectionTopic); ObjectMessage sendMessage = publishSession.createObjectMessage(); sendMessage.setObject((Serializable) response); sendMessage.setStringProperty("DESTINATION", enablerName); tPub.publish(sendMessage); } catch (JMSException e) { e.printStackTrace(); } }
From source file:eu.learnpad.simulator.mon.manager.ResponseDispatcher.java
public static void sendResponse(ComplexEventException exception, String enablerName, String answerTopic) { try {/* w w w .j av a2 s .c o m*/ publicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); connectionTopic = publishSession.createTopic(answerTopic); tPub = publishSession.createPublisher(connectionTopic); ObjectMessage sendMessage = publishSession.createObjectMessage(); sendMessage.setObject((Serializable) exception); sendMessage.setStringProperty("DESTINATION", enablerName); tPub.publish(sendMessage); } catch (JMSException e) { e.printStackTrace(); } }
From source file:eu.learnpad.simulator.mon.manager.ResponseDispatcher.java
public static void sendResponse(Object object, String enablerName, String answerTopic) { try {//from ww w . ja va 2 s .c o m publicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); connectionTopic = publishSession.createTopic(answerTopic); tPub = publishSession.createPublisher(connectionTopic); ObjectMessage sendMessage = publishSession.createObjectMessage(); sendMessage.setObject((Serializable) object); sendMessage.setStringProperty("DESTINATION", enablerName); tPub.publish(sendMessage); } catch (JMSException e) { e.printStackTrace(); } }
From source file:eu.learnpad.simulator.mon.manager.ResponseDispatcher.java
public static void sendScoresEvaluation(HashMap<ScoreType, Float> scores, String destination, String channel, String userid, String simulationSessionID) { try {/*w ww . j a v a 2 s.co m*/ publicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); connectionTopic = publishSession.createTopic(channel); tPub = publishSession.createPublisher(connectionTopic); ObjectMessage sendMessage = publishSession.createObjectMessage(); sendMessage.setObject((Serializable) scores); sendMessage.setStringProperty("DESTINATION", destination); sendMessage.setStringProperty("USERID", userid); sendMessage.setBooleanProperty("ISASCORE", true); sendMessage.setStringProperty("SIMSESSIONID", simulationSessionID); tPub.publish(sendMessage); } catch (JMSException e) { DebugMessages.println(TimeStamp.getCurrentTime(), ResponseDispatcher.class.getSimpleName(), "Exception during sendScoresEvaluation method execution"); } }
From source file:com.mirth.connect.connectors.jms.JmsMessageUtils.java
public static Message getMessageForObject(Object object, Session session) throws JMSException { if (object instanceof Message) { return (Message) object; } else if (object instanceof String) { TextMessage text = session.createTextMessage((String) object); return text; } else if (object instanceof Map) { MapMessage map = session.createMapMessage(); Map.Entry entry = null;//from ww w .j a v a 2 s .c o m Map temp = (Map) object; for (Iterator i = temp.entrySet().iterator(); i.hasNext();) { entry = (Map.Entry) i.next(); map.setObject(entry.getKey().toString(), entry.getValue()); } return map; } else if (object instanceof InputStream) { StreamMessage stream = session.createStreamMessage(); InputStream temp = (InputStream) object; byte[] buffer = new byte[1024 * 4]; int len = 0; try { while ((len = temp.read(buffer)) != -1) { stream.writeBytes(buffer, 0, len); } } catch (IOException e) { throw new JMSException("Failed to read input stream to create a stream message: " + e); } return stream; } else if (object instanceof byte[]) { BytesMessage bytes = session.createBytesMessage(); byte[] buf = (byte[]) object; for (int i = 0; i < buf.length; i++) { bytes.writeByte(buf[i]); } return bytes; } else if (object instanceof Serializable) { ObjectMessage oMsg = session.createObjectMessage(); oMsg.setObject((Serializable) object); return oMsg; } else { throw new JMSException( "Source was not a supported type, data must be Serializable, String, byte[], Map or InputStream"); } }
From source file:org.mule.transport.jms.JmsMessageUtils.java
private static Message serializableToMessage(Serializable value, Session session) throws JMSException { ObjectMessage oMsg = session.createObjectMessage(); oMsg.setObject(value); return oMsg;/*from ww w.j av a2 s . c om*/ }
From source file:com.cws.esolutions.core.utils.MQUtils.java
/** * Puts an MQ message on a specified queue and returns the associated * correlation ID for retrieval upon request. * * @param connName - The connection name to utilize * @param authData - The authentication data to utilize, if required * @param requestQueue - The request queue name to put the message on * @param targetHost - The target host for the message * @param value - The data to place on the request. MUST be <code>Serialiable</code> * @return <code>String</code> - the JMS correlation ID associated with the message * @throws UtilityException {@link com.cws.esolutions.core.utils.exception.UtilityException} if an error occurs processing *///from w w w .j av a 2 s.com public static final synchronized String sendMqMessage(final String connName, final List<String> authData, final String requestQueue, final String targetHost, final Serializable value) throws UtilityException { final String methodName = MQUtils.CNAME + "sendMqMessage(final String connName, final List<String> authData, final String requestQueue, final String targetHost, final Serializable value) throws UtilityException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", connName); DEBUGGER.debug("Value: {}", requestQueue); DEBUGGER.debug("Value: {}", targetHost); DEBUGGER.debug("Value: {}", value); } Connection conn = null; Session session = null; Context envContext = null; InitialContext initCtx = null; MessageProducer producer = null; ConnectionFactory connFactory = null; final String correlationId = RandomStringUtils.randomAlphanumeric(64); if (DEBUG) { DEBUGGER.debug("correlationId: {}", correlationId); } try { try { initCtx = new InitialContext(); envContext = (Context) initCtx.lookup(MQUtils.INIT_CONTEXT); connFactory = (ConnectionFactory) envContext.lookup(connName); } catch (NamingException nx) { // we're probably not in a container connFactory = new ActiveMQConnectionFactory(connName); } if (DEBUG) { DEBUGGER.debug("ConnectionFactory: {}", connFactory); } if (connFactory == null) { throw new UtilityException("Unable to create connection factory for provided name"); } // Create a Connection conn = connFactory.createConnection(authData.get(0), PasswordUtils.decryptText(authData.get(1), authData.get(2), authData.get(3), Integer.parseInt(authData.get(4)), Integer.parseInt(authData.get(5)), authData.get(6), authData.get(7), authData.get(8))); conn.start(); if (DEBUG) { DEBUGGER.debug("Connection: {}", conn); } // Create a Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); if (DEBUG) { DEBUGGER.debug("Session: {}", session); } // Create a MessageProducer from the Session to the Topic or Queue if (envContext != null) { try { producer = session.createProducer((Destination) envContext.lookup(requestQueue)); } catch (NamingException nx) { throw new UtilityException(nx.getMessage(), nx); } } else { Destination destination = session.createTopic(requestQueue); if (DEBUG) { DEBUGGER.debug("Destination: {}", destination); } producer = session.createProducer(destination); } if (producer == null) { throw new JMSException("Failed to create a producer object"); } producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); if (DEBUG) { DEBUGGER.debug("MessageProducer: {}", producer); } ObjectMessage message = session.createObjectMessage(true); message.setJMSCorrelationID(correlationId); message.setStringProperty("targetHost", targetHost); if (DEBUG) { DEBUGGER.debug("correlationId: {}", correlationId); } message.setObject(value); if (DEBUG) { DEBUGGER.debug("ObjectMessage: {}", message); } producer.send(message); } catch (JMSException jx) { throw new UtilityException(jx.getMessage(), jx); } finally { try { // Clean up if (!(session == null)) { session.close(); } if (!(conn == null)) { conn.close(); conn.stop(); } } catch (JMSException jx) { ERROR_RECORDER.error(jx.getMessage(), jx); } } return correlationId; }
From source file:biz.fstechnology.micro.server.jms.ResponseMessageCreator.java
/** * @see org.springframework.jms.core.MessageCreator#createMessage(javax.jms.Session) *///from w ww. j a v a 2 s. co m @Override public Message createMessage(Session session) throws JMSException { ObjectMessage message = session.createObjectMessage(); message.setObject(getContents()); message.setJMSCorrelationID(getRequestId()); return message; }
From source file:biz.fstechnology.micro.common.jms.RequestMessageCreator.java
/** * @see org.springframework.jms.core.MessageCreator#createMessage(javax.jms.Session) *///from www .j a v a2 s. c o m @Override public Message createMessage(Session session) throws JMSException { ObjectMessage message = session.createObjectMessage(); message.setObject(getContents()); message.setJMSReplyTo(getReplyTo()); if (getRequestId() == null) { setRequestId(Double.toHexString(Math.random())); } message.setJMSCorrelationID(getRequestId()); return message; }
From source file:org.acruxsource.sandbox.spring.jmstows.jms.JmsMessageSender.java
public void sendMessage(String destination, final Serializable message) { jmsTemplate.send(destination, new MessageCreator() { @Override// ww w . j a v a 2 s. c o m public Message createMessage(Session session) throws JMSException { ObjectMessage objectMessage = session.createObjectMessage(); objectMessage.setObject(message); return objectMessage; } }); }