List of usage examples for javax.jms TextMessage getStringProperty
String getStringProperty(String name) throws JMSException;
From source file:com.solveapuzzle.mapping.agnostic.JmsMessageListener.java
/** * Implementation of <code>MessageListener</code>. *//* www .j a v a 2s. c o m*/ public void onMessage(Message message) { try { int messageCount = message.getIntProperty(JmsMessageProducer.MESSAGE_COUNT); logger.info("Processed message '{}'. value={}", message, messageCount); counter.incrementAndGet(); if (message instanceof TextMessage) { TextMessage tm = (TextMessage) message; String msg = tm.getText(); logger.info(" Read Transform property " + message.getStringProperty(TRANSFORM)); try { String parser = tm.getStringProperty(PARSER); String key = tm.getStringProperty(TRANSFORM); logger.info(" Read Transform propertys " + parser + " " + key); String response = engine.onTransformEvent(this.createConfig(parser, key), tm.getText(), Charset.defaultCharset()); logger.info(" Response " + response); logger.info("message ReplyTo ID " + tm.getJMSCorrelationID()); tm.setJMSDestination(this.outDestination); javax.jms.Queue queue = (javax.jms.Queue) tm.getJMSDestination(); logger.info("ReplyTo Queue name = " + queue.getQueueName()); tm.clearBody(); tm.setText(response); // Push to response queue } catch (MappingException e) { logger.error("Mapping exception from transformation ", e); // push to mapping error Queue? // May be fixable with input xml change or due to data quality, invalid against schema throw new RuntimeException(e); } catch (ConfigurationException e) { logger.error("Configuration exception from transformation", e); // Can't fix - dead letter queue - but worth tracing what config went missing? throw new RuntimeException(e); } } } catch (JMSException e) { logger.error(e.getMessage(), e); throw new RuntimeException(e); } }
From source file:org.ala.jms.JmsMessageProducer.java
/** * Generates JMS messages/*from ww w .j a v a2 s. com*/ */ @Test public void generateCreateMessage() throws JMSException { template.send(new MessageCreator() { public Message createMessage(Session session) throws JMSException { String json = getJson("" + myGuid); TextMessage message = session.createTextMessage(json); message.setStringProperty(JmsMessageListener.MESSAGE_METHOD, JmsMessageListener.Method.CREATE.toString()); logger.debug("B Sending message: " + message.getStringProperty(JmsMessageListener.MESSAGE_METHOD) + " == " + json); return message; } }); }
From source file:org.ala.jms.JmsMessageProducer.java
@Test public void generateUpdateMessage() throws JMSException { template.send(new MessageCreator() { public Message createMessage(Session session) throws JMSException { String json = getJson("" + myGuid); TextMessage message = session.createTextMessage(json); message.setStringProperty(JmsMessageListener.MESSAGE_METHOD, JmsMessageListener.Method.UPDATE.toString()); logger.debug("B Sending message: " + message.getStringProperty(JmsMessageListener.MESSAGE_METHOD) + " == " + json); return message; }/*from ww w . j a v a 2 s . c o m*/ }); }
From source file:org.ala.jms.JmsMessageProducer.java
@Test public void generateDeleteMessage() throws JMSException { template.send(new MessageCreator() { public Message createMessage(Session session) throws JMSException { String json = getJson("" + myGuid); TextMessage message = session.createTextMessage(json); message.setStringProperty(JmsMessageListener.MESSAGE_METHOD, JmsMessageListener.Method.DELETE.toString()); logger.debug("B Sending message: " + message.getStringProperty(JmsMessageListener.MESSAGE_METHOD) + " == " + json); return message; }//w ww . j ava2s .c o m }); }
From source file:org.ala.jms.JmsMessageProducer.java
@Test public void generateInvalidMessage() throws JMSException { template.send(new MessageCreator() { public Message createMessage(Session session) throws JMSException { String json = ""; TextMessage message = session.createTextMessage(json); message.setStringProperty(JmsMessageListener.MESSAGE_METHOD, JmsMessageListener.Method.CREATE.toString()); logger.debug("B Sending message: " + message.getStringProperty(JmsMessageListener.MESSAGE_METHOD) + " == " + json); return message; }// w w w . j a va 2 s.c o m }); }
From source file:com.oneops.controller.jms.InductorListener.java
private void processResponseMessage(TextMessage msg) throws JMSException { String corelationId = msg.getJMSCorrelationID(); if (corelationId == null) { corelationId = msg.getStringProperty("task_id"); }/*from ww w.j a v a2 s. c o m*/ String[] props = corelationId.split("!"); String processId = props[0]; String executionId = props[1]; //String taskName = props[2]; String woTaskResult = msg.getStringProperty("task_result_code"); logger.debug("Inductor responce >>>>>>" + ((TextMessage) msg).getText()); String type = msg.getStringProperty("type"); Map<String, Object> params = new HashMap<String, Object>(); logger.info("Got inductor response with JMSCorrelationID: " + corelationId + " result " + woTaskResult); CmsWorkOrderSimpleBase wo = null; CmsWorkOrderSimple strippedWo = null; if ("opsprocedure".equalsIgnoreCase(type)) { wo = gson.fromJson(((TextMessage) msg).getText(), CmsActionOrderSimple.class); logger.info("Action ci_id = " + ((CmsActionOrderSimple) wo).getCiId()); } else if ("deploybom".equalsIgnoreCase(type)) { wo = gson.fromJson(((TextMessage) msg).getText(), CmsWorkOrderSimple.class); strippedWo = controllerUtil.stripWO((CmsWorkOrderSimple) wo); if (woTaskResult.equalsIgnoreCase("200")) { try { sensorClient.processMonitors((CmsWorkOrderSimple) wo); } catch (SensorClientException e) { logger.error(e); e.printStackTrace(); } } logger.info("WorkOrder rfc_id = " + ((CmsWorkOrderSimple) wo).getRfcId()); } else { throw new JMSException("the type property of the received msg is uknown - " + type); } if (strippedWo != null) { params.put("wo", strippedWo); } else { params.put("wo", wo); } if (woTaskResult.equalsIgnoreCase("200")) { params.put("wostate", "complete"); } else { params.put("wostate", "failed"); } setWoTimeStamps(wo); String woCorelationId = processId + executionId; wfController.pokeSubProcess(processId, executionId, params); woPublisher.publishMessage(wo, type, woCorelationId); }
From source file:com.oneops.controller.jms.CmsListener.java
private void processMessage(TextMessage message) throws JsonSyntaxException, JMSException { String source = message.getStringProperty("source"); logger.info("Message from source: " + source); String processKey;/* ww w.j a va 2 s .c o m*/ String pokeActivitiProcessId = null; Map<String, Object> wfParams = new HashMap<String, Object>(); if (source.equals("deployment")) { CmsDeployment dpmt = gson.fromJson(message.getText(), CmsDeployment.class); if (dpmt == null) { logger.error("Got bad message:" + message.getText() + "/n end msg"); return; } else { if (isDeployerEnabled(dpmt.getNsPath()) && cmsClient.isDeployerStepsInLimit(dpmt.getDeploymentId())) { notifyIfRequired(dpmt); logger.info("Executing deployment using Deployer : " + dpmt.getDeploymentId()); startDeployment(dpmt); } else { logger.info("Executing deployment using activiti : " + dpmt.getDeploymentId()); processKey = getDpmtProcessKey(dpmt); if (processKey != null && !processKey.equals("skip")) { wfParams.put("dpmt", dpmt); wfParams.put("execOrder", 1); pokeActivitiProcessId = wfController.startDpmtProcess(processKey, wfParams); } else { notifyIfRequired(dpmt); } } } } else if (source.equals("opsprocedure")) { CmsOpsProcedure proc = gson.fromJson(message.getText(), CmsOpsProcedure.class); if (proc == null) { logger.error("Got bad message:" + message.getText() + "/n end msg"); return; } //logger.info() if (isProcDeployerEnabled(proc.getNsPath())) { logger.info("Executing procedure using ProcedureRunner : " + proc.getProcedureId()); startProcedure(proc); } else { processKey = getOpsProcedureProcessKey(proc); if (processKey != null && !processKey.equals("skip")) { wfParams.put("proc", proc); wfParams.put("execOrder", 1); } else { return; } pokeActivitiProcessId = wfController.startOpsProcess(processKey, wfParams); } } else if (source.equals("release")) { CmsRelease release = gson.fromJson(message.getText(), CmsRelease.class); if (release == null) { logger.error("Got bad message:" + message.getText() + "/n end msg"); return; } processKey = getDeployReleaseProcessKey(release); if (processKey != null && !processKey.equals("skip")) { wfParams.put("release", release); } else { return; } pokeActivitiProcessId = wfController.startReleaseProcess(processKey, wfParams); } else { logger.error("Unsupported source:" + source); return; } if (pokeActivitiProcessId != null) { wfController.pokeProcess(pokeActivitiProcessId); } }
From source file:eu.planets_project.tb.impl.system.batch.listener.BatchExperimentListenerImpl.java
public void doOnMessage(Message m, long timeOutMillis, Thread thread) { log.debug("BatchExecutionListener: doOnMessage"); //1.check if message got redelivered before doing any processing try {/* w ww .j a va 2 s . co m*/ if (m.getJMSRedelivered()) { log.debug( "BatchExperimentListener_shortTimeout: onMessage: re-receive message from the queue. Not processing it"); return; } } catch (JMSException e) { log.debug(e); return; } //2. extract the message: it contains the ticket for identifying the job on the workflow system TextMessage msg = null; String ticket = ""; String batchProcessorID = ""; if (m instanceof TextMessage) { msg = (TextMessage) m; try { ticket = msg.getText(); batchProcessorID = msg.getStringProperty(BatchProcessor.QUEUE_PROPERTY_NAME_FOR_SENDING); log.debug("BatchExperimentListener_shortTimeout: received message at timestamp: " + msg.getJMSTimestamp() + " for ticket: " + ticket + "on batch processor: " + batchProcessorID); } catch (JMSException e) { log.debug(e); return; } } else { return; } //3. get the BatchProcessing system that's notified TestbedBatchProcessorManager batchManager = TestbedBatchProcessorManager.getInstance(); BatchProcessor bp = batchManager.getBatchProcessor(batchProcessorID); //check rollback and if batch processor has persistent jobs if ((bp.getJob(ticket) == null) || (bp.getJobStatus(ticket).equals(TestbedBatchJob.NO_SUCH_JOB))) { log.debug("EJBTransactionRollback - BatchProcessor no persistent job - dropp job: " + ticket); return; } //4. check for updates and store extracted information in experiment long t0 = System.currentTimeMillis(); long t1 = System.currentTimeMillis(); boolean bInfomredStarted = false; //do until we have reached our time-out time or completed while (t1 - t0 < timeOutMillis) { //a) check started //use batchProcessor specific implementation for checking on this. boolean bStarted = bp.isStarted(ticket); if (bStarted) { if (!bInfomredStarted) { //callback: inform once about started bp.notifyStart(ticket, bp.getJob(ticket)); log.debug("BatchExecutionListener: notify STARTED for: " + ticket); bInfomredStarted = true; } if (bp.isRunning(ticket)) { TestbedBatchJob job = bp.getJob(ticket); job.setStatus(TestbedBatchJob.RUNNING); bp.notifyRunning(ticket, job); log.debug("BatchExecutionListener: notify RUNNING for: " + ticket); } if (bp.isUpdated(ticket)) { bp.notifyUpdate(ticket, bp.getJob(ticket)); log.debug("BatchExecutionListener: notify UPDATE for: " + ticket); } if (bp.isFailed(ticket)) { TestbedBatchJob job = bp.getJob(ticket); job.setStatus(TestbedBatchJob.FAILED); bp.notifyFailed(ticket, job); log.debug("BatchExecutionListener: notify FAILED for: " + ticket); } //check if completed if (bp.isCompleted(ticket)) { TestbedBatchJob job = bp.getJob(ticket); job.setStatus(TestbedBatchJob.DONE); bp.notifyComplete(ticket, job); log.debug("BatchExecutionListener: notify COMPLETE for: " + ticket); return; } } //status is: still no completed - sleep and repoll try { Thread.sleep(sleep); } catch (InterruptedException e) { log.debug("Error while waiting for ticket: " + ticket, e); TestbedBatchJob job = bp.getJob(ticket); job.setStatus(TestbedBatchJob.FAILED); bp.notifyFailed(ticket, job); return; } t1 = System.currentTimeMillis(); } //b) in this case a time-out occurred TestbedBatchJob job = bp.getJob(ticket); job.setStatus(TestbedBatchJob.FAILED); job.setWorkflowFailureReport(new String("BatchExperimentListener with timeout of " + timeOutMillis / 1000 + " Sec. has timed-out. This normally indicates a failure within the remote workflow execution processor")); bp.notifyFailed(ticket, job); log.debug("BatchExecutionListener: notify FAILED due to time-out for: " + ticket); }
From source file:it.cnr.isti.labsedc.glimpse.manager.GlimpseManager.java
public void onMessage(Message arg0) { TextMessage msg = null; try {//from ww w .j av a 2s . c om msg = (TextMessage) arg0; DebugMessages.line(); DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "receive " + msg.getText()); DebugMessages.line(); String XMLRule = msg.getText(); String sender = msg.getStringProperty("SENDER"); ComplexEventRuleActionListDocument ruleDoc; ruleDoc = ComplexEventRuleActionListDocument.Factory.parse(XMLRule); ComplexEventRuleActionType rules = ruleDoc.getComplexEventRuleActionList(); //the topic where the listener will give analysis results answerTopic = "answerTopic" + "#" + this.getName() + "#" + System.nanoTime(); DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Create answerTopic"); connectionTopic = publishSession.createTopic(answerTopic); //tPub = publishSession.createPublisher(connectionTopic); DebugMessages.ok(); DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Setting up ComplexEventProcessor with new rule."); try { Object[] loadedKnowledgePackage = rulesManagerOne.loadRules(rules); //inserisco la coppia chiave valore dove la chiave il KnowledgePackage //caricato, generato da DroolsRulesManager con la loadRules //e il valore l'enabler che l'ha inviata //(il KnowledgePackage array dovrebbe avere sempre dimensione 1 essendo creato ad ogni loadrules) for (int i = 0; i < loadedKnowledgePackage.length; i++) { KnowledgePackageImp singleKnowlPack = (KnowledgePackageImp) loadedKnowledgePackage[i]; Rule[] singleRuleContainer = new Rule[singleKnowlPack.getRules().size()]; singleRuleContainer = singleKnowlPack.getRules().toArray(singleRuleContainer); for (int j = 0; j < singleRuleContainer.length; j++) { requestMap.put(singleRuleContainer[j].getName(), new ConsumerProfile(sender, answerTopic)); } } DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "KnowledgeBase packages loaded: " + rulesManagerOne.getLoadedKnowledgePackageCardinality()); DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Communicate the answerTopic to the requester"); sendMessage(createMessage("AnswerTopic == " + answerTopic, sender)); DebugMessages.ok(); } catch (IncorrectRuleFormatException e) { sendMessage(createMessage("PROVIDED RULE CONTAINS ERRORS", sender)); } } catch (NullPointerException asd) { try { sendMessage(createMessage("PROVIDED RULE IS NULL, PLEASE PROVIDE A VALID RULE", msg.getStringProperty("SENDER"))); } catch (JMSException e) { e.printStackTrace(); } } catch (XmlException e) { try { sendMessage(createMessage("PROVIDED XML CONTAINS ERRORS", msg.getStringProperty("SENDER"))); } catch (JMSException e1) { e1.printStackTrace(); } } catch (JMSException ee) { ee.printStackTrace(); } DebugMessages.line(); }
From source file:it.cnr.isti.labse.glimpse.manager.GlimpseManager.java
public void onMessage(Message arg0) { TextMessage msg = null; try {/*from w w w .ja v a2 s . c om*/ msg = (TextMessage) arg0; DebugMessages.line(); DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "receive " + msg.getText()); DebugMessages.line(); String XMLRule = msg.getText(); String sender = msg.getStringProperty("SENDER"); /* * check if the message contains a ComplexEventRule or a Model * in the second case, it must be forwarded to the new component * Transformer that will convert Model to Drools rule * */ ComplexEventRuleActionType rules; if (XMLRule.contains("ComplexEventRuleActionList")) { //if the message contains a rule represented through ComplexEventRule XSD ComplexEventRuleActionListDocument ruleDoc; ruleDoc = ComplexEventRuleActionListDocument.Factory.parse(XMLRule); rules = ruleDoc.getComplexEventRuleActionList(); } else { //if the message contains a rule represented through a model (CPMM) Transformer transformer = new TransformerImpl(null); /*TODO: as parameter of the transformerImpl, we must put the * path of the metamodel file. */ rules = transformer.convertInputModel(XMLRule).getComplexEventRuleActionList(); } //the topic where the listener will give analysis results answerTopic = "answerTopic" + "#" + this.getName() + "#" + System.nanoTime(); DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Create answerTopic"); connectionTopic = publishSession.createTopic(answerTopic); //tPub = publishSession.createPublisher(connectionTopic); DebugMessages.ok(); DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Setup ComplexEventProcessor with Enabler request."); try { Object[] loadedKnowledgePackage = rulesManager.loadRules(rules); //inserisco la coppia chiave valore dove la chiave il KnowledgePackage //caricato, generato da DroolsRulesManager con la loadRules //e il valore l'enabler che l'ha inviata //(il KnowledgePackage array dovrebbe avere sempre dimensione 1 essendo creato ad ogni loadrules) for (int i = 0; i < loadedKnowledgePackage.length; i++) { KnowledgePackageImp singleKnowlPack = (KnowledgePackageImp) loadedKnowledgePackage[i]; Rule singleRuleContainer[] = new Rule[singleKnowlPack.getRules().size()]; singleRuleContainer = singleKnowlPack.getRules().toArray(singleRuleContainer); for (int j = 0; j < singleRuleContainer.length; j++) { requestMap.put(singleRuleContainer[j].getName(), new ConsumerProfile(sender, answerTopic)); } DebugMessages.ok(); DebugMessages.println(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "KnowledgeBase packages loaded: " + rulesManager.getLoadedKnowledgePackageCardinality()); } DebugMessages.print(TimeStamp.getCurrentTime(), this.getClass().getSimpleName(), "Communicate the answerTopic to the enabler"); sendMessage(createMessage("AnswerTopic == " + answerTopic, sender)); DebugMessages.ok(); } catch (IncorrectRuleFormatException e) { sendMessage(createMessage("PROVIDED RULE CONTAINS ERRORS", sender)); } } catch (NullPointerException asd) { try { sendMessage(createMessage("PROVIDED RULE IS NULL, PLEASE PROVIDE A VALID RULE", msg.getStringProperty("SENDER"))); } catch (JMSException e) { e.printStackTrace(); } } catch (XmlException e) { try { sendMessage(createMessage("PROVIDED XML CONTAINS ERRORS", msg.getStringProperty("SENDER"))); } catch (JMSException e1) { e1.printStackTrace(); } } catch (JMSException ee) { ee.printStackTrace(); } DebugMessages.line(); }