org.jivesoftware.smack.packet.Message.setBody()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(164)

本文整理了Java中org.jivesoftware.smack.packet.Message.setBody()方法的一些代码示例,展示了Message.setBody()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.setBody()方法的具体详情如下:
包路径:org.jivesoftware.smack.packet.Message
类名称:Message
方法名:setBody

Message.setBody介绍

[英]Sets the body of the message.
[中]设置消息的正文。

代码示例

代码示例来源:origin: igniterealtime/Smack

/**
 * Set a hint about the message being OX-IM encrypted as body of the message.
 *
 * @param message message
 */
private static void setOXBodyHint(Message message) {
  message.setBody("This message is encrypted using XEP-0374: OpenPGP for XMPP: Instant Messaging.");
}

代码示例来源:origin: igniterealtime/Smack

/**
 * Creates a new message to the specified recipient and with the specified body.
 *
 * @param to the user to send the message to.
 * @param body the body of the message.
 */
public Message(Jid to, String body) {
  this(to);
  setBody(body);
}

代码示例来源:origin: igniterealtime/Smack

/**
 * Sets the body of the message.
 *
 * @param body the body of the message.
 * @see #setBody(String)
 * @since 4.2
 */
public void setBody(CharSequence body) {
  String bodyString;
  if (body != null) {
    bodyString = body.toString();
  } else {
    bodyString = null;
  }
  setBody(bodyString);
}

代码示例来源:origin: igniterealtime/Smack

/**
 * Sends a message to the chat room.
 *
 * @param text the text of the message to send.
 * @throws NotConnectedException
 * @throws InterruptedException
 */
public void sendMessage(String text) throws NotConnectedException, InterruptedException {
  Message message = createMessage();
  message.setBody(text);
  connection.sendStanza(message);
}

代码示例来源:origin: igniterealtime/Smack

/**
 * Sends a message to the chat room.
 *
 * @param text
 *            the text of the message to send.
 * @throws NotConnectedException
 * @throws InterruptedException
 */
public void sendMessage(String text) throws NotConnectedException, InterruptedException {
  Message message = createMessage();
  message.setBody(text);
  connection.sendStanza(message);
}

代码示例来源:origin: igniterealtime/Smack

/**
 * Sends the specified text as a message to the other chat participant.
 * This is a convenience method for:
 *
 * <pre>
 *     Message message = chat.createMessage();
 *     message.setBody(messageText);
 *     chat.sendMessage(message);
 * </pre>
 *
 * @param text the text to send.
 * @throws NotConnectedException
 * @throws InterruptedException
 */
public void sendMessage(String text) throws NotConnectedException, InterruptedException {
  Message message = new Message();
  message.setBody(text);
  sendMessage(message);
}

代码示例来源:origin: igniterealtime/Smack

private static void send(String messageString, XMPPConnection from, XMPPConnection to)
        throws NotConnectedException, InterruptedException {
  Message message = new Message(to.getUser());
  message.setBody(messageString);
  from.sendStanza(message);
}

代码示例来源:origin: igniterealtime/Smack

public void send(CharSequence message) throws NotConnectedException, InterruptedException {
  Message stanza = new Message();
  stanza.setBody(message);
  stanza.setType(Message.Type.chat);
  send(stanza);
}

代码示例来源:origin: igniterealtime/Smack

private static Message createChatPacket(final String threadId, final boolean isEntityFullJid) {
  Message chatMsg = new Message(JidTestUtil.BARE_JID_1, Message.Type.chat);
  chatMsg.setBody("the body message - " + System.currentTimeMillis());
  Jid jid;
  if (isEntityFullJid) {
    jid = JidTestUtil.DUMMY_AT_EXAMPLE_ORG_SLASH_DUMMYRESOURCE;
  } else {
    jid = JidTestUtil.DUMMY_AT_EXAMPLE_ORG;
  }
  chatMsg.setFrom(jid);
  chatMsg.setThread(threadId);
  return chatMsg;
}

代码示例来源:origin: igniterealtime/Smack

