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.rules.service.bean.ExchangeRuleServiceBean.java

@Override
public boolean identificationRefExists(String refGuid, String... typeRefType) {
    Boolean faQueryIdentificationExists = false;
    try {/*from w ww. j a va  2 s  .c  o m*/
        LogRefIdByTypeExistsRequest existsRequest = new LogRefIdByTypeExistsRequest();
        for (String refType : typeRefType) {
            existsRequest.getRefTypes().add(EnumUtils.getEnum(TypeRefType.class, refType));
        }
        existsRequest.getRefTypes().removeAll(Collections.singleton(null));
        existsRequest.setRefGuid(refGuid);
        existsRequest.setMethod(ExchangeModuleMethod.LOG_REF_ID_BY_TYPE_EXISTS);
        String jaxBObjectToString = marshallJaxBObjectToString(existsRequest);
        String jmsMessageID = producer.sendDataSourceMessage(jaxBObjectToString, EXCHANGE);
        TextMessage message = consumer.getMessage(jmsMessageID, TextMessage.class);
        String text = message.getText();
        LogRefIdByTypeExistsResponse response = unMarshallMessage(text, LogRefIdByTypeExistsResponse.class);
        faQueryIdentificationExists = response.getRefGuid() != null;

    } catch (JAXBException | MessageException | JMSException e) {
        log.error(e.getMessage(), e);
    }
    return faQueryIdentificationExists;
}

From source file:org.hoteia.qalingo.core.jms.document.listener.DocumentQueueListener.java

/**
 * Implementation of <code>MessageListener</code>.
 *///from   w ww  .  j  av  a 2  s  .  c o m
