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(String text) throws JMSException;

Source Link

Document

Creates an initialized TextMessage object.

Usage

From source file:org.apache.servicemix.jms.JmsProviderEndpointTest.java

public void testSoapProviderInOut() throws Exception {
    JmsComponent component = new JmsComponent();

    JmsSoapProviderEndpoint endpoint = new JmsSoapProviderEndpoint();
    endpoint.setService(new QName("uri:HelloWorld", "HelloService"));
    endpoint.setEndpoint("HelloPort");
    endpoint.setConnectionFactory(connectionFactory);
    endpoint.setDestinationName("destination");
    endpoint.setReplyDestinationName("reply");
    endpoint.setWsdl(new ClassPathResource("org/apache/servicemix/jms/HelloWorld-RPC.wsdl"));
    component.setEndpoints(new JmsProviderEndpoint[] { endpoint });
    container.activateComponent(component, "servicemix-jms");

    Thread th = new Thread() {
        public void run() {
            try {
                final Message msg = jmsTemplate.receive("destination");
                assertNotNull(msg);//  ww w .  jav a  2s.  c  om
                final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                FileUtil.copyInputStream(
                        new ClassPathResource("org/apache/servicemix/jms/HelloWorld-RPC-Output.xml")
                                .getInputStream(),
                        baos);
                jmsTemplate.send("reply", new MessageCreator() {
                    public Message createMessage(Session session) throws JMSException {
                        TextMessage rep = session.createTextMessage(baos.toString());
                        rep.setJMSCorrelationID(msg.getJMSCorrelationID() != null ? msg.getJMSCorrelationID()
                                : msg.getJMSMessageID());
                        return rep;
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    th.start();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    FileUtil.copyInputStream(
            new ClassPathResource("org/apache/servicemix/jms/HelloWorld-RPC-Input-Hello.xml").getInputStream(),
            baos);
    InOut me = client.createInOutExchange();
    me.getInMessage().setContent(new StringSource(baos.toString()));
    me.setOperation(new QName("uri:HelloWorld", "Hello"));
    me.setService(new QName("uri:HelloWorld", "HelloService"));
    client.sendSync(me);
    assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
    assertNotNull(me.getOutMessage());
    assertNotNull(me.getOutMessage().getContent());
    System.err.println(new SourceTransformer().contentToString(me.getOutMessage()));
    client.done(me);

}

From source file:org.ala.jms.JmsMessageProducer.java

@Test
public void generateInvalidMethod() throws JMSException {
    template.send(new MessageCreator() {
        public Message createMessage(Session session) throws JMSException {
            String json = getJson("" + myGuid);
            TextMessage message = session.createTextMessage(json);

            message.setStringProperty(JmsMessageListener.MESSAGE_METHOD, "");

            logger.debug("B Sending message: " + message.getStringProperty(JmsMessageListener.MESSAGE_METHOD)
                    + " == " + json);

            return message;
        }/* www .j  a v a 2  s  .  co  m*/
    });
}

From source file:org.ala.jms.JmsMessageProducer.java

/**
 * Generates JMS messages// ww w .ja v  a2s  .c  om
 */
@Test
public void generateCreateMessage() throws JMSException {
    template.send(new MessageCreator() {
        public Message createMessage(Session session) throws JMSException {
            String json = getJson("" + myGuid);
            TextMessage message = session.createTextMessage(json);

            message.setStringProperty(JmsMessageListener.MESSAGE_METHOD,
                    JmsMessageListener.Method.CREATE.toString());
            logger.debug("B Sending message: " + message.getStringProperty(JmsMessageListener.MESSAGE_METHOD)
                    + " == " + json);

            return message;
        }
    });
}

From source file:org.ala.jms.JmsMessageProducer.java

@Test
public void generateUpdateMessage() throws JMSException {
    template.send(new MessageCreator() {
        public Message createMessage(Session session) throws JMSException {
            String json = getJson("" + myGuid);
            TextMessage message = session.createTextMessage(json);

            message.setStringProperty(JmsMessageListener.MESSAGE_METHOD,
                    JmsMessageListener.Method.UPDATE.toString());

            logger.debug("B Sending message: " + message.getStringProperty(JmsMessageListener.MESSAGE_METHOD)
                    + " == " + json);

            return message;
        }/*from   ww w.  j  av  a  2  s .c  o  m*/
    });
}

From source file:org.ala.jms.JmsMessageProducer.java

@Test
public void generateDeleteMessage() throws JMSException {
    template.send(new MessageCreator() {
        public Message createMessage(Session session) throws JMSException {
            String json = getJson("" + myGuid);
            TextMessage message = session.createTextMessage(json);

            message.setStringProperty(JmsMessageListener.MESSAGE_METHOD,
                    JmsMessageListener.Method.DELETE.toString());

            logger.debug("B Sending message: " + message.getStringProperty(JmsMessageListener.MESSAGE_METHOD)
                    + " == " + json);

            return message;
        }/*from w  ww  .  j  av  a2 s  .  c o m*/
    });
}

From source file:org.logicblaze.lingo.jms.marshall.DefaultMarshaller.java

public Message createObjectMessage(Session session, Object value) throws JMSException {
    Message message = null;/*  ww w  .  j  av  a  2 s .  c o  m*/
    if (value instanceof String) {
        message = session.createTextMessage((String) value);
    } else {
        message = session.createObjectMessage((Serializable) value);
    }
    appendMessageHeaders(message, session, value);
    return message;
}

From source file:com.inkubator.sms.gateway.service.impl.SmsActivityServiceImpl.java

@Override
@Transactional(readOnly = false, isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public void sendSms(SmsSendModel ssm) throws Exception {
    ModemDefinition modemDefinition = this.modemDefinitionDao.getEntiyByPK(ssm.getModemId());
    double hargaPerSms = modemDefinition.getPricePerSms();
    List<String> toLoop = ssm.getListPhone();
    for (String toLoop1 : toLoop) {
        final SMSSend smss = new SMSSend();
        smss.setPricePerSms(hargaPerSms);
        smss.setContent(ssm.getSmsContent());
        smss.setFrom("System");
        smss.setDestination(toLoop1);//from   w w  w. ja  va  2s .  c  o m
        smss.setModemId(modemDefinition.getModemId());
        this.jmsTemplateSMS.send(new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                return session.createTextMessage(jsonConverter.getJson(smss));
            }
        });

        //            OutboundMessage msg = new OutboundMessage(toLoop1, ssm.getSmsContent());
        //            org.smslib.Service.getInstance().sendMessage(msg, modemDefinition.getModemId());
    }
    //        OutboundMessage msg = new OutboundMessage("+6287887051607", "Test UP");
    //        org.smslib.Service.getInstance().sendMessage(msg);

}

From source file:com.provenance.cloudprovenance.connector.traceability.TraceabilityEventConsumer.java

public void onMessage(final Message newMessage) {

    logger.info("Received Traceability Statements Message = " + counter++);

    if (newMessage instanceof TextMessage) {
        TextMessage textMessage = (TextMessage) newMessage;

        String traceabilityRecord = null;
        try {//from  w  w  w  . j a va2  s  .  c  o m
            traceabilityRecord = textMessage.getText();

            logger.info(" Traceability content: \n" + traceabilityRecord);

            /**
             * Get the record Id, if it is just use POST request, otherwise
             * use PUT reequest
             */

            if (traceabilityRecordUri == null || traceabilityRecordUri.equals("")) {

                logger.info("Calling get Resource URI ...");
                String traceabilityRecordResponse = trConnection.getCurrentTraceabilityRecordId(serviceID);

                if (traceabilityRecordResponse != null || traceabilityRecordResponse == "") {

                    logger.info("Resource URI does not exist, creation a new resource with content");

                    traceabilityRecordUri = (resExtraction.getResponseURI(traceabilityRecordResponse));

                    logger.info("New resource created URI is: " + traceabilityRecordUri);

                    trConnection.updateTraceabilityRecord(serviceID, traceabilityRecordUri, traceabilityRecord);

                    logger.info("Sucessfully updated the traceability record: " + traceabilityRecordUri);

                } else {
                    // get a new record Id
                    String response = trConnection.createNewTraceabilityRecord(serviceID, traceabilityRecord);

                    traceabilityRecordUri = (resExtraction.getResponseURI(response));// .split(":")[1];
                    logger.info("Sucessfully created a new traceability record: " + response + "\n"
                            + traceabilityRecordUri);
                }
            } else {
                logger.info("Updating record :" + traceabilityRecordUri);
                trConnection.updateTraceabilityRecord(serviceID, traceabilityRecordUri, traceabilityRecord);

                logger.info("Sucessfully updated the traceability record: " + traceabilityRecordUri);

            }

            // If an ack is required, use the reponse queue
            if (traceabilityStoreStorageAck) {
                logger.info("Sending an ACK to response tranceability queue" + traceabilityRecordUri);

                jmsTemplate.send(responseTraceabilityQueueName, new MessageCreator() {

                    public Message createMessage(Session session) throws JMSException {
                        TextMessage message = session.createTextMessage("Sucessfully Stored, ID: " + counter);
                        // message.setIntProperty("messageCount",
                        // i);
                        return message;
                    }
                });
            }

        } catch (JMSException e) {
            logger.error(e.toString());
            e.printStackTrace();
        } catch (XPathExpressionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {
        logger.warn("Unknown message type, cannot process");
    }
}

From source file:org.fcrepo.fixity.service.FixityService.java

/**
 * Queue a single object for a fixity check
 * //  w  w w . ja va 2  s .c  om
 * @param uri the Uri of the Object to queue
 */
public void queueFixityCheck(final String uri) {

    /* send a JMS message to the fixity queue for each object */
    this.fixityJmsTemplate.send(new MessageCreator() {

        @Override
        public Message createMessage(Session session) throws JMSException {
            /* create a message containing the object uri */
            return session.createTextMessage(uri);
        }
    });
}

From source file:org.soitoolkit.commons.studio.components.logger.impl.DefaultLogEventSender.java

protected void sendOneTextMessage(Session session, String queueName, String message) {

    MessageProducer publisher = null;//from w  w  w  . j ava  2  s  . c  om

    try {
        publisher = session.createProducer(session.createQueue(queueName));
        TextMessage textMessage = session.createTextMessage(message);
        publisher.send(textMessage);

    } catch (JMSException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            if (publisher != null)
                publisher.close();
        } catch (JMSException e) {
        }
    }
}