首页 人力资源openfire插件开发入门

人力资源openfire插件开发入门

举报
开通vip

人力资源openfire插件开发入门人力资源openfire插件开发入门 openfire源码构建指导(E文): html android openfire 插件开发: 代码 实现功能,客户端发送一个IQ包含内容的节给服务器,服务器取得内容,然后广播给所有的在线用户 新定义的iq为输入发言内容 服务器端: 建立org.jivesoftware.openfire.handler.IQHandler的实现类 view plaincopy to clipboardprint? 1. package test.plugin; 2. 3. im...

人力资源openfire插件开发入门
人力资源openfire插件开发入门 openfire源码构建指导(E文): html android openfire 插件开发: 代码 实现功能,客户端发送一个IQ包含内容的节给服务器,服务器取得内容,然后广播给所有的在线用户 新定义的iq为输入发言内容 服务器端: 建立org.jivesoftware.openfire.handler.IQHandler的实现类 view plaincopy to clipboardprint? 1. package test.plugin; 2. 3. import org.dom4j.Element; 4. import org.jivesoftware.openfire.IQHandlerInfo; 5. import org.jivesoftware.openfire.XMPPServer; 6. import org.jivesoftware.openfire.auth.UnauthorizedException; 7. import org.jivesoftware.openfire.handler.IQHandler; 8. import org.xmpp.packet.IQ; 9. 10. public class BroadcastsIQ extends IQHandler { 11. 12. private IQHandlerInfo info; 13. public BroadcastsIQ() { 14. super("用户广播模块"); 15. info = new IQHandlerInfo("b", "com:message:broadcasts"); 16. } 17. 18. @Override 19. public IQHandlerInfo getInfo() { 20. return info; 21. } 22. 23. @Override 24. public IQ handleIQ(IQ packet) throws UnauthorizedException { 25. Element iq = packet.getElement(); 26. Element b = iq.element("b"); 27. String text = b.getText(); 28. XMPPServer.getInstance().getSessionManager().sendServerMessage(nu ll, text);//广播信息 29. return null; 30. } 31. 32. } package test.plugin; import org.dom4j.Element; import org.jivesoftware.openfirimport org.jivesoftware.openfirimport org.jivesoftware.openfir 建立org.jivesoftware.openfire.container.Plugin的实现类 view plaincopy to clipboardprint? 1. package test.plugin; 2. 3. import java.io.File; 4. import java.util.List; 5. 6. import org.jivesoftware.openfire.XMPPServer; 7. import org.jivesoftware.openfire.container.Plugin; 8. import org.jivesoftware.openfire.container.PluginManager; 9. import org.jivesoftware.openfire.handler.IQHandler; 10. 11. public class MyPlugin implements Plugin { 12. 13. private IQHandler iQHandler; 14. @Override 15. public void destroyPlugin() { 16. XMPPServer.getInstance().getIQRouter().removeHandler(iQHandler); 17. System.out.println("插件停止成功"); 18. } 19. 20. @Override 21. public void initializePlugin(PluginManager manager, File pluginDirect ory) { 22. iQHandler = new BroadcastsIQ(); 23. XMPPServer.getInstance().getIQRouter().addHandler(iQHandler); 24. System.out.println("插件运行成功"); 25. } 26. } package test.plugin; import java.io.File; import java.util.List; import org.jivesoftware.openfir 建立plugin.xml文件 view plaincopy to clipboardprint? 1. 2. 3. test.plugin.MyPlugin 4. Broadcasts messages 5. This is an Broadcasts messages plugin. 6. me 7. 8. 1.0 9. 01/01/2011/date> 10. none 11. 3.0.0 12. gpl 13. 14. 15. test.plugin.MyPlugin Broadcasts messagesThis is an Bro me 打包为任意名称的jar文件 结构如下 test.jar --classes --test --plugin --BroadcastsIQ.class --MyPlugin.class --META-INF --MANIFEST.MF --plugin.xml 然后把打好包的jar文件放到openfire的plugins目录下,openfire会自动加载,观察控制 台是否输出 插件运行成功 客户端: 建立org.jivesoftware.smack.packet.IQ的实现类 view plaincopy to clipboardprint? 1. package test.xmpp; 2. 3. import org.jivesoftware.smack.packet.IQ; 4. 5. public class Broadcasts extends IQ { 6. 7. private String body; 8. public String getElementName() { 9. return "b"; 10. } 11. 12. public String getNamespace() { 13. return "com:message:broadcasts"; 14. } 15. 16. public void setBody(String body) { 17. this.body = body; 18. } 19. 20. public String getBody() { 21. return body; 22. } 23. 24. @Override 25. public String getChildElementXML() { 26. if(getBody() == null){ 27. throw new RuntimeException("Broadcasts body is empty"); 28. } 29. StringBuilder sb = new StringBuilder(); 30. sb.append("<").append(getElementName()).append(" xmlns=\"").appen d(getNamespace()).append("\">").append(getBody()).append(""); 31. return sb.toString(); 32. } 33. 34. } public String getBody() { return body; } @Override 然后在程序中 view plaincopy to clipboardprint? 1. Broadcasts b = new Broadcasts(); 2. b.setBody("测试广播内容"); 3. b.setType(IQ.Type.SET); 4. conn.sendPacket(b); Broadcasts b = new Broadcasts()b.setBody("测试广播内容"); b.setType(IQ.Type.SET); conn.sendPacket(b); 实现功能比较简单,算是学习openfire 插件开发的开始吧
本文档为【人力资源openfire插件开发入门】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_036899
暂无简介~
格式:doc
大小:23KB
软件:Word
页数:0
分类:企业经营
上传时间:2018-04-27
浏览量:10