首页 > 代码库 > smack item-not-found(404) cancle 及asmack8-4.0.5.jar包的使用简介

smack item-not-found(404) cancle 及asmack8-4.0.5.jar包的使用简介

      smack发布节点时,出现如下两个错误:

      1.<error code="409" type="cancel"><conflict xmlns="urn:ietf:params:xml:ns:xmpp〉这个错误, 明明还没有创建,就提示冲突了

       2.smack item-not-found(404) cancle

       在网上查了一下说是jar包的bug问题,在4.0.4修复了这个bug,翻译过来就是当创建PayloadItems时PubSub ItemProvider 仅仅处理定义的最外层的命名空间

       

     换了个最新的asmack8-4.0.5.jar包(下载地址:http://asmack.freakempire.de/),更多可访问https://github.com/Flowdalic/asmack

     smack 在4.0之后某些类有些变化,具体可以将smack下载下来,自己查看api,同时参考http://www.igniterealtime.org/builds/smack/docs/latest/documentation/index.html

     好了,现在说说目前用到改变的方法:

    1.SmackConfiguration.DEBUG_ENABLED = true;//开启DEBUG模式

     2.ConnectionConfiguration config = new ConnectionConfiguration(
SERVER_HOST, SERVER_PORT,
SERVER_NAME);
config.setReconnectionAllowed(true);
config.setSendPresence(true);
config.setDebuggerEnabled(true);
config.setSecurityMode(SecurityMode.disabled);
//System.setProperty("javax.net.ssl.trustStore", "akeystore.jks");
// config.setSASLAuthenticationEnabled(true);/
connection = new XMPPTCPConnection(config);

try {
connection.connect();
} catch (SmackException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//连接到服务器


3. //消息监听
ChatManager cm = ChatManager.getInstanceFor(XmppConnection.getConnection());

4.注册

/**
* *
* <ul>
* <li>name -- the user‘s name. 031 *
* <li>first -- the user‘s first name. 032 *
* <li>last -- the user‘s last name. 033 *
* <li>email -- the user‘s email address. 034 *
* <li>city -- the user‘s city. 035 *
* <li>state -- the user‘s state. 036 *
* <li>zip -- the user‘s ZIP code. 037 *
* <li>phone -- the user‘s phone number. 038 *
* <li>url -- the user‘s website. 039 *
* <li>date -- the date the registration took place. 040 *
* <li>misc -- other miscellaneous information to associate with the
* account. 041 *
* <li>text -- textual information to associate with the account. 042 *
* <li>remove -- empty flag to remove account. 043 *
* </ul>

* @throws NotConnectedException
*/
private void registered() throws NotConnectedException {


String accounts = mNameEt.getText().toString();
String password = mPasswdEt.getText().toString();
String email = mEmailEt.getText().toString();
String mingcheng = nameMCH.getText().toString();


Map<String, String> attributes = new HashMap<String, String>();
attributes.put("name", mingcheng);
attributes.put("email", email);
attributes.put("misc", "android");
attributes.put("username", accounts);  
attributes.put("password", password);  
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(XmppConnection.getConnection().getServiceName());


reg.setAttributes(attributes);
// reg.addAttribute("name", mingcheng);
// reg.addAttribute("email", email);


// reg.addAttribute("android", "geolo_createUser_android");
PacketFilter filter = new AndFilter(new PacketIDFilter(
reg.getPacketID()), new PacketTypeFilter(IQ.class));
PacketCollector collector = XmppConnection.getConnection()
.createPacketCollector(filter);
XmppConnection.getConnection().sendPacket(reg);
IQ result = (IQ) collector.nextResult(SmackConfiguration
.getDefaultPacketReplyTimeout());
// Stop queuing results
collector.cancel();// 停止请求results(是否成功的结果)


还有部分改变,更多可参考官方的api


smack item-not-found(404) cancle 及asmack8-4.0.5.jar包的使用简介