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.apigw.monitoring.svc.impl.JmsOAuthMonitoringService.java

private void sendLog(final String logObject, String eventName) {
    log.debug("sendLog(log: {}, queue: {})", logObject, monitoringQueue.toString());
    try {/* ww  w. j a va 2  s . com*/
        template.send(monitoringQueue, new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                TextMessage message = session.createTextMessage(logObject);
                return message;
            }
        });
    } catch (Exception e) {
        log.error("caught error while trying to send log for event {}:", eventName, e);
        throw new ApigwMonitoringException(e);
    }
}

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

private void sendingEmailJadwalKaryawan(List<TempJadwalKaryawan> listAll, String locale) {
    //initialization
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMMM yyyy");
    SimpleDateFormat fullDateFormat = new SimpleDateFormat("EEEE, dd MMMM yyyy", new Locale(locale));
    SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");

    //grouping by empData
    Group<TempJadwalKaryawan> groupByEmpData = Lambda.group(listAll,
            Lambda.by(Lambda.on(TempJadwalKaryawan.class).getEmpData().getId()));

    //looping based on empData
    for (String key : groupByEmpData.keySet()) {
        List<TempJadwalKaryawan> listJadwalEmployee = groupByEmpData.find(key);
        listJadwalEmployee = Lambda.sort(listJadwalEmployee,
                Lambda.on(TempJadwalKaryawan.class).getTanggalWaktuKerja());

        EmpData empData = empDataDao.getEntiyByPK(listJadwalEmployee.get(0).getEmpData().getId());
        HrmUser user = hrmUserDao.getByEmpDataId(empData.getId());
        Date startDate = listJadwalEmployee.get(0).getTanggalWaktuKerja();
        Date endDate = listJadwalEmployee.get(listJadwalEmployee.size() - 1).getTanggalWaktuKerja();
        List<String> jadwals = new ArrayList<String>();
        for (TempJadwalKaryawan tempJK : listJadwalEmployee) {
            TempJadwalKaryawan jadwal = tempJadwalKaryawanDao.getEntiyByPK(tempJK.getId());
            StringBuffer sb = new StringBuffer();
            sb.append(fullDateFormat.format(jadwal.getTanggalWaktuKerja()));
            sb.append(", ");
            sb.append(timeFormat.format(jadwal.getWtWorkingHour().getWorkingHourBegin()));
            sb.append(" - ");
            sb.append(timeFormat.format(jadwal.getWtWorkingHour().getWorkingHourEnd()));
            sb.append(". ");
            jadwals.add(sb.toString());// w w  w  .j  a v a2  s  . c om
        }

        //only send the working schedule to the employee that have a valid email
        if (user != null && StringUtils.isNotEmpty(user.getEmailAddress())) {
            final JsonObject jsonObj = new JsonObject();
            jsonObj.addProperty("startDate", simpleDateFormat.format(startDate));
            jsonObj.addProperty("endDate", simpleDateFormat.format(endDate));
            jsonObj.addProperty("userEmail", user.getEmailAddress());
            jsonObj.addProperty("locale", locale);
            jsonObj.addProperty("userName", empData.getBioData().getFullName());
            jsonObj.addProperty("userNik", empData.getNik());
            jsonObj.addProperty("listSchedule", new GsonBuilder().create().toJson(jadwals));

            //send messaging, to trigger sending email
            jmsTemplateJadwalKerjaEmail.send(new MessageCreator() {
                @Override
                public Message createMessage(Session session) throws JMSException {
                    return session.createTextMessage(jsonObj.toString());
                }
            });
        }
    }
}

From source file:org.fusesource.stompjms.JmsTestSupport.java

protected void sendMessages(Session session, Destination destination, int count) throws JMSException {
    MessageProducer producer = session.createProducer(destination);
    for (int i = 0; i < count; i++) {
        producer.send(session.createTextMessage(messageTextPrefix + i));
    }/*  www  . ja  va  2  s  .  c o  m*/
    producer.close();
}

From source file:ProducerTool.java

protected void sendLoop(Session session, MessageProducer producer) throws Exception {

    for (int i = 0; i < messageCount || messageCount == 0; i++) {

        TextMessage message = session.createTextMessage(createMessageText(i));

        if (verbose) {
            String msg = message.getText();
            if (msg.length() > 50) {
                msg = msg.substring(0, 50) + "...";
            }/*from w  w  w.  j a v a 2  s . co m*/
            System.out.println("[" + this.getName() + "] Sending message: '" + msg + "'");
        }

        producer.send(message);

        if (transacted && (i % batch == 0)) {
            System.out.println("[" + this.getName() + "] Committing " + messageCount + " messages");
            session.commit();
        }
        Thread.sleep(sleepTime);
    }
}

From source file:de.elomagic.carafile.server.bl.SeedBean.java

public void seedChunk(final InputStream inputStream, final String chunkId)
        throws IOException, GeneralSecurityException, JMSException {
    LOG.debug("Seeding chunk " + chunkId);
    Chunk chunk = chunkDAO.findByIdentifier(chunkId);

    if (chunk == null) {
        throw new FileNotFoundException(
                "Chunk id " + chunkId + " not found. File already registered at registry?");
    }/* w w  w  .j  a v a  2s . c o  m*/

    byte[] buf = new byte[chunk.getFileMeta().getChunkSize()];
    int bufferSize;
    try (InputStream in = inputStream) {
        bufferSize = readBlock(in, buf);
    } catch (IOException ex) {
        throw ex;
    }

    // Check SHA-1
    String sha1 = Hex.encodeHexString(DigestUtils.sha1(Arrays.copyOf(buf, bufferSize)));
    if (!chunk.getHash().equalsIgnoreCase(sha1)) {
        throw new GeneralSecurityException(
                "Chunk SHA-1 validation failed (Expected " + chunk.getHash() + ", but is " + sha1 + ")");
    }

    repositoryBean.writeChunk(chunkId, buf, bufferSize);

    LOG.debug("Chunk id " + chunkId + " seed");

    // Initiate to register at tracker
    LOG.debug("Queue up new file for registration.");
    Connection connection = connectionFactory.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer messageProducer = session.createProducer(chunkQueue);

    TextMessage message = session.createTextMessage(chunkId);
    messageProducer.send(message);
    connection.close();
}

From source file:fr.xebia.sample.springframework.jms.requestreply.RequestReplyClientInvoker.java

/**
 * Request/Reply SpringFramework sample.
 * /*w ww.  j  a va 2  s  .  com*/
 * @param request
 *            sent to the remote service
 * @return reply returned by the remote service
 * @throws JMSException
 */
public String requestReply(String request) throws JMSException {

    Connection connection = connectionFactory.createConnection();
    try {
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        try {
            MessageProducer messageProducer = session.createProducer(this.requestDestination);
            try {
                Message requestMessage = session.createTextMessage(request);
                requestMessage.setJMSReplyTo(this.replyToDestination);
                // requestMessage.setJMSCorrelationID(String.valueOf(random.nextLong()));

                messageProducer.send(requestMessage);
                String messageSelector = "JMSCorrelationID  LIKE '" + requestMessage.getJMSMessageID() + "'";

                MessageConsumer messageConsumer = session.createConsumer(this.replyToDestination,
                        messageSelector);
                TextMessage replyMessage = (TextMessage) messageConsumer.receive(timeoutInMillis);
                Assert.notNull(replyMessage, "Timeout waiting for jms response");
                logger.debug(
                        "requestReply " + "\r\nrequest : " + requestMessage + "\r\nreply : " + replyMessage);
                String result = replyMessage.getText();
                logger.debug("requestReply('" + request + "'): '" + result + "'");
                return result;
            } finally {
                JmsUtils.closeMessageProducer(messageProducer);
            }
        } finally {
            JmsUtils.closeSession(session);
        }
    } finally {
        JmsUtils.closeConnection(connection);
    }
}

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

private void sendSmsPasswordExpiredNotification(final HrmUser hrmUser) {

    final SMSSend mSSend = new SMSSend();
    mSSend.setFrom(HRMConstant.SYSTEM_ADMIN);
    mSSend.setDestination(hrmUser.getPhoneNumber());
    mSSend.setContent("Dear " + hrmUser.getRealName() + " Password anda pada Aplikasi " + applicationName
            + " Telah Kadaluwarsa. Segera Hubungi Administrator untuk mengaktifkan kembali akun anda.");

    jmsTemplateSMS.send(new MessageCreator() {
        @Override/*from w w w  . j a v  a  2 s  .com*/
        public Message createMessage(Session session) throws JMSException {
            return session.createTextMessage(jsonConverter.getJson(mSSend));
        }
    });

}

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

@Override
@Transactional(readOnly = false, isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public void resetPassword(SmsGatewayUser user) throws Exception {
    SmsGatewayUser smsGatewayUser = this.userDao.getEntiyByPK(user.getId());
    smsGatewayUser.setPassword(HashingUtils.getHashSHA256(user.getPassword()));
    smsGatewayUser.setUpdatedBy(SMSGATEWAY.INKUBA_SYSTEM);
    smsGatewayUser.setUpdatedOn(new Date());
    this.userDao.update(smsGatewayUser);
    final PasswordHistory passwordHistory = new PasswordHistory();
    passwordHistory.setId(Long.parseLong(RandomNumberUtil.getRandomNumber(9)));
    passwordHistory.setCreatedBy(SMSGATEWAY.INKUBA_SYSTEM);
    passwordHistory.setCreatedOn(new Date());
    passwordHistory.setEmailAddress(user.getEmailAddress());
    passwordHistory.setEmailNotification(0);
    passwordHistory.setRequestType(SMSGATEWAY.USER_RESET);
    passwordHistory.setSmsNotification(-1);
    passwordHistory.setRealName(user.getRealName());
    passwordHistory.setPhoneNumber(user.getPhoneNumber());
    passwordHistory.setPassword(//ww  w. j  a  v a 2s  .  com
            AESUtil.getAESEncription(user.getPassword(), SMSGATEWAY.KEYVALUE, SMSGATEWAY.AES_ALGO));
    passwordHistory.setUserName(user.getUserId());
    passwordHistory.setLocalId("en");
    List<String> roleNames = new ArrayList<>();
    for (UserRole userRole : userRoleDao.getByUserId(user.getId())) {
        roleNames.add(userRole.getRole().getRoleName());
    }
    passwordHistory.setListRole(jsonConverter.getJson(roleNames.toArray(new String[roleNames.size()])));
    this.passwordHistoryDao.save(passwordHistory);
    //send messaging, for processing sending email
    this.jmsTemplate.send(new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            return session.createTextMessage(jsonConverter.getJson(passwordHistory));
        }
    });
}

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

private void sendSmsPasswordAlmostExpiredNotification(final HrmUser hrmUser, SimpleDateFormat dateFormat,
        PasswordComplexity passwordComplexity) {
    Date expiredDate = DateTimeUtil.getDateFrom(hrmUser.getUpdatedOn(), passwordComplexity.getExpiredPeriod(),
            CommonUtilConstant.DATE_FORMAT_MONTH);

    final SMSSend mSSend = new SMSSend();
    mSSend.setFrom(HRMConstant.SYSTEM_ADMIN);
    mSSend.setDestination(hrmUser.getPhoneNumber());
    mSSend.setContent("Dear " + hrmUser.getRealName() + " Password anda pada Aplikasi " + applicationName
            + " mendekati Kadaluwarsa. Password anda akan kadaluarsa pada tanggal "
            + dateFormat.format(expiredDate) + ". Segera ubah password anda segera, Terima Kasih.");

    jmsTemplateSMS.send(new MessageCreator() {
        @Override/*w w w.  j a v  a2 s  .  c  o  m*/
        public Message createMessage(Session session) throws JMSException {
            return session.createTextMessage(jsonConverter.getJson(mSSend));
        }
    });

}

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

@Override
@Transactional(readOnly = false, isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public void saveAndNotification(SmsGatewayUser user) throws Exception {
    String pass = user.getPassword();
    final PasswordHistory passwordHistory = new PasswordHistory();
    passwordHistory.setId(Long.parseLong(RandomNumberUtil.getRandomNumber(12)));
    passwordHistory.setPassword(/*from w w w. ja  va2s  .com*/
            AESUtil.getAESEncription(user.getPassword(), SMSGATEWAY.KEYVALUE, SMSGATEWAY.AES_ALGO));
    user.setCreatedBy(UserInfoUtil.getUserName());
    user.setPassword(HashingUtils.getHashSHA256(user.getPassword()));
    user.setCreatedOn(new Date());
    userDao.save(user);
    passwordHistory.setEmailNotification(SMSGATEWAY.EMAIL_NOTIFICATION_NOT_YET_SEND);
    passwordHistory.setSmsNotification(SMSGATEWAY.SMA_NOTIFICATION_NOT_SEND);
    passwordHistory.setEmailAddress(user.getEmailAddress());
    passwordHistory.setRequestType(SMSGATEWAY.USER_NEW);
    passwordHistory.setPhoneNumber(user.getPhoneNumber());
    passwordHistory.setRealName(user.getRealName());
    passwordHistory.setUserName(user.getUserId());
    passwordHistory.setLocalId(FacesUtil.getSessionAttribute(SMSGATEWAY.BAHASA_ACTIVE).toString());
    passwordHistory.setCreatedBy(UserInfoUtil.getUserName());
    passwordHistory.setCreatedOn(new Date());
    List<String> dataRole = new ArrayList<>();
    List<Role> roles = new ArrayList<>();

    for (UserRole userRole : userRoleDao.getByUserId(user.getId())) {
        roles.add(userRole.getRole());
    }

    for (Role role : roles) {
        dataRole.add(role.getRoleName());
    }

    passwordHistory.setListRole(jsonConverter.getJson(dataRole.toArray(new String[dataRole.size()])));

    this.passwordHistoryDao.save(passwordHistory);
    this.jmsTemplate.send(new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            return session.createTextMessage(jsonConverter.getJson(passwordHistory));
        }
    });
}