使用aSmack客户端映射Openfire自定义插件 [英] Mapping Openfire Custom plugin with aSmack Client

查看:131
本文介绍了使用aSmack客户端映射Openfire自定义插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是XMPP的新手,请原谅我,如果这个问题听起来很愚蠢。我想创建一个自定义插件并将其映射到Android上的aSmack客户端。我正在尝试应用我的Web服务知识,但我没有赢。所以请引导我的思路走向最佳方法,一个例子将非常有用。 Thanx提前。

I'm a newbie to XMPP so forgive me if this question sounds silly. I want to create a custom plugin and map it with my aSmack client on Android. I'm trying to apply my knowledge of Web Services but I'm not winning. So please guide my thinking toward the best approach, an example will be really helpful. Thanx in advance.

推荐答案

有很多类型的插件,让我们来谈谈pourpose。
Igniterealtime插件指南

There are many types of plugins, let's talk in general pourpose. Igniterealtime Plugin guide

您想要定义一个全新的IQ Stanza来管理UserCustomParam。
假设:

You want to define a brand new IQ Stanza to manage an UserCustomParam. Let's say:

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

您需要:

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

step 1: define a plugin (class that implemements Plugin) that adds a new handler

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

Step2:根据需要实现MyCustomHandler(读取数据库,写上数据库,读取服务器端等)。

Step2: implements MyCustomHandler as you need (read on database, write on database, read server side and so on).

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

现在您的服务器已准备好管理您的自定义IQ请求。

Now your server it's ready to manage your custom IQ request.

到客户端的时间:

步骤3:向您的ProviderManager注册IQProvider

Step3: register to your ProviderManager an IQProvider

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

Step4:根据需要实施您的IQUserCustomParamProvider

Step4: implements your IQUserCustomParamProvider as you need

public class IQUserCustomParamProvider extends IQProvider<IQUserCustomParam>

进入Provider你将解析来自服务器的传入IQ,你将创建一个带有实例的IQUserCustomParam param like

into Provider you'll parse the incoming IQ from server and you'll create a IQUserCustomParam with an instance param like

String favouriteColor

Step5:你需要实现IQUserCustomParam

Step5: you need to implement 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

Step 6: now set up it's completed, but you haven't defined yet when to accept IQUserCustomParam when it comes from server. So you need a StanzaFilter

public class IQUserCustomParamFilter implements StanzaFilter

第7步:当你来自服务器时,你还没有定义如何处理IQUserCustomParam。所以你需要一个StanzaListner

Step 7: and you haven't defined yet what to do with IQUserCustomParam when it comes from server. So you need a StanzaListner

public class IQUserCustomParamListner implements StanzaListener

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

Step 8: finally you'll have to register the combo filter/listner on your connection:

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

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

if that helped, please don't forget to accept the answer!

这篇关于使用aSmack客户端映射Openfire自定义插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