栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用aSmack Client映射Openfire自定义插件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用aSmack Client映射Openfire自定义插件

有很多类型的插件,让我们大致来讲一下。
Igniterealtime插件指南

您想定义一个全新的IQ Stanza来管理UserCustomParam。比方说:

<iq from="user1@myserver" to="myserver" type="get"> <usercustomparam xmls:"com.records.iq" retrive="favouritecolor"></iq>

您必须:

步骤1: 定义一个添加新处理程序的插件(实现插件的类)

MyCustomHandler colorshandler;IQRouter iqRouter = XMPPServer.getInstance().getIQRouter();iqRouter.addHandler(colorshandler);

步骤2: 根据需要实现MyCustomHandler(在数据库上读取,在数据库上写入,读取服务器端等等)。

public class MyCustomHandler extends IQHandler {    public static final String NAMESPACE_TICKET_IQ = "com.records.iq";    public static final String TAG_TICKET_IQ = "usercustomparam ";

现在,您的服务器已准备就绪,可以管理您的自定义IQ请求。

是时候去客户端了:

第三步: 向您的ProviderManager注册一个IQProvider

ProviderManager.addIQProvider("usercustomparam ","com.records.iq", new IQUserCustomParamProvider());

步骤4: 根据需要实现IQUserCustomParamProvider

public class IQUserCustomParamProvider extends IQProvider<IQUserCustomParam>

到Provider中,您将解析来自服务器的传入IQ,并创建一个IQUserCustomParam,其实例参数如下

String favouriteColor

步骤5: 您需要实现IQUserCustomParam

public class IQUserCustomParam extends IQ    private final static String childElementName = "usercustomparam";    private final static String childElementNamespace = "com.records.iq";public IQUserCustomParam (String color)    {        this(childElementName , childElementNamespace );        this.setType(IQ.Type.result);        this.setFavouriteColor(color);    }

步骤6 :现在完成设置,但是您还没有定义何时从服务器接收IQUserCustomParam。所以你需要一个StanzaFilter

public class IQUserCustomParamFilter implements StanzaFilter

步骤7 :您还没有定义IQUserCustomParam来自服务器时的处理方法。所以你需要一个StanzaListner

public class IQUserCustomParamListner implements StanzaListener

步骤8: 最后,您必须在连接上注册组合过滤器/侦听器:

AbstractXMPPConnection connection = ...;connection.addAsyncStanzaListener(new PersonalConfigListner(this), new IQMUCConfigTicketFIlter();

如果有帮助,请不要忘记接受答案!



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/569374.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号