List of usage examples for org.springframework.messaging Message getHeaders
MessageHeaders getHeaders();
From source file:com.consol.citrus.samples.greeting.AbstractMarshallingMessageService.java
/** * Unmarshal message payload./* w w w .j av a 2 s .c o m*/ * * @param message * @return */ @SuppressWarnings("unchecked") private Message<T> unmarshalMessage(Message<?> message) { T payload = (T) unmarshallingTransformer.transformPayload(message.getPayload()); MessageBuilder<T> builder = MessageBuilder.withPayload(payload).copyHeaders(message.getHeaders()); return builder.build(); }
From source file:ru.asmsoft.p2p.transaction.OutgoingTransactionManager.java
private Message prepareResponse(Message requestMessage, P2PPacket response) { return MessageBuilder.withPayload(response) .setHeader("ip_address", requestMessage.getHeaders().get("ip_address")) .setHeader("ip_port", nodeConfiguration.getPort()).setHeader("uuid", response.getUuid()).build(); }
From source file:org.opencredo.couchdb.outbound.CouchDbSendingMessageHandlerTest.java
@Test public void handleMessage() throws Exception { DummyDocument document = new DummyDocument("Klaatu Berada Nikto"); Message<DummyDocument> message = MessageBuilder.withPayload(document).build(); messageHandler.handleMessage(message); //assert message in the database DummyDocument result = getDocument(message.getHeaders().getId().toString(), DummyDocument.class); assertThat(document.getMessage(), equalTo(result.getMessage())); }
From source file:org.opencredo.couchdb.outbound.CouchDbOutboundChannelAdapterPollerTest.java
@Test @Repeat(10)/*w w w . j a v a 2 s .c o m*/ @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public void sendMessage() throws Exception { DummyDocument document = new DummyDocument("polling test - " + UUID.randomUUID()); Message<DummyDocument> message = MessageBuilder.withPayload(document).build(); messagingTemplate.send(message); DummyDocument response = (DummyDocument) messagingTemplate.convertSendAndReceive("testRequestChannel", message.getHeaders().getId(), DummyDocument.class); assertThat(document.getMessage(), equalTo(response.getMessage())); }
From source file:nz.co.senanque.messaging.GenericEndpoint.java
public void issueResponseFor(final Message<?> message) { MessageHeaders messageHeaders = message.getHeaders(); Long correlationId = message.getHeaders().get(IntegrationMessageHeaderAccessor.CORRELATION_ID, Long.class); log.debug("ProcessInstance: correlationId {}", correlationId); if (correlationId == null) { log.error("correlation Id is null"); throw new WorkflowException("correlation Id is null"); }//from w ww .j a va 2s . c om 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.GenericEndpoint.issueResponseFor"); 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()); log.debug("completed lock message processing"); } }); if (!lockTemplate.doAction()) { throw new WorkflowRetryableException("Failed to get a lock"); // this will be retried later, not a hard error } log.debug("completed incomming message processing"); }
From source file:ru.asmsoft.p2p.transaction.IncomingTransactionManager.java
private Message prepareResponse(Message requestMessage, P2PPacket response) { Message responseMessage = MessageBuilder.withPayload(response) .setHeader("ip_address", requestMessage.getHeaders().get("ip_address")) .setHeader("ip_port", nodeConfiguration.getPort()).setHeader("uuid", response.getUuid()).build(); return responseMessage; }
From source file:org.opencredo.couchdb.outbound.CouchDbSendingMessageHandlerTest.java
@Test public void handleMessageTemplateUrl() throws Exception { DummyDocument document = new DummyDocument("We use template variables in our URL"); HashMap<String, Object> headers = new HashMap<String, Object>(); headers.put("greatDatabase", "couchdb"); Message<DummyDocument> message = MessageBuilder.withPayload(document).copyHeaders(headers).build(); messageHandlerTemplateUrl.handleMessage(message); //assert message in the database DummyDocument result = getDocument("couchdb-" + message.getHeaders().getId().toString(), DummyDocument.class); assertThat(document.getMessage(), equalTo(result.getMessage())); }
From source file:com.qpark.eip.core.spring.statistics.impl.AppUserStatisticsChannelAdapter.java
/** * @see org.springframework.integration.channel.ChannelInterceptor#postSend(org.springframework.integration.Message, * org.springframework.integration.MessageChannel, boolean) *//*from w w w .j a va 2 s . c o m*/ @Override public void postSend(final Message<?> message, final MessageChannel channel, final boolean sent) { UUID requestId = (UUID) message.getHeaders().get(RequestIdMessageHeaderEnhancer.HEADER_NAME_REQUEST_ID); if (channel.toString().contains("Response") && requestId != null) { SimpleEntry<String, Long> entry = this.requestMap.get(requestId); if (entry != null) { ApplicationUserLogType log = new ApplicationUserLogType(); log.setStopItem(new Date()); log.setDurationMillis(log.getStopItem().getTime() - entry.getValue().longValue()); log.setStartItem(new Date(entry.getValue().longValue())); log.setDurationString(AppUserStatisticsChannelAdapter.getDuration(log.getDurationMillis())); log.setContext(this.contextNameProvider.getContextName()); log.setVersion(this.contextNameProvider.getContextVersion()); log.setUserName(entry.getKey()); log.setServiceName(EipRoleVoter.getServiceName(message, ".service.", ".msg.")); log.setOperationName(EipRoleVoter.getOperationName(message)); log.setReturnedEntities(this.messageContentProvider.getNumberOfReturns(message)); log.setReturnedFailures(this.messageContentProvider.getNumberOfFailures(message)); log.setHostName(this.getHostName()); if (this.logger.isTraceEnabled()) { this.logger.trace("{},{},{},{},{},{},{},{}", log.getContext(), log.getHostName(), log.getServiceName(), log.getOperationName(), log.getUserName(), log.getReturnedFailures(), log.getDurationString(), log.getStartItem()); } this.submitApplicationUserLogType(log); } } }
From source file:com.qpark.eip.core.spring.statistics.impl.AppUserStatisticsChannelAdapter.java
/** * Add the request time stamp to the {@link #requestMap}. * * @see org.springframework.integration.channel.ChannelInterceptor#preSend(org.springframework.integration.Message, * org.springframework.integration.MessageChannel) */// w w w . ja v a 2 s. c om @Override public Message<?> preSend(final Message<?> message, final MessageChannel channel) { if (channel.toString().contains("Request")) { UUID requestId = (UUID) message.getHeaders().get(RequestIdMessageHeaderEnhancer.HEADER_NAME_REQUEST_ID); if (requestId == null) { requestId = message.getHeaders().getId(); } this.requestMap.put(requestId, new SimpleEntry<String, Long>( this.messageContentProvider.getUserName(message), System.currentTimeMillis())); } return message; }
From source file:it.pcan.test.integration.amqp.ErrorHandler.java
@ServiceActivator public Message handleException(Message msg) { System.out.println("Exception thrown: " + msg); MessageHandlingException payload = (MessageHandlingException) msg.getPayload(); MessageHeaders headers = payload.getFailedMessage().getHeaders(); HashMap<String, Object> newHeaders = new HashMap<>(headers); newHeaders.putAll(msg.getHeaders()); Throwable cause = payload.getCause(); RuntimeException ex = (cause instanceof RuntimeException) ? (RuntimeException) cause : new RuntimeException(cause); Message m = new GenericMessage(new RuntimeExceptionHolder(ex), newHeaders); return m;/* ww w. j a va2 s . c o m*/ }