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

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

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

Message.setTo介绍

暂无

代码示例

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

/**
 * Creates a new "normal" message to the specified recipient.
 *
 * @param to the recipient of the message.
 */
public Message(Jid to) {
  setTo(to);
}

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

/**
 * Sends a Message to the chat room.
 *
 * @param message the message.
 * @throws NotConnectedException
 * @throws InterruptedException
 */
public void sendMessage(Message message) throws NotConnectedException, InterruptedException {
  message.setTo(room);
  message.setType(Message.Type.groupchat);
  connection.sendStanza(message);
}

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

/**
 * Sends a Message to the chat room.
 *
 * @param message
 *            the message.
 * @throws NotConnectedException
 * @throws InterruptedException
 */
public void sendMessage(Message message) throws NotConnectedException, InterruptedException {
  message.setTo(room);
  message.setType(Message.Type.groupchat);
  connection.sendStanza(message);
}

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

public void send(Message message) throws NotConnectedException, InterruptedException {
  switch (message.getType()) {
  case normal:
  case chat:
    break;
  default:
    throw new IllegalArgumentException("Message must be of type 'normal' or 'chat'");
  }
  Jid to = lockedResource;
  if (to == null) {
    to = jid;
  }
  message.setTo(to);
  connection().sendStanza(message);
}

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

/**
 * Sends a message to the other chat participant. The thread ID, recipient,
 * and message type of the message will automatically set to those of this chat.
 *
 * @param message the message to send.
 * @throws NotConnectedException
 * @throws InterruptedException
 */
public void sendMessage(Message message) throws NotConnectedException, InterruptedException {
  // Force the recipient, message type, and thread ID since the user elected
  // to send the message through this chat object.
  message.setTo(participant);
  message.setType(Message.Type.chat);
  message.setThread(threadID);
  chatManager.sendMessage(this, message);
}

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

/**
 * Invites another user to the room in which one is an occupant using a given Message. The invitation
 * will be sent to the room which in turn will forward the invitation to the invitee.<p>
 *
 * If the room is password-protected, the invitee will receive a password to use to join
 * the room. If the room is members-only, the the invitee may be added to the member list.
 *
 * @param message the message to use for sending the invitation.
 * @param user the user to invite to the room.(e.g. hecate@shakespeare.lit)
 * @param reason the reason why the user is being invited.
 * @throws NotConnectedException
 * @throws InterruptedException
 */
public void invite(Message message, EntityBareJid user, String reason) throws NotConnectedException, InterruptedException {
  // TODO listen for 404 error code when inviter supplies a non-existent JID
  message.setTo(room);
  // Create the MUCUser packet that will include the invitation
  MUCUser mucUser = new MUCUser();
  MUCUser.Invite invite = new MUCUser.Invite(reason, user);
  mucUser.setInvite(invite);
  // Add the MUCUser packet that includes the invitation to the message
  message.addExtension(mucUser);
  connection.sendStanza(message);
}

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

