本文整理汇总了Java中org.jivesoftware.smack.packet.IQ.getType方法的典型用法代码示例。如果您正苦于以下问题:Java IQ.getType方法的具体用法?Java IQ.getType怎么用?Java IQ.getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jivesoftware.smack.packet.IQ
的用法示例。
在下文中一共展示了IQ.getType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: regist
import org.jivesoftware.smack.packet.IQ; //导入方法依赖的package包/类
/**
* 注册用户
* @param xmppConnection
* @param userName
* @param password
* @return 1、注册成功 0、服务器没有返回结果2、这个账号已经存在3、注册失败
*/
public static int regist(XMPPConnection xmppConnection, String userName, String password) {
Registration registration = new Registration();
registration.setType(IQ.Type.SET);
registration.setTo(xmppConnection.getServiceName());
registration.setUsername(userName);
registration.setPassword(password);
// 这边addAttribute不能为空,否则出错。所以做个标志是android手机创建的吧!!!!!
registration.addAttribute("android", "fhr");
PacketFilter filter = new AndFilter(new PacketIDFilter(registration.getPacketID()), new PacketTypeFilter(IQ.class));
PacketCollector collector = xmppConnection.createPacketCollector(filter);
xmppConnection.sendPacket(registration);
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results停止请求results(是否成功的结果)
collector.cancel();
if (result == null) {
Log.e("regist", "No response from server.");
return 0;
} else if (result.getType() == IQ.Type.RESULT) {
Log.v("regist", "regist success.");
return 1;
} else {
if (result.getError().toString().equalsIgnoreCase("conflict(409)")) {
Log.e("regist", "IQ.Type.ERROR: " + result.getError().toString());
return 2;
} else {
Log.e("regist", "IQ.Type.ERROR: " + result.getError().toString());
return 3;
}
}
}
示例2: register
import org.jivesoftware.smack.packet.IQ; //导入方法依赖的package包/类
/**
* 注册
*
* @param account
* 注册帐号
* @param password
* 注册密码
* @return 1、注册成功 0、服务器没有返回结果2、这个账号已经存在3、注册失败
*/
public static int register(XMPPConnection mXMPPConnection,String account, String password) {
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(mXMPPConnection.getServiceName());
// 注意这里createAccount注册时,参数是UserName,不是jid,是"@"前面的部分。
reg.setUsername(account);
reg.setPassword(password);
// 这边addAttribute不能为空,否则出错。所以做个标志是android手机创建的吧!!!!!
reg.addAttribute("android", "geolo_createUser_android");
PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
PacketCollector collector =mXMPPConnection.createPacketCollector(filter);
mXMPPConnection.sendPacket(reg);
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results停止请求results(是否成功的结果)
collector.cancel();
if (result == null) {
return 0;
} else if (result.getType() == IQ.Type.RESULT) {
return 1;
} else {
if (result.getError().toString().equalsIgnoreCase("conflict(409)")) {
return 2;
} else {
return 3;
}
}
}
示例3: testInvalidNamespace
import org.jivesoftware.smack.packet.IQ; //导入方法依赖的package包/类
/**
* Check that the server responds a 503 error code when the client sends an IQ stanza(/packet) with an
* invalid namespace.
*/
public void testInvalidNamespace() {
IQ iq = new IQ() {
public String getChildElementXML() {
StringBuilder buf = new StringBuilder();
buf.append("<query xmlns=\"jabber:iq:anything\">");
buf.append("</query>");
return buf.toString();
}
};
PacketFilter filter = new AndFilter(new PacketIDFilter(iq.getStanzaId()),
new StanzaTypeFilter(IQ.class));
PacketCollector collector = getConnection(0).createPacketCollector(filter);
// Send the iq packet with an invalid namespace
getConnection(0).sendStanza(iq);
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
if (result == null) {
fail("No response from server");
}
else if (result.getType() != IQ.Type.error) {
fail("The server didn't reply with an error packet");
}
else {
assertEquals("Server answered an incorrect error code", 503, result.getError().getCode());
}
}
示例4: acceptSpecific
import org.jivesoftware.smack.packet.IQ; //导入方法依赖的package包/类
@Override
protected boolean acceptSpecific(IQ iq) {
return iq.getType() == type;
}
示例5: testParseIQSimple
import org.jivesoftware.smack.packet.IQ; //导入方法依赖的package包/类
/**
* Test for parsing a Jingle
*/
public void testParseIQSimple() {
// Create a dummy packet for testing...
IQfake iqSent = new IQfake (
" <jingle xmlns='urn:xmpp:tmp:jingle'" +
" initiator=\"[email protected]\"" +
" responder=\"[email protected]\"" +
" action=\"transport-info\" sid=\"\">" +
" <transport xmlns='urn:xmpp:tmp:jingle:transports:ice-udp'>" +
" <candidate generation=\"1\"" +
" ip=\"192.168.1.1\"" +
" password=\"secret\"" +
" port=\"8080\"" +
" username=\"username\"" +
" preference=\"1\"/>" +
" </transport>" +
"</jingle>");
iqSent.setTo(getFullJID(0));
iqSent.setFrom(getFullJID(0));
iqSent.setType(IQ.Type.get);
// Create a filter and a collector...
PacketFilter filter = new StanzaTypeFilter(IQ.class);
PacketCollector collector = getConnection(0).createPacketCollector(filter);
System.out.println("Testing if a Jingle IQ can be sent and received...");
// Send the iq packet with an invalid namespace
getConnection(0).sendStanza(iqSent);
// Receive the packet
IQ iqReceived = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
if (iqReceived == null) {
fail("No response from server");
}
else if (iqReceived.getType() == IQ.Type.error) {
fail("The server did reply with an error packet: " + iqReceived.getError().getCode());
}
else {
assertTrue(iqReceived instanceof Jingle);
Jingle jin = (Jingle) iqReceived;
System.out.println("Sent: " + iqSent.toXML());
System.out.println("Received: " + jin.toXML());
}
}