新增 实现获取离线消息的示例,完善文档

This commit is contained in:
xiajun 2014-12-26 12:44:40 +08:00
parent d1e486657d
commit fa14078188
7 changed files with 108 additions and 4 deletions

Binary file not shown.

View File

@ -42,7 +42,9 @@
<entry key="sessionClosedHander"> <entry key="sessionClosedHander">
<bean class="com.farsunset.ichat.cim.handler.SessionClosedHandler"/> <bean class="com.farsunset.ichat.cim.handler.SessionClosedHandler"/>
</entry> </entry>
<entry key="client_get_offline_message">
<bean class="com.farsunset.ichat.cim.handler.PushOfflineMessageHandler"/>
</entry>
</map> </map>
</property> </property>
</bean> </bean>

View File

@ -0,0 +1,49 @@
/**
* probject:cim
* @version 1.1.0
*
* @author 3979434@qq.com
*/
package com.farsunset.ichat.cim.handler;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import com.farsunset.cim.nio.constant.CIMConstant;
import com.farsunset.cim.nio.handler.CIMRequestHandler;
import com.farsunset.cim.nio.mutual.Message;
import com.farsunset.cim.nio.mutual.ReplyBody;
import com.farsunset.cim.nio.mutual.SentBody;
import com.farsunset.cim.nio.session.CIMSession;
/**
* 推送离线消息
*/
public class PushOfflineMessageHandler implements CIMRequestHandler {
protected final Logger logger = Logger
.getLogger(PushOfflineMessageHandler.class);
public ReplyBody process(CIMSession ios, SentBody message) {
ReplyBody reply = new ReplyBody();
reply.setCode(CIMConstant.ReturnCode.CODE_200);
try {
String account = message.get("account");
//获取到存储的离线消息
//List<Message> list = messageService.queryOffLineMessages(account);
List<Message> list = new ArrayList<Message>();
for (Message m : list) {
ios.write(m);
}
} catch (Exception e) {
reply.setCode(CIMConstant.ReturnCode.CODE_500);
e.printStackTrace();
logger.error("拉取离线消息失败", e);
}
return reply;
}
}

View File

@ -42,7 +42,9 @@
<entry key="sessionClosedHander"> <entry key="sessionClosedHander">
<bean class="com.farsunset.ichat.cim.handler.SessionClosedHandler"/> <bean class="com.farsunset.ichat.cim.handler.SessionClosedHandler"/>
</entry> </entry>
<entry key="client_get_offline_message">
<bean class="com.farsunset.ichat.cim.handler.PushOfflineMessageHandler"/>
</entry>
</map> </map>
</property> </property>
</bean> </bean>

View File

@ -2,9 +2,9 @@
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="D:/soft/adt-bundle-windows-x86_64-20140321/sdk/platforms/android-19/android.jar"/>
<classpathentry kind="lib" path="/ichat-server/WebRoot/WEB-INF/lib/commons-lang3-3.1.jar"/> <classpathentry kind="lib" path="/ichat-server/WebRoot/WEB-INF/lib/commons-lang3-3.1.jar"/>
<classpathentry kind="lib" path="/ichat-server/WebRoot/WEB-INF/lib/log4j.jar"/> <classpathentry kind="lib" path="/ichat-server/WebRoot/WEB-INF/lib/log4j.jar"/>
<classpathentry kind="lib" path="/ichat-server/WebRoot/WEB-INF/lib/netty-3.6.5.Final.jar"/> <classpathentry kind="lib" path="/ichat-server/WebRoot/WEB-INF/lib/netty-3.6.5.Final.jar"/>
<classpathentry kind="lib" path="D:/android-eclipse/adt-bundle-windows-x86_64-20131030/sdk/platforms/android-19/android.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -0,0 +1,49 @@
/**
* probject:cim
* @version 1.1.0
*
* @author 3979434@qq.com
*/
package com.farsunset.ichat.cim.handler;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import com.farsunset.cim.nio.constant.CIMConstant;
import com.farsunset.cim.nio.handler.CIMRequestHandler;
import com.farsunset.cim.nio.mutual.Message;
import com.farsunset.cim.nio.mutual.ReplyBody;
import com.farsunset.cim.nio.mutual.SentBody;
import com.farsunset.cim.nio.session.CIMSession;
/**
* 推送离线消息
*/
public class PushOfflineMessageHandler implements CIMRequestHandler {
protected final Logger logger = Logger
.getLogger(PushOfflineMessageHandler.class);
public ReplyBody process(CIMSession ios, SentBody message) {
ReplyBody reply = new ReplyBody();
reply.setCode(CIMConstant.ReturnCode.CODE_200);
try {
String account = message.get("account");
//获取到存储的离线消息
//List<Message> list = messageService.queryOffLineMessages(account);
List<Message> list = new ArrayList<Message>();
for (Message m : list) {
ios.write(m);
}
} catch (Exception e) {
reply.setCode(CIMConstant.ReturnCode.CODE_500);
e.printStackTrace();
logger.error("拉取离线消息失败", e);
}
return reply;
}
}

View File

@ -30,7 +30,9 @@
<entry key="sessionClosedHander"> <entry key="sessionClosedHander">
<bean class="com.farsunset.ichat.cim.handler.SessionClosedHandler"/> <bean class="com.farsunset.ichat.cim.handler.SessionClosedHandler"/>
</entry> </entry>
<entry key="client_get_offline_message">
<bean class="com.farsunset.ichat.cim.handler.PushOfflineMessageHandler"/>
</entry>
</map> </map>
</property> </property>
</bean> </bean>