Example usage for javax.jms TextMessage getText

List of usage examples for javax.jms TextMessage getText

Introduction

In this page you can find the example usage for javax.jms TextMessage getText.

Prototype


String getText() throws JMSException;

Source Link

Document

Gets the string containing this message's data.

Usage

From source file:eu.europa.ec.fisheries.uvms.spatial.service.bean.impl.SpatialUserServiceBean.java

private static void validateResponse(TextMessage response, String correlationId)
        throws SpatialModelValidationException {

    try {//  w  w  w .  ja  va  2 s. c  o m
        if (response == null) {
            throw new SpatialModelValidationException(
                    "Error when validating response in ResponseMapper: Response is Null");
        }

        if (response.getJMSCorrelationID() == null) {
            throw new SpatialModelValidationException(
                    "No correlationId in response (Null) . Expected was: " + correlationId);
        }

        if (!correlationId.equalsIgnoreCase(response.getJMSCorrelationID())) {
            throw new SpatialModelValidationException("Wrong correlationId in response. Expected was: "
                    + correlationId + " But actual was: " + response.getJMSCorrelationID());
        }

        try {
            Fault fault = JAXBUtils.unMarshallMessage(response.getText(), Fault.class);
            throw new SpatialModelValidationException(fault.getCode() + " : " + fault.getFault());
        } catch (JAXBException e) {
            log.info("Expected Exception"); // Exception received in case if the validation is success
        }

    } catch (JMSException e) {
        log.error("JMS exception during validation ", e);
        throw new SpatialModelValidationException("JMS exception during validation " + e.getMessage());
    }
}

From source file:nh.examples.springintegration.order.utils.XmlJmsMessageConverter.java

@Override
public Object fromMessage(Message message) throws JMSException, MessageConversionException {
    TextMessage textMessage = (TextMessage) message;

    String xml = textMessage.getText();
    Object object = _xmlConverter.fromXml(xml);

    return object;
}

From source file:gov.nih.nci.caarray.application.file.DirectJobSubmitter.java

private TextMessage getMessageStub(String messageText) {
    TextMessage message = mock(TextMessage.class);
    try {/*  w w  w. jav a2s.  co  m*/
        when(message.getText()).thenReturn(messageText);
    } catch (JMSException e) {
        throw new UnhandledException(e);
    }
    return message;
}

From source file:org.btc4j.jms.BtcMessageConverter.java

@Override
public Object fromMessage(Message object) throws JMSException, MessageConversionException {
    if ((object != null) && (object instanceof TextMessage)) {
        BtcRequestMessage request = new BtcRequestMessage();
        TextMessage message = (TextMessage) object;
        request.setBody(message.getText());
        request.setAccount(message.getStringProperty(BtcRequestMessage.BTCAPI_ACCOUNT));
        request.setPassword(message.getStringProperty(BtcRequestMessage.BTCAPI_PASSWORD));
        return request;
    }//from w  ww  .j  av  a2s.c om
    return super.fromMessage(object);
}

From source file:com.amazon.notification.utils.Receiver.java

