List of usage examples for org.springframework.messaging Message getPayload
T getPayload();
From source file:uk.co.jemos.experiments.integration.HelloWorldApp.java
public static void main(String[] args) { AbstractApplicationContext context = new ClassPathXmlApplicationContext( "/META-INF/spring/integration/helloWorldDemo.xml", HelloWorldApp.class); MessageChannel inputChannel = context.getBean("podamInputChannel", MessageChannel.class); Message<Object> intMessage = MessageBuilder.withPayload(new Object()) .setHeader("type", int.class.toString()).build(); Message<Object> boolMessage = MessageBuilder.withPayload(new Object()) .setHeader("type", boolean.class.toString()).build(); Message<Object> stringMessage = MessageBuilder.withPayload(new Object()) .setHeader("type", String.class.getName()).build(); MessagingTemplate template = new MessagingTemplate(); Message reply = template.sendAndReceive(inputChannel, intMessage); logger.info(reply.getPayload()); reply = template.sendAndReceive(inputChannel, boolMessage); logger.info(reply.getPayload());//from w ww . ja v a2 s .co m reply = template.sendAndReceive(inputChannel, stringMessage); logger.info(reply.getPayload()); context.close(); }
From source file:com.qpark.eip.core.spring.security.EipRoleVoter.java
/** * Get the service name by using the class name of the {@link Message} * payload//from w w w . j a v a 2 s . co m * * @param m * the {@link Message}. * @return the service name. */ public static String getOperationName(final Message<?> m) { String operationName = ""; if (m != null && m.getPayload() != null && JAXBElement.class.isInstance(m.getPayload()) && ((JAXBElement<?>) m.getPayload()).getValue() != null) { String className = ((JAXBElement<?>) m.getPayload()).getValue().getClass().getSimpleName(); if (className.endsWith("ResponseType")) { operationName = className.substring(0, className.length() - 12); } else if (className.endsWith("RequestType")) { operationName = className.substring(0, className.length() - 11); } } return operationName; }
From source file:com.qpark.eip.core.spring.security.EipRoleVoter.java
/** * Get the service name by using the class name of the {@link Message} * payload/*from w ww . jav a 2 s . c o m*/ * * @param m * the {@link Message}. * @param serviceIdentifierStart * e.g. <code>".service."</code> * @param serviceIdentifierEnd * e.g. <code>".msg"</code> * @return the service name. */ public static String getServiceName(final Message<?> m, final String serviceIdentifierStart, final String serviceIdentifierEnd) { String serviceName = ""; if (m != null && m.getPayload() != null && JAXBElement.class.isInstance(m.getPayload()) && ((JAXBElement<?>) m.getPayload()).getValue() != null) { String className = ((JAXBElement<?>) m.getPayload()).getValue().getClass().getName(); int serviceIndex = className.indexOf(serviceIdentifierStart); int msgIndex = className.indexOf(serviceIdentifierEnd); if (serviceIndex >= 0 && msgIndex > 0 && serviceIndex + serviceIdentifierStart.length() < msgIndex) { serviceName = className.substring(serviceIndex + serviceIdentifierStart.length(), msgIndex); } } return serviceName; }
From source file:com.acme.PayloadValueCounterHandler.java
@ServiceActivator public void handleMessage(Message<?> message) throws Exception { if (message.getPayload() != null) { fieldValueCounterRepository.increment(name, message.getPayload().toString()); }//from ww w . j a va2s . com }
From source file:simple.flow.lambda.Application.java
@Bean IntegrationFlow flow() {//from w w w . ja v a2s .c om return f -> f.handle(new GenericHandler<Message>() { @Override public Object handle(Message payload, Map<String, Object> headers) { System.out.println(payload.getPayload().getClass() + " " + payload.getPayload()); return payload; } }); }
From source file:nz.co.senanque.messaging.OrderEndpoint.java
public Message<Order> issueResponseFor(Message<Order> order) { if (order.getPayload().getOrderName().equals("fatal error")) { throw new RuntimeException("fatal error"); }/*from w ww . j a v a 2 s .com*/ if (order.getPayload().getOrderName().equals("recoverable error")) { throw new RuntimeException("recoverable error"); } Order ret = new ObjectFactory().createOrder(); OrderItem orderItem = new ObjectFactory().createOrderItem(); orderItem.setItemName("#1"); ret.setRejected(false); ret.setOrderName("whatever"); ret.getOrderItems().add(orderItem); log.debug("processed order: correlationId {}", order.getHeaders().get(IntegrationMessageHeaderAccessor.CORRELATION_ID, Long.class)); MessageBuilder<Order> messageBuilder = MessageBuilder.withPayload(ret); messageBuilder.copyHeaders(order.getHeaders()); return messageBuilder.build(); }
From source file:com.qpark.eip.core.spring.JAXBElementValueGetterTransformer.java
/** * @param message//from w w w . j a va 2 s . c om * @return The value out of the {@link JAXBElement} */ @SuppressWarnings("unchecked") public Message<? extends T> transform(final Message<JAXBElement<?>> message) { JAXBElement<?> payload = message.getPayload(); return MessageBuilder.withPayload((T) payload.getValue()).copyHeaders(message.getHeaders()).build(); }
From source file:it.pcan.test.integration.amqp.ClientErrorInterceptor.java
@Override public Message<?> preSend(Message<?> message, MessageChannel channel) { if (message.getPayload() instanceof RuntimeExceptionHolder) { RuntimeExceptionHolder holder = (RuntimeExceptionHolder) message.getPayload(); throw holder.getException(); }//from w w w .j av a2s . co m if (message.getPayload() instanceof NullObject) { /** * @see NullReturningHandlerAdvice */ MessageHeaders headers = message.getHeaders(); Map<String, Object> newHeaders = new HashMap<>(headers); newHeaders.put("replyChannel", "nullChannel"); return new GenericMessage(message.getPayload(), newHeaders); } return message; }
From source file:org.cloudbyexample.dc.service.si.application.ApplicationFlowEndpoint.java
/** * Process an application.// w ww. j av a 2 s .com */ public void processMessage(Message<Application> message) { Application application = message.getPayload(); logger.debug("Processed application '{}' {}. imageTemplateSize={}", new Object[] { application.getName(), application.getVersion(), application.getImageTemplates().size() }); }
From source file:apiserver.services.cache.services.DocumentService.java
public Message<?> deleteFromCache(Message<?> message) { if (!(message.getPayload() instanceof DocumentJob)) { return message; }/* w ww. j a v a 2s . co m*/ return message; }