Example usage for javax.jms Session createTextMessage

List of usage examples for javax.jms Session createTextMessage

Introduction

In this page you can find the example usage for javax.jms Session createTextMessage.

Prototype


TextMessage createTextMessage() throws JMSException;

Source Link

Document

Creates a TextMessage object.

Usage

From source file:com.amalto.core.storage.task.staging.ClusteredStagingTaskManager.java

protected void sendCancellationMessage(final String dataContainer, final String taskId) {
    jmsTemplate.send(new MessageCreator() {
        @Override//  w ww  .j  av  a2 s . c om
        public Message createMessage(Session session) throws JMSException {
            TextMessage message = session.createTextMessage();
            try {
                String msg = StagingJobCancellationMessage
                        .toString(new StagingJobCancellationMessage(dataContainer, taskId));
                message.setText(msg);
                return message;
            } catch (JAXBException e) {
                LOGGER.error("Cannot unmarshall message", e);
                throw new JMSException("Cannot unmarshall message");
            }
        }
    });
}

From source file:de.taimos.dvalin.interconnect.core.spring.DaemonMessageSender.java

private void sendIVO(final String correlationID, final Destination replyTo, final InterconnectObject ico,
        final boolean secure) throws Exception {
    final String json = InterconnectMapper.toJson(ico);
    this.logger.debug("TextMessage send: " + json);
    this.template.send(replyTo, new MessageCreator() {

        @Override//from  ww  w. ja  v a 2s .c  om
        public Message createMessage(final Session session) throws JMSException {
            final TextMessage textMessage = session.createTextMessage();
            textMessage.setStringProperty(InterconnectConnector.HEADER_ICO_CLASS, ico.getClass().getName());
            textMessage.setJMSCorrelationID(correlationID);
            textMessage.setText(json);
            if (secure) {
                try {
                    MessageConnector.secureMessage(textMessage);
                } catch (CryptoException e) {
                    throw new JMSException(e.getMessage());
                }
            }
            return textMessage;
        }
    });
}

From source file:unic.mentoring.jms.ctrl.MessageCtrl.java

protected void sendMessage(String message, String topicName) throws JMSException {
    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
    Connection connection = connectionFactory.createConnection();
    connection.start();/*from  w  w w . ja va2  s.c  om*/

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic topic = session.createTopic(topicName);
    MessageProducer producer = session.createProducer(topic);
    TextMessage jmsMessage = session.createTextMessage();
    jmsMessage.setText(message);

    producer.send(jmsMessage);
    connection.close();
}

From source file:com.mdmserver.managers.ControllerFacade.java

public void lockPhone(int accountId) throws IOException {
    Account account = databaseManager.getAccountByAccountId(accountId);
    Context ctx;/*w w  w  . j ava 2s. co  m*/
    try {
        ctx = new InitialContext();
        ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("jms/mdmConnectionFactory");
        Queue queue = (Queue) ctx.lookup("jms/mdmQueue");
        MessageProducer messageProducer;
        System.out.println("Naming success");
        try {

            javax.jms.Connection connection = connectionFactory.createConnection();
            javax.jms.Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            messageProducer = session.createProducer(queue);
            TextMessage message = session.createTextMessage();
            message.setStringProperty(Account.FIELD_NAME_CLOUD_ID, account.getCloudId());
            ControlClient cClient = new ControlClient();
            cClient.setCommandType(ControlClient.LOCK_PHONE_CONTROL);
            Gson gson = new Gson();
            message.setStringProperty(ControlClient.CONTROL_CLIENT_KEY, gson.toJson(cClient));
            System.out.println("It come from Servlet:" + message.getText());
            messageProducer.send(message);
            System.out.println("JMS success");
        } catch (JMSException ex) {
            //                  Logger.getLogger(Control.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("JMS exception");
        }

    } catch (NamingException ex) {
        //                Logger.getLogger(Control.class.getName()).log(Level.SEVERE, null, ex);
        System.out.println("Naming exception");
    }
}

From source file:com.mdmserver.managers.ControllerFacade.java

public void uninstallApp(int accountId, String appPackageName) {
    Account account = databaseManager.getAccountByAccountId(accountId);
    Context ctx;//  w  w  w.j  a v a2s .c  om
    try {
        ctx = new InitialContext();
        ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("jms/mdmConnectionFactory");
        Queue queue = (Queue) ctx.lookup("jms/mdmQueue");
        MessageProducer messageProducer;
        System.out.println("Naming success");
        try {

            javax.jms.Connection connection = connectionFactory.createConnection();
            javax.jms.Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            messageProducer = session.createProducer(queue);
            TextMessage message = session.createTextMessage();
            message.setStringProperty(Account.FIELD_NAME_CLOUD_ID, account.getCloudId());
            ControlClient cClient = new ControlClient();
            cClient.setCommandType(ControlClient.UNINSTALL_APP_CONTROL);
            cClient.setJsonCommandDetails(appPackageName);
            Gson gson = new Gson();
            message.setStringProperty(ControlClient.CONTROL_CLIENT_KEY, gson.toJson(cClient));
            System.out.println("It come from Servlet:" + message.getText());
            messageProducer.send(message);
            System.out.println("JMS success");
        } catch (JMSException ex) {
            //                  Logger.getLogger(Control.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("JMS exception");
        }

    } catch (NamingException ex) {
        //                Logger.getLogger(Control.class.getName()).log(Level.SEVERE, null, ex);
        System.out.println("Naming exception");
    }
}

