Search in sources :

Example 41 with PacketCollector

use of org.jivesoftware.smack.PacketCollector in project ecf by eclipse.

the class SyncPacketSend method getReply.

public static Packet getReply(Connection connection, Packet packet, long timeout) throws XMPPException {
    PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID());
    PacketCollector response = connection.createPacketCollector(responseFilter);
    connection.sendPacket(packet);
    // Wait up to a certain number of seconds for a reply.
    Packet result = response.nextResult(timeout);
    // Stop queuing results
    response.cancel();
    if (result == null) {
        throw new XMPPException(SmackError.NO_RESPONSE_FROM_SERVER);
    } else if (result.getError() != null) {
        throw new XMPPException(result.getError());
    }
    return result;
}
Also used : Packet(org.jivesoftware.smack.packet.Packet) PacketFilter(org.jivesoftware.smack.filter.PacketFilter) PacketCollector(org.jivesoftware.smack.PacketCollector) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 42 with PacketCollector

use of org.jivesoftware.smack.PacketCollector in project ecf by eclipse.

the class Agent method getWorkgroups.

public static Collection<String> getWorkgroups(String serviceJID, String agentJID, Connection connection) throws XMPPException {
    AgentWorkgroups request = new AgentWorkgroups(agentJID);
    request.setTo(serviceJID);
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(request.getPacketID()));
    // Send the request
    connection.sendPacket(request);
    AgentWorkgroups response = (AgentWorkgroups) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return response.getWorkgroups();
}
Also used : AgentWorkgroups(org.jivesoftware.smackx.workgroup.packet.AgentWorkgroups) PacketCollector(org.jivesoftware.smack.PacketCollector) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 43 with PacketCollector

use of org.jivesoftware.smack.PacketCollector in project ecf by eclipse.

the class Agent method getName.

/**
 * Return the agents name.
 *
 * @return - the agents name.
 */
public String getName() throws XMPPException {
    AgentInfo agentInfo = new AgentInfo();
    agentInfo.setType(IQ.Type.GET);
    agentInfo.setTo(workgroupJID);
    agentInfo.setFrom(getUser());
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(agentInfo.getPacketID()));
    // Send the request
    connection.sendPacket(agentInfo);
    AgentInfo response = (AgentInfo) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return response.getName();
}
Also used : PacketCollector(org.jivesoftware.smack.PacketCollector) AgentInfo(org.jivesoftware.smackx.workgroup.packet.AgentInfo) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 44 with PacketCollector

use of org.jivesoftware.smack.PacketCollector in project ecf by eclipse.

the class Agent method setName.

/**
 * Changes the name of the agent in the server. The server may have this functionality
 * disabled for all the agents or for this agent in particular. If the agent is not
 * allowed to change his name then an exception will be thrown with a service_unavailable
 * error code.
 *
 * @param newName the new name of the agent.
 * @throws XMPPException if the agent is not allowed to change his name or no response was
 *                       obtained from the server.
 */
public void setName(String newName) throws XMPPException {
    AgentInfo agentInfo = new AgentInfo();
    agentInfo.setType(IQ.Type.SET);
    agentInfo.setTo(workgroupJID);
    agentInfo.setFrom(getUser());
    agentInfo.setName(newName);
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(agentInfo.getPacketID()));
    // Send the request
    connection.sendPacket(agentInfo);
    IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return;
}
Also used : PacketCollector(org.jivesoftware.smack.PacketCollector) IQ(org.jivesoftware.smack.packet.IQ) AgentInfo(org.jivesoftware.smackx.workgroup.packet.AgentInfo) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 45 with PacketCollector

use of org.jivesoftware.smack.PacketCollector in project ecf by eclipse.

the class TranscriptSearchManager method getSearchForm.

/**
 * Returns the Form to use for searching transcripts. It is unlikely that the server
 * will change the form (without a restart) so it is safe to keep the returned form
 * for future submissions.
 *
 * @param serviceJID the address of the workgroup service.
 * @return the Form to use for searching transcripts.
 * @throws XMPPException if an error occurs while sending the request to the server.
 */
public Form getSearchForm(String serviceJID) throws XMPPException {
    TranscriptSearch search = new TranscriptSearch();
    search.setType(IQ.Type.GET);
    search.setTo(serviceJID);
    PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(search.getPacketID()));
    connection.sendPacket(search);
    TranscriptSearch response = (TranscriptSearch) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Cancel the collector.
    collector.cancel();
    if (response == null) {
        throw new XMPPException("No response from server on status set.");
    }
    if (response.getError() != null) {
        throw new XMPPException(response.getError());
    }
    return Form.getFormFrom(response);
}
Also used : PacketCollector(org.jivesoftware.smack.PacketCollector) TranscriptSearch(org.jivesoftware.smackx.workgroup.packet.TranscriptSearch) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Aggregations

PacketCollector (org.jivesoftware.smack.PacketCollector)46 XMPPException (org.jivesoftware.smack.XMPPException)44 PacketIDFilter (org.jivesoftware.smack.filter.PacketIDFilter)36 IQ (org.jivesoftware.smack.packet.IQ)24 PacketFilter (org.jivesoftware.smack.filter.PacketFilter)21 Packet (org.jivesoftware.smack.packet.Packet)10 ArrayList (java.util.ArrayList)6 AndFilter (org.jivesoftware.smack.filter.AndFilter)6 PacketTypeFilter (org.jivesoftware.smack.filter.PacketTypeFilter)6 MUCAdmin (org.jivesoftware.smackx.packet.MUCAdmin)6 MUCOwner (org.jivesoftware.smackx.packet.MUCOwner)6 FromMatchesFilter (org.jivesoftware.smack.filter.FromMatchesFilter)4 Message (org.jivesoftware.smack.packet.Message)4 OfflineMessageRequest (org.jivesoftware.smackx.packet.OfflineMessageRequest)4 PacketInterceptor (org.jivesoftware.smack.PacketInterceptor)3 Presence (org.jivesoftware.smack.packet.Presence)3 MUCInitialPresence (org.jivesoftware.smackx.packet.MUCInitialPresence)3 Registration (org.jivesoftware.smack.packet.Registration)2 StreamInitiation (org.jivesoftware.smackx.packet.StreamInitiation)2 AgentInfo (org.jivesoftware.smackx.workgroup.packet.AgentInfo)2