Search in sources :

Example 1 with AgentInfo

use of org.jivesoftware.smackx.workgroup.packet.AgentInfo 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 2 with AgentInfo

use of org.jivesoftware.smackx.workgroup.packet.AgentInfo 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 3 with AgentInfo

use of org.jivesoftware.smackx.workgroup.packet.AgentInfo in project Smack by igniterealtime.

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 XMPPErrorException if there was an XMPP error returned.
 * @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 setName(String newName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    AgentInfo agentInfo = new AgentInfo();
    agentInfo.setType(IQ.Type.set);
    agentInfo.setTo(workgroupJID);
    agentInfo.setFrom(getUser());
    agentInfo.setName(newName);
    connection.sendIqRequestAndWaitForResponse(agentInfo);
}
Also used : AgentInfo(org.jivesoftware.smackx.workgroup.packet.AgentInfo)

Example 4 with AgentInfo

use of org.jivesoftware.smackx.workgroup.packet.AgentInfo in project Smack by igniterealtime.

the class Agent method getName.

/**
 * Return the agents name.
 *
 * @return - the agents name.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @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 String getName() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    AgentInfo agentInfo = new AgentInfo();
    agentInfo.setType(IQ.Type.get);
    agentInfo.setTo(workgroupJID);
    agentInfo.setFrom(getUser());
    AgentInfo response = connection.sendIqRequestAndWaitForResponse(agentInfo);
    return response.getName();
}
Also used : AgentInfo(org.jivesoftware.smackx.workgroup.packet.AgentInfo)

Aggregations

AgentInfo (org.jivesoftware.smackx.workgroup.packet.AgentInfo)4 PacketCollector (org.jivesoftware.smack.PacketCollector)2 XMPPException (org.jivesoftware.smack.XMPPException)2 PacketIDFilter (org.jivesoftware.smack.filter.PacketIDFilter)2 IQ (org.jivesoftware.smack.packet.IQ)1