List of usage examples for javax.jms MapMessage getString
String getString(String name) throws JMSException;
From source file:org.openmrs.module.atomfeed.GeneralEventListener.java
@Override public void onMessage(Message msgParam) { Context.openSession();/*from w ww. j a v a 2s . c om*/ String username = Context.getAdministrationService() .getGlobalProperty(AtomFeedConstants.GP_MESSAGE_USERNAME, ""); String password = Context.getAdministrationService() .getGlobalProperty(AtomFeedConstants.GP_MESSAGE_PASSWORD, ""); if (!username.isEmpty()) Context.authenticate(username, password); MapMessage msg = (MapMessage) msgParam; String action; String uuid; String classname; try { action = msg.getString("action"); classname = msg.getString("classname"); uuid = msg.getString("uuid"); } catch (JMSException e) { log.error("unable to get strings off of the MapMessage", e); // fail hard here return; } log.error("action: " + action + " object : " + classname + " uuid: " + uuid); AtomFeedService atomFeedService = Context.getService(AtomFeedService.class); DataPoint dp = new DataPoint(); /* * intentionally separating the methods here so that AtomFeedUtil * doesn't have a dependency on Event.Action */ if (action.equals(Event.Action.CREATED.name())) { dp.setAction("CREATED"); } else if (action.equals(Event.Action.UPDATED.name())) { dp.setAction("UPDATED"); } else if (action.equals(Event.Action.VOIDED.name())) { dp.setAction("VOIDED"); } else if (action.equals(Event.Action.PURGED.name())) { dp.setAction("PURGED"); } dp.setObjectClass(classname); dp.setDateCreated(new Date()); dp.setUuid(uuid); atomFeedService.saveDataPoint(dp); Context.closeSession(); }
From source file:org.openmrs.module.deriveddata.api.event.DerivedDataEventListener.java
@Override public void onMessage(final Message message) { // TODO: this need to be changed. See ticket: TRUNK-3781 // on newer version of OpenMRS (1.9): // - set the activator to become DaemonTokenAware and set the module token // - we can then handle this message inside Daemon.runInDaemonThread Context.openSession();//from w ww. j av a 2s.c om Context.addProxyPrivilege(PrivilegeConstants.VIEW_OBS); Context.addProxyPrivilege(PrivilegeConstants.VIEW_ENCOUNTERS); try { MapMessage mapMessage = (MapMessage) message; String uuid = mapMessage.getString("uuid"); String classname = mapMessage.getString("classname"); String actionString = mapMessage.getString("action"); Event.Action action = Event.Action.valueOf(actionString); if (StringUtils.equals(classname, ENCOUNTER_CLASS_NAME)) handleEncounter(uuid, action); else if (StringUtils.equals(classname, OBS_CLASS_NAME)) handleObservation(uuid, action); else log.error("This will be a bug in event module. We're only interested with two classes!"); } catch (JMSException e) { log.error("Reading JMS message failed!", e); } finally { Context.removeProxyPrivilege(PrivilegeConstants.VIEW_OBS); Context.removeProxyPrivilege(PrivilegeConstants.VIEW_ENCOUNTERS); Context.clearSession(); Context.closeSession(); } }
From source file:org.openmrs.module.emrapi.event.PatientViewedEventListener.java
/** * Processes the specified jms message/* ww w.j a v a 2 s . c o m*/ * * @should add the patient to the last viewed user property * @should remove the first patient and add the new one to the start if the list is full * @should not add a duplicate and should move the existing patient to the start * @should not remove any patient if a duplicate is added to a full list */ public void processMessage(Message message) throws Exception { MapMessage mapMessage = (MapMessage) message; String patientUuid = mapMessage.getString(EmrApiConstants.EVENT_KEY_PATIENT_UUID); String userUuid = mapMessage.getString(EmrApiConstants.EVENT_KEY_USER_UUID); Patient patientToAdd = Context.getPatientService().getPatientByUuid(patientUuid); if (patientToAdd == null || patientToAdd.getId() == null) { throw new APIException( "failed to find a patient with uuid:" + patientUuid + " or the patient is not yet saved"); } UserService userService = Context.getUserService(); User user = userService.getUserByUuid(userUuid); if (user != null && patientToAdd != null) { EmrApiProperties emrProperties = Context.getRegisteredComponents(EmrApiProperties.class).iterator() .next(); Integer limit = emrProperties.getLastViewedPatientSizeLimit(); List<Integer> patientIds = new ArrayList<Integer>(limit); if (limit > 0) { List<Patient> lastViewedPatients = GeneralUtils.getLastViewedPatients(user); patientIds.add(patientToAdd.getId()); for (Patient p : lastViewedPatients) { if (patientIds.size() == limit) break; if (patientIds.contains(p.getId())) continue; patientIds.add(p.getId()); } Collections.reverse(patientIds); } String property = StringUtils.join(patientIds, ","); if (StringUtils.isNotBlank(property) && property.length() > 255) { //exceeded the user property max size and hence needs trimming. //find the last comma before index 255 and cut off from there //RA-200 Wyclif says patients ids at the end of the string are the most recent //so that is why we trim from begining instead of end. property = property.substring(property.indexOf(',', property.length() - 255) + 1); } userService.setUserProperty(user, EmrApiConstants.USER_PROPERTY_NAME_LAST_VIEWED_PATIENT_IDS, property); } }
From source file:org.smartfrog.avalanche.shared.jms.MessageListener.java
public MonitoringEvent receive() throws Exception { MonitoringEvent event = null;/* w w w.java2 s. c om*/ // TODO : no need to open a new session every time .. fix it QueueSession qs = null; QueueReceiver qr = null; try { qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); qr = qs.createReceiver(queue); // TODO : Fix message timeout log.info("MonitoringEvent.receive() : Checking for new message on Queue"); MapMessage mm = (MapMessage) qr.receive(jmsTimeout); if (mm != null) { log.info("Message received"); event = new MonitoringEventDefaultImpl(); event.setHost(mm.getString(MonitoringEvent.HOST)); event.setInstanceName(mm.getString(MonitoringEvent.INSTANCE_NAME)); event.setModuleId(mm.getString(MonitoringEvent.MODULEID)); event.setModuleState(mm.getString(MonitoringEvent.MODULE_STATE)); event.setMsg(mm.getString(MonitoringEvent.MODULE_STATE)); event.setMessageType(mm.getInt(MonitoringEvent.MESSAGE_TYPE)); log.info("MessageListener.receive() - " + event); } else { log.info("No message found in queue"); } return event; } finally { qr.close(); qs.close(); } }
From source file:org.toobsframework.jms.email.JmsEmailReceiver.java
public EmailBean recieveMessage() throws JmsEmailException { Message msg = jmsTemplate.receive(); if (msg == null) { return null; }/*from w w w. j av a 2s . com*/ EmailBean bean = new EmailBean(); MapMessage mapMessage = (MapMessage) msg; try { bean.setEmailSender(mapMessage.getString("sender")); bean.setEmailSubject(mapMessage.getString("subject")); bean.setRecipients(getRecipientList(mapMessage.getString("recipients"))); bean.setMessageHtml(mapMessage.getString("messageHtml")); bean.setMessageText(mapMessage.getString("messageText")); bean.setMailSenderKey(mapMessage.getString("mailSenderKey")); bean.setAttempts(mapMessage.getInt("attempts")); bean.setType(mapMessage.getInt("type")); bean.setFailureCause(mapMessage.getString("failureCause")); } catch (JMSException e) { log.error("Exception getting email from queue: " + e.getMessage(), e); throw new JmsEmailException(e); } return bean; }
From source file:org.wso2.carbon.appfactory.resource.mgt.listeners.TenantCreationMessageListener.java
/** * @param message - map message which contains data to tenant creation via a rest call. *//*from w w w.j a va 2 s . c om*/ @Override public void onMessage(Message message) { TenantInfoBean tenantInfoBean = null; MapMessage mapMessage; if (message instanceof MapMessage) { mapMessage = (MapMessage) message; String tenantInfoJson; try { tenantInfoJson = mapMessage.getString(AppFactoryConstants.TENANT_INFO); ObjectMapper mapper = new ObjectMapper(); tenantInfoBean = mapper.readValue(tenantInfoJson, TenantInfoBean.class); if (log.isDebugEnabled()) { log.debug("Received a message for tenant domain " + tenantInfoBean.getTenantDomain()); } mapMessage.acknowledge(); } catch (JMSException e) { log.error("Error while getting message content.", e); throw new RuntimeException(e); } catch (JsonParseException e) { log.error("Error while converting the json to object.", e); throw new RuntimeException(e); } catch (JsonMappingException e) { log.error("Error while converting the json to object.", e); throw new RuntimeException(e); } catch (IOException e) { log.error("Error while converting the json to object.", e); throw new RuntimeException(e); } } try { int tenantId = ServiceHolder.getRealmService().getTenantManager() .getTenantId(tenantInfoBean.getTenantDomain()); if (tenantId == MultitenantConstants.INVALID_TENANT_ID) { addTenant(tenantInfoBean); } else { if (log.isDebugEnabled()) { log.debug("Tenant Already exist, skipping the tenant addition. Tenant domain : " + tenantInfoBean.getTenantDomain() + "and tenant Id : " + tenantInfoBean.getTenantId()); } } } catch (JMSException e) { String msg = "Can not read received map massage"; log.error(msg, e); throw new RuntimeException(e); } catch (AppFactoryException e) { String msg = "Can not create tenant"; log.error(msg, e); throw new RuntimeException(e); } catch (Exception e) { String msg = "Can not create tenant"; log.error(msg, e); throw new RuntimeException(e); } }
From source file:org.wso2.carbon.appfactory.stratos.listeners.StratosSubscriptionMessageListener.java
/** * @param message - map message which contains data to stratos subscriptions via a rest call. *//*from w ww. j a va2 s . co m*/ @Override public void onMessage(Message message) { RuntimeBean[] runtimeBeans; TenantInfoBean tenantInfoBean; MapMessage mapMessage; if (message instanceof MapMessage) { mapMessage = (MapMessage) message; String tenantInfoJson = null; try { String runtimesJson = mapMessage.getString(AppFactoryConstants.RUNTIMES_INFO); tenantInfoJson = mapMessage.getString(AppFactoryConstants.TENANT_INFO); ObjectMapper mapper = new ObjectMapper(); runtimeBeans = mapper.readValue(runtimesJson, RuntimeBean[].class); tenantInfoBean = mapper.readValue(tenantInfoJson, TenantInfoBean.class); if (log.isDebugEnabled()) { log.debug("Received a message for tenant domain " + tenantInfoBean.getTenantDomain()); } String stage = mapMessage.getString(AppFactoryConstants.STAGE); if (!TenantManager.getInstance().tenantExists(tenantInfoBean.getTenantId())) { addTenant(tenantInfoBean); } else { if (log.isDebugEnabled()) { log.debug("Tenant Already added in stratos, skipping the tenant addition and continuing " + "with subscription to cartridges. Tenant domain : " + tenantInfoBean.getTenantDomain() + "and tenant Id : " + tenantInfoBean.getTenantId()); } } try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext() .setTenantDomain(tenantInfoBean.getTenantDomain(), true); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(tenantInfoBean.getAdmin()); for (RuntimeBean runtimeBean : runtimeBeans) { RepositoryBean repositoryBean = createGitRepository(runtimeBean, tenantInfoBean, stage); subscribe(runtimeBean, tenantInfoBean, repositoryBean, getConfigContext(), stage); } if (log.isDebugEnabled()) { log.debug("Tenant added and subscribed to cartridges successfully for tenant : " + tenantInfoBean.getTenantDomain()); } } finally { PrivilegedCarbonContext.endTenantFlow(); } mapMessage.acknowledge(); if (log.isDebugEnabled()) { log.debug("Message processed successfully. Acknowledged to MB for tenant : " + tenantInfoBean.getTenantDomain()); } } catch (AppFactoryException e) { log.error( "Error while subscribing tenant to stratos cartridge. tenantInfoJason : " + tenantInfoJson); } catch (JsonMappingException e) { log.error( "Error while subscribing tenant to stratos cartridge. tenantInfoJason : " + tenantInfoJson); } catch (JsonParseException e) { log.error( "Error while subscribing tenant to stratos cartridge. tenantInfoJason : " + tenantInfoJson); } catch (IOException e) { log.error( "Error while subscribing tenant to stratos cartridge. tenantInfoJason : " + tenantInfoJson); } catch (JMSException e) { log.error( "Error while subscribing tenant to stratos cartridge. tenantInfoJason : " + tenantInfoJson); } catch (Exception e) { log.error( "Error while subscribing tenant to stratos cartridge. tenantInfoJason : " + tenantInfoJson); } } else { log.error("Message received is not a Map Message"); } }
From source file:org.wso2.carbon.appfactory.stratos.listeners.TenantStratosSubscriptionMessageListener.java
/** * @param message - map message which contains data to stratos subscriptions via a rest call. *///w w w. j a va2 s. co m @Override public void onMessage(Message message) { //TODO remove this log log.info("message received to topic name : " + topicSubscriber.toString() + ">>>>>>>>>>>>"); RuntimeBean[] runtimeBeans = null; TenantInfoBean tenantInfoBean = null; if (message instanceof MapMessage) { try { String runtimesJson = ((MapMessage) message).getString(AppFactoryConstants.RUNTIMES_INFO); String tenantInfoJson = ((MapMessage) message).getString(AppFactoryConstants.TENANT_INFO); ObjectMapper mapper = new ObjectMapper(); runtimeBeans = mapper.readValue(runtimesJson, RuntimeBean[].class); tenantInfoBean = mapper.readValue(tenantInfoJson, TenantInfoBean.class); if (log.isDebugEnabled()) { log.debug("Received a message for tenant domain " + tenantInfoBean.getTenantDomain()); } } catch (JMSException e) { log.error("Error while getting message content.", e); throw new RuntimeException(e); } catch (JsonParseException e) { log.error("Error while converting the json to object.", e); throw new RuntimeException(e); } catch (JsonMappingException e) { log.error("Error while converting the json to object.", e); throw new RuntimeException(e); } catch (IOException e) { log.error("Error while converting the json to object.", e); throw new RuntimeException(e); } } MapMessage mapMessage; if (message instanceof MapMessage) { mapMessage = (MapMessage) message; try { currentMsgCount++; // //String serverURL = mapMessage.getString(SERVER_URL_FOR_REST); // String tenantAdmin = mapMessage.getString(AppFactoryConstants.TENANT_ADMIN_FOR_REST); // //String tenantAdminPassword = mapMessage.getString(TENANT_ADMIN_PASSWORD_FOR_REST); // String tenantDomain = mapMessage.getString(AppFactoryConstants.TENANT_DOMAIN); // String stage = mapMessage.getString(AppFactoryConstants.STAGE); // String username = tenantAdmin + UserCoreConstants.TENANT_DOMAIN_COMBINER + tenantDomain; // String appendStageToCartridgeInfo = AppFactoryUtil.getAppfactoryConfiguration(). // getFirstProperty(AppFactoryConstants.APPEND_STAGE_TO_CARTRIDGE_INFO); String stage = mapMessage.getString(AppFactoryConstants.STAGE); addTenant(tenantInfoBean); for (RuntimeBean runtimeBean : runtimeBeans) { RepositoryBean repositoryBean = createGitRepository(runtimeBean, tenantInfoBean, stage); try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext() .setTenantDomain(tenantInfoBean.getTenantDomain(), true); PrivilegedCarbonContext.getThreadLocalCarbonContext() .setUsername(tenantInfoBean.getAdmin()); subscribe(runtimeBean, tenantInfoBean, repositoryBean, getConfigContext(), stage); } finally { PrivilegedCarbonContext.endTenantFlow(); } } // restService = new StratosRestService(serverURL, username, tenantAdminPassword); // restService.subscribe(cartridgeType, // subscriptionAlias, // mapMessage.getString(REPO_URL), true, // mapMessage.getString(AppFactoryConstants // .PAAS_ARTIFACT_STORAGE_REPOSITORY_PROVIDER_ADMIN_USER_NAME), // mapMessage.getString(AppFactoryConstants // .PAAS_ARTIFACT_STORAGE_REPOSITORY_PROVIDER_ADMIN_PASSWORD), // mapMessage.getString(DATA_CARTRIDGE_TYPE), // mapMessage.getString(DATA_CARTRIDGE_ALIAS), // mapMessage.getString(AUTO_SCALE_POLICY), // mapMessage.getString(DEPLOYMENT_POLICY)); // TODO remove this log log.info("subscription done in environment : " + mapMessage.getString(AppFactoryConstants.STAGE) + "of tenant :" + tenantInfoBean.getTenantDomain()); mapMessage.acknowledge(); } catch (JMSException e) { String msg = "Can not read received map massage at count " + currentMsgCount; log.error(msg, e); throw new RuntimeException(e); } catch (AppFactoryException e) { String msg = "Can not subscribe to stratos cartridge"; log.error(msg, e); throw new RuntimeException(e); } catch (Exception e) { String msg = "Can not subscribe to stratos cartridge"; log.error(msg, e); throw new RuntimeException(e); } } }
From source file:org.wso2.carbon.inbound.endpoint.protocol.jms.JMSInjectHandler.java
/** * // w w w .j a v a 2 s.c om * @param message * JMSMap message * @return XML representation of JMS Map message */ public static OMElement convertJMSMapToXML(MapMessage message) { OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace jmsMapNS = OMAbstractFactory.getOMFactory().createOMNamespace(JMSConstants.JMS_MAP_NS, ""); OMElement jmsMap = fac.createOMElement(JMSConstants.JMS_MAP_ELEMENT_NAME, jmsMapNS); try { Enumeration names = message.getMapNames(); while (names.hasMoreElements()) { String nextName = names.nextElement().toString(); String nextVal = message.getString(nextName); OMElement next = fac.createOMElement(nextName.replace(" ", ""), jmsMapNS); next.setText(nextVal); jmsMap.addChild(next); } } catch (JMSException e) { log.error("Error while processing the JMS Map Message. " + e.getMessage()); } return jmsMap; }