- 浏览: 7246295 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (1546)
- 企业中间件 (236)
- 企业应用面临的问题 (236)
- 小布Oracle学习笔记汇总 (36)
- Spring 开发应用 (54)
- IBatis开发应用 (16)
- Oracle基础学习 (23)
- struts2.0 (41)
- JVM&ClassLoader&GC (16)
- JQuery的开发应用 (17)
- WebService的开发应用 (21)
- Java&Socket (44)
- 开源组件的应用 (254)
- 常用Javascript的开发应用 (28)
- J2EE开发技术指南 (163)
- EJB3开发应用 (11)
- GIS&Mobile&MAP (36)
- SWT-GEF-RCP (52)
- 算法&数据结构 (6)
- Apache开源组件研究 (62)
- Hibernate 学习应用 (57)
- java并发编程 (59)
- MySQL&Mongodb&MS/SQL (15)
- Oracle数据库实验室 (55)
- 搜索引擎的开发应用 (34)
- 软件工程师笔试经典 (14)
- 其他杂项 (10)
- AndroidPn& MQTT&C2DM&推技术 (29)
- ActiveMQ学习和研究 (38)
- Google技术应用开发和API分析 (11)
- flex的学习总结 (59)
- 项目中一点总结 (20)
- java疑惑 java面向对象编程 (28)
- Android 开发学习 (133)
- linux和UNIX的总结 (37)
- Titanium学习总结 (20)
- JQueryMobile学习总结 (34)
- Phonegap学习总结 (32)
- HTML5学习总结 (41)
- JeeCMS研究和理解分析 (9)
最新评论
-
lgh1992314:
[u][i][b][flash=200,200][url][i ...
看看mybatis 源代码 -
尼古拉斯.fwp:
图片根本就不出来好吧。。。。。。
Android文件图片上传的详细讲解(一)HTTP multipart/form-data 上传报文格式实现手机端上传 -
ln94223:
第一个应该用排它网关吧 怎么是并行网关, 并行网关是所有exe ...
工作流Activiti的学习总结(八)Activiti自动执行的应用 -
ZY199266:
获取不到任何消息信息,请问这是什么原因呢?
ActiveMQ 通过JMX监控Connection,Queue,Topic的信息 -
xiaoyao霄:
DestinationSourceMonitor 报错 应该导 ...
ActiveMQ 通过JMX监控Connection,Queue,Topic的信息
androidpn的学习研究(六)Androidpn-server的Mina编码和解码解析过程
在许多网络应用中可能针对传输的数据进行加密操作,接收到数据之后进行解码操作。
在mina中提供许多加密和解密的解析方式:
1.带一定前缀的字符串的解析方式。
2.序列化对象的字符串解析方式。
3.分隔符方式的字符串解析方式。
在mina中提供相关的filterchain支持相关的操作。
Mina的源代码如下:
package org.apache.mina.filter.codec; import org.apache.mina.core.session.IoSession; /** * Provides {@link ProtocolEncoder} and {@link ProtocolDecoder} which translates * binary or protocol specific data into message object and vice versa. * <p> * Please refer to * <a href="../../../../../xref-examples/org/apache/mina/examples/reverser/ReverseProtocolProvider.html"><code>ReverserProtocolProvider</code></a> * example. * * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ public interface ProtocolCodecFactory { /** * Returns a new (or reusable) instance of {@link ProtocolEncoder} which * encodes message objects into binary or protocol-specific data. */ ProtocolEncoder getEncoder(IoSession session) throws Exception; /** * Returns a new (or reusable) instance of {@link ProtocolDecoder} which * decodes binary or protocol-specific data into message objects. */ ProtocolDecoder getDecoder(IoSession session) throws Exception; }
加密处理类:
package org.apache.mina.filter.codec; import org.apache.mina.core.buffer.IoBuffer; import org.apache.mina.core.session.IoSession; /** * Encodes higher-level message objects into binary or protocol-specific data. * MINA invokes {@link #encode(IoSession, Object, ProtocolEncoderOutput)} * method with message which is popped from the session write queue, and then * the encoder implementation puts encoded messages (typically {@link IoBuffer}s) * into {@link ProtocolEncoderOutput} by calling {@link ProtocolEncoderOutput#write(Object)}. * <p> * Please refer to * <a href="../../../../../xref-examples/org/apache/mina/examples/reverser/TextLineEncoder.html"><code>TextLineEncoder</code></a> * example. * * @author <a href="http://mina.apache.org">Apache MINA Project</a> * * @see ProtocolEncoderException */ public interface ProtocolEncoder { /** * Encodes higher-level message objects into binary or protocol-specific data. * MINA invokes {@link #encode(IoSession, Object, ProtocolEncoderOutput)} * method with message which is popped from the session write queue, and then * the encoder implementation puts encoded messages (typically {@link IoBuffer}s) * into {@link ProtocolEncoderOutput}. * * @throws Exception if the message violated protocol specification */ void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception; /** * Releases all resources related with this encoder. * * @throws Exception if failed to dispose all resources */ void dispose(IoSession session) throws Exception; }
解密类如下:
package org.apache.mina.filter.codec; import org.apache.mina.core.buffer.IoBuffer; import org.apache.mina.core.session.IoSession; /** * Decodes binary or protocol-specific data into higher-level message objects. * MINA invokes {@link #decode(IoSession, IoBuffer, ProtocolDecoderOutput)} * method with read data, and then the decoder implementation puts decoded * messages into {@link ProtocolDecoderOutput} by calling * {@link ProtocolDecoderOutput#write(Object)}. * <p> * Please refer to * <a href="../../../../../xref-examples/org/apache/mina/examples/reverser/TextLineDecoder.html"><code>TextLineDecoder</code></a> * example. * * @author <a href="http://mina.apache.org">Apache MINA Project</a> * * @see ProtocolDecoderException */ public interface ProtocolDecoder { /** * Decodes binary or protocol-specific content into higher-level message objects. * MINA invokes {@link #decode(IoSession, IoBuffer, ProtocolDecoderOutput)} * method with read data, and then the decoder implementation puts decoded * messages into {@link ProtocolDecoderOutput}. * * @throws Exception if the read data violated protocol specification */ void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception; /** * Invoked when the specified <tt>session</tt> is closed. This method is useful * when you deal with the protocol which doesn't specify the length of a message * such as HTTP response without <tt>content-length</tt> header. Implement this * method to process the remaining data that {@link #decode(IoSession, IoBuffer, ProtocolDecoderOutput)} * method didn't process completely. * * @throws Exception if the read data violated protocol specification */ void finishDecode(IoSession session, ProtocolDecoderOutput out) throws Exception; /** * Releases all resources related with this decoder. * * @throws Exception if failed to dispose all resources */ void dispose(IoSession session) throws Exception; }
在androidpn中的没有采取任何加密方式,但是提供相关的类org.androidpn.server.xmpp.codec,如果需要可以针对传输的数据进行加密和解密工作。
package org.androidpn.server.xmpp.codec; import org.apache.mina.core.session.IoSession; import org.apache.mina.filter.codec.ProtocolCodecFactory; import org.apache.mina.filter.codec.ProtocolDecoder; import org.apache.mina.filter.codec.ProtocolEncoder; /** * Factory class that specifies the encode and decoder to use for parsing XMPP stanzas. * * @author Sehwan Noh (devnoh@gmail.com) */ public class XmppCodecFactory implements ProtocolCodecFactory { private final XmppEncoder encoder; private final XmppDecoder decoder; /** * Constructor. */ public XmppCodecFactory() { encoder = new XmppEncoder(); decoder = new XmppDecoder(); } /** * Returns a new (or reusable) instance of ProtocolEncoder. */ public ProtocolEncoder getEncoder(IoSession session) throws Exception { return encoder; } /** * Returns a new (or reusable) instance of ProtocolDecoder. */ public ProtocolDecoder getDecoder(IoSession session) throws Exception { return decoder; } }
androidpn的解密类:
package org.androidpn.server.xmpp.codec; import org.androidpn.server.xmpp.net.XmppIoHandler; import org.apache.mina.core.buffer.IoBuffer; import org.apache.mina.core.session.IoSession; import org.apache.mina.filter.codec.CumulativeProtocolDecoder; import org.apache.mina.filter.codec.ProtocolDecoderOutput; import org.jivesoftware.openfire.nio.XMLLightweightParser; /** * Decoder class that parses ByteBuffers and generates XML stanzas. * * @author Sehwan Noh (devnoh@gmail.com) */ public class XmppDecoder extends CumulativeProtocolDecoder { // private final Log log = LogFactory.getLog(XmppDecoder.class); @Override public boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { // log.debug("doDecode(...)..."); XMLLightweightParser parser = (XMLLightweightParser) session .getAttribute(XmppIoHandler.XML_PARSER); parser.read(in); if (parser.areThereMsgs()) { for (String stanza : parser.getMsgs()) { out.write(stanza); } } return !in.hasRemaining(); } }
androidpn的加密类:
package org.androidpn.server.xmpp.codec; import org.apache.mina.core.session.IoSession; import org.apache.mina.filter.codec.ProtocolEncoder; import org.apache.mina.filter.codec.ProtocolEncoderOutput; /** * Encoder class that does nothing (to the already encoded data). * * @author Sehwan Noh (devnoh@gmail.com) */ public class XmppEncoder implements ProtocolEncoder { // private final Log log = LogFactory.getLog(XmppEncoder.class); public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception { // log.debug("encode()..."); } public void dispose(IoSession session) throws Exception { // log.debug("dispose()..."); } }
最终将编码解析器转换为过滤器使用,具体配置如下:
<bean class="org.apache.mina.filter.codec.ProtocolCodecFilter"> <constructor-arg> <bean class="org.androidpn.server.xmpp.codec.XmppCodecFactory" /> </constructor-arg> </bean>
发表评论
-
[转]年度最实用50款免费Android应用推荐
2012-11-08 16:39 3256据国外媒体报道,有人说Android应用市场比iPhone应用 ... -
MQTT的学习研究(十七)Mosquitto简要教程(安装&使用)
2012-10-23 16:34 19744Mosquitto是一个实现了MQTT3.1协议的代理服务器, ... -
MQTT的学习研究(十六) MQTT的Mosquitto的window安装部署
2012-10-23 16:28 38745在mqtt的官方网站,有许多mqtt, 其中: Mos ... -
GIS的学习(四十五)【转】Integration of the MBTiles format on Android
2012-10-22 17:13 2876转载自 http:/ ... -
MQTT的学习研究(十五) MQTT 和android整合文章
2012-10-22 17:06 5173详细参考: How to Implement Pu ... -
MQTT的学习研究(十四) MQTT moquette 的 Callback API 消息发布订阅的实现
2012-10-19 14:08 11847在moquette-mqtt中提供了回调callback ... -
MQTT的学习研究(十三) IBM MQTTV3 简单发布订阅实例
2012-10-19 13:51 12711使用IBM MQTTv3实现相关的发布订阅功能 MQTTv3 ... -
MQTT的学习研究(十二) MQTT moquette 的 Future API 消息发布订阅的实现
2012-10-19 13:38 7668基于Future 模式的 ... -
MQTT的学习研究(十一) IBM MQTT 简单发布订阅实例
2012-10-19 13:30 6275package com.etrip.push; impo ... -
MQTT的学习研究(十)【转】mosquitto——一个开源的mqtt代理
2012-10-19 13:21 13364MQTT(MQ Teleme ... -
MQTT的学习研究(九)基于HTTP GET MQTT 抓取消息服务端使用
2012-10-18 15:25 4980官方参看文档: HTTP GET 接收主题请求协议和响应协议 ... -
MQTT的学习研究(八)基于HTTP DELETE MQTT 订阅消息服务端使用
2012-10-18 15:20 4212参看官方文档 HTTP DELETE 订阅主题 ... -
MQTT的学习研究(七)基于HTTP POST MQTT 发布消息服务端使用
2012-10-18 15:11 7725参阅官方文档 http:// ... -
MQTT的学习研究(六) MQTT moquette 的 Blocking API 订阅消息客户端使用
2012-10-17 16:56 21862参阅官方文档: http://publib.boulder. ... -
MQTT的学习研究(五) MQTT moquette 的 Blocking API 发布消息服务端使用
2012-10-17 16:52 30636参看官方文档: http://publib.bould ... -
MQTT的学习研究(四)moquette-mqtt 的使用之mqtt Blocking API客户端订阅并接收主题信息
2012-10-16 15:51 14546在上面两篇关于mqtt的broker的启动和mqtt的服 ... -
MQTT的学习研究(三)moquette-mqtt 的使用之mqtt服务发布主题信息
2012-10-16 15:48 19735接着上一篇的moquette-mqtt 的使用之 ... -
MQTT的学习研究(二)moquette-mqtt 的使用之mqtt broker的启动
2012-10-16 15:42 36707在MQTT 官网 (http://mqtt.o ... -
MQTT的学习研究(一)MQTT学习网站
2012-10-16 15:21 11181MQTT的官方推荐网站: http://mqtt.org/s ... -
GIS的学习(四十四)osmdroid sdcard检查
2012-10-15 16:12 2272在许多应用中使用到sdcard的检查,在osmdro ...
相关推荐
首先, 我们需要下载androidpn-client-0.5.0.zip和androidpn-server-0.5.0-bin.zip。 下载地址:http://sourceforge.net/projects/Androidpn/ 解压两个包,Eclipse导入client,配置好目标平台,打开raw/...
androidpn-server-0.5.0-bin.zip解压后,打卡bin目录下run.bat运行,之后在浏览器中输入http://127.0.0.1:7070/ 将androidpn-client-0.5.0解压后导入Eclipse,修改/raw/androidpn.properties中的xmppHost=xxx.xxx.x...
androidpn-client-0.5.0和androidpn-server-0.5.0-bin
androidpn-server-0.5.0-bin.zip、androidpn-client-0.5.0.zip、androidpn-demoapp-0.5.0.zip全给你们了,不用再去网站翻了
使用Apndroid Push Notification 实现android信息推送,AndroidPn项目是使用XMPP协议实现信息推送的一个开源项目。内涵服务端和客户端源码
该程序包修改至开源项目androidpn-server-0.0.5,携带jre7(此为windows版本,如要运行在linix,需更换为linix jre7),无需java配置运行环境,实现离线推送功能,支持推送消息有效期设置,服务端能够自主判断消息...
androidpn-server-bin-tomcat,看题目估计就知道的。 关于推送端的 服务器端的JAVA代码。
这个是androidpn的服务端.........................................
内含:配置方法一份、androidpn-server-0.5.0-bin.zip、androidpn-demoapp-0.5.0-bin.zip、androidpn-client-0.5.0-bin.zip。三个压缩包都是从官网下载http://sourceforge.net/projects/androidpn/,未做任何修改。...
androidpn-server-0.6.0.jar
androidPn Tomcat 版 ,用于推送的 android
androidpn-client.zip和androidpn-server-0.5.0-bin.zip, 解压两个包,Eclipse导入client,配置好目标平台,打开raw/androidpn.properties文件, apiKey=1234567890 xmppHost=10.0.2.2 xmppPort=5222 如果是...
基于XMPP协议、使用Androidpn服务器,Asmack编程的即时通讯IM客户端源代码;主要功能实现向客户端推送消息!
这是一个消息推送客户端,安装在自己的手机上,可以实现与andriodpn-sever的连接,接受推送的消息
androidpn0.5.0,包括androidpn-server-0.5.0-bin.zip、androidpn-demoapp-0.5.0.zip、androidpn-client-0.5.0.zip
androidpn-client-0.5.0 修改后的版本 修改原来的通知操作 为action配置 这样就可以定义自己的操作 action为: org.androidpn.client.NotificationProcess 请看文章: ...
这个是androidpn的客户端...............................
androidpn xmpp 消息推送 供研究学习使用 项目相关的jar包 androidpn-client-0.5.0,androidpn-server-0.5.0-binmandroidpn-server-0.5.0-src
官方版本,亲测可用