Really Need Help on Ad-hoc Command Implementation

Hi all,

I’ve been searching through the API’s for implementing ad-hoc commands and now I’m using Smack and the ad-hoc command source code from the repository: http://svn.igniterealtime.org/svn/repos/smack/trunk/source/org/jivesoftware/smac kx/commands/

But I still can’t figure out how to use the source code and have struggled for some time… I’ve seen some discussion here, which was helpful but not sufficient for me ( because this is the first time I try Smack and XMPP).

What I have done is to create a connection associated with an AdHocCommandManager, then login to the server (e.g., jabber.org). Also, I have implemented an ad-hoc command (say, ReadPort.java, which extends LocalCommand).

Now my questions are:

  1. Should I use AdHocCommandManager.registerCommand() to add the command (ReadPort.class) to the ower’s account (say, owner@jabber.org/Home)

  2. After I finish step 1, how can I remotely execute this ad-hoc command? I can’t figure out how the responder can know where to find the corresponding class to run (e.g. ReadPort.java). It seems to me that AdHocCommandManager.registerCommand() only uses the command class to initialize the AdHocCommandInfo local variable, but I couldn’t see where my command class will be invoked.

  3. What’s the difference between AdHocCommandManager.processAdHocCommand() and RemoteCommand.execute() except one is private and the other is public? It seems that AdHocCommandManager.processAdHocCommand() is called in AdHocCommandManager.init(), however, AdHocCommandManager.init() is called from AdHocCommandManager’s constructor when the ad-hoc command hasn’t been specified, though.

I’m quite confused and really need help from you all. Is there any java example that can help me get started?

I will really really appreciate your help!!

Best regards.

June

1 Like

I need the same example, as is posible, because I have to do a xmpp client with ad-hoc commands, whitch will do something like the example in book, returning messages from my computer client, so please someone, help us…

Sadly, there are several undocumented parts of the API which can certainly be frustrating to learn. There is already an issue logged for this (SMACK-292).

I wish I could be of more help, but my own experience with it is limited to this. It sends the following command which returns a form.

<command xmlns=‘http://jabber.org/protocol/commands

       node='[http://jabber.org/protocol/pubsub#get-pending](http://jabber.org/protocol/pubsub#get-pending)'

action=‘execute’/>

AdHocCommandManager mgr = AdHocCommandManager.getAddHocCommandsManager(con);

    RemoteCommand cmd = mgr.getRemoteCommand(to, "[http://jabber.org/protocol/pubsub#get-pending](http://jabber.org/protocol/pubsub#get-pending)");

cmd.execute();

Form pendingSubs = cmd.getForm();

FormField field = pendingSubs.getField(“pubsub#node”);

Iterator it = field.getValues();

ArrayList nodeList = new ArrayList();

while (it.hasNext())

nodeList.add(getNode(it.next()));

return nodeList;

Good luck!