congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
GenericMessage
Code IndexAdd Tabnine to your IDE (free)

How to use
GenericMessage
in
org.springframework.messaging.support

Best Java code snippets using org.springframework.messaging.support.GenericMessage (Showing top 20 results out of 918)

origin: spring-projects/spring-framework

/**
 * A shortcut factory method for creating a message with the given payload
 * and {@code MessageHeaders}.
 * <p><strong>Note:</strong> the given {@code MessageHeaders} instance is used
 * directly in the new message, i.e. it is not copied.
 * @param payload the payload to use (never {@code null})
 * @param messageHeaders the headers to use (never {@code null})
 * @return the created message
 * @since 4.1
 */
@SuppressWarnings("unchecked")
public static <T> Message<T> createMessage(@Nullable T payload, MessageHeaders messageHeaders) {
  Assert.notNull(payload, "Payload must not be null");
  Assert.notNull(messageHeaders, "MessageHeaders must not be null");
  if (payload instanceof Throwable) {
    return (Message<T>) new ErrorMessage((Throwable) payload, messageHeaders);
  }
  else {
    return new GenericMessage<>(payload, messageHeaders);
  }
}
origin: spring-projects/spring-framework

@Override
public String toString() {
  if (this.originalMessage == null) {
    return super.toString();
  }
  return super.toString() + " for original " + this.originalMessage;
}
origin: spring-projects/spring-framework

@Test
public void existingHeadersModification() throws InterruptedException {
  Map<String, Object> map = new HashMap<>();
  map.put("foo", "bar");
  map.put("bar", "baz");
  GenericMessage<String> message = new GenericMessage<>("payload", map);
  Thread.sleep(50);
  MessageHeaderAccessor accessor = new MessageHeaderAccessor(message);
  accessor.setHeader("foo", "BAR");
  MessageHeaders actual = accessor.getMessageHeaders();
  assertEquals(3, actual.size());
  assertNotEquals(message.getHeaders().getId(), actual.getId());
  assertEquals("BAR", actual.get("foo"));
  assertEquals("baz", actual.get("bar"));
}
origin: spring-projects/spring-integration

@Test
public void testProcessMessageWithStaticKey() {
  Expression expression = expressionParser.parseExpression("headers[headers.ID]");
  ExpressionEvaluatingMessageProcessor<UUID> processor = new ExpressionEvaluatingMessageProcessor<>(expression);
  processor.setBeanFactory(mock(BeanFactory.class));
  GenericMessage<String> message = new GenericMessage<>("foo");
  assertEquals(message.getHeaders().getId(), processor.processMessage(message));
}
origin: spring-projects/spring-integration-samples

public void runAdapterWithConveter() throws Exception {
  @SuppressWarnings("resource")
  ClassPathXmlApplicationContext context =
      new ClassPathXmlApplicationContext("mongodb-out-config.xml", MongoDbOutboundAdapterDemo.class);
  MessageChannel messageChannel = context.getBean("adapterWithConverter", MessageChannel.class);
  messageChannel.send(new GenericMessage<String>("John, Dow, Palo Alto, 3401 Hillview Ave, 94304, CA"));
}
origin: spring-projects/spring-integration

@Test
public void testMessageHeadersNotConverted() {
  BeanFactoryTypeConverter typeConverter = new BeanFactoryTypeConverter();
  typeConverter.setBeanFactory(new DefaultListableBeanFactory());
  MessageHeaders headers = new GenericMessage<>("foo").getHeaders();
  assertSame(headers, typeConverter.convertValue(headers, TypeDescriptor.valueOf(MessageHeaders.class),
      TypeDescriptor.valueOf(MessageHeaders.class)));
}
origin: spring-projects/spring-integration-samples

private static GenericMessage<Document> createXmlMessageFromResource(String path) throws Exception {
  Resource orderRes = new ClassPathResource(path);
  DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
  builderFactory.setNamespaceAware(true);
  DocumentBuilder builder = builderFactory.newDocumentBuilder();
  Document orderDoc = builder.parse(orderRes.getInputStream());
  return new GenericMessage<Document>(orderDoc);
}
origin: spring-projects/spring-integration-samples

public void runDefaultAdapter() throws Exception {
  @SuppressWarnings("resource")
  ClassPathXmlApplicationContext context =
      new ClassPathXmlApplicationContext("mongodb-out-config.xml", MongoDbOutboundAdapterDemo.class);
  MessageChannel messageChannel = context.getBean("deafultAdapter", MessageChannel.class);
  messageChannel.send(new GenericMessage<Person>(this.createPersonA()));
  messageChannel.send(new GenericMessage<Person>(this.createPersonB()));
  messageChannel.send(new GenericMessage<Person>(this.createPersonC()));
}
origin: spring-projects/spring-batch

  public Message<String> receive() {
    return new GenericMessage<>(payload);
  }
}
origin: spring-projects/spring-framework

  @Override
  public void handleMessage(Message<?> message) throws MessagingException {
    MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
    replyChannel.send(new GenericMessage<>("response"));
  }
});
origin: spring-projects/spring-framework

