List of usage examples for org.springframework.messaging Message getPayload
T getPayload();
From source file:org.openwms.common.comm.transformer.tcp.HeaderAppendingTransformer.java
@Transformer public Message<Payload> transform(Message<Payload> msg) { MessageHeaderAccessor mha = new MessageHeaderAccessor(); mha.copyHeaders(msg.getHeaders());/*from w ww . j a va 2 s. c o m*/ mha.setHeader(CommHeader.SYNC_FIELD_NAME, msg.getHeaders().get(CommHeader.SYNC_FIELD_NAME)); mha.setHeader(CommHeader.MSG_LENGTH_FIELD_NAME, headerLength(msg.getHeaders()) + msg.getPayload().asString().length()); mha.setHeader(CommHeader.SENDER_FIELD_NAME, msg.getHeaders().get(CommHeader.RECEIVER_FIELD_NAME)); mha.setHeader(CommHeader.RECEIVER_FIELD_NAME, msg.getHeaders().get(CommHeader.SENDER_FIELD_NAME)); mha.setHeader(CommHeader.SEQUENCE_FIELD_NAME, Integer.parseInt(String.valueOf(msg.getHeaders().get(CommHeader.SEQUENCE_FIELD_NAME))) + 1); return org.springframework.messaging.support.MessageBuilder.withPayload(msg.getPayload()).setHeaders(mha) .build(); }
From source file:ru.asmsoft.p2p.transaction.IncomingTransactionManager.java
@ServiceActivator(inputChannel = "incoming-commit-transaction") public void handleCommitTransaction(Message<CommitTransactionPacket> message) { logger.info("Commit transaction received: {}", message.toString()); stateMachine.sendEvent(NodeEvents.CommitReceived); // commit/* w ww . jav a 2 s. co m*/ CommitTransactionPacket commitPacket = message.getPayload(); try { messageRepository.applyChangeset(commitPacket.getDbVersion()); } catch (NoChangesetFoundException e) { // failed to update logger.error(e.getMessage()); // set wrong version to re-sync messageRepository.updateDbVersion(-1L); } // Switch state machine stateMachine.sendEvent(NodeEvents.CommitReceived); }
From source file:com.qpark.eip.core.spring.RequestIdMessageHeaderEnhancer.java
/** * Enhance the message header with name of this class. * * @see org.springframework.integration.channel.ChannelInterceptor#preSend(org.springframework.integration.Message, * org.springframework.integration.MessageChannel) *///w w w .j a v a 2s.c o m @Override public Message<?> preSend(final Message<?> message, final MessageChannel channel) { Message<?> msg = null; if (message.getHeaders().get(HEADER_NAME_REQUEST_ID) == null) { Map<String, Object> headerMap = new HashMap<String, Object>(message.getHeaders()); headerMap.put(HEADER_NAME_REQUEST_ID, message.getHeaders().getId()); msg = MessageBuilder.withPayload(message.getPayload()).copyHeaders(headerMap).build(); } else { msg = message; } return msg; }
From source file:ru.asmsoft.p2p.transaction.IncomingTransactionManager.java
@ServiceActivator(inputChannel = "incoming-update-transaction", outputChannel = "outgoing-channel") public Message handeIncomingUpdateTransaction(Message<MessagePacket> message) { logger.info("Incoming update received: {}", message.toString()); // Switch state machine stateMachine.sendEvent(NodeEvents.UpdateReceived); // Prepare response packet MessageReceivedPacket packet = new MessageReceivedPacket(message.getPayload()); // registerChangeset MessagePacket messagePacket = message.getPayload(); messageRepository.registerChangeset(messagePacket.getDbVersion(), messagePacket.getMessages()); // Send response return prepareResponse(message, packet); }
From source file:com.kinglcc.spring.jms.core.Jackson2PayloadArgumentResolver.java
@Override public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { Payload ann = parameter.getParameterAnnotation(Payload.class); if (ann != null && StringUtils.hasText(ann.value())) { throw new IllegalStateException("@Payload SpEL expressions not supported by this resolver"); }/*from ww w . j a v a 2 s . c o m*/ Object payload = message.getPayload(); boolean isGeneric = isGenericMessage(payload); if (isGeneric) { payload = ((GenericMessage) payload).getContent(); MessageBuilder<Object> builder = MessageBuilder.withPayload(payload); message = builder.copyHeadersIfAbsent(message.getHeaders()).build(); } if (isEmptyPayload(payload)) { if (ann == null || ann.required()) { bindEmptyPayloadError(parameter, message, payload); } return null; } if (isGeneric) { return convertFromMessage(parameter, message); } else { if (ClassUtils.isAssignable(parameter.getParameterType(), payload.getClass())) { validate(message, parameter, payload); return payload; } return convertFromMessage(parameter, message); } }
From source file:ch.rasc.wampspring.method.PayloadArgumentResolver.java
@Override public Object resolveArgument(MethodParameter param, Message<?> message) throws Exception { Payload ann = param.getParameterAnnotation(Payload.class); if (ann != null && StringUtils.hasText(ann.value())) { throw new IllegalStateException("@Payload SpEL expressions not supported by this resolver"); }/*from w w w . j a v a 2s .c om*/ Object payload = message.getPayload(); if (isEmptyPayload(payload)) { if (ann == null || ann.required()) { String paramName = getParameterName(param); BindingResult bindingResult = new BeanPropertyBindingResult(payload, paramName); bindingResult.addError(new ObjectError(paramName, "@Payload param is required")); throw new MethodArgumentNotValidException(message, param, bindingResult); } return null; } Class<?> targetClass = param.getParameterType(); if (ClassUtils.isAssignable(targetClass, payload.getClass())) { validate(message, param, payload); return payload; } payload = this.methodParameterConverter.convert(param, message.getPayload()); if (payload == null) { throw new MessageConversionException(message, "No converter found to convert to " + targetClass + ", message=" + message); } validate(message, param, payload); return payload; }
From source file:ru.asmsoft.p2p.transaction.IncomingTransactionManager.java
@ServiceActivator(inputChannel = "incoming-start-transaction", outputChannel = "outgoing-channel") public Message handeIncomingStartTransaction(Message<StartTransactionPacket> message) { logger.info("Incoming transaction received: {}", message.toString()); // Switch state machine stateMachine.sendEvent(NodeEvents.StartTransactionReceived); // Prepare response packet ConfirmTransactionStartedPacket packet = new ConfirmTransactionStartedPacket(message.getPayload()); // Send response return prepareResponse(message, packet); }
From source file:ru.asmsoft.p2p.transaction.IncomingTransactionManager.java
@ServiceActivator(inputChannel = "incoming-update-me-channel", outputChannel = "outgoing-channel") public Message handeUpdateMeRequest(Message<UpdateMePacket> message) { logger.info("UpdateMe received: {}", message.toString()); // Switch state machine stateMachine.sendEvent(NodeEvents.UpdateMeRequestReceived); // Prepare response packet UpdateMeResponse packet = new UpdateMeResponse(messageRepository.getDbVersion(), messageRepository.getMessage(), message.getPayload()); // Switch state machine stateMachine.sendEvent(NodeEvents.UpdateByRequestSent); // Send response return prepareResponse(message, packet); }
From source file:nl.rav.comparision.integration.unitofwork.java.UnitOfWorkSpringTest.java
private void createRouteBuilder() { handler = new AbstractReplyProducingMessageHandler() { @Override/* w w w .java 2 s. c o m*/ protected Object handleRequestMessage(Message<?> requestMessage) { return "baz"; } }; AbstractReplyProducingMessageHandler handler2 = new AbstractReplyProducingMessageHandler() { @Override protected Object handleRequestMessage(Message<?> requestMessage) { if (doFail.get()) { throw new RuntimeException("qux"); } return requestMessage.getPayload(); } }; SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor(); taskExecutor.setThreadNamePrefix("test-"); ExecutorChannel intermediate = new ExecutorChannel(taskExecutor); handler.setOutputChannel(intermediate); intermediate.subscribe(handler2); replies = new QueueChannel(); handler2.setOutputChannel(replies); successChannel = new QueueChannel(); failureChannel = new QueueChannel(); ExpressionEvaluatingRequestHandlerAdvice advice = new ExpressionEvaluatingRequestHandlerAdvice(); advice.setBeanFactory(mock(BeanFactory.class)); advice.setSuccessChannel(successChannel); advice.setFailureChannel(failureChannel); advice.setOnSuccessExpression("'foo'"); advice.setOnFailureExpression("'bar:' + #exception.message"); List<Advice> adviceChain = new ArrayList<Advice>(); adviceChain.add(advice); handler.setAdviceChain(adviceChain); handler.afterPropertiesSet(); handler2.setAdviceChain(adviceChain); handler2.afterPropertiesSet(); }
From source file:com.wk.lodge.composite.web.tomcat.IntegrationCompositeTests.java
private String parseMessageJson(Message<?> message) throws UnsupportedEncodingException { return new String((byte[]) message.getPayload(), "UTF-8"); }