@Test
public void oneMessageBodyTest() throws IOException, SAXException {
  final String messageBody = "This is a test of the emergency broadcast system.";
  StringBuilder controlBuilder = new StringBuilder();
  controlBuilder.append("<message>")
      .append("<body>")
      .append(messageBody)
      .append("</body>")
      .append("</message>");
  String control = controlBuilder.toString();
  Message message = getNewMessage();
  message.setBody(messageBody);
  assertEquals(messageBody, message.getBody());
  assertXMLEqual(control, message.toXML(StreamOpen.CLIENT_NAMESPACE).toString());
}

代码示例来源:origin: igniterealtime/Smack

/**
   * Return the OmemoElement wrapped in a Message ready to be sent.
   * The message is addressed to recipient, contains the OmemoElement
   * as well as an optional clear text hint as body, a MAM storage hint
   * and an EME hint about OMEMO encryption.
   *
   * @param recipient recipient for the to-field of the message.
   * @return Message
   */
  public Message asMessage(Jid recipient) {
    Message messageStanza = new Message(recipient, Message.Type.chat);
    messageStanza.addExtension(getElement());
    if (OmemoConfiguration.getAddOmemoHintBody()) {
      messageStanza.setBody(BODY_OMEMO_HINT);
    }
    StoreHint.set(messageStanza);
    messageStanza.addExtension(new ExplicitMessageEncryptionElement(OMEMO_NAMESPACE_V_AXOLOTL, OMEMO));
    return messageStanza;
  }
}

代码示例来源:origin: igniterealtime/Smack

@Test
public void removeMessageBodyTest() {
  Message message = getNewMessage();
  message.setBody("test");
  assertTrue(message.getBodies().size() == 1);
  message.setBody(null);
  assertTrue(message.getBodies().size() == 0);
  assertFalse(message.removeBody("sp"));
  Message.Body body = message.addBody("es", "test");
  assertTrue(message.getBodies().size() == 1);
  message.removeBody(body);
  assertTrue(message.getBodies().size() == 0);
}

代码示例来源:origin: igniterealtime/Smack

@Test
public void checkMarkableExtension() throws Exception {
  Message message = new Message(JidCreate.from("ingrichard@royalty.england.lit/throne"));
  message.setStanzaId("message-1");
  message.setBody("My lord, dispatch; read o'er these articles.");
  message.addExtension(ChatMarkersElements.MarkableExtension.INSTANCE);
  Assert.assertEquals(markableMessageStanza, message.toXML(null).toString());
}

代码示例来源:origin: igniterealtime/Smack

String messageId = message.setStanzaId();
final String messageBody = "Test MAM message (" + testRunId + ')';
message.setBody(messageBody);

代码示例来源:origin: igniterealtime/Smack

msg.setBody("To enter a case please fill out this form and send it back to me");
msg.addExtension(formToSend.getDataFormToSend());
  msg2.setThread(msg.getThread());
  msg2.setType(Message.Type.chat);
  msg2.setBody("To enter a case please fill out this form and send it back to me");

代码示例来源:origin: igniterealtime/Smack

@Test
public void checkMamQueryResults() throws Exception {
  Message message = new Message();
  message.setStanzaId("iasd207");
  message.setFrom(JidCreate.from("coven@chat.shakespeare.lit"));
  message.setTo(JidCreate.from("hag66@shakespeare.lit/pda"));
  GregorianCalendar calendar = new GregorianCalendar(2002, 10 - 1, 13, 23, 58, 37);
  calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
  Date date = calendar.getTime();
  DelayInformation delay = new DelayInformation(date);
  Message forwardedMessage = new Message();
  forwardedMessage.setFrom(JidCreate.from("coven@chat.shakespeare.lit/firstwitch"));
  forwardedMessage.setStanzaId("162BEBB1-F6DB-4D9A-9BD8-CFDCC801A0B2");
  forwardedMessage.setType(Type.chat);
  forwardedMessage.setBody("Thrice the brinded cat hath mew.");
  Forwarded forwarded = new Forwarded(delay, forwardedMessage);
  message.addExtension(new MamResultExtension("g27", "34482-21985-73620", forwarded));
  // FIXME: The order of assertEquals is reversed, fix it by switching it.
  Assert.assertEquals(message.toXML(StreamOpen.CLIENT_NAMESPACE).toString(), mamQueryResultExample);
  MamResultExtension mamResultExtension = MamResultExtension.from(message);
  Assert.assertEquals(mamResultExtension.getId(), "34482-21985-73620");
  Assert.assertEquals(mamResultExtension.getForwarded().getDelayInformation().getStamp(), date);
  Message resultMessage = (Message) mamResultExtension.getForwarded().getForwardedStanza();
  Assert.assertEquals(resultMessage.getFrom(), JidCreate.from("coven@chat.shakespeare.lit/firstwitch"));
  Assert.assertEquals(resultMessage.getStanzaId(), "162BEBB1-F6DB-4D9A-9BD8-CFDCC801A0B2");
  Assert.assertEquals(resultMessage.getType(), Type.chat);
  Assert.assertEquals(resultMessage.getBody(), "Thrice the brinded cat hath mew.");
}