From source file:com.adaptris.core.jms.MetadataCorrelationIdSourceTest.java

public void testJmsCorrelationIdToAdaptrisMessageMetadata_NoValue() throws Exception {
    EmbeddedActiveMq broker = new EmbeddedActiveMq();
    JmsConnection conn = broker.getJmsConnection();
    try {/*w ww. j  a  va2 s . c  om*/
        broker.start();
        start(conn);
        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        AdaptrisMessage adpMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT);
        TextMessage jmsMsg = session.createTextMessage();
        MetadataCorrelationIdSource mcs = new MetadataCorrelationIdSource(CORRELATIONID_KEY);
        mcs.processCorrelationId(jmsMsg, adpMsg);
        assertFalse(adpMsg.containsKey(CORRELATIONID_KEY));
        session.close();
    } finally {
        stop(conn);
        broker.destroy();
    }
}

From source file:com.adaptris.core.jms.MetadataCorrelationIdSourceTest.java

public void testJmsCorrelationIdToAdaptrisMessageMetadata_NoMetadataKey() throws Exception {
    EmbeddedActiveMq broker = new EmbeddedActiveMq();
    JmsConnection conn = broker.getJmsConnection();
    try {//  w  w  w .j a  v a  2  s. c o  m
        broker.start();
        start(conn);
        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        AdaptrisMessage adpMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT);
        TextMessage jmsMsg = session.createTextMessage();
        jmsMsg.setJMSCorrelationID(TEXT2);
        MetadataCorrelationIdSource mcs = new MetadataCorrelationIdSource();
        mcs.processCorrelationId(jmsMsg, adpMsg);
        assertNotSame(jmsMsg.getJMSCorrelationID(), adpMsg.getMetadataValue(CORRELATIONID_KEY));
        session.close();
    } finally {
        stop(conn);
        broker.destroy();
    }
}

From source file:com.adaptris.core.jms.MetadataCorrelationIdSourceTest.java

public void testJmsCorrelationIdToAdaptrisMessageMetadata() throws Exception {
    EmbeddedActiveMq broker = new EmbeddedActiveMq();
    JmsConnection conn = broker.getJmsConnection();
    try {//from   w  w w.  j av  a2  s.c  om
        broker.start();
        start(conn);
        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        AdaptrisMessage adpMsg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT);
        TextMessage jmsMsg = session.createTextMessage();
        jmsMsg.setJMSCorrelationID(TEXT2);
        MetadataCorrelationIdSource mcs = new MetadataCorrelationIdSource(CORRELATIONID_KEY);
        mcs.processCorrelationId(jmsMsg, adpMsg);
        assertEquals("Check Correlation Id Keys", jmsMsg.getJMSCorrelationID(),
                adpMsg.getMetadataValue(CORRELATIONID_KEY));
        session.close();
    } finally {
        stop(conn);
        broker.destroy();
    }
}

From source file:org.bremersee.common.jms.DefaultJmsConverter.java

private Message createJsonMessage(Object object, Session session) throws JMSException {
    try {//  w  ww.ja  v a2s  .  c  o m
        TextMessage msg = session.createTextMessage();
        String payload = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(object);
        msg.setText(payload);
        msg.setJMSType(object.getClass().getName());
        return msg;

    } catch (Throwable t) { // NOSONAR
        log.info("Creating JSON JMS from object of type ["
                + (object == null ? "null" : object.getClass().getName()) + "] failed.");
        return null;
    }
}

From source file:org.bremersee.common.jms.DefaultJmsConverter.java

private Message createXmlMessage(Object object, Session session) throws JMSException {
    try {//  w w w.jav a2 s . c o m
        TextMessage msg = session.createTextMessage();
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        StreamResult streamResult = new StreamResult(outputStream);
        marshaller.marshal(object, streamResult);
        String payload = CodingUtils.toStringSilently(outputStream.toByteArray(), StandardCharsets.UTF_8);
        msg.setText(payload);
        msg.setJMSType(object.getClass().getName());
        return msg;

    } catch (Throwable t) { // NOSONAR
        log.info("Creating XML JMS from object of type ["
                + (object == null ? "null" : object.getClass().getName()) + "] failed.");
        return null;
    }
}