@SuppressWarnings("unchecked")
public Message<T> build() {
  if (this.originalMessage != null && !this.headerAccessor.isModified()) {
    return this.originalMessage;
  }
  MessageHeaders headersToUse = this.headerAccessor.toMessageHeaders();
  if (this.payload instanceof Throwable) {
    return (Message<T>) new ErrorMessage((Throwable) this.payload, headersToUse);
  }
  else {
    return new GenericMessage<>(this.payload, headersToUse);
  }
}
origin: spring-projects/spring-integration-samples

public static void main(String[] args) {
  AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/helloWorldDemo.xml", HelloWorldApp.class);
  MessageChannel inputChannel = context.getBean("inputChannel", MessageChannel.class);
  PollableChannel outputChannel = context.getBean("outputChannel", PollableChannel.class);
  inputChannel.send(new GenericMessage<String>("World"));
  logger.info("==> HelloWorldDemo: " + outputChannel.receive(0).getPayload());
  context.close();
}
origin: spring-projects/spring-framework

@Test(expected = IllegalStateException.class)
public void sendMissingDestination() {
  Message<?> message = new GenericMessage<Object>("payload");
  this.template.send(message);
}
origin: spring-projects/spring-framework

private MessageHandler createLateReplier(final CountDownLatch latch, final AtomicReference<Throwable> failure) {
  MessageHandler handler = message -> {
    try {
      Thread.sleep(500);
      MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
      replyChannel.send(new GenericMessage<>("response"));
      failure.set(new IllegalStateException("Expected exception"));
    }
    catch (InterruptedException e) {
      failure.set(e);
    }
    catch (MessageDeliveryException ex) {
      String expected = "Reply message received but the receiving thread has exited due to a timeout";
      String actual = ex.getMessage();
      if (!expected.equals(actual)) {
        failure.set(new IllegalStateException(
            "Unexpected error: '" + actual + "'"));
      }
    }
    finally {
      latch.countDown();
    }
  };
  return handler;
}
origin: spring-projects/spring-framework

@Test
public void testToString() {
  ErrorMessage em = new ErrorMessage(new RuntimeException("foo"));
  String emString = em.toString();
  assertThat(emString, not(containsString("original")));
  em = new ErrorMessage(new RuntimeException("foo"), new GenericMessage<>("bar"));
  emString = em.toString();
  assertThat(emString, containsString("original"));
  assertThat(emString, containsString(em.getOriginalMessage().toString()));
}
origin: spring-projects/spring-framework

@Test(expected = IllegalStateException.class)
public void sendAndReceiveMissingDestination() {
  this.template.sendAndReceive(new GenericMessage<Object>("request"));
}
origin: spring-projects/spring-framework

@Test
public void handleMessageWhenBrokerNotRunning() {
  this.handler.handleMessage(new GenericMessage<Object>("payload"));
  assertEquals(Collections.emptyList(), this.handler.messages);
}
origin: spring-projects/spring-integration-samples

  @Test
  public void runDemo() throws Exception{
    ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/integration/SendInstantMessageSample-context.xml");
    
    MessageChannel toUserChannel = context.getBean("toUserChannel", MessageChannel.class);
    Message<String> message = new GenericMessage<String>("Hello from Spring Integration XMPP");
    toUserChannel.send(message);
  }
}
origin: spring-projects/spring-integration-samples

  @Test
  public void runDemo() throws Exception{
    ApplicationContext context = 
      new ClassPathXmlApplicationContext("META-INF/spring/integration/TwitterSendUpdates-context.xml");
    
    MessageChannel twitterOutChannel = context.getBean("twitterOut", MessageChannel.class);
    Message<String> twitterUpdate = new GenericMessage<String>("Testing new Twitter samples for #springintegration");
    twitterOutChannel.send(twitterUpdate);
  }
}
origin: spring-projects/spring-batch

public void write(List<? extends T> items) throws Exception {
  // Block until expecting <= throttle limit
  while (localState.getExpecting() > throttleLimit) {
    getNextResult();
  }
  if (!items.isEmpty()) {
    ChunkRequest<T> request = localState.getRequest(items);
    if (logger.isDebugEnabled()) {
      logger.debug("Dispatching chunk: " + request);
    }
    messagingGateway.send(new GenericMessage<>(request));
    localState.incrementExpected();
  }
}
org.springframework.messaging.supportGenericMessage

Javadoc

An implementation of Message with a generic payload. Once created, a GenericMessage is immutable.

Most used methods

  • <init>
    A constructor with the MessageHeaders instance to use.Note: the given MessageHeaders instance is use
  • toString
  • getHeaders
  • getPayload

Popular in Java

  • Reading from database using SQL prepared statement
  • getSupportFragmentManager (FragmentActivity)
  • setScale (BigDecimal)
  • onRequestPermissionsResult (Fragment)
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now