Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

java - Mapping Openfire Custom plugin with aSmack Client

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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>

What you have to:

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: 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 ";

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

Time to go client side:

Step3: register to your ProviderManager an IQProvider

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

Step4: implements your IQUserCustomParamProvider as you need

public class IQUserCustomParamProvider extends IQProvider<IQUserCustomParam>

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

String favouriteColor

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);
    }

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

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

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...