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

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

本文整理了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

  1. /**
  2. * Creates a new "normal" message to the specified recipient.
  3. *
  4. * @param to the recipient of the message.
  5. */
  6. public Message(Jid to) {
  7. setTo(to);
  8. }

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

  1. /**
  2. * Sends a Message to the chat room.
  3. *
  4. * @param message the message.
  5. * @throws NotConnectedException
  6. * @throws InterruptedException
  7. */
  8. public void sendMessage(Message message) throws NotConnectedException, InterruptedException {
  9. message.setTo(room);
  10. message.setType(Message.Type.groupchat);
  11. connection.sendStanza(message);
  12. }

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

  1. /**
  2. * Sends a Message to the chat room.
  3. *
  4. * @param message
  5. * the message.
  6. * @throws NotConnectedException
  7. * @throws InterruptedException
  8. */
  9. public void sendMessage(Message message) throws NotConnectedException, InterruptedException {
  10. message.setTo(room);
  11. message.setType(Message.Type.groupchat);
  12. connection.sendStanza(message);
  13. }

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

  1. public void send(Message message) throws NotConnectedException, InterruptedException {
  2. switch (message.getType()) {
  3. case normal:
  4. case chat:
  5. break;
  6. default:
  7. throw new IllegalArgumentException("Message must be of type 'normal' or 'chat'");
  8. }
  9. Jid to = lockedResource;
  10. if (to == null) {
  11. to = jid;
  12. }
  13. message.setTo(to);
  14. connection().sendStanza(message);
  15. }

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

  1. /**
  2. * Sends a message to the other chat participant. The thread ID, recipient,
  3. * and message type of the message will automatically set to those of this chat.
  4. *
  5. * @param message the message to send.
  6. * @throws NotConnectedException
  7. * @throws InterruptedException
  8. */
  9. public void sendMessage(Message message) throws NotConnectedException, InterruptedException {
  10. // Force the recipient, message type, and thread ID since the user elected
  11. // to send the message through this chat object.
  12. message.setTo(participant);
  13. message.setType(Message.Type.chat);
  14. message.setThread(threadID);
  15. chatManager.sendMessage(this, message);
  16. }

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

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

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

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

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

  1. /**
  2. * Send an empty OMEMO message to contactsDevice in order to forward the ratchet.
  3. * @param managerGuard
  4. * @param contactsDevice
  5. * @throws CorruptedOmemoKeyException if our or their OMEMO key is corrupted.
  6. * @throws InterruptedException
  7. * @throws SmackException.NoResponseException
  8. * @throws NoSuchAlgorithmException if AES encryption fails
  9. * @throws SmackException.NotConnectedException
  10. * @throws CryptoFailedException if encryption fails (should not happen though, but who knows...)
  11. * @throws CannotEstablishOmemoSessionException if we cannot establish a session with contactsDevice.
  12. */
  13. private void sendRatchetUpdate(OmemoManager.LoggedInOmemoManager managerGuard, OmemoDevice contactsDevice)
  14. throws CorruptedOmemoKeyException, InterruptedException, SmackException.NoResponseException,
  15. NoSuchAlgorithmException, SmackException.NotConnectedException, CryptoFailedException,
  16. CannotEstablishOmemoSessionException {
  17. OmemoManager manager = managerGuard.get();
  18. OmemoElement ratchetUpdate = createRatchetUpdateElement(managerGuard, contactsDevice);
  19. Message m = new Message();
  20. m.setTo(contactsDevice.getJid());
  21. m.addExtension(ratchetUpdate);
  22. manager.getConnection().sendStanza(m);
  23. }

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

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

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

  1. /**
  2. * Send a ratchet update message. This can be used to advance the ratchet of a session in order to maintain forward
  3. * secrecy.
  4. *
  5. * @param recipient recipient
  6. * @throws CorruptedOmemoKeyException When the used identityKeys are corrupted
  7. * @throws CryptoFailedException When something fails with the crypto
  8. * @throws CannotEstablishOmemoSessionException When we can't establish a session with the recipient
  9. * @throws SmackException.NotLoggedInException
  10. * @throws InterruptedException
  11. * @throws SmackException.NoResponseException
  12. * @throws NoSuchAlgorithmException
  13. * @throws SmackException.NotConnectedException
  14. */
  15. public void sendRatchetUpdateMessage(OmemoDevice recipient)
  16. throws SmackException.NotLoggedInException, CorruptedOmemoKeyException, InterruptedException,
  17. SmackException.NoResponseException, NoSuchAlgorithmException, SmackException.NotConnectedException,
  18. CryptoFailedException, CannotEstablishOmemoSessionException {
  19. synchronized (LOCK) {
  20. Message message = new Message();
  21. message.setFrom(getOwnJid());
  22. message.setTo(recipient.getJid());
  23. OmemoElement element = getOmemoService()
  24. .createRatchetUpdateElement(new LoggedInOmemoManager(this), recipient);
  25. message.addExtension(element);
  26. // Set MAM Storage hint
  27. StoreHint.set(message);
  28. connection().sendStanza(message);
  29. }
  30. }

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

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

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

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

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

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

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

  1. /**
  2. * Creates a new "normal" message to the specified recipient.
  3. *
  4. * @param to the recipient of the message.
  5. */
  6. public Message(String to) {
  7. setTo(to);
  8. }

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

  1. /**
  2. * Creates a new message of the specified type to a recipient.
  3. *
  4. * @param to the user to send the message to.
  5. * @param type the message type.
  6. */
  7. public Message(String to, Type type) {
  8. setTo(to);
  9. this.type = type;
  10. }

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

  1. @Test
  2. public void testInboundAdapterUsageWithHeaderMapper() throws Exception {
  3. XMPPConnection xmppConnection = Mockito.mock(XMPPConnection.class);
  4. ChatMessageListeningEndpoint adapter = context.getBean("xmppInboundAdapter", ChatMessageListeningEndpoint.class);
  5. Field xmppConnectionField = ReflectionUtils.findField(ChatMessageListeningEndpoint.class, "xmppConnection");
  6. xmppConnectionField.setAccessible(true);
  7. ReflectionUtils.setField(xmppConnectionField, adapter, xmppConnection);
  8. StanzaListener stanzaListener = TestUtils.getPropertyValue(adapter, "stanzaListener", StanzaListener.class);
  9. Message message = new Message();
  10. message.setBody("hello");
  11. message.setTo(JidCreate.from("oleg"));
  12. JivePropertiesManager.addProperty(message, "foo", "foo");
  13. JivePropertiesManager.addProperty(message, "bar", "bar");
  14. stanzaListener.processStanza(message);
  15. org.springframework.messaging.Message<?> siMessage = xmppInbound.receive(0);
  16. assertEquals("foo", siMessage.getHeaders().get("foo"));
  17. assertEquals("oleg", siMessage.getHeaders().get("xmpp_to"));
  18. }

代码示例来源:origin: org.mobicents.resources/mobicents-slee-ra-xmpp-library

  1. /**
  2. * Creates a new "normal" message to the specified recipient.
  3. *
  4. * @param to the recipient of the message.
  5. */
  6. public Message(String to) {
  7. if (to == null) {
  8. throw new IllegalArgumentException("Parameter cannot be null");
  9. }
  10. setTo(to);
  11. }

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

  1. public void dispatch(Message message) throws XMPPException
  2. {
  3. message.setType(Message.Type.groupchat);
  4. message.setTo(recipient);
  5. chat.sendMessage(message);
  6. }

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

  1. protected Message newError(final String from, final Long tid) {
  2. final Message error = new Message();
  3. error.setProperty(P2PConstants.MESSAGE_TYPE,
  4. P2PConstants.INVITE_ERROR);
  5. if (tid != null) {
  6. error.setProperty(P2PConstants.TRANSACTION_ID, tid);
  7. }
  8. error.setTo(from);
  9. return error;
  10. }

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

  1. protected Message newError(final String from, final Long tid) {
  2. final Message error = new Message();
  3. error.setProperty(P2PConstants.MESSAGE_TYPE,
  4. P2PConstants.INVITE_ERROR);
  5. if (tid != null) {
  6. error.setProperty(P2PConstants.TRANSACTION_ID, tid);
  7. }
  8. error.setTo(from);
  9. return error;
  10. }

相关文章