Scripts 学盟

标题: openfire How to register Plugin as IQHandler? [打印本页]

作者: 那个谁    时间: 2011-7-18 14:03:32     标题: openfire How to register Plugin as IQHandler?

I am interested in write a plugin which could handle my IQ messages.

1.

I see the code to Register a plugin as an IQHandler in the link

http://www.jivesoftware.org/buil ... entation/plugin-dev -guide.html


How to register Plugin as IQHandler?IQHandler myHandler = new MyIQHander();

IQRouter iqRouter = XMPPServer.getInstance().getIQRouter();

iqRouter.addHandler(myHandler);[/code]


Where do you I need to add this code in the plugin? Or have to write a separate IQHandler? Can someone point me to an example for this?


作者: 那个谁    时间: 2011-7-18 14:04:26

  1. Example:


  2. Re: How to register Plugin as IQHandler?


  3. public class AddressbookPlugin implements Plugin{


  4.       
  5.      public AddressbookPlugin() {

  6.           IQHandler iqAddressbookHandler = new IQAddressbookHandler();

  7.           IQRouter iqRouter = XMPPServer.getInstance().getIQRouter();

  8.           iqRouter.addHandler(iqAddressbookHandler);

  9.      }


  10.      public void initializePlugin(PluginManager manager, File pluginDirectory) {     

  11.      }


  12.      public void destroyPlugin() {         

  13.      }


  14. }


  15. protected class IQAddressbookHandler extends IQHandler {

  16.           public IQAddressbookHandler () {

  17.                super("Addressbook Handler");

  18.           }

  19.           /* (non-Javadoc)

  20.             
  21. @see org.jivesoftware.wildfire.handler.IQHandler#getInfo()

  22.            */

  23.           public IQHandlerInfo getInfo() {

  24.                // TODO Auto-generated method stub

  25.                return new IQHandlerInfo("query","http://www.hupoo.net/protocol/addressbook");

  26.           }

  27.           /* (non-Javadoc)

  28.             
  29. @see org.jivesoftware.wildfire.handler.IQHandler#handleIQ(org.xmpp.packet.IQ)

  30.            */

  31.           public IQ handleIQ(IQ packet) throws UnauthorizedException {

  32.                System.out.println("pa: "+packet);

  33.                return null;

  34.           }

  35.            
  36.     }
复制代码

作者: 混混@普宁.中国    时间: 2011-7-21 00:22:04

这个 openfire 是不是搞聊天室的哈。。。还不知是什么玩易
作者: 那个谁    时间: 2011-7-21 08:31:01

混混@普宁.中国 发表于 2011-7-21 00:22
这个 openfire 是不是搞聊天室的哈。。。还不知是什么玩易

标准XMPP协议通信。。




欢迎光临 Scripts 学盟 (http://www.iscripts.org/) Powered by Discuz! X2