List of usage examples for org.springframework.messaging Message getPayload
T getPayload();
From source file:com.it355.jmsdemo.app.messaging.MessageReceiver.java
@JmsListener(destination = ORDER_RESPONSE_QUEUE) public void receiveMessage(final Message<InventoryResponse> message) throws JMSException { LOG.info("+++++++++++++++++++++++++++++++++++++++++++++++++++++"); MessageHeaders headers = message.getHeaders(); LOG.info("Application : headers received : {}", headers); InventoryResponse response = message.getPayload(); LOG.info("Application : response received : {}", response); rderService.updateOrder(response);//from ww w . ja v a2 s . co m LOG.info("+++++++++++++++++++++++++++++++++++++++++++++++++++++"); }
From source file:biz.c24.io.spring.integration.config.ValidatingSelectorTests.java
@Test public void testInvalid() { Employee employee = new Employee(); employee.setSalutation("Mr"); // Invalid as first char not capitalised employee.setFirstName("andy"); employee.setLastName("Acheson"); // Invalid as no job title //employee.setJobTitle("Software Developer"); template.convertAndSend(employee);//from ww w.j a v a2s. c o m @SuppressWarnings("unchecked") Message<Employee> result = (Message<Employee>) invalidChannel.receive(1); assertThat(result, is(not(nullValue()))); assertThat(result.getPayload(), is(Employee.class)); // Make sure there are no other messages floating around assertThat(validChannel.receive(1), is(nullValue())); assertThat(invalidChannel.receive(1), is(nullValue())); }
From source file:org.springintegration.PayloadAwareTimingInterceptor.java
@Override public Message<?> preSend(Message<?> message, MessageChannel channel) { StopWatch stopWatch = new StopWatch(); stopWatch.start();/* w ww . j a v a2 s . c o m*/ this.stopWatchHolder.set(new StopWatchHolder(stopWatch, message.getPayload().getClass())); return super.preSend(message, channel); }
From source file:nz.co.senanque.messaging.ErrorEndpoint.java
public void processErrorMessage(final Message<MessagingException> message) { MessageHeaders messageHeaders = message.getHeaders(); final MessagingException messagingException = (MessagingException) message.getPayload(); Long correlationId = message.getHeaders().get(IntegrationMessageHeaderAccessor.CORRELATION_ID, Long.class); if (correlationId == null) { correlationId = messagingException.getFailedMessage().getHeaders() .get(IntegrationMessageHeaderAccessor.CORRELATION_ID, Long.class); }/*from ww w.j a v a 2 s . c o m*/ log.debug("ProcessInstance: correlationId {}", correlationId); if (correlationId == null) { log.error("correlation Id is null"); throw new WorkflowException("correlation Id is null"); } final ProcessInstance processInstance = getWorkflowDAO().findProcessInstance(correlationId); if (processInstance == null) { throw new WorkflowException("Failed to find processInstance for " + correlationId); } getBundleSelector().selectBundle(processInstance); List<Lock> locks = ContextUtils.getLocks(processInstance, getLockFactory(), "nz.co.senanque.messaging.ErrorEndpoint.processErrorMessage"); LockTemplate lockTemplate = new LockTemplate(locks, new LockAction() { public void doAction() { if (processInstance.getStatus() != TaskStatus.WAIT) { throw new WorkflowException("Process is not in a wait state"); } getWorkflowManager().processMessage(processInstance, message, getMessageMapper()); } }); if (!lockTemplate.doAction()) { throw new WorkflowRetryableException("Failed to get a lock"); // This will be retried } }
From source file:nz.co.senanque.messaging.OrderReplyEndpoint.java
public void issueResponseFor(Message<org.w3c.dom.Document> orderResponse) { log.debug("processed orderResponse: correlationId {}", orderResponse.getHeaders().get(IntegrationMessageHeaderAccessor.CORRELATION_ID, Long.class)); org.w3c.dom.Document doc = orderResponse.getPayload(); Document document = new DOMBuilder().build(doc); Element root = document.getRootElement(); Order context = new Order(); @SuppressWarnings("unchecked") Iterator<Text> itr = (Iterator<Text>) root .getDescendants(new ContentFilter(ContentFilter.TEXT | ContentFilter.CDATA)); while (itr.hasNext()) { Text text = itr.next();/* w ww .j av a 2 s . c o m*/ log.debug("name {} value {}", text.getParentElement().getName(), text.getValue()); String name = getName(text); try { Class<?> targetType = PropertyUtils.getPropertyType(context, name); Object value = ConvertUtils.convert(text.getValue(), targetType); PropertyUtils.setProperty(context, name, value); } catch (IllegalAccessException e) { // Ignore these and move on log.debug("{} {}", name, e.getMessage()); } catch (InvocationTargetException e) { // Ignore these and move on log.debug("{} {}", name, e.getMessage()); } catch (NoSuchMethodException e) { // Ignore these and move on log.debug("{} {}", name, e.getMessage()); } } }
From source file:biz.c24.io.spring.integration.transformer.C24Transformer.java
/** * /*from w w w . ja v a 2 s . c o m*/ * @return The transformed payload * * @see org.springframework.integration.transformer.AbstractTransformer#doTransform * (org.springframework.messaging.Message) */ @Override protected Object doTransform(Message<?> message) throws Exception { Transform transform = buildTransform(message); // TODO Support list or array as input Object payload = message.getPayload(); Object[][] results = transform.transform(new Object[][] { new Object[] { payload } }); Object output = extractOutputPayload(results); return output; }
From source file:com.codeveo.lago.bot.stomp.client.LagoJsonMessageConverter.java
@Override public Object fromMessage(Message<?> message, Class<?> targetClass) { try {/*from w w w . jav a 2 s . c o m*/ /* NOTE: Message that came from STOMP broker */ /* class discovery */ RObjectType rObjectType = mapper.readValue((byte[]) message.getPayload(), RObjectType.class); if (rObjectType == null) { LOG.warn("Could not get R-object type from message '{}'", message); throw new Exception("Could not get R-Object type"); } Class<?> clazz = ClientCommunicationHelperService.getClassFromClassId(rObjectType.getClassId()); if (clazz == null) { LOG.warn("Could not identify class of R-object with class ID '{}' in message '{}'", rObjectType.getClassId(), message); throw new Exception("Could not identify class of R-object"); } Object obj = mapper.readValue((byte[]) message.getPayload(), clazz); if (clazz.equals(RClientMessage.class)) { JsonNode rootNode = mapper.readValue((byte[]) message.getPayload(), JsonNode.class); JsonNode dataJsonObject = rootNode.get("data"); RObjectType data = null; RClientMessage clientMessage = (RClientMessage) obj; if (clientMessage.getData() != null) { Class<?> dataClass = ClientCommunicationHelperService .getClassFromClassId(clientMessage.getData().getClassId()); data = (RObjectType) mapper.readValue(dataJsonObject.toString(), dataClass); } clientMessage.setData(data); } return obj; } catch (Exception e) { LOG.error("Error occured during message deserialization", e); } return null; }
From source file:ru.asmsoft.p2p.transaction.IncomingTransactionManager.java
@ServiceActivator(inputChannel = "incoming-rollback-transaction") public void handleRollbackTransaction(Message<RollbackTransactionPacket> message) { logger.info("Rollback transaction received: {}", message.toString()); // rollback//from ww w .j a v a 2 s.c o m RollbackTransactionPacket commitPacket = message.getPayload(); try { messageRepository.cancelChangeset(commitPacket.getDbVersion()); } catch (NoChangesetFoundException e) { logger.error(e.getMessage()); } // Switch state machine stateMachine.sendEvent(NodeEvents.RollbackReceived); }
From source file:apiserver.core.connectors.coldfusion.ColdFusionHttpBridge.java
public Object execute(Message<?> message) throws ColdFusionException { IProxyJob props = (IProxyJob) message.getPayload(); try {//from ww w . ja va2 s . c om // extract properties //Map<String, Object> methodArgs = coldFusionBridge.extractPropertiesFromPayload(props); // execute ResponseEntity cfResults = invokeFilePost(cfcPath, cfcMethod, props.getArguments()); props.setHttpResponse(cfResults); return message; } catch (Throwable e) { e.printStackTrace(); //todo use logging library throw new RuntimeException(e); } }
From source file:eric.bottard.tis100.Runner.java
public Runner(int rows, int columns, String specificationFile, File solution) throws IOException { Specification specification = new LuaSpecification(specificationFile, rows, columns); List<String> nodeSources = loadSolution(solution, specification.getLayout()); this.rows = rows; this.columns = columns; verticalChannels = new MessageChannel[columns * (rows + 1) * 2]; horizontalChannels = new MessageChannel[rows * (columns + 1) * 2]; // channels[2*x] = ltr / down-to-up // channels[2*x + 1] = rtl / up-to-down for (int row = 0; row <= rows; row++) { for (int column = 0; column < columns; column++) { verticalChannels[(row * columns + column) * 2] = (row == 0 || row == rows) ? new NullChannel() : new RendezvousChannel(); if (row == 0) { verticalChannels[(row * columns + column) * 2 + 1] = new QueueChannel(40); } else if (row == rows) { verticalChannels[(row * columns + column) * 2 + 1] = new PublishSubscribeChannel(); } else { verticalChannels[(row * columns + column) * 2 + 1] = new RendezvousChannel(); }//from w w w . j a v a 2 s . c o m } } for (int row = 0; row < rows; row++) { for (int column = 0; column <= columns; column++) { horizontalChannels[(column * rows + row) * 2] = (column == 0 || column == columns) ? new NullChannel() : new RendezvousChannel(); horizontalChannels[(column * rows + row) * 2 + 1] = (column == 0 || column == columns) ? new NullChannel() : new RendezvousChannel(); } } Thread[] threads = new Thread[rows * columns]; Object mutex = new Object(); for (int row = 0; row < rows; row++) { for (int column = 0; column < columns; column++) { final SpringNode node = NodeFactory.buildNode(nodeSources.get(row * columns + column)); final NodePrettyPrinter printer = new NodePrettyPrinter(4 + row * 19, SpecificationPrettyPrinter.WIDTH + 10 + column * 37, node); Ports ports = new PortsMapping(row, column); node.setPorts(ports); nodes.add(node); threads[row * columns + column] = new Thread() { @Override public void run() { boolean more; do { synchronized (mutex) { printer.draw(System.out); } try { Thread.sleep(150); } catch (InterruptedException e) { e.printStackTrace(); } more = node.tick(); } while (more); } }; } } List<Integer>[] actuals = new List[columns]; SpecificationPrettyPrinter specificationPrettyPrinter = new SpecificationPrettyPrinter(specification, 2, 2, actuals); for (int i = 0; i < columns; i++) { Specification.Stream stream = specification.getInputStreams()[i]; if (stream != null) { for (Integer in : stream.getData()) { verticalChannels[1 + 2 * i].send(new GenericMessage<>(in)); } } stream = specification.getOutputStreams()[i]; final List<Integer> actual = actuals[i] = new ArrayList<>(); if (stream != null) { ((SubscribableChannel) verticalChannels[1 + 2 * (i + rows * columns)]) .subscribe(new MessageHandler() { @Override public void handleMessage(Message<?> message) throws MessagingException { actual.add((Integer) message.getPayload()); synchronized (mutex) { specificationPrettyPrinter.draw(System.out); } } }); } } synchronized (mutex) { specificationPrettyPrinter.draw(System.out); } for (int i = 0; i < rows * columns; i++) { threads[i].start(); } }