public void onMessage(Message message) {
    try {
        if (message instanceof TextMessage) {
            TextMessage tm = (TextMessage) message;
            String valueJMSMessage = tm.getText();

            if (StringUtils.isNotEmpty(valueJMSMessage)) {
                final GenerationDocumentMessageJms documentMessageJms = xmlMapper.getXmlMapper()
                        .readValue(valueJMSMessage, GenerationDocumentMessageJms.class);

                final OrderPurchase order = orderPurchaseService.getOrderById(documentMessageJms.getOrderId());

                if (documentMessageJms.getDocumentType()
                        .equals(OrderDocumentType.ORDER_CONFIRMATION.getPropertyKey())) {
                    documentService.generateOrderConfirmation(order);

                } else if (documentMessageJms.getDocumentType()
                        .equals(OrderDocumentType.SHIPPING_CONFIRMATION.getPropertyKey())) {
                    documentService.generateShippingConfirmation(order);

                } else if (documentMessageJms.getDocumentType()
                        .equals(OrderDocumentType.INVOICE.getPropertyKey())) {
                    documentService.generateInvoice(order);

                }

                if (logger.isDebugEnabled()) {
                    logger.debug("Processed message, value: " + valueJMSMessage);
                }
            } else {
                logger.warn("Document generation: Jms Message is empty");
            }
        }
    } catch (JMSException e) {
        logger.error(e.getMessage(), e);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:de.fzi.ALERT.actor.MessageObserver.PatternObserver.JMSPatternListener.java

public void onMessage(Message msg) {
    if ((msg instanceof TextMessage)) {
        TextMessage tMsg = (TextMessage) msg;
        try {//from  w  ww.  j ava  2s.c  o m
            Pattern pattern = this.parser.parseJsoup(tMsg.getText());
            System.out.println("Get a new Pattern with ID: " + pattern.getPatternID());
            System.out.println("Get a new Pattern with name: " + pattern.getPatternName());
            System.out.println("The Action is " + pattern.getStatus());
            if (pattern.getPatternID() == null || pattern.getPatternName() == null) {
                System.out.println("pattern id and name can't be null!!");
                return;
            }
            switch (pattern.getStatus()) {
            case 0:
                this.manager.savePattern(pattern);
                break;
            case 1:
                this.manager.updatePattern(pattern);
                break;
            case 2:
                this.manager.deletePattern(pattern);
                break;
            default:
                System.out.println("The wrong action type!");
            }
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.hoteia.qalingo.core.jms.entitycheck.listener.EntityCheckQueueListener.java

/**
 * Implementation of <code>MessageListener</code>.
 *///from   w w w. j av a  2  s  .  c o m
public void onMessage(Message message) {
    try {
        if (message instanceof TextMessage) {
            TextMessage tm = (TextMessage) message;
            String valueJMSMessage = tm.getText();

            if (StringUtils.isNotEmpty(valueJMSMessage)) {
                final EntityCheckMessageJms documentMessageJms = xmlMapper.getXmlMapper()
                        .readValue(valueJMSMessage, EntityCheckMessageJms.class);

                if (logger.isDebugEnabled()) {
                    logger.debug("Processed message, value: " + valueJMSMessage);
                }

                //                    try {
                //                        SpringCamelContext camelContext = (SpringCamelContext) context.getBean("camelContext");
                //                        
                //                        if(!camelContext.getRouteStatus("entityCheckRoute").isStarted()){
                //                            camelContext.startRoute("entityCheckRoute");
                //                        }
                //                        ProducerTemplate template = context.getBean("camelTemplate", ProducerTemplate.class);
                //
                //                        Map<String, Object> params = new HashMap<String, Object>();
                //                        params.put("id", documentMessageJms.getObjectId());
                //                        params.put("type", documentMessageJms.getObjectType());
                //                        template.asyncSendBody("direct:startEntityCheckRoute", params);
                //                        
                //                    } catch (Exception e) {
                //                        e.printStackTrace();
                //                    }
            } else {
                logger.warn("Document generation: Jms Message is empty");
            }
        }
    } catch (JMSException e) {
        logger.error(e.getMessage(), e);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:org.apache.storm.jms.spout.JmsSpoutTest.java

public Message sendMessage(ConnectionFactory connectionFactory, Destination destination) throws JMSException {
    Session mySess = connectionFactory.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
    MessageProducer producer = mySess.createProducer(destination);
    TextMessage msg = mySess.createTextMessage();
    msg.setText("Hello World");
    log.debug("Sending Message: " + msg.getText());
    producer.send(msg);//from www . j av a  2s .  com
    return msg;
}

From source file:net.blogracy.services.LookupService.java

@Override
public void onMessage(final Message request) {
    String text = null;//from  w ww. jav a 2 s . c  om
    try {
        TextMessage textRequest = (TextMessage) request;
        text = textRequest.getText();
        Logger.info("lookup service:" + text + ";");
        JSONObject record = new JSONObject(text);

        final long TIMEOUT = 5 * 60 * 1000; // 5 mins
        DistributedDatabase ddb = plugin.getDistributedDatabase();
        ddb.read(new DhtListener(textRequest), ddb.createKey(record.getString("key")), TIMEOUT,
                DistributedDatabase.OP_EXHAUSTIVE_READ);
    } catch (DistributedDatabaseException e) {
        Logger.error("DDB error: lookup service: " + text);
    } catch (JMSException e) {
        Logger.error("JMS error: lookup service: " + text);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.oneops.antenna.jms.AntennaListener.java

/**
 * Parse json  from JMS text message/*from  w  w w  . j  a v  a  2s .c o  m*/
 *
 * @param message JMS message
 * @return parsed notification message
 * @throws JMSException
 */
private NotificationMessage parseMsg(TextMessage message) throws JMSException {
    return gson.fromJson(message.getText(), NotificationMessage.class);
}

From source file:org.wso2.carbon.automation.extensions.servers.jmsserver.client.JMSTopicMessageConsumer.java

public void onMessage(Message message) {
    if (message != null) {
        if (message instanceof TextMessage) {
            TextMessage textMessage = (TextMessage) message;
            try {
                addMessage(textMessage.getText());
            } catch (JMSException e) {
                log.error(e);//  w  w  w  . j  ava  2  s.  co  m
            }
        }
    }
}

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

@SuppressWarnings("unchecked")
@Override/* ww  w  . j ava 2  s .c  o m*/
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, timeout = 50, rollbackFor = Exception.class)
public void onMessage(Message message) {
    try {
        TextMessage textMessage = (TextMessage) message;
        String json = textMessage.getText();
        Gson gson = new GsonBuilder().create();
        JsonObject jsonObject = (JsonObject) gson.fromJson(json, JsonObject.class);
        String locale = jsonObject.get("locale").getAsString();
        String userEmail = jsonObject.get("userEmail").getAsString();

        List<String> toSend = new ArrayList<>();
        List<String> toSentCC = new ArrayList<String>();
        List<String> toSentBCC = new ArrayList<String>();
        toSend.add(userEmail);
        toSentCC.add("rizky.maulana@incubatechnology.com");
        toSentCC.add("rizkykojek@gmail.com");
        toSentCC.add("rizal2_dfhr@yahoo.com");
        VelocityTempalteModel vtm = new VelocityTempalteModel();
        vtm.setFrom(ownerEmail);
        vtm.setTo(toSend.toArray(new String[toSend.size()]));
        vtm.setCc(toSentCC.toArray(new String[toSentCC.size()]));
        vtm.setBcc(toSentBCC.toArray(new String[toSentBCC.size()]));

        Map maptoSend = new HashMap();
        maptoSend.put("startDate", jsonObject.get("startDate").getAsString());
        maptoSend.put("endDate", jsonObject.get("endDate").getAsString());
        maptoSend.put("userName", jsonObject.get("userName").getAsString());
        maptoSend.put("userNik", jsonObject.get("userNik").getAsString());
        maptoSend.put("ownerAdministrator", ownerAdministrator);
        maptoSend.put("ownerCompany", ownerCompany);
        maptoSend.put("applicationUrl", applicationUrl);
        maptoSend.put("applicationName", applicationName);
        List<String> listSchedule = gson.fromJson(jsonObject.get("listSchedule").getAsString(),
                new TypeToken<List<String>>() {
                }.getType());
        maptoSend.put("listSchedule", listSchedule);
        if (StringUtils.equals(locale, "en")) {
            vtm.setSubject("Employee Working Schedule");
            vtm.setTemplatePath("email_employee_working_schedule_en.vm");
        } else {
            vtm.setSubject("Jadwal Kerja Karyawan");
            vtm.setTemplatePath("email_employee_working_schedule.vm");
        }

        velocityTemplateSender.sendMail(vtm, maptoSend);
    } catch (Exception ex) {
        LOGGER.error("Error", ex);
    }
}

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

public Object readMessage(Message message) throws JMSException {
    handleMessageHeaders(message);/*w  ww.ja v  a2  s  . c  om*/
    if (message instanceof ObjectMessage) {
        ObjectMessage objectMessage = (ObjectMessage) message;
        return objectMessage.getObject();
    } else if (message instanceof TextMessage) {
        TextMessage textMessage = (TextMessage) message;
        return textMessage.getText();
    }
    return onInvalidMessage(message);
}