本文整理汇总了Java中org.jivesoftware.smack.filter.PacketIDFilter类的典型用法代码示例。如果您正苦于以下问题:Java PacketIDFilter类的具体用法?Java PacketIDFilter怎么用?Java PacketIDFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PacketIDFilter类属于org.jivesoftware.smack.filter包,在下文中一共展示了PacketIDFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFullJIDToOfflineUser
import org.jivesoftware.smack.filter.PacketIDFilter; //导入依赖的package包/类
/**
* 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.
PacketCollector collector = getConnection(0).createPacketCollector(
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());
}
示例2: testIQNotImplemented
import org.jivesoftware.smack.filter.PacketIDFilter; //导入依赖的package包/类
/**
* Verify that when Smack receives a "not implemented IQ" answers with an IQ packet
* with error code 501.
*/
public void testIQNotImplemented() {
// Create a new type of IQ to send. The new IQ will include a
// non-existant namespace to cause the "feature-not-implemented" answer
IQ iqPacket = new IQ() {
public String getChildElementXML() {
return "<query xmlns=\"my:ns:test\"/>";
}
};
iqPacket.setTo(getFullJID(1));
iqPacket.setType(IQ.Type.get);
// Send the IQ and wait for the answer
PacketCollector collector = getConnection(0).createPacketCollector(
new PacketIDFilter(iqPacket.getStanzaId()));
getConnection(0).sendStanza(iqPacket);
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
if (response == null) {
fail("No response from the other user.");
}
assertEquals("The received IQ is not of type ERROR", IQ.Type.error, response.getType());
assertEquals("The error code is not 501", 501, response.getError().getCode());
collector.cancel();
}
示例3: testRespondWithErrorOnInBandBytestreamRequest
import org.jivesoftware.smack.filter.PacketIDFilter; //导入依赖的package包/类
/**
* Target should respond with not-acceptable error if no listeners for incoming In-Band
* Bytestream requests are registered.
*
* @throws XMPPException should not happen
*/
public void testRespondWithErrorOnInBandBytestreamRequest() throws XMPPException {
XMPPConnection targetConnection = getConnection(0);
XMPPConnection initiatorConnection = getConnection(1);
Open open = new Open("sessionID", 1024);
open.setFrom(initiatorConnection.getUser());
open.setTo(targetConnection.getUser());
PacketCollector collector = initiatorConnection.createPacketCollector(new PacketIDFilter(
open.getStanzaId()));
initiatorConnection.sendStanza(open);
Packet result = collector.nextResult();
assertNotNull(result.getError());
assertEquals(XMPPError.Condition.no_acceptable.toString(), result.getError().getCondition());
}
示例4: testRespondWithErrorOnSocks5BytestreamRequest
import org.jivesoftware.smack.filter.PacketIDFilter; //导入依赖的package包/类
/**
* Target should respond with not-acceptable error if no listeners for incoming Socks5
* bytestream requests are registered.
*
* @throws XMPPException should not happen
*/
public void testRespondWithErrorOnSocks5BytestreamRequest() throws XMPPException {
XMPPConnection targetConnection = getConnection(0);
XMPPConnection initiatorConnection = getConnection(1);
Bytestream bytestreamInitiation = Socks5PacketUtils.createBytestreamInitiation(
initiatorConnection.getUser(), targetConnection.getUser(), "session_id");
bytestreamInitiation.addStreamHost("proxy.localhost", "127.0.0.1", 7777);
PacketCollector collector = initiatorConnection.createPacketCollector(new PacketIDFilter(
bytestreamInitiation.getStanzaId()));
initiatorConnection.sendStanza(bytestreamInitiation);
Packet result = collector.nextResult();
assertNotNull(result.getError());
assertEquals(XMPPError.Condition.no_acceptable.toString(), result.getError().getCondition());
}
示例5: testGetServerVersion
import org.jivesoftware.smack.filter.PacketIDFilter; //导入依赖的package包/类
/**
* Get the version of the server and make sure that all the required data is present
*
* Note: This test expects the server to answer an iq:version packet.
*/
public void testGetServerVersion() {
Version version = new Version();
version.setType(IQ.Type.get);
version.setTo(getServiceName());
// Create a packet collector to listen for a response.
PacketCollector collector = getConnection(0).createPacketCollector(new PacketIDFilter(version.getStanzaId()));
getConnection(0).sendStanza(version);
// Wait up to 5 seconds for a result.
IQ result = (IQ)collector.nextResult(5000);
// Close the collector
collector.cancel();
assertNotNull("No result from the server", result);
assertEquals("Incorrect result type", IQ.Type.result, result.getType());
assertNotNull("No name specified in the result", ((Version)result).getName());
assertNotNull("No version specified in the result", ((Version)result).getVersion());
}
示例6: getLastActivity
import org.jivesoftware.smack.filter.PacketIDFilter; //导入依赖的package包/类
/**
* Retrieve the last activity of a particular jid.
* @param con the current Connection.
* @param jid the JID of the user.
* @return the LastActivity packet of the jid.
* @throws XMPPException thrown if a server error has occured.
* @deprecated This method only retreives the lapsed time since the last logout of a particular jid.
* Replaced by {@link org.jivesoftware.smackx.LastActivityManager#getLastActivity(Connection, String) getLastActivity}
*/
public static LastActivity getLastActivity(Connection con, String jid) throws XMPPException {
LastActivity activity = new LastActivity();
jid = StringUtils.parseBareAddress(jid);
activity.setTo(jid);
PacketCollector collector = con.createPacketCollector(new PacketIDFilter(activity.getPacketID()));
con.sendPacket(activity);
LastActivity response = (LastActivity) 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;
}
示例7: authenticateAnonymously
import org.jivesoftware.smack.filter.PacketIDFilter; //导入依赖的package包/类
public String authenticateAnonymously() throws XMPPException {
// Create the authentication packet we'll send to the server.
Authentication auth = new Authentication();
PacketCollector collector =
connection.createPacketCollector(new PacketIDFilter(auth.getPacketID()));
// Send the packet.
connection.sendPacket(auth);
// Wait up to a certain number of seconds for a response from the server.
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
if (response == null) {
throw new XMPPException("Anonymous login failed.");
}
else if (response.getType() == IQ.Type.ERROR) {
throw new XMPPException(response.getError());
}
// We're done with the collector, so explicitly cancel it.
collector.cancel();
if (response.getTo() != null) {
return response.getTo();
}
else {
return connection.getServiceName() + "/" + ((Authentication) response).getResource();
}
}
示例8: changePassword
import org.jivesoftware.smack.filter.PacketIDFilter; //导入依赖的package包/类
/**
* Changes the password of the currently logged-in account. This operation can only
* be performed after a successful login operation has been completed. Not all servers
* support changing passwords; an XMPPException will be thrown when that is the case.
*
* @throws IllegalStateException if not currently logged-in to the server.
* @throws XMPPException if an error occurs when changing the password.
*/
public void changePassword(String newPassword) throws XMPPException {
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(connection.getServiceName());
Map<String, String> map = new HashMap<String, String>();
map.put("username",StringUtils.parseName(connection.getUser()));
map.put("password",newPassword);
reg.setAttributes(map);
PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
if (result == null) {
throw new XMPPException("No response from server.");
}
else if (result.getType() == IQ.Type.ERROR) {
throw new XMPPException(result.getError());
}
}
示例9: deleteAccount
import org.jivesoftware.smack.filter.PacketIDFilter; //导入依赖的package包/类
/**
* Deletes the currently logged-in account from the server. This operation can only
* be performed after a successful login operation has been completed. Not all servers
* support deleting accounts; an XMPPException will be thrown when that is the case.
*
* @throws IllegalStateException if not currently logged-in to the server.
* @throws XMPPException if an error occurs when deleting the account.
*/
public void deleteAccount() throws XMPPException {
if (!connection.isAuthenticated()) {
throw new IllegalStateException("Must be logged in to delete a account.");
}
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(connection.getServiceName());
Map<String, String> attributes = new HashMap<String, String>();
// To delete an account, we add a single attribute, "remove", that is blank.
attributes.put("remove", "");
reg.setAttributes(attributes);
PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
if (result == null) {
throw new XMPPException("No response from server.");
}
else if (result.getType() == IQ.Type.ERROR) {
throw new XMPPException(result.getError());
}
}
示例10: getLastActivity
import org.jivesoftware.smack.filter.PacketIDFilter; //导入依赖的package包/类
/**
* Returns the last activity of a particular jid. If the jid is a full JID
* (i.e., a JID of the form of '[email protected]/resource') then the last activity
* is the idle time of that connected resource. On the other hand, when the
* jid is a bare JID (e.g. '[email protected]') then the last activity is the lapsed
* time since the last logout or 0 if the user is currently logged in.
* Moreover, when the jid is a server or component (e.g., a JID of the form
* 'host') the last activity is the uptime.
*
* @param con
* the current Connection.
* @param jid
* the JID of the user.
* @return the LastActivity packet of the jid.
* @throws XMPPException
* thrown if a server error has occured.
*/
public static LastActivity getLastActivity(Connection con, String jid) throws XMPPException {
LastActivity activity = new LastActivity();
activity.setTo(jid);
PacketCollector collector = con.createPacketCollector(new PacketIDFilter(activity.getPacketID()));
con.sendPacket(activity);
LastActivity response = (LastActivity) 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;
}
示例11: getConfigurationForm
import org.jivesoftware.smack.filter.PacketIDFilter; //导入依赖的package包/类
/**
* Returns the room's configuration form that the room's owner can use or <tt>null</tt> if
* no configuration is possible. The configuration form allows to set the room's language,
* enable logging, specify room's type, etc..
*
* @return the Form that contains the fields to complete together with the instrucions or
* <tt>null</tt> if no configuration is possible.
* @throws XMPPException if an error occurs asking the configuration form for the room.
*/
public Form getConfigurationForm() throws XMPPException {
MUCOwner iq = new MUCOwner();
iq.setTo(room);
iq.setType(IQ.Type.GET);
// Filter packets looking for an answer from the server.
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
PacketCollector response = connection.createPacketCollector(responseFilter);
// Request the configuration form to the server.
connection.sendPacket(iq);
// Wait up to a certain number of seconds for a reply.
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
response.cancel();
if (answer == null) {
throw new XMPPException("No response from server.");
}
else if (answer.getError() != null) {
throw new XMPPException(answer.getError());
}
return Form.getFormFrom(answer);
}
示例12: sendConfigurationForm
import org.jivesoftware.smack.filter.PacketIDFilter; //导入依赖的package包/类
/**
* Sends the completed configuration form to the server. The room will be configured
* with the new settings defined in the form. If the form is empty then the server
* will create an instant room (will use default configuration).
*
* @param form the form with the new settings.
* @throws XMPPException if an error occurs setting the new rooms' configuration.
*/
public void sendConfigurationForm(Form form) throws XMPPException {
MUCOwner iq = new MUCOwner();
iq.setTo(room);
iq.setType(IQ.Type.SET);
iq.addExtension(form.getDataFormToSend());
// Filter packets looking for an answer from the server.
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
PacketCollector response = connection.createPacketCollector(responseFilter);
// Send the completed configuration form to the server.
connection.sendPacket(iq);
// Wait up to a certain number of seconds for a reply.
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
response.cancel();
if (answer == null) {
throw new XMPPException("No response from server.");
}
else if (answer.getError() != null) {
throw new XMPPException(answer.getError());
}
}
示例13: getRegistrationForm
import org.jivesoftware.smack.filter.PacketIDFilter; //导入依赖的package包/类
/**
* Returns the room's registration form that an unaffiliated user, can use to become a member
* of the room or <tt>null</tt> if no registration is possible. Some rooms may restrict the
* privilege to register members and allow only room admins to add new members.<p>
*
* If the user requesting registration requirements is not allowed to register with the room
* (e.g. because that privilege has been restricted), the room will return a "Not Allowed"
* error to the user (error code 405).
*
* @return the registration Form that contains the fields to complete together with the
* instrucions or <tt>null</tt> if no registration is possible.
* @throws XMPPException if an error occurs asking the registration form for the room or a
* 405 error if the user is not allowed to register with the room.
*/
public Form getRegistrationForm() throws XMPPException {
Registration reg = new Registration();
reg.setType(IQ.Type.GET);
reg.setTo(room);
PacketFilter filter =
new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
collector.cancel();
if (result == null) {
throw new XMPPException("No response from server.");
}
else if (result.getType() == IQ.Type.ERROR) {
throw new XMPPException(result.getError());
}
return Form.getFormFrom(result);
}
示例14: setName
import org.jivesoftware.smack.filter.PacketIDFilter; //导入依赖的package包/类
/**
* 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;
}
示例15: changeAffiliationByOwner
import org.jivesoftware.smack.filter.PacketIDFilter; //导入依赖的package包/类
private void changeAffiliationByOwner(String jid, String affiliation) throws XMPPException {
MUCOwner iq = new MUCOwner();
iq.setTo(room);
iq.setType(IQ.Type.SET);
// Set the new affiliation.
MUCOwner.Item item = new MUCOwner.Item(affiliation);
item.setJid(jid);
iq.addItem(item);
// Wait for a response packet back from the server.
PacketFilter responseFilter = new PacketIDFilter(iq.getPacketID());
PacketCollector response = connection.createPacketCollector(responseFilter);
// Send the change request to the server.
connection.sendPacket(iq);
// Wait up to a certain number of seconds for a reply.
IQ answer = (IQ) response.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
response.cancel();
if (answer == null) {
throw new XMPPException("No response from server.");
}
else if (answer.getError() != null) {
throw new XMPPException(answer.getError());
}
}