@Override
public void onMessage(Message msg) {
    if (msg instanceof TextMessage) {
        try {/*from  w w  w . j  a v  a2  s .  c om*/
            TextMessage text = (TextMessage) msg;

            String[] toArr = { text.getText().split(",")[0] };
            String[] bccArr = {};

            notificationManager.sendEmail("amazehackathon2015@gmail.com", toArr, bccArr,
                    "Notification for Subscriber", text.getText().split(",")[1]);

            System.out.println("Message is : " + text.getText());
        } catch (JMSException ex) {
            Logger.getLogger(Receiver.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:org.hoteia.qalingo.core.jms.cms.listener.CmsQueueListener.java

/**
 * Implementation of <code>MessageListener</code>.
 *//* w  ww  .j  a  v a 2 s.co  m*/
public void onMessage(Message message) {
    try {
        if (message instanceof TextMessage) {
            TextMessage tm = (TextMessage) message;
            String valueJMSMessage = tm.getText();
            if (logger.isDebugEnabled()) {
                logger.debug("Processed message, value: " + valueJMSMessage);
            }
        }
    } catch (JMSException e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:net.homecredit.book.jms.JmsMessageListener.java

/**
 * Implementation of <code>MessageListener</code>.
 *//*  w  w w .  j a v a  2  s.  c om*/
public void onMessage(Message message) {
    try {
        int messageCount = message.getIntProperty(JmsMessageProducer.MESSAGE_COUNT);

        if (message instanceof TextMessage) {
            TextMessage tm = (TextMessage) message;
            String msg = tm.getText();

            logger.info("Processed message '{}'.  value={}", msg, messageCount);

            counter.incrementAndGet();
        }
    } catch (JMSException e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:org.mule.transport.jms.JmsMuleMessageFactoryTestCase.java

@Override
protected Object getValidTransportMessage() throws Exception {
    TextMessage textMessage = mock(TextMessage.class);
    when(textMessage.getText()).thenReturn(MESSAGE_TEXT);
    when(textMessage.getJMSCorrelationID()).thenReturn(null);
    when(textMessage.getJMSDeliveryMode()).thenReturn(Integer.valueOf(1));
    when(textMessage.getJMSDestination()).thenReturn(null);
    when(textMessage.getJMSExpiration()).thenReturn(Long.valueOf(0));
    when(textMessage.getJMSMessageID()).thenReturn("1234567890");
    when(textMessage.getJMSPriority()).thenReturn(Integer.valueOf(4));
    when(textMessage.getJMSRedelivered()).thenReturn(Boolean.FALSE);
    when(textMessage.getJMSReplyTo()).thenReturn(null);
    when(textMessage.getJMSTimestamp()).thenReturn(Long.valueOf(0));
    when(textMessage.getJMSType()).thenReturn(null);
    when(textMessage.getPropertyNames())
            .thenReturn(IteratorUtils.asEnumeration(IteratorUtils.arrayIterator(new Object[] { "foo" })));
    when(textMessage.getObjectProperty("foo")).thenReturn("bar");
    return textMessage;
}

From source file:sk.seges.test.jms.activemq.SimpleActiveMQQueueReceiveTest.java

@Test
public void testReceive() throws Exception {
    Connection connection = activeMQConnectionFactory.createConnection();
    connection.start();/*  w  w w .j  a  v a2 s.com*/
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createConsumer(activeMQTestQueueA);

    Message rawMessage = consumer.receive(1000);
    assertTrue(rawMessage instanceof TextMessage);

    TextMessage message = (TextMessage) rawMessage;
    assertEquals("test text", message.getText());
    connection.close();
}

From source file:com.inkubator.hrm.service.impl.RiwayatAccessMessagesListener.java

@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = Exception.class)
public void onMessage(Message message) {
    try {//from   w w  w . j  ava2  s  .  c o m
        TextMessage textMessage = (TextMessage) message;
        String json = textMessage.getText();
        RiwayatAkses riwayatAccess = (RiwayatAkses) jsonConverter.getClassFromJson(json, RiwayatAkses.class);
        riwayatAccess.setId(Long.parseLong(RandomNumberUtil.getRandomNumber(14)));
        String data = StringUtils.substringAfter(riwayatAccess.getPathUrl(), riwayatAccess.getContextPath());
        HrmMenu hrmMenu = hrmMenuDao.getByPathRelative(data);
        riwayatAccess.setHrmMenu(hrmMenu);
        //            String b = StringUtils.reverse(riwayatAccess.getPathUrl());
        //            String c = StringUtils.substringBefore(b, "/");
        //            String d = StringUtils.reverse(c);
        //            riwayatAccess.setName(d);
        //            if (StringUtils.containsOnly(c, "htm")) {
        //                d = StringUtils.substringAfter(c, ".");
        //                riwayatAccess.setName(StringUtils.reverse(d));
        //            }
        riwayatAksesDao.save(riwayatAccess);
    } catch (JMSException | NumberFormatException ex) {
        LOGGER.error("Error", ex);
    }
}