use of org.jivesoftware.smack.filter.PacketIDFilter 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();
}
use of org.jivesoftware.smack.filter.PacketIDFilter 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;
}
use of org.jivesoftware.smack.filter.PacketIDFilter 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);
}
use of org.jivesoftware.smack.filter.PacketIDFilter 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("No response from server.");
} else if (result.getError() != null) {
throw new XMPPException(result.getError());
}
return result;
}
use of org.jivesoftware.smack.filter.PacketIDFilter in project Smack by igniterealtime.
the class IQTest method testFullJIDToOfflineUser.
/**
* Check that sending an IQ to a full JID that is offline returns an IQ ERROR instead
* of being route to some other resource of the same user.
*/
public void testFullJIDToOfflineUser() {
// Request the version from the server.
Version versionRequest = new Version();
versionRequest.setType(IQ.Type.get);
versionRequest.setFrom(getFullJID(0));
versionRequest.setTo(getBareJID(0) + "/Something");
// Create a packet collector to listen for a response.
StanzaCollector collector = getConnection(0).createStanzaCollector(new PacketIDFilter(versionRequest.getStanzaId()));
getConnection(0).sendStanza(versionRequest);
// Wait up to 5 seconds for a result.
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
assertNotNull("No response from server", result);
assertEquals("The server didn't reply with an error packet", IQ.Type.error, result.getType());
assertEquals("Server answered an incorrect error code", 503, result.getError().getCode());
}
Aggregations