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;
结构为:
- java.lang.Object
- org.jivesoftware.admin.AdminConsole
- org.jivesoftware.admin.AdminPageBean
- org.jivesoftware.admin.AdminPageBean.Breadcrumb
- org.jivesoftware.admin.AuthCheckFilter (implements javax.servlet.Filter)
- org.jivesoftware.admin.LdapGroupTester
- org.jivesoftware.admin.LdapGroupTester.Group
- org.jivesoftware.admin.LdapUserProfile
- org.jivesoftware.admin.LdapUserTester
- org.jivesoftware.admin.LoginLimitManager
- org.jivesoftware.admin.PluginFilter (implements javax.servlet.Filter)
- javax.servlet.jsp.tagext.TagSupport (implements javax.servlet.jsp.tagext.IterationTag, java.io.Serializable)
- javax.servlet.jsp.tagext.BodyTagSupport (implements javax.servlet.jsp.tagext.BodyTag)
- org.jivesoftware.admin.SidebarTag
- org.jivesoftware.admin.SubSidebarTag
- org.jivesoftware.admin.SubnavTag
- org.jivesoftware.admin.TabsTag
- org.jivesoftware.admin.SidebarTag
- javax.servlet.jsp.tagext.BodyTagSupport (implements javax.servlet.jsp.tagext.BodyTag)
其中登录成功和失败等校验在:LgoinLimitManager类中,这里我写了system.out.println,打印结果为:
https://t1500-pc:9091
LgoinLimitManager login
LgoinLimitManager login fail
LgoinLimitManager login
LgoinLimitManager login success
第二个包package org.jivesoftware.database;
结构为:
- java.lang.Object
- org.jivesoftware.database.CachedPreparedStatement
- org.jivesoftware.database.DbConnectionManager
- org.jivesoftware.database.DefaultConnectionProvider (implements org.jivesoftware.database.ConnectionProvider)
- org.jivesoftware.database.EmbeddedConnectionProvider (implements org.jivesoftware.database.ConnectionProvider)
- org.jivesoftware.util.JiveBeanInfo (implements java.beans.BeanInfo)
- org.jivesoftware.database.DefaultConnectionProviderBeanInfo
- org.jivesoftware.database.JNDIDataSourceProvider (implements org.jivesoftware.database.ConnectionProvider)
- org.jivesoftware.database.SchemaManager
- org.jivesoftware.database.SequenceManager
数据库连接代码,第一个类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. |
第五个包:package org.jivesoftware.openfire.admin;
目录结构为:
- java.lang.Object
- org.jivesoftware.openfire.admin.AdminManager
- org.jivesoftware.openfire.admin.DefaultAdminProvider (implements org.jivesoftware.openfire.admin.AdminProvider)
第六个包:package org.jivesoftware.openfire.audit;
- java.lang.Object
- org.jivesoftware.openfire.audit.AuditEvent
- org.jivesoftware.openfire.audit.SessionEvent
- org.jivesoftware.openfire.audit.AuditStreamIDFactory (implements org.jivesoftware.openfire.StreamIDFactory)
- org.jivesoftware.openfire.audit.AuditEvent
xmpp数据服务记录。
第七个包:Package org.jivesoftware.openfire.audit.spi
- java.lang.Object
- org.jivesoftware.openfire.audit.spi.AuditorImpl (implements org.jivesoftware.openfire.audit.Auditor)
- org.jivesoftware.openfire.container.BasicModule (implements org.jivesoftware.openfire.container.Module)
- org.jivesoftware.openfire.audit.spi.AuditManagerImpl (implements org.jivesoftware.openfire.audit.AuditManager)
第八个包:Package org.jivesoftware.openfire.auth
- java.lang.Object
- org.jivesoftware.openfire.auth.AuthFactory
- org.jivesoftware.openfire.auth.AuthorizationManager
- org.jivesoftware.openfire.auth.AuthToken
- org.jivesoftware.openfire.auth.DefaultAuthorizationMapping (implements org.jivesoftware.openfire.auth.AuthorizationMapping)
- org.jivesoftware.openfire.auth.DefaultAuthorizationPolicy (implements org.jivesoftware.openfire.auth.AuthorizationPolicy)
- org.jivesoftware.openfire.auth.DefaultAuthProvider (implements org.jivesoftware.openfire.auth.AuthProvider)
- org.jivesoftware.openfire.auth.HybridAuthProvider (implements org.jivesoftware.openfire.auth.AuthProvider)
- org.jivesoftware.openfire.auth.JDBCAuthProvider (implements org.jivesoftware.openfire.auth.AuthProvider)
- org.jivesoftware.openfire.auth.NativeAuthProvider (implements org.jivesoftware.openfire.auth.AuthProvider)
- org.jivesoftware.openfire.auth.POP3AuthProvider (implements org.jivesoftware.openfire.auth.AuthProvider)
- java.lang.Throwable (implements java.io.Serializable)
- java.lang.Exception
- org.jivesoftware.openfire.auth.ConnectionException
- org.jivesoftware.openfire.auth.InternalUnauthenticatedException
- org.jivesoftware.openfire.auth.UnauthenticatedException
- org.jivesoftware.openfire.auth.UnauthorizedException
- java.lang.Exception
第九个包:Package org.jivesoftware.openfire.carbons
- java.lang.Object
第十个包: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
- java.lang.Object
- org.jivesoftware.openfire.cluster.ClusterManager
- org.jivesoftware.openfire.cluster.GetBasicStatistics (implements org.jivesoftware.util.cache.ClusterTask)
- org.jivesoftware.openfire.cluster.NodeID (implements java.io.Externalizable)