Example usage for javax.jms Message getStringProperty

List of usage examples for javax.jms Message getStringProperty

Introduction

In this page you can find the example usage for javax.jms Message getStringProperty.

Prototype


String getStringProperty(String name) throws JMSException;

Source Link

Document

Returns the value of the String property with the specified name.

Usage

From source file:springchat.jms.NewTextMessage.java

@Override
public void onMessage(Message jms) {
    MessageDto dto = new MessageDto();
    try {/*from   ww w .jav a  2s  .  co m*/
        dto.setContent(jms.getStringProperty("message"));
        dto.setFrom(jms.getStringProperty("user"));
        dto.setTimestamp(jms.getLongProperty("date"));
    } catch (JMSException e) {
        throw new UnmanagedException(e);
    }
    MessageEntity bean = messagesService.save(dto.getTimestamp(), dto.getFrom(), dto.getContent());
    dto.setId(bean.getUid());
    connections.sendToAll("text", dto);
}

From source file:com.mdmserver.mdb.ControllerQueue.java

@Override
public void onMessage(Message message) {

    System.out.println("Control message received on the queue!!");
    try {//from   w  ww.jav a2s.  c  o  m
        String jsonData = message.getStringProperty(ControlClient.CONTROL_CLIENT_KEY);
        String cloudId = message.getStringProperty(Account.FIELD_NAME_CLOUD_ID);
        sendGCMMessge(cloudId, jsonData);
    } catch (JMSException ex) {
        Logger.getLogger(ControllerQueue.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.fusesource.forge.jmstest.tests.simple.SimpleConsumer.java

protected void run() {
    Connection con = null;//from   w  ww  .j a va  2s .c  o m
    Session session = null;
    final CountDownLatch latch = new CountDownLatch(Integer.MAX_VALUE);
    try {
        con = getConnection();
        session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination dest = getDestinationProvider().getDestination(session, "queue:TEST");
        MessageConsumer consumer = session.createConsumer(dest);
        consumer.setMessageListener(new MessageListener() {
            public void onMessage(Message msg) {
                String grp = null;
                long nr = 0L;
                try {
                    grp = msg.getStringProperty("JMSXGroupID");
                    nr = msg.getLongProperty("MsgNr");
                } catch (JMSException jme) {
                }
                log().info("Received Message Group=(" + grp + ") MsgNr=" + nr);
                latch.countDown();
            }
        });
        con.start();
        latch.await();
        con.close();
    } catch (Exception e) {
    } finally {
        if (con != null) {
            try {
                con.close();
            } catch (Exception e) {
            }
        }
    }
}

From source file:springchat.test.NewTextMessageTest.java

@Test
public void testOnMessage() throws JMSException {
    final long uid = 10l;
    final String content = "Hi there!";
    final String user = "boto";
    final long timestamp = System.currentTimeMillis();

    Message jmsMessage = EasyMock.createNiceMock(Message.class);
    EasyMock.expect(jmsMessage.getStringProperty("message")).andReturn(content).once();
    EasyMock.expect(jmsMessage.getStringProperty("user")).andReturn(user).once();
    EasyMock.expect(jmsMessage.getLongProperty("date")).andReturn(timestamp).once();

    MessageEntity entityMessage = new MessageEntity();
    entityMessage.setUid(uid);/* w w  w.j av a 2 s.co m*/
    entityMessage.setDate(new Date(timestamp));
    entityMessage.setMessage(content);
    entityMessage.setUser(user);

    EasyMock.expect(messagesService.save(timestamp, user, content)).andReturn(entityMessage).once();

    connections.sendToAll(EasyMock.anyObject(String.class), EasyMock.anyObject(MessageDto.class));
    EasyMock.expectLastCall().andDelegateTo(new ConnectionsService() {
        @Override
        public void addSession(WebSocketSession session) {
            Assert.fail();
        }

        @Override
        public void removeSession(WebSocketSession session) {
            Assert.fail();
        }

        @Override
        public void sendToAll(String typeName, Object data) {
            Assert.assertEquals(MessageDto.class, data.getClass());
            Assert.assertEquals(uid, MessageDto.class.cast(data).getId().longValue());
        }
    });

    EasyMock.replay(messagesService, connections, jmsMessage);
    newTextMessage.onMessage(jmsMessage);
    EasyMock.verify(messagesService, connections, jmsMessage);
}

From source file:com.kinglcc.spring.jms.core.converter.GenericJmsMessageConverter.java

private MessageConverter getMessageConverterFrom(Message message) throws JMSException {
    String converterName = message.getStringProperty(CONVERTER_PROP);
    if (StringUtils.isNotBlank(converterName)) {
        return getConverterByConverterName(converterName);
    }//from  w w  w  .  ja v a2 s .co m
    for (JmsMessageConverter converter : messageConverters) {
        if (converter.canConvertFrom(message)) {
            return converter;
        }
    }
    return defaultMessageConverter;
}

From source file:org.ct.amq.jdbc.security.JdbcAuthenticationPluginTest.java

public void testPredefinedDestinations() throws JMSException {
    Message sent = doSend(false);
    assertEquals("guest", ((ActiveMQMessage) sent).getUserID());
    assertEquals("guest", sent.getStringProperty("JMSXUserID"));
}

From source file:be.fedict.eid.dss.model.bean.TaskMDB.java

public void onMessage(Message message) {
    LOG.debug("onMessage");
    String taskName;//w w w  . j a  va  2s. co m
    try {
        taskName = message.getStringProperty(MailManagerBean.TASK_NAME_PROPERTY);
    } catch (JMSException e) {
        throw new RuntimeException("JMS error: " + e.getMessage(), e);
    }

    if (MailSignedDocumentTaskMessage.TASK_NAME.equals(taskName)) {
        MailSignedDocumentTaskMessage mailSignedDocumentTaskMessage = new MailSignedDocumentTaskMessage(
                message);
        processMailSignedDocumentTask(mailSignedDocumentTaskMessage);
    } else {
        LOG.error("unknown task: " + taskName);
    }
}

From source file:com.seajas.search.bridge.jms.integration.GroupIdJmsHeaderMapper.java

@Override
public Map<String, Object> toHeaders(final javax.jms.Message jmsMessage) {
    Map<String, Object> result = super.toHeaders(jmsMessage);

    try {/*from  ww  w.j a v  a  2 s  .  co m*/
        if (jmsMessage.getStringProperty(JMS_HEADER_GROUPID) != null)
            result.put(SPI_HEADER_GROUPID, jmsMessage.getStringProperty(JMS_HEADER_GROUPID));
        if (jmsMessage.getStringProperty(JMS_HEADER_SEAJAS_DOMAIN) != null) {
            result.put(SPI_HEADER_SEAJAS_DOMAIN, jmsMessage.getStringProperty(JMS_HEADER_SEAJAS_DOMAIN));
        }
    } catch (JMSException e) {
        logger.error("Could not retrieve the JMS " + JMS_HEADER_GROUPID + " or " + JMS_HEADER_SEAJAS_DOMAIN
                + " header", e);
    }

    return result;
}

From source file:org.hawkular.apm.server.jms.span.SpanCacheMDB.java

@Override
public void onMessage(Message message) {
    if (log.isLoggable(Level.FINEST)) {
        log.finest("Message received=" + message);
    }/*from   w  w w .  j  a  v a2 s .  c o m*/

    try {
        String tenantId = message.getStringProperty("tenant");

        String data = ((TextMessage) message).getText();

        List<Span> items = mapper.readValue(data, typeRef);

        spanCache.store(tenantId, items, SpanUniqueIdGenerator::toUnique);

    } catch (JMSException | IOException | CacheException e) {
        log.log(Level.SEVERE, "Failed to process message", e);
    }
}

From source file:org.hawkular.apm.server.jms.trace.SourceInfoCacheMDB.java

@Override
public void onMessage(Message message) {
    if (log.isLoggable(Level.FINEST)) {
        log.finest("Message received=" + message);
    }/*  ww w .j av  a2  s. c o  m*/

    try {
        String tenantId = message.getStringProperty("tenant");

        String data = ((TextMessage) message).getText();

        List<Trace> items = mapper.readValue(data, typeRef);

        List<SourceInfo> sourceInfoList = SourceInfoUtil.getSourceInfo(tenantId, items);

        sourceInfoCache.store(tenantId, sourceInfoList);

    } catch (JMSException | IOException | CacheException | RetryAttemptException e) {
        log.log(Level.SEVERE, "Failed to handle message", e);
    }
}