• Android openfire插件开发


    我这里做了一个例子主要是针对于XMPP的通信。后边会说一点smack和openfire通信的实现。
      注:这里的例子中的注释纯属个人理解。
      在openfire的源码里有很多插件。我这里实际就是拷贝了其中的一个插件。重名了一下名字。目录结构如下:

    貌似图片传不上来了。如果看不到图,就看看源码中的其他插件的例子。跟其他插件的目录结构是一样一样的。

    在这些文件里最重要的就是plugin.xml文件。因为有这个文件openfire才认识这个插件。在这个文件里会配置插件的入口类。我这里简单写了一个plugin.xml.示例如下。

    < ?xml version="1.0" encoding="UTF-8"?>
    
    < plugin>
    < class>org.yangzc.testplugin.TestPlugin< /class>
    < name>test Plugin< /name>
    < description>test Plugin descript< /description>
    < author>yangzc< /author>
    < version>1.0.0< /version>
    < date>20/6/2011< /date>
    < minServerVersion>3.7.0< /minServerVersion>
    < databaseKey>testPlugin< /databaseKey>
    < databaseVersion>0< /databaseVersion>
    < adminconsole>
    < /adminconsole>
    < /plugin>
    package eoe.demo;
    
    import java.io.File;
    import org.dom4j.Element;
    import org.jivesoftware.openfire.IQHandlerInfo;
    import org.jivesoftware.openfire.XMPPServer;
    import org.jivesoftware.openfire.auth.UnauthorizedException;
    import org.jivesoftware.openfire.container.Plugin;
    import org.jivesoftware.openfire.container.PluginManager;
    import org.jivesoftware.openfire.handler.IQHandler;
    import org.xmpp.packet.IQ;
    import org.xmpp.packet.PacketError;
    
    public class TestPlugin implements Plugin{
    
    @Override
    public void destroyPlugin() {
    }
    
    @Override
    public void initializePlugin(PluginManager manager, File pluginDirectory) {
    XMPPServer service = XMPPServer.getInstance();
    service.getIQRouter().addHandler(new MyIQHandler());
    }
    
    class MyIQHandler extends IQHandler{
    public static final String moduleName = "testPlugin";
    private IQHandlerInfo info;
    public MyIQHandler(){
    super(moduleName);
    info = new IQHandlerInfo("group", "com:im:group");//设置监听的命名空间
    }
    
    @Override
    public IQHandlerInfo getInfo() {
    return info;//取得指定监听命名空间的IQHandeler
    }
    
    @Override
    public IQ handleIQ(IQ packet) throws UnauthorizedException {
    IQ reply = IQ.createResultIQ(packet);
    Element groups = packet.getChildElement();//取得客户端发送过来的xml
    if (!IQ.Type.get.equals(packet.getType())){
    System.out.println("非法的请求类型");
    reply.setChildElement(groups.createCopy());
    reply.setError(PacketError.Condition.bad_request);
    return reply;
    }
    
    //String userName = StringUtils.substringBefore(packet.getFrom().toString(),"@");
    //GroupManager.getInstance().initElement(groups,userName);
    //reply.setChildElement(groups.createCopy());//2
    //System.out.println("返回的最终XML" reply.toXML());
    return reply;
    
    }
    
    }
    
    }
  • 相关阅读:
    改进动物园
    异常动手脑总结
    代码大全2 阅读笔记
    抽象和接口
    Appium+python自动化2-启动百度app
    Appium+python自动化1-环境搭建
    python之图像识别
    python之栈和队列
    python之语音识别(speech模块)
    使用Python计算IP、TCP、UDP校验和
  • 原文地址:https://www.cnblogs.com/vus520/p/2561893.html
Copyright © 2020-2023  润新知