代码示例来源:origin: igniterealtime/Smack

msg.setBody("Body of the chat");
addProperty(msg, "favoriteColor", "red");
addProperty(msg, "age", 30);

代码示例来源:origin: spring-projects/spring-integration

@Test
@Ignore
public void validateSmackMessageSent() throws XmppStringprepException {
  ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("SmackMessageSampleTest-context.xml",
      this.getClass());
  MessageChannel xmppInput = ac.getBean("xmppInput", MessageChannel.class);
  org.jivesoftware.smack.packet.Message smackMessage =
      new org.jivesoftware.smack.packet.Message(JidCreate.from("springintegration@gmail.com"));
  smackMessage.setBody("Message sent as Smack Message");
  Message<org.jivesoftware.smack.packet.Message> message = new GenericMessage<>(smackMessage);
  xmppInput.send(message);
  ac.close();
}

代码示例来源:origin: spring-projects/spring-integration

@Test
public void testInboundAdapterUsageWithHeaderMapper() throws Exception {
  XMPPConnection xmppConnection = Mockito.mock(XMPPConnection.class);
  ChatMessageListeningEndpoint adapter = context.getBean("xmppInboundAdapter", ChatMessageListeningEndpoint.class);
  Field xmppConnectionField = ReflectionUtils.findField(ChatMessageListeningEndpoint.class, "xmppConnection");
  xmppConnectionField.setAccessible(true);
  ReflectionUtils.setField(xmppConnectionField, adapter, xmppConnection);
  StanzaListener stanzaListener = TestUtils.getPropertyValue(adapter, "stanzaListener", StanzaListener.class);
  Message message = new Message();
  message.setBody("hello");
  message.setTo(JidCreate.from("oleg"));
  JivePropertiesManager.addProperty(message, "foo", "foo");
  JivePropertiesManager.addProperty(message, "bar", "bar");
  stanzaListener.processStanza(message);
  org.springframework.messaging.Message<?> siMessage = xmppInbound.receive(0);
  assertEquals("foo", siMessage.getHeaders().get("foo"));
  assertEquals("oleg", siMessage.getHeaders().get("xmpp_to"));
}

代码示例来源:origin: spring-projects/spring-integration

@Test
public void testWithErrorChannel() throws Exception {
  DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
  XMPPConnection connection = mock(XMPPConnection.class);
  bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, connection);
  ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint();
  DirectChannel outChannel = new DirectChannel();
  outChannel.subscribe(message -> {
    throw new RuntimeException("ooops");
  });
  PollableChannel errorChannel = new QueueChannel();
  endpoint.setBeanFactory(bf);
  endpoint.setOutputChannel(outChannel);
  endpoint.setErrorChannel(errorChannel);
  endpoint.afterPropertiesSet();
  StanzaListener listener = (StanzaListener) TestUtils.getPropertyValue(endpoint, "stanzaListener");
  Message smackMessage = new Message(JidCreate.from("kermit@frog.com"));
  smackMessage.setBody("hello");
  smackMessage.setThread("1234");
  listener.processStanza(smackMessage);
  ErrorMessage msg =
      (ErrorMessage) errorChannel.receive();
  assertEquals("hello", ((MessagingException) msg.getPayload()).getFailedMessage().getPayload());
}

相关文章