if (replyAddress != null && replyAddress.getJid() != null) {
  reply.setTo(replyAddress.getJid());
  connection.sendStanza(reply);

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

/**
 * Send an empty OMEMO message to contactsDevice in order to forward the ratchet.
 * @param managerGuard
 * @param contactsDevice
 * @throws CorruptedOmemoKeyException if our or their OMEMO key is corrupted.
 * @throws InterruptedException
 * @throws SmackException.NoResponseException
 * @throws NoSuchAlgorithmException if AES encryption fails
 * @throws SmackException.NotConnectedException
 * @throws CryptoFailedException if encryption fails (should not happen though, but who knows...)
 * @throws CannotEstablishOmemoSessionException if we cannot establish a session with contactsDevice.
 */
private void sendRatchetUpdate(OmemoManager.LoggedInOmemoManager managerGuard, OmemoDevice contactsDevice)
    throws CorruptedOmemoKeyException, InterruptedException, SmackException.NoResponseException,
    NoSuchAlgorithmException, SmackException.NotConnectedException, CryptoFailedException,
    CannotEstablishOmemoSessionException {
  OmemoManager manager = managerGuard.get();
  OmemoElement ratchetUpdate = createRatchetUpdateElement(managerGuard, contactsDevice);
  Message m = new Message();
  m.setTo(contactsDevice.getJid());
  m.addExtension(ratchetUpdate);
  manager.getConnection().sendStanza(m);
}

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

Message message = new Message();
message.setStanzaId(parser.getAttributeValue("", "id"));
message.setTo(ParserUtils.getJidAttribute(parser, "to"));
message.setFrom(ParserUtils.getJidAttribute(parser, "from"));
String typeString = parser.getAttributeValue("", "type");

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

/**
 * Send a ratchet update message. This can be used to advance the ratchet of a session in order to maintain forward
 * secrecy.
 *
 * @param recipient recipient
 * @throws CorruptedOmemoKeyException           When the used identityKeys are corrupted
 * @throws CryptoFailedException                When something fails with the crypto
 * @throws CannotEstablishOmemoSessionException When we can't establish a session with the recipient
 * @throws SmackException.NotLoggedInException
 * @throws InterruptedException
 * @throws SmackException.NoResponseException
 * @throws NoSuchAlgorithmException
 * @throws SmackException.NotConnectedException
 */
public void sendRatchetUpdateMessage(OmemoDevice recipient)
    throws SmackException.NotLoggedInException, CorruptedOmemoKeyException, InterruptedException,
    SmackException.NoResponseException, NoSuchAlgorithmException, SmackException.NotConnectedException,
    CryptoFailedException, CannotEstablishOmemoSessionException {
  synchronized (LOCK) {
    Message message = new Message();
    message.setFrom(getOwnJid());
    message.setTo(recipient.getJid());
    OmemoElement element = getOmemoService()
        .createRatchetUpdateElement(new LoggedInOmemoManager(this), recipient);
    message.addExtension(element);
    // Set MAM Storage hint
    StoreHint.set(message);
    connection().sendStanza(message);
  }
}

代码示例来源: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

msg2.setTo(conOne.getUser().asBareJid());
msg2.setThread(msg.getThread());
msg2.setType(Message.Type.chat);

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

if (StringUtils.hasText(to)) {
  try {
    target.setTo(JidCreate.from(to));

代码示例来源:origin: org.igniterealtime.smack/smack

/**
 * Creates a new "normal" message to the specified recipient.
 *
 * @param to the recipient of the message.
 */
public Message(String to) {
  setTo(to);
}

代码示例来源:origin: org.igniterealtime.smack/smack

/**
 * Creates a new message of the specified type to a recipient.
 *
 * @param to the user to send the message to.
 * @param type the message type.
 */
public Message(String to, Type type) {
  setTo(to);
  this.type = type;
}

代码示例来源: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: org.mobicents.resources/mobicents-slee-ra-xmpp-library

/**
 * Creates a new "normal" message to the specified recipient.
 *
 * @param to the recipient of the message.
 */
public Message(String to) {
  if (to == null) {
    throw new IllegalArgumentException("Parameter cannot be null");
  }
  setTo(to);
}

代码示例来源:origin: org.mule.transports/mule-transport-xmpp

public void dispatch(Message message) throws XMPPException
{
  message.setType(Message.Type.groupchat);
  message.setTo(recipient);
  
  chat.sendMessage(message);
}

代码示例来源:origin: org.littleshoot/xmpp

protected Message newError(final String from, final Long tid) {
  final Message error = new Message();
  error.setProperty(P2PConstants.MESSAGE_TYPE,
    P2PConstants.INVITE_ERROR);
  if (tid != null) {
    error.setProperty(P2PConstants.TRANSACTION_ID, tid);
  }
  error.setTo(from);
  return error;
}

代码示例来源:origin: org.littleshoot/xmpp

protected Message newError(final String from, final Long tid) {
  final Message error = new Message();
  error.setProperty(P2PConstants.MESSAGE_TYPE,
    P2PConstants.INVITE_ERROR);
  if (tid != null) {
    error.setProperty(P2PConstants.TRANSACTION_ID, tid);
  }
  error.setTo(from);
  return error;
}

相关文章