Example usage for org.springframework.messaging Message getPayload

List of usage examples for org.springframework.messaging Message getPayload

Introduction

In this page you can find the example usage for org.springframework.messaging Message getPayload.

Prototype

T getPayload();

Source Link

Document

Return the message payload.

Usage

From source file:org.springframework.xd.reactor.SynchronousDispatcherMessageHandler.java

@Override
protected void handleMessageInternal(Message<?> message) throws Exception {

    if (ClassUtils.isAssignable(inputType.getRawClass(), message.getClass())) {
        stream.onNext(message);/*from  www. j a  va  2 s  .  c  om*/
    } else if (ClassUtils.isAssignable(inputType.getRawClass(), message.getPayload().getClass())) {
        //TODO handle type conversion of payload to input type if possible
        stream.onNext(message.getPayload());
    }

    if (logger.isDebugEnabled()) {
        logger.debug(consume.debug());
    }
}

From source file:org.springframework.xd.rxjava.MultipleSubjectMessageHandler.java

@Override
protected void handleMessageInternal(Message<?> message) throws Exception {
    Subject subjectToUse = getSubject(message);
    if (ClassUtils.isAssignable(inputType.getRawClass(), message.getClass())) {
        subjectToUse.onNext(message);/*from  ww w . j a v a 2 s .com*/
    } else if (ClassUtils.isAssignable(inputType.getRawClass(), message.getPayload().getClass())) {
        subjectToUse.onNext(message.getPayload());
    } else {
        throw new MessageHandlingException(message, "Processor signature does not match [" + message.getClass()
                + "] or [" + message.getPayload().getClass() + "]");
    }
}

From source file:org.springframework.xd.rxjava.SubjectMessageHandler.java

@Override
protected void handleMessageInternal(Message<?> message) throws Exception {
    if (ClassUtils.isAssignable(inputType.getRawClass(), message.getClass())) {
        subject.onNext(message);/* w  w w .  j a va2s  .co m*/
    } else if (ClassUtils.isAssignable(inputType.getRawClass(), message.getPayload().getClass())) {
        subject.onNext(message.getPayload());
    } else {
        throw new MessageHandlingException(message, "Processor signature does not match [" + message.getClass()
                + "] or [" + message.getPayload().getClass() + "]");
    }
}

From source file:org.springframework.xd.shell.command.JobCommandTests.java

@Test
public void testLaunchJobTwiceWhereMakeUniqueIsFalse() throws Exception {
    logger.info("Launch batch job (makeUnique=false) twice");
    String jobName = generateJobName();
    // Batch 3.0 requires at least one parameter to reject duplicate executions of an instance
    String myJobParams = "{\"-param(long)\":\"12345\"}";
    JobParametersHolder.reset();//  ww  w .ja  v a  2s .c o  m
    final JobParametersHolder jobParametersHolder = new JobParametersHolder();

    executeJobCreate(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR + " --makeUnique=false");
    checkForJobInList(jobName, JOB_WITH_PARAMETERS_DESCRIPTOR + " --makeUnique=false", true);
    executeJobLaunch(jobName, myJobParams);
    assertTrue("The countdown latch expired and did not count down.", jobParametersHolder.isDone());

    final SynchronousQueue<Message<?>> rendezvous = new SynchronousQueue<Message<?>>();
    MessageHandler handler = new MessageHandler() {

        @Override
        public void handleMessage(Message<?> message) throws MessagingException {
            rendezvous.add(message);
        }
    };
    getErrorChannel().subscribe(handler);
    executeCommand("job launch --name " + jobName + " --params " + myJobParams);
    Message<?> error = rendezvous.poll(5, TimeUnit.SECONDS);
    getErrorChannel().unsubscribe(handler);
    assertNotNull("expected an error message", error);
    Object payload = error.getPayload();
    assertTrue("payload should be a MessagingException", payload instanceof MessagingException);
    assertEquals(JobInstanceAlreadyCompleteException.class,
            ((MessagingException) payload).getCause().getClass());
}

From source file:org.springframework.yarn.integration.ip.mind.MindIntegrationRawTests.java

@Test
public void testVanillaChannels() throws Exception {
    log.info("randomTestPort=" + randomTestPort);
    waitPort();/*from  w  w w.  jav a2 s .co m*/

    assertNotNull(socketSupport);

    SimpleTestRequest req = new SimpleTestRequest();
    ObjectMapper objectMapper = new ObjectMapper();

    String content = objectMapper.writeValueAsString(req);

    Map<String, String> headers = new HashMap<String, String>();
    headers.put("type", "SimpleTestRequest");
    MindRpcMessageHolder holder = new MindRpcMessageHolder(headers, content);
    clientRequestChannel.send(MessageBuilder.withPayload(holder).build());

    Message<?> receive = clientResponseChannel.receive();
    holder = (MindRpcMessageHolder) receive.getPayload();
    String contentRes = new String(holder.getContent());
    assertNotNull(contentRes);
}

From source file:org.springframework.yarn.support.statemachine.AbstractStateMachine.java

private void processEventQueue() {
    log.debug("Process event queue");
    Message<E> queuedEvent = null;
    while ((queuedEvent = eventQueue.poll()) != null) {
        Message<E> defer = null;//w w  w .j a v a  2s.c  om
        for (Transition<S, E> transition : transitions) {
            State<S, E> source = transition.getSource();
            State<S, E> target = transition.getTarget();
            Trigger<S, E> trigger = transition.getTrigger();
            if (source.equals(currentState)) {
                if (trigger != null && trigger.evaluate(queuedEvent.getPayload())) {
                    transition.transit(queuedEvent.getHeaders());
                    if (transition.getKind() != TransitionKind.INTERNAL) {
                        switchToState(target);
                    }
                    break;
                } else if (source.getDeferredEvents() != null
                        && source.getDeferredEvents().contains(queuedEvent.getPayload())) {
                    defer = queuedEvent;
                }
            }
        }
        if (defer != null) {
            log.info("Deferring event " + defer);
            deferList.addLast(defer);
        }
    }
}

From source file:org.springframework.yarn.support.statemachine.AbstractStateMachine.java

private void processDeferList() {
    log.debug("Process defer list");
    ListIterator<Message<E>> iterator = deferList.listIterator();
    while (iterator.hasNext()) {
        Message<E> event = iterator.next();
        for (Transition<S, E> transition : transitions) {
            State<S, E> source = transition.getSource();
            State<S, E> target = transition.getTarget();
            Trigger<S, E> trigger = transition.getTrigger();
            if (source.equals(currentState)) {
                if (trigger != null && trigger.evaluate(event.getPayload())) {
                    transition.transit(event.getHeaders());
                    if (transition.getKind() != TransitionKind.INTERNAL) {
                        switchToState(target);
                    }/*  www  .  j  a  va2s.  co  m*/
                    iterator.remove();
                }
            }
        }
    }
}