List of usage examples for org.springframework.messaging Message getHeaders
MessageHeaders getHeaders();
From source file:biz.c24.io.spring.integration.config.ValidatingHeaderEnricherTests.java
@Test public void testValid() { Employee employee = new Employee(); employee.setSalutation("Mr"); employee.setFirstName("Andy"); employee.setLastName("Acheson"); employee.setJobTitle("Software Developer"); template.convertAndSend(employee);/*from www . ja v a 2s.co m*/ @SuppressWarnings("unchecked") Message<Employee> result = (Message<Employee>) outputChannel.receive(1); assertThat(result, is(not(nullValue()))); MessageHeaders headers = result.getHeaders(); assertThat(headers.containsKey(C24Headers.VALID), is(true)); assertThat(headers.get(C24Headers.VALID, Boolean.class), is(true)); assertThat(headers.containsKey(C24Headers.FAIL_EVENTS), is(true)); assertThat(headers.get(C24Headers.FAIL_EVENTS, Collection.class).size(), is(0)); assertThat(headers.containsKey(C24Headers.PASS_EVENTS), is(true)); assertThat(headers.get(C24Headers.PASS_EVENTS, Collection.class).size(), is(greaterThan(0))); }
From source file:biz.c24.io.spring.integration.config.ValidatingHeaderEnricherTests.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);// w ww . j av a 2 s .c o m @SuppressWarnings("unchecked") Message<Employee> result = (Message<Employee>) outputChannel.receive(1); assertThat(result, is(not(nullValue()))); MessageHeaders headers = result.getHeaders(); assertThat(headers.containsKey(C24Headers.VALID), is(true)); assertThat(headers.get(C24Headers.VALID, Boolean.class), is(false)); assertThat(headers.containsKey(C24Headers.FAIL_EVENTS), is(true)); assertThat(headers.get(C24Headers.FAIL_EVENTS, Collection.class).size(), is(2)); assertThat(headers.containsKey(C24Headers.PASS_EVENTS), is(true)); assertThat(headers.get(C24Headers.PASS_EVENTS, Collection.class).size(), is(greaterThan(0))); }
From source file:xolpoc.plugins.StreamPlugin.java
private void track(final Module module, MessageChannel channel, final Map<String, Object> historyProps) { final MessageBuilderFactory messageBuilderFactory = module.getComponent( IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME, MessageBuilderFactory.class) == null ? new DefaultMessageBuilderFactory() : module.getComponent(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME, MessageBuilderFactory.class); if (channel instanceof ChannelInterceptorAware) { ((ChannelInterceptorAware) channel).addInterceptor(new ChannelInterceptorAdapter() { @Override/*from w w w . j a va 2 s. c om*/ public Message<?> preSend(Message<?> message, MessageChannel channel) { @SuppressWarnings("unchecked") Collection<Map<String, Object>> history = (Collection<Map<String, Object>>) message.getHeaders() .get(XdHeaders.XD_HISTORY); if (history == null) { history = new ArrayList<Map<String, Object>>(1); } else { history = new ArrayList<Map<String, Object>>(history); } Map<String, Object> map = new LinkedHashMap<String, Object>(); map.putAll(historyProps); map.put("thread", Thread.currentThread().getName()); history.add(map); Message<?> out = messageBuilderFactory.fromMessage(message) .setHeader(XdHeaders.XD_HISTORY, history).build(); return out; } }); } }
From source file:apiserver.services.images.services.ImageInfoService.java
public Object execute(Message<?> message) throws IOException { FileInfoJob props = (FileInfoJob) message.getPayload(); Map result = new HashMap(); result.put(ApiServerConstants.WIDTH, props.getBufferedImage().getWidth()); result.put(ApiServerConstants.HEIGHT, props.getBufferedImage().getHeight()); // return results MessageBuilder mb = MessageBuilder.withPayload(result); mb.copyHeaders(message.getHeaders()); return mb.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 a va 2 s .c o 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.thingsplode.server.bus.executors.AbstractSyncExecutor.java
public void process(Message<?> msg) { AbstractRequest req = (AbstractRequest) msg.getPayload(); Device callerDevice = getDeviceRepo().findByIdentification(req.getDeviceId()); if (callerDevice == null) { throw new IllegalStateException(String.format("The device identified by id [%s] is not registered", req.getDeviceId() != null ? req.getDeviceId() : "<NULL>")); }/* w ww . j av a 2 s . c o m*/ try { executeImpl((REQ) msg.getPayload(), msg.getHeaders(), callerDevice); } catch (SrvExecutionException ex) { logger.error(ex.getMessage(), ex); getMsgTemplate().send(MessageBuilder .withPayload(new ErrorMessage(ex.getExecutionStatus(), ex.getResponseCode(), ex)).build()); } catch (Exception ex) { logger.error(ex.getMessage(), ex); getMsgTemplate().send(MessageBuilder .withPayload(new ErrorMessage(ExecutionStatus.DECLINED, determineResponseCode(ex), ex)) .build()); } }
From source file:com.consol.citrus.samples.greeting.GreetingService.java
@Override public Message<GreetingResponseMessage> processMessage(Message<GreetingRequestMessage> request) { GreetingResponseMessage response = new GreetingResponseMessage(); response.setOperation(request.getPayload().getOperation()); response.setCorrelationId(request.getPayload().getCorrelationId()); response.setUser("GreetingService"); response.setText("Hello " + request.getPayload().getUser() + "!"); MessageBuilder<GreetingResponseMessage> builder = MessageBuilder.withPayload(response); builder.setHeader("CorrelationId", request.getHeaders().get("CorrelationId")); builder.setHeader("Operation", "sayHello"); builder.setHeader("Type", "response"); return builder.build(); }
From source file:com.googlecode.msidor.springframework.integration.channel.ConcurentOrderedMultiQueueChannel.java
/** * Get the queue ID from message based on its header value * @param message to get the queue id from * @return queue id based on message's header value *///from ww w . j av a 2 s. c om private Object getQueueIdFromMessage(Message<?> message) { if (getQueueIdHeaderParameter() != null && message.getHeaders().containsKey(getQueueIdHeaderParameter())) { return message.getHeaders().get(getQueueIdHeaderParameter()); } return null; }
From source file:com.googlecode.msidor.springframework.integration.channel.ConcurentOrderedMultiQueueChannel.java
/** * Get the execution ID from message based on its header value * @param message to get the execution id from * @return execution id based on message's header value *//*from w w w . ja v a2 s .c om*/ private Object getExecutionIdFromMessage(Message<?> message) { if (getExecutionIdHeaderParameter() != null && message.getHeaders().containsKey(getExecutionIdHeaderParameter())) { return message.getHeaders().get(getExecutionIdHeaderParameter()); } return null; }
From source file:com.vedri.mtp.frontend.support.stomp.DefaultSubscriptionRegistry.java
@Override protected void addSubscriptionInternal(String sessionId, String subsId, String destination, Message<?> message) { Expression expression = null; MessageHeaders headers = message.getHeaders(); String selector = SimpMessageHeaderAccessor.getFirstNativeHeader(getSelectorHeaderName(), headers); if (selector != null) { try {/*from w w w . j av a2 s.c o m*/ expression = this.expressionParser.parseExpression(selector); this.selectorHeaderInUse = true; if (logger.isTraceEnabled()) { logger.trace("Subscription selector: [" + selector + "]"); } } catch (Throwable ex) { if (logger.isDebugEnabled()) { logger.debug("Failed to parse selector: " + selector, ex); } } } this.subscriptionRegistry.addSubscription(sessionId, subsId, destination, expression); this.destinationCache.updateAfterNewSubscription(destination, sessionId, subsId); }