【你不知道的android】-【hessian】
来源:互联网 发布:大数据 思维变革 编辑:程序博客网 时间:2024/05/16 15:30
一 、背景
android项目不会去直接连接远程数据库,你懂的。
一般都是调用接口,接口的技术实现多种多样,这次来介绍下hessian。
二 、hessian
在这里你能找到你所需要的文档,jar包,各种语言的实现。
这里主要看java的实现。
三 、目标
做一个类似微博api的接口,供android程序调用。
可参考腾讯微博api,如下
urlhttp://open.t.qq.com/api/t/showhttps://open.t.qq.com/api/t/show (oauth2.0使用)支持验证方式oauth1.0、oauth2.0、openid&openkey格式xml,jsonhttp请求方式get是否需要鉴权true请求数限制true, 查看API调用权限说明接口测试点击这里测试我们做一个比较简单的,不带认证,仅支持json格式的数据返回。
四 、code
1、 api
urlhttp://localhost:9999/hessianServer/show例子http://localhost:9999/hessianServer/show?name=abc格式jsonhttp请求方式post2、server
Creating a Hessian service using Java has four steps:
- Create an Java interface as the public API
- Create a client using HessianProxyFactory
- Create the Service implementation class
- Configure the service in your servlet engine.
- 创建一个接口
public interface IShow {
String show();
}
- 实现接口,继承hession
- 配置servlet
3、client
调用
public class Client {
public static void main(String[] args) { String url = “http://localhost:9999/hessianServer/show?name=abc“;
HessianProxyFactory factory = new HessianProxyFactory(); IShow show; try { show = (IShow) factory.create(IShow.class,url);
String str = show.show(); System.out.println(str); } catch (MalformedURLException e) { e.printStackTrace(); }
} }
注:
hessian仅支持post方式,url访问,会有提示,查看hessian源码可以看见。
hessian的HessianServlet如下:
public class HessianServlet extends GenericServlet
继承了Servlet,你懂的。
hessian会先执行service方法,然后才去直接借口的方法。
五、下载
点我下载
- 【你不知道的android】-【hessian】
- Android模拟器你不知道的秘密
- Android开发你不知道的TIPS
- Android-你所不知道的context
- Android Studio你不知道的快捷键
- Android RecyclerView 你不知道的用法
- android一些你知道的或不知道的style
- [Android] 你所不知道的drawable的那些细节
- android中你所不知道的高效的ArrayMap
- 数据库的漏洞你知道不知道
- Android中Context详解 ---- 你所不知道的Context
- Android中Context详解 ---- 你所不知道的Context
- Android中Context详解 ---- 你所不知道的Context
- Android中Context详解 ---- 你所不知道的Context
- Android中Context详解 ---- 你所不知道的Context
- Android中Context详解 ---- 你所不知道的Context
- Android中Context详解 ---- 你所不知道的Context
- Android中Context详解 ---- 你所不知道的Context
- HDU 1002 A + B Problem II
- linux 下java环境变量的设置
- linux下关于tomcat的几个问题
- Teamcenter 开发中的一些问题
- POJ 2451 Uyuw's Concert(半平面交nlgn)
- 【你不知道的android】-【hessian】
- linux 下如何发布java项目
- linux 下如何查找文件夹
- 检查MySql的版本
- Visual Studio 2012 Ultimate RTM 体验(附下载地址和KEY)
- linux下如何安装MySQL
- The Bottom of a Graph 强连通分量加缩点
- hdu1525-------Euclid's Game 找规律
- 存储过程HelloWorld