XMPP即时通信实现(一)

xmpp即时通信为我们提供了很好的即时通信机制,实现了消息对、推送、状态信息等强大的功能。这里我们要做二次开发,包括服务器和客户端。

1.二次开发源码开发环境搭建

参考:http://blog.csdn.net/chejiangongren/article/details/17502933

文章中讲的已经是很具体。

2.如何进行服务器openfire框架的修改

网上较少的资料提及如何去修改openfire框架,看到大量的源码,笔者也是很无奈,不知如何下手,下面记录笔者的一步步修改过程,如有相似开采用之。

2.1熟悉源码的框架

源码目录结构为:

src/java代码

src/plugins代码

这里的plugins是插件代码,src/java是openfire的核心代码。

2.2 src/java代码中目录结构

第一个包:package org.jivesoftware.admin;

结构为:

此包的作用是管理控制台,提供admin管理功能。

其中登录成功和失败等校验在:LgoinLimitManager类中,这里我写了system.out.println,打印结果为:

 https://t1500-pc:9091
LgoinLimitManager login
LgoinLimitManager login fail
LgoinLimitManager login
LgoinLimitManager login success

第二个包package org.jivesoftware.database;

结构为:

数据库连接代码,第一个类CachedPreparedStatement用来缓存数据,DbConnectionManager是数据库管理的核心代码EmbeddedConnectionProvider提供了内部数据库hsqlDB服务,SchemaManager用来管理openfire和openfire数据库。

第三个包:package org.jivesoftware.database.bugfix;

用于软件缺陷异常跟踪。

第四个包:package org.jivesoftware.openfire;

目录结构为:

Interface Summary
ChannelHandler<T extends Packet> 接口——处理数据包的传送,传送到不同的通道
Connection 接口——实现与服务器的一个连接
ConnectionCloseListener 接口——监听连接中断问题
ConnectionManager 接口——协调连接后的(accept, read, termination) 在服务器上。
OfflineMessageListener 接口——监听离线消息。
PacketDeliverer 接口——传送数据包至本地数据流
PacketRouter 接口——路由接收传入的数据包
PresenceManager 接口——管理在线状态
RemotePacketRouter 接口——远程数据包路由器
RoutableChannelHandler 接口——远程数据包接收处理
RoutingTable 接口——节点信息表
StreamID 接口——独一无二的数据流标识
StreamIDFactory Generates stream ids in different ways depending on the server set up.
XMPPServerInfo 接口——服务器状态
XMPPServerListener 接口——服务器启动,关闭状态监听
 

Class Summary
Channel<T extends Packet> A channel provides a mechanism to queue work units for processing.
FlashCrossDomainHandler  
IQHandlerInfo 一个简单的数据元类用来存储IQ处理的协议关系.
IQRouter 服务器上所有iq数据包
JMXManager 管理JMX在Openfire上的配置.
MessageRouter 服务器上数据包
MulticastRouter 多个收件人信息
OfflineMessage 离线数据管理
OfflineMessageStore 离线数据存储
OfflineMessageStrategy 控制离线消息内容
PresenceRouter 服务器上存在的路由数据包
PrivateStorage Private storage for user accounts (JEP-0049).
ServerPort 代表一个服务器将监听的端口连接
SessionManager 通过一个账户管理会议信息
SessionPacketRouter 处理会议信息
SessionResultFilter 过滤和排序会议信息列表
XMPPContextListener An XMPPContextListener starts an XMPPServer when a ServletContext is initialized and stops the xmpp server when the servlet context is destroyed.
XMPPServer 主要的XMPP服务器负载,并启动所有服务器的模块进行初始化。
 

Enum Summary
Connection.ClientAuth Enumeration that specifies if clients should be authenticated (and how) while negotiating TLS.
Connection.CompressionPolicy Enumeration of possible compression policies required to interact with the server.
Connection.TLSPolicy Enumeration of possible TLS policies required to interact with the server.
OfflineMessageStrategy.Type Strategy types.
ServerPort.Type  
 

Exception Summary
ChannelNotFoundException Thrown when a channel lookup fails to find the specified channel.
PacketException Represents a runtime packet exception typically from a malformed packet.
RemoteConnectionFailedException Thrown when something failed verifying the key of a Originating Server with an Authoritative Server in a dialback operation.
SessionNotFoundException  
SharedGroupException Thrown when a a user is trying to add or remove a contact from his/her roster that belongs to a shared group.
上面包含了openfire的消息处理机制,是机制的核心部分。

第五个包:package org.jivesoftware.openfire.admin;

目录结构为:

服务器管理用户列表管理。

第六个包:package org.jivesoftware.openfire.audit;

目录结构为:

xmpp数据服务记录。

第七个包:Package org.jivesoftware.openfire.audit.spi

数据服务接口。

第八个包:Package org.jivesoftware.openfire.auth

目录结构:
身份认证与授权服务接口与类。

第九个包:Package org.jivesoftware.openfire.carbons

目录结构:
  • java.lang.Object
    • org.xmpp.packet.PacketExtension
      • org.jivesoftware.openfire.carbons.Received
      • org.jivesoftware.openfire.carbons.Sent

提供扩展协议XEP-0280:Message carbons服务。

第十个包:Package org.jivesoftware.openfire.clearspace

目录结构:
Class Summary
ClearspaceAdminProvider Handles retrieving list of admins from Clearspace.
ClearspaceAuthProvider The ClearspaceAuthProvider uses the PermissionService web service inside of Clearspace to retrieve authenticate users.
ClearspaceGroupProvider  
ClearspaceLockOutProvider The ClearspaceLockOutProvider uses the UserService web service inside of Clearspace to retrieve user properties from Clearspace.
ClearspaceManager Centralized administration of Clearspace connections.
ClearspaceMUCEventDelegate Handles checking with Clearspace regarding whether a user can join a particular MUC room (based on their permissions with the Clearspace JiveObject (eg.
ClearspaceMUCTranscriptEvent A MUC event that is intended to be recorded in a transcript for a group chat room in Clearspace.
ClearspaceMUCTranscriptManager Stores MUC events that are intended to be recorded as a transcript for a group chat room in Clearspace.
ClearspaceSaslServer Implements the CLEARSPACE server-side SASL mechanism.
ClearspaceSecurityAuditProvider The ClearspaceSecurityAuditProvider uses the AuditService web service inside of Clearspace to send audit logs into Clearspace's own audit handler.
ClearspaceUserProvider The ClearspaceUserProvider uses the UserService and ProfileSearchService web service inside of Clearspace to retrieve user information and to search for users from Clearspace.
ClearspaceVCardProvider The ClearspaceLockOutProvider uses the UserService web service inside of Clearspace to retrieve, edit and delete user information from Clearspace.
ClearspaceX509TrustManager Trust manager that validates Clearspace certificates.
SSLProtocolSocketFactory Implementation of SecureProtocolSocketFactory that will use a custom trust manager for certification validation.
URLUTF8Encoder Provides a method to encode any string into a URL-safe form.
WSUtils Several utilities to handle REST webservices.
 

Enum Summary
ClearspaceManager.HttpType Different kind of HTTP request types
ClearspaceMUCTranscriptEvent.Type  
ConnectionException.ErrorType  
 

Exception Summary
ConnectionException Thrown when an exception occurs connecting to CS.

清除空间服务。

第十一个包:Package org.jivesoftware.openfire.cluster

目录结构:
群组管理服务。



没有更多推荐了,返回首页