vysper 保存消息日志到数据库(纯备忘)

1. 新建一个表用于存储消息记录

//消息日志记录
@Entity
@Table(name = "T_BIZ_MESSAGE_LOG")
public class MessageLogVO implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7667535307488288863L;
	@Id
	@Column(name = "id")
	private String id; // 联系人ID
	@Column(name = "fromjid")
	private String fromjid; // 当前用户jid

	@Column(name = "tojid")
	private String tojid; // 当前用户联系人jid

	@Lob
    @Basic(fetch=FetchType.LAZY)
	@Column(name = "message")
	private String message; //消息内容
	
	
	@Column(name = "createddatetime")
	private Timestamp createddatetime; // 创建时间
2.创建消息记录控制器

//消息日志控制器
public class OALogStorageProvider extends AbstractBodyTextLogStorageProvider {
	private final static Logger logger = LoggerFactory
			.getLogger(OALogStorageProvider.class);
	@Autowired
	IMessageLogDAO messageLogDAO;

	// 写入日志到数据库
	@Override
	protected void logText(Entity from, Entity to, String message) {
		// TODO Auto-generated method stub
		MessageLogVO vo = new MessageLogVO();
		vo.setId(UUIDGenerator.generate());// uuid
		vo.setFromjid(from.getBareJID().toString());// 发送人
		vo.setTojid(to.getBareJID().toString());// 发送人
		vo.setMessage(message);// 消息内容
		vo.setCreateddatetime(new Timestamp(new Date().getTime()));
		try {
			messageLogDAO.saveMessageLog(vo);// 保存消息
		} catch (Exception e) {
			// TODO Auto-generated catch block
			logger.error("", e);
		}

	}

}
3. spring 注入

<!-- SSO用户验证模块登记 -->
    <bean id="ssoStorageRegistry" class="com.oawebchat.sso.SSOStorageProviderRegistry" >
          <property name="ssoUserAuthentication" ref="ssoUserAuthentication" />
          <property name="oaVcardTempPersistenceManager" ref="oaVcardTempPersistenceManager" />
          <property name="oaRosterManager" ref="oaRosterManager" />
          <property name="ssoJabberSearchManager" ref="ssoJabberSearchManager" />
          <property name="oaLogStorageProvider" ref="OALogStorageProvider" />
    </bean>
public class SSOStorageProviderRegistry extends OpenStorageProviderRegistry {
.......
public void setOaLogStorageProvider(OALogStorageProvider oaLogStorageProvider) {
 this.oaLogStorageProvider = oaLogStorageProvider;
 this.add(this.oaLogStorageProvider);//注入消息日志模块
 }

 
 

 

 
  
  
  
  

你可能感兴趣的:(XMPP,vysper)