List of usage examples for javax.jms TextMessage getText
String getText() throws JMSException;
From source file:org.wso2.carbon.event.core.internal.delivery.jms.JMSMessageListener.java
public void onMessage(Message message) { try {/*from www . ja va2s.co m*/ PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(this.subscription.getTenantId()); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(this.subscription.getOwner()); PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true); if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; StAXOMBuilder stAXOMBuilder = new StAXOMBuilder( new ByteArrayInputStream(textMessage.getText().getBytes())); org.wso2.carbon.event.core.Message messageToSend = new org.wso2.carbon.event.core.Message(); messageToSend.setMessage(stAXOMBuilder.getDocumentElement()); // set the properties Enumeration propertyNames = message.getPropertyNames(); String key = null; while (propertyNames.hasMoreElements()) { key = (String) propertyNames.nextElement(); messageToSend.addProperty(key, message.getStringProperty(key)); } this.notificationManager.sendNotification(messageToSend, this.subscription); } else { log.warn("Non text message received"); } } catch (JMSException e) { log.error("Can not read the text message ", e); } catch (XMLStreamException e) { log.error("Can not build the xml string", e); } catch (EventBrokerException e) { log.error("Can not send the notification ", e); } finally { PrivilegedCarbonContext.endTenantFlow(); } }
From source file:org.globus.crux.messaging.utils.JAXBMessageConverter.java
/** * <p>/*from w w w . j ava 2 s .c o m*/ * Unmarshal given <code>message</code> into an <code>object</code>. * </p> * * <p> * Should we raise an exception if the XML message encoding is not in sync with the underlying TextMessage encoding when the JMS * Provider supports MOM message's encoding ? * </p> * * @param message * message to unmarshal, MUST be an instance of {@link TextMessage} or of {@link BytesMessage}. * @see org.springframework.jms.support.converter.MessageConverter#fromMessage(javax.jms.Message) */ public Object fromMessage(Message message) throws JMSException, MessageConversionException { Source source; if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; source = new StreamSource(new StringReader(textMessage.getText())); } else if (message instanceof BytesMessage) { BytesMessage bytesMessage = (BytesMessage) message; byte[] bytes = new byte[(int) bytesMessage.getBodyLength()]; bytesMessage.readBytes(bytes); source = new StreamSource(new ByteArrayInputStream(bytes)); } else { throw new MessageConversionException("Unsupported JMS Message type " + message.getClass() + ", expected instance of TextMessage or BytesMessage for " + message); } Object result; try { result = context.createUnmarshaller().unmarshal(source); } catch (JAXBException e) { throw new MessageConversionException("Error unmarshalling message", e); } return result; }
From source file:eu.europa.ec.fisheries.uvms.rules.service.bean.MDRCache.java
@SneakyThrows private List<ObjectRepresentation> mdrCodeListByAcronymType(MDRAcronymType acronym) { String request = MdrModuleMapper.createFluxMdrGetCodeListRequest(acronym.name()); String s = producer.sendDataSourceMessage(request, DataSourceQueue.MDR_EVENT); TextMessage message = consumer.getMessage(s, TextMessage.class); if (message != null) { MdrGetCodeListResponse response = unmarshallTextMessage(message.getText(), MdrGetCodeListResponse.class); return response.getDataSets(); }/*from w w w .j a va2s. co m*/ return new ArrayList<>(); }
From source file:org.hoteia.qalingo.core.jms.geoloc.listener.AddressGeolocQueueListener.java
/** * Implementation of <code>MessageListener</code>. *///from w w w .j a va 2s. c om public void onMessage(Message message) { try { if (message instanceof TextMessage) { TextMessage tm = (TextMessage) message; String valueJMSMessage = tm.getText(); if (StringUtils.isNotEmpty(valueJMSMessage)) { final AddressGeolocMessageJms documentMessageJms = xmlMapper.getXmlMapper() .readValue(valueJMSMessage, AddressGeolocMessageJms.class); String address = documentMessageJms.getAddress(); String postalCode = documentMessageJms.getPostalCode(); String city = documentMessageJms.getCity(); String countryCode = documentMessageJms.getCountryCode(); String formatedAddress = geolocService.encodeGoogleAddress(address, postalCode, city, countryCode); if ("Store".equals(documentMessageJms.getObjectType())) { final Store store = retailerService.getStoreById(documentMessageJms.getObjectId()); if (store != null && StringUtils.isEmpty(store.getLatitude())) { GeolocAddress geolocAddress = geolocService .getGeolocAddressByFormatedAddress(formatedAddress); if (geolocAddress != null && StringUtils.isNotEmpty(geolocAddress.getLatitude()) && StringUtils.isNotEmpty(geolocAddress.getLongitude())) { store.setLatitude(geolocAddress.getLatitude()); store.setLongitude(geolocAddress.getLongitude()); retailerService.saveOrUpdateStore(store); } else { // LATITUDE/LONGITUDE DOESN'T EXIST - WE USE GOOGLE GEOLOC TO FOUND IT geolocAddress = geolocService.geolocByAddress(address, postalCode, city, countryCode); if (geolocAddress != null && StringUtils.isNotEmpty(geolocAddress.getLatitude()) && StringUtils.isNotEmpty(geolocAddress.getLongitude())) { store.setLatitude(geolocAddress.getLatitude()); store.setLongitude(geolocAddress.getLongitude()); retailerService.saveOrUpdateStore(store); } } } } else if ("Retailer".equals(documentMessageJms.getObjectType())) { final Retailer retailer = retailerService.getRetailerById(documentMessageJms.getObjectId(), new FetchPlan(retailerFetchPlans)); RetailerAddress retailerAddress = retailer.getAddressByValue(address); if (retailer != null && retailerAddress != null && StringUtils.isEmpty(retailerAddress.getLatitude())) { GeolocAddress geolocAddress = geolocService .getGeolocAddressByFormatedAddress(formatedAddress); if (geolocAddress != null && StringUtils.isNotEmpty(geolocAddress.getLatitude()) && StringUtils.isNotEmpty(geolocAddress.getLongitude())) { retailerAddress.setLatitude(geolocAddress.getLatitude()); retailerAddress.setLongitude(geolocAddress.getLongitude()); retailerService.saveOrUpdateRetailer(retailer); } else { // LATITUDE/LONGITUDE DOESN'T EXIST - WE USE GOOGLE GEOLOC TO FOUND IT geolocAddress = geolocService.geolocByAddress(address, postalCode, city, countryCode); if (geolocAddress != null && StringUtils.isNotEmpty(geolocAddress.getLatitude()) && StringUtils.isNotEmpty(geolocAddress.getLongitude())) { retailerAddress.setLatitude(geolocAddress.getLatitude()); retailerAddress.setLongitude(geolocAddress.getLongitude()); retailerService.saveOrUpdateRetailer(retailer); } } } } 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.NotificationObserver.JMSNotificationListener.java
public void onMessage(Message msg) { // TODO Auto-generated method stub if (msg instanceof TextMessage) { // model.Message message = new model.Message(); // message.setMsgID(1); //// Pattern pattern = (Pattern) patternDAO.findByPatternName("pattern1"); // Pattern pattern = (Pattern) patternDAO.find(2); // message.setPatternId(pattern); TextMessage tMsg = (TextMessage) msg; try {//from w w w . ja va 2s.c o m // message.setContent(tMsg.getText()); de.fzi.ALERT.actor.Model.Message message = parser.parseJsoup(tMsg.getText()); if (message == null) { System.out.println("message is null!!!!"); return; } // messageDAO.create(message); if (!message.getContent().equals("ERROR!") && !message.getContent().equals("")) { manager.saveMessage(message); // manager.sendAnnouncement(message); } else { System.out.println("message doesn't have content and will be discarded!"); } } catch (JMSException e) { System.out.println("ERROR in paring complex event: " + e.getMessage()); } } }
From source file:de.fzi.ALERT.actor.MessageObserver.ComplexEventObserver.JMSMessageListener.java
public void onMessage(Message msg) { // TODO Auto-generated method stub if (msg instanceof TextMessage) { // model.Message message = new model.Message(); // message.setMsgID(1); //// Pattern pattern = (Pattern) patternDAO.findByPatternName("pattern1"); // Pattern pattern = (Pattern) patternDAO.find(2); // message.setPatternId(pattern); TextMessage tMsg = (TextMessage) msg; try {/*from www . j av a 2 s .c om*/ // message.setContent(tMsg.getText()); de.fzi.ALERT.actor.Model.Message message = parser.parseJsoup(tMsg.getText()); if (message == null) return; // messageDAO.create(message); if (!message.getContent().equals("ERROR!") && !message.getContent().equals("")) { manager.saveMessage(message); manager.sendAnnouncement(message); } else { System.out.println("message doesn't have content and will be discarded!"); } } catch (JMSException e) { System.out.println("ERROR in paring complex event: " + e.getMessage()); } } }
From source file:com.inkubator.sms.gateway.service.impl.NotificationUserMessagesListener.java
@Override @Transactional(readOnly = false, propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, timeout = 50, rollbackFor = Exception.class) public void onMessage(Message message) { try {/*from www. j a va2s .com*/ TextMessage textMessage = (TextMessage) message; String json = textMessage.getText(); PasswordHistory passwordHistory = (PasswordHistory) jsonConverter.getClassFromJson(json, PasswordHistory.class); passwordHistory.setPassword(AESUtil.getAESDescription(passwordHistory.getPassword(), SMSGATEWAY.KEYVALUE, SMSGATEWAY.AES_ALGO)); if (Objects.equals(passwordHistory.getEmailNotification(), SMSGATEWAY.EMAIL_NOTIFICATION_NOT_YET_SEND)) { VelocityTempalteModel vtm = new VelocityTempalteModel(); List<String> toSend = new ArrayList<>(); List<String> toSentCC = new ArrayList<String>(); vtm.setFrom(ownerEmail); toSend.add(passwordHistory.getEmailAddress()); vtm.setTo(toSend.toArray(new String[toSend.size()])); vtm.setCc(toSentCC.toArray(new String[toSentCC.size()])); vtm.setBcc(toSentCC.toArray(new String[toSentCC.size()])); vtm.setSubject("User Notification"); Map maptoSend = new HashMap(); if (passwordHistory.getLocalId().equals("en")) { vtm.setTemplatePath("email_user_confirmation_en.vm"); // if (passwordHistory.getRequestType().equalsIgnoreCase(SMSGATEWAY.USER_UPDATE)) { // maptoSend.put("headerInfo", "Your password in OPTIMA HR has been updated. <br/>"); // } if (passwordHistory.getRequestType().equalsIgnoreCase(SMSGATEWAY.USER_NEW)) { maptoSend.put("headerInfo", "Your account in OPTIMA HR already created.<br/>"); } if (passwordHistory.getRequestType().equalsIgnoreCase(SMSGATEWAY.USER_RESET)) { maptoSend.put("headerInfo", "Your Password in OPTIMA HR has been reset. <br/>"); } } System.out.println(" suksesss"); if (passwordHistory.getLocalId().equals("in")) { vtm.setTemplatePath("email_user_confirmation.vm"); // if (passwordHistory.getRequestType().equalsIgnoreCase(SMSGATEWAY.USER_UPDATE)) { // maptoSend.put("headerInfo", "Password Anda pada Aplikasi OPTIMA HR berhasil diubah. <br/>"); // } if (passwordHistory.getRequestType().equalsIgnoreCase(SMSGATEWAY.USER_NEW)) { maptoSend.put("headerInfo", "Anda telah terdaftar di Aplikasi OPTIMA HR <br/>"); } if (passwordHistory.getRequestType().equalsIgnoreCase(SMSGATEWAY.USER_RESET)) { maptoSend.put("headerInfo", "Password Anda pada Aplikasi OPTIMA HR berhasil direset. <br/>"); } } Gson gson = new GsonBuilder().create(); TypeToken<List<String>> token = new TypeToken<List<String>>() { }; List<String> dataRole = gson.fromJson(passwordHistory.getListRole(), token.getType()); maptoSend.put("role", dataRole); maptoSend.put("user", passwordHistory); maptoSend.put("ownerAdministrator", ownerAdministrator); maptoSend.put("ownerCompany", ownerCompany); maptoSend.put("applicationUrl", applicationUrl); maptoSend.put("applicationName", applicationName); try { velocityTemplateSender.sendMail(vtm, maptoSend); } catch (Exception ex) { LOGGER.error("Error", ex); } passwordHistory.setEmailNotification(1); passwordHistory.setPassword(HashingUtils.getHashSHA256(passwordHistory.getPassword())); this.passwordHistoryDao.update(passwordHistory); System.out.println(" suksesss"); } } catch (Exception ex) { LOGGER.error("Error", ex); } }
From source file:hermes.renderers.fix.FIXMessageRenderer.java
protected JComponent handleTextMessage(final TextMessage textMessage) throws JMSException { String text = textMessage.getText(); return createComponent(new QuickFIXMessage(cache, text.getBytes())); }
From source file:org.openbaton.common.vnfm_sdk.amqp.VnfmSpringHelper.java
/** * This method should be used for receiving text message from EMS * * resp = { 'output': out, // the output of the command 'err': err, // the error outputs of the * commands 'status': status // the exit status of the command } * * @param queueName//from w ww .j ava 2 s .c o m * @return * @throws JMSException */ public String receiveTextFromQueue(String queueName) throws JMSException, ExecutionException, InterruptedException, VnfmSdkException { String res; Connection connection = connectionFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createConsumer(session.createQueue(queueName)); connection.start(); String scriptMaxTime = properties.getProperty("script-max-time"); if (scriptMaxTime != null) { TextMessage textMessage = (TextMessage) consumer.receive(Long.parseLong(scriptMaxTime)); if (textMessage != null) res = textMessage.getText(); else throw new VnfmSdkException("No message got from queue " + queueName + " after " + scriptMaxTime); } else res = ((TextMessage) consumer.receive()).getText(); log.debug("Received Text from " + queueName + ": " + res); consumer.close(); session.close(); connection.close(); return res; }
From source file:org.apache.stratos.cloud.controller.topic.instance.status.InstanceStatusEventMessageListener.java
@Override public void onMessage(Message message) { TextMessage receivedMessage = (TextMessage) message; InstanceStatusEventMessageQueue.getInstance().add(receivedMessage); if (log.isDebugEnabled()) { try {//from w ww. j av a 2 s .com log.debug(String.format("Instance status message added to queue: %s", receivedMessage.getText())); } catch (JMSException e) { log.error(e); } } }