Java Code Examples for org.jivesoftware.smack.packet.IQ#setType()

The following examples show how to use org.jivesoftware.smack.packet.IQ#setType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThreadedDummyConnection.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Override
protected void sendStanzaInternal(Stanza packet) {
    super.sendStanzaInternal(packet);

    if (packet instanceof IQ && !timeout) {
        timeout = false;
        // Set reply packet to match one being sent. We haven't started the
        // other thread yet so this is still safe.
        IQ replyPacket = replyQ.peek();

        // If no reply has been set via addIQReply, then we create a simple reply
        if (replyPacket == null) {
            replyPacket = IQ.createResultIQ((IQ) packet);
            replyQ.add(replyPacket);
        }
        replyPacket.setStanzaId(packet.getStanzaId());
        replyPacket.setTo(packet.getFrom());
        if (replyPacket.getType() == null) {
            replyPacket.setType(Type.result);
        }

        new ProcessQueue(replyQ).start();
    }
}
 
Example 2
Source File: VersionManagerTest.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
private void init(Version local, Version remote) {
  XMPPContactsService aliceContactsService = SarosMocks.contactsServiceMockFor(bobJID);
  bobContact = aliceContactsService.getContact(bobJID.getRAW()).get();

  InfoManager infoManager =
      new InfoManager(aliceReceiver, aliceTransmitter, aliceContactsService);
  versionManagerLocal = new VersionManager(local.toString(), infoManager);

  HashMap<String, String> info = new HashMap<>();
  info.put(VersionManager.VERSION_KEY, remote.toString());
  InfoExchangeExtension versionExchangeResponse = new InfoExchangeExtension(info);

  IQ reply = InfoExchangeExtension.PROVIDER.createIQ(versionExchangeResponse);
  reply.setType(IQ.Type.SET);
  reply.setTo(aliceJID.getRAW());
  aliceReceiver.processPacket(reply);
}
 
Example 3
Source File: IBBPacketUtils.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an error IQ.
 *
 * @param from the senders JID
 * @param to the recipients JID
 * @param condition the XMPP error condition
 * @return an error IQ
 */
public static IQ createErrorIQ(Jid from, Jid to, StanzaError.Condition condition) {
    StanzaError xmppError = StanzaError.getBuilder(condition).build();
    IQ errorIQ = new ErrorIQ(xmppError);
    errorIQ.setType(IQ.Type.error);
    errorIQ.setFrom(from);
    errorIQ.setTo(to);
    return errorIQ;
}
 
Example 4
Source File: IBBPacketUtils.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a result IQ.
 *
 * @param from the senders JID
 * @param to the recipients JID
 * @return a result IQ
 */
public static IQ createResultIQ(Jid from, Jid to) {
    IQ result = new EmptyResultIQ();
    result.setType(IQ.Type.result);
    result.setFrom(from);
    result.setTo(to);
    return result;
}
 
Example 5
Source File: InfoManager.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sends Info Packet to a Contact if it has Saros Support.
 *
 * @param contact
 */
private void sendInfo(XMPPContact contact) {
  String sarosJid = contact.getSarosJid().map(JID::toString).orElse(null);
  if (sarosJid == null) return;

  IQ packet = InfoExchangeExtension.PROVIDER.createIQ(new InfoExchangeExtension(localInfo));
  packet.setType(IQ.Type.SET);
  packet.setTo(sarosJid);
  try {
    transmitter.sendPacket(packet);
  } catch (IOException e) {
    log.error("could not send info packet to " + sarosJid, e);
  }
}
 
Example 6
Source File: AgentSession.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * Invites a user or agent to an existing session support. The provided invitee's JID can be of
 * a user, an agent, a queue or a workgroup. In the case of a queue or a workgroup the workgroup service
 * will decide the best agent to receive the invitation.<p>
 *
 * This method will return either when the service returned an ACK of the request or if an error occurred
 * while requesting the invitation. After sending the ACK the service will send the invitation to the target
 * entity. When dealing with agents the common sequence of offer-response will be followed. However, when
 * sending an invitation to a user a standard MUC invitation will be sent.<p>
 *
 * The agent or user that accepted the offer <b>MUST</b> join the room. Failing to do so will make
 * the invitation to fail. The inviter will eventually receive a message error indicating that the invitee
 * accepted the offer but failed to join the room.
 *
 * Different situations may lead to a failed invitation. Possible cases are: 1) all agents rejected the
 * offer and there are no agents available, 2) the agent that accepted the offer failed to join the room or
 * 2) the user that received the MUC invitation never replied or joined the room. In any of these cases
 * (or other failing cases) the inviter will get an error message with the failed notification.
 *
 * @param type type of entity that will get the invitation.
 * @param invitee JID of entity that will get the invitation.
 * @param sessionID ID of the support session that the invitee is being invited.
 * @param reason the reason of the invitation.
 * @throws XMPPErrorException if the sender of the invitation is not an agent or the service failed to process
 *         the request.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void sendRoomInvitation(RoomInvitation.Type type, Jid invitee, String sessionID, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    final RoomInvitation invitation = new RoomInvitation(type, invitee, sessionID, reason);
    IQ iq = new RoomInvitation.RoomInvitationIQ(invitation);
    iq.setType(IQ.Type.set);
    iq.setTo(workgroupJID);
    iq.setFrom(connection.getUser());

    connection.createStanzaCollectorAndSend(iq).nextResultOrThrow();
}
 
Example 7
Source File: AgentSession.java    From Smack with Apache License 2.0 3 votes vote down vote up
/**
 * Transfer an existing session support to another user or agent. The provided invitee's JID can be of
 * a user, an agent, a queue or a workgroup. In the case of a queue or a workgroup the workgroup service
 * will decide the best agent to receive the invitation.<p>
 *
 * This method will return either when the service returned an ACK of the request or if an error occurred
 * while requesting the transfer. After sending the ACK the service will send the invitation to the target
 * entity. When dealing with agents the common sequence of offer-response will be followed. However, when
 * sending an invitation to a user a standard MUC invitation will be sent.<p>
 *
 * Once the invitee joins the support room the workgroup service will kick the inviter from the room.<p>
 *
 * Different situations may lead to a failed transfers. Possible cases are: 1) all agents rejected the
 * offer and there are no agents available, 2) the agent that accepted the offer failed to join the room
 * or 2) the user that received the MUC invitation never replied or joined the room. In any of these cases
 * (or other failing cases) the inviter will get an error message with the failed notification.
 *
 * @param type type of entity that will get the invitation.
 * @param invitee JID of entity that will get the invitation.
 * @param sessionID ID of the support session that the invitee is being invited.
 * @param reason the reason of the invitation.
 * @throws XMPPErrorException if the sender of the invitation is not an agent or the service failed to process
 *         the request.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void sendRoomTransfer(RoomTransfer.Type type, String invitee, String sessionID, String reason) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    final RoomTransfer transfer = new RoomTransfer(type, invitee, sessionID, reason);
    IQ iq = new RoomTransfer.RoomTransferIQ(transfer);
    iq.setType(IQ.Type.set);
    iq.setTo(workgroupJID);
    iq.setFrom(connection.getUser());

    connection.createStanzaCollectorAndSend(iq).nextResultOrThrow();
}