List of usage examples for javax.jms Session createMapMessage
MapMessage createMapMessage() throws JMSException;
From source file:org.atmars.service.impls.Jmail.java
public String sendEmail(String email, String nickname, Date date) throws UnsupportedEncodingException { String plain = email + nickname + date.getTime(); BasicPasswordEncryptor passwordEncryptor = new BasicPasswordEncryptor(); String encrypted = passwordEncryptor.encryptPassword(plain); String urlEncodedString = java.net.URLEncoder.encode(encrypted, "UTF-8"); final String to = email; final String subject = "AtMars Microblog New User Register Comfirmation Email"; final String content = "<div style='width:713px; background-color:#A1E0E9; padding-top:30px; padding-bottom:30px; margin: 0 auto;'><img src='" + serverURL + logo_img + "' width='160' /><img src='" + serverURL + poster_img + "' width='100%' /><div style='background-color:#FFFFFF; border-radius:3px; box-shadow:0 1px 3px rgba(0,0,0,0.25); border:1px solid #CCC; padding:20px 20px 20px 20px; margin-left:30px; margin-right:30px; margin-top:30px;'><p><b>Welcome to AtMars MicroBlog</b></p><p>Thank you for registering AtMars MicroBlog.</p><p>To comfirm the email address you provided during registration. please click the following link in 24 hours:</p><p><a href='" + serverURL + "checkEmail?email=" + email + "&ticket=" + urlEncodedString + "'>" + serverURL + "checkEmail?email=" + email + "&ticket=" + urlEncodedString + "</a></p><p>If this link does not work, copy and paste the link into your browser.</p></div></div>"; jmsTemplate.send(destination, new MessageCreator() { @Override/*from w w w. j a v a2 s .c o m*/ public Message createMessage(Session session) throws JMSException { MapMessage message = session.createMapMessage(); message.setString("To", to); message.setString("Subject", subject); message.setString("Content", content); return message; } }); return encrypted; }
From source file:org.toobsframework.jms.email.JmsEmailSender.java
public void sendMessage(final EmailBean emailBean) { jmsTemplate.send(new MessageCreator() { public Message createMessage(Session session) throws JMSException { MapMessage mapMessage = null; try { mapMessage = session.createMapMessage(); mapMessage.setString("sender", emailBean.getEmailSender()); mapMessage.setString("subject", emailBean.getEmailSubject()); mapMessage.setString("recipients", getRecipientList(emailBean.getRecipients())); mapMessage.setString("messageText", emailBean.getMessageText()); mapMessage.setString("messageHtml", emailBean.getMessageHtml()); mapMessage.setString("mailSenderKey", emailBean.getMailSenderKey()); mapMessage.setInt("attempts", emailBean.getAttempts()); mapMessage.setInt("type", emailBean.getType()); mapMessage.setString("failureCause", emailBean.getFailureCause()); } catch (Exception e) { log.error("JMS Mail exception " + e.getMessage(), e); throw new JMSException(e.getMessage()); }/*from w ww.ja v a 2s.com*/ return mapMessage; } }); }
From source file:org.atmars.service.impls.Jmail.java
public boolean checkLink(String email, String nickname, Date date, String encrypted) throws UnsupportedEncodingException { String plain = email + nickname + date.getTime(); BasicPasswordEncryptor passwordEncryptor = new BasicPasswordEncryptor(); if (!passwordEncryptor.checkPassword(plain, encrypted)) { return false; }// ww w . ja va2 s . c om Date now = new Date(); if (now.getTime() - now.getTime() > 86400000) { return false; } final String subject = "Your New Account in AtMars Microblog has been Activated"; final String content = "<div style='width:713px; background-color:#A1E0E9; padding-top:30px; padding-bottom:30px; margin: 0 auto;'><img src='" + serverURL + logo_img + "' width='160' /><img src='" + serverURL + poster_img + "' width='100%' /><div style='background-color:#FFFFFF; border-radius:3px; box-shadow:0 1px 3px rgba(0,0,0,0.25); border:1px solid #CCC; padding:20px 20px 20px 20px; margin-left:30px; margin-right:30px; margin-top:30px;'><p><b>Welcome to AtMars MicroBlog</b></p><p>Congratulations to you! Your email account " + email + " is activated. Thank you for registering AtMars MicroBlog.</p><p>Try to use AtMars to follow your friends:</p><p> <a href='" + serverURL + "'>" + serverURL + "</a></p><p>We are glad to meet you in AtMars MicroBlog.</p></div></div>"; final String to = email; jmsTemplate.send(destination, new MessageCreator() { @Override public Message createMessage(Session session) throws JMSException { MapMessage message = session.createMapMessage(); message.setString("To", to); message.setString("Subject", subject); message.setString("Content", content); return message; } }); return true; }
From source file:com.espertech.esperio.jms.JMSDefaultMapMessageMarshaller.java
public Message marshal(EventBean eventBean, Session session, long timestamp) throws EPException { EventType eventType = eventBean.getEventType(); MapMessage mapMessage = null;//from w ww. j a v a 2 s. co m try { mapMessage = session.createMapMessage(); String[] properties = eventType.getPropertyNames(); for (String property : properties) { if ((ExecutionPathDebugLog.isDebugEnabled) && (log.isDebugEnabled())) { log.debug( ".Marshal EventProperty property==" + property + ", value=" + eventBean.get(property)); } Class clazz = eventType.getPropertyType(property); if (JavaClassHelper.isNumeric(clazz)) { Class boxedClazz = JavaClassHelper.getBoxedType(clazz); if (boxedClazz == Double.class) { mapMessage.setDouble(property, (Double) eventBean.get(property)); } if (boxedClazz == Float.class) { mapMessage.setFloat(property, (Float) eventBean.get(property)); } if (boxedClazz == Byte.class) { mapMessage.setFloat(property, (Byte) eventBean.get(property)); } if (boxedClazz == Short.class) { mapMessage.setShort(property, (Short) eventBean.get(property)); } if (boxedClazz == Integer.class) { mapMessage.setInt(property, (Integer) eventBean.get(property)); } if (boxedClazz == Long.class) { mapMessage.setLong(property, (Long) eventBean.get(property)); } } else if ((clazz == boolean.class) || (clazz == Boolean.class)) { mapMessage.setBoolean(property, (Boolean) eventBean.get(property)); } else if ((clazz == Character.class) || (clazz == char.class)) { mapMessage.setChar(property, (Character) eventBean.get(property)); } else if (clazz == String.class) { mapMessage.setString(property, (String) eventBean.get(property)); } else { mapMessage.setObject(property, eventBean.get(property)); } } mapMessage.setJMSTimestamp(timestamp); } catch (JMSException ex) { throw new EPException(ex); } return mapMessage; }
From source file:eu.domibus.submission.jms.BackendJMSImpl.java
/** * This method is called when a message was received at the incoming queue * * @param message The incoming JMS Message *//*from ww w . jav a 2 s. co m*/ @Override public void onMessage(final Message message) { final MapMessage map = (MapMessage) message; try { final Connection con = this.cf.createConnection(); final Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); final MapMessage res = session.createMapMessage(); try { final String messageID = this.submit(map); res.setStringProperty("messageId", messageID); } catch (final TransformationException | ValidationException e) { BackendJMSImpl.LOG.error("Exception occurred: ", e); res.setString("ErrorMessage", e.getMessage()); } res.setJMSCorrelationID(map.getJMSCorrelationID()); final MessageProducer sender = session.createProducer(this.outQueue); sender.setDeliveryMode(DeliveryMode.NON_PERSISTENT); sender.send(res); sender.close(); session.close(); con.close(); } catch (final JMSException ex) { BackendJMSImpl.LOG.error("Error while sending response to queue", ex); } }
From source file:eu.domibus.submission.jms.BackendJMSImpl.java
private Boolean submitToBackend(final String messageId) { Connection connection;//from w w w . j a v a2 s . co m MessageProducer producer; try { connection = this.cf.createConnection(); final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); producer = session.createProducer(this.receivingQueue); producer.setDeliveryMode(DeliveryMode.PERSISTENT); final MapMessage resMessage = session.createMapMessage(); this.downloadMessage(messageId, resMessage); producer.send(resMessage); producer.close(); session.close(); connection.close(); } catch (JMSException | ValidationException e) { BackendJMSImpl.LOG.error("", e); return false; } return true; }
From source file:eu.domibus.submission.jms.BackendJMSImpl.java
private Boolean submitErrorMessage(String messageId) { Connection connection;//ww w .j av a 2s . co m MessageProducer producer; List<ErrorLogEntry> errors = this.errorLogDao.getUnnotifiedErrorsForMessage(messageId); try { connection = this.cf.createConnection(); final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); producer = session.createProducer(this.receivingQueue); producer.setDeliveryMode(DeliveryMode.PERSISTENT); final MapMessage resMessage = session.createMapMessage(); for (int i = 0; i < errors.size(); ++i) { resMessage.setString(String.valueOf(i), errors.get(i).toString()); errors.get(i).setNotified(new Date()); this.errorLogDao.update(errors.get(i)); } producer.send(resMessage); producer.close(); session.close(); connection.close(); } catch (JMSException e) { BackendJMSImpl.LOG.error("", e); return false; } return true; }
From source file:eu.domibus.submission.jms.BackendJMSImpl.java
/** * This method checks for pending messages received by another gateway and processes them to a JMS destination * * @param ctx/*from w ww.j a v a 2 s .c om*/ */ public void executeInternal(final JobExecutionContext ctx) { try { final Collection<String> ids = this.messageRetriever.listPendingMessages(); if (!ids.isEmpty() || ids.size() > 0) { final String[] messageIds = ids.toArray(new String[ids.size()]); Connection connection; MessageProducer producer; connection = this.cf.createConnection(); for (final String messageId : messageIds) { final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); producer = session.createProducer(this.receivingQueue); producer.setDeliveryMode(DeliveryMode.PERSISTENT); final MapMessage resMessage = session.createMapMessage(); this.downloadMessage(messageId, resMessage); producer.send(resMessage); producer.close(); session.close(); } connection.close(); } else { BackendJMSImpl.LOG.debug("No pending messages to send"); } } catch (final JMSException | ValidationException ex) { BackendJMSImpl.LOG.error(ex); } }
From source file:org.openmrs.event.EventEngine.java
/** * @param dest/*from w ww.jav a 2 s . c o m*/ * @param eventMessage */ private void doFireEvent(final Destination dest, final EventMessage eventMessage) { initializeIfNeeded(); jmsTemplate.send(dest, new MessageCreator() { @Override public Message createMessage(Session session) throws JMSException { if (log.isInfoEnabled()) log.info("Sending data " + eventMessage); MapMessage mapMessage = session.createMapMessage(); if (eventMessage != null) { for (Map.Entry<String, Serializable> entry : eventMessage.entrySet()) { mapMessage.setObject(entry.getKey(), entry.getValue()); } } return mapMessage; } }); }
From source file:Retailer.java
public void run() { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, password, url); try {/* ww w.ja v a 2 s. com*/ Connection connection = connectionFactory.createConnection(); // The Retailer's session is non-trasacted. Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination vendorOrderQueue = session.createQueue("VendorOrderQueue"); TemporaryQueue retailerConfirmQueue = session.createTemporaryQueue(); MessageProducer producer = session.createProducer(vendorOrderQueue); MessageConsumer replyConsumer = session.createConsumer(retailerConfirmQueue); connection.start(); for (int i = 0; i < 5; i++) { MapMessage message = session.createMapMessage(); message.setString("Item", "Computer(s)"); int quantity = (int) (Math.random() * 4) + 1; message.setInt("Quantity", quantity); message.setJMSReplyTo(retailerConfirmQueue); producer.send(message); System.out.println("Retailer: Ordered " + quantity + " computers."); MapMessage reply = (MapMessage) replyConsumer.receive(); if (reply.getBoolean("OrderAccepted")) { System.out.println("Retailer: Order Filled"); } else { System.out.println("Retailer: Order Not Filled"); } } // Send a non-MapMessage to signal the end producer.send(session.createMessage()); replyConsumer.close(); connection.close(); } catch (JMSException e) { e.printStackTrace(); } }