REST:Atom的开源框架Apache Abdera
来源:互联网 发布:最红网络歌曲36首 编辑:程序博客网 时间:2024/05/23 15:45
Apache Abdera的目标是高效的实现Atom Syndication Format(简称Atom) 和 Atom Publishing Protocol(简称AtomPub) 定义的规范,并且功能完整,性能高。
AtomPub Server
Abdera提供classes对应atomPub的basics,详细概念解释见上篇。
- Services - Provider
- Workspaces - WorkspaceInfo & WorkspaceManager
- Collections - CollectionAdapter
引入maven最小依赖
<dependency> <groupId>org.apache.abdera</groupId> <artifactId>abdera-server</artifactId> <version>1.1.1</version></dependency>CollectionAdapter
public class Employee { private int id; private String name; private Date updated; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Date getUpdated() { return updated; } public void setUpdated(Date updated) { this.updated = updated; } }
AtomPub Client
添加maven最小依赖
<dependency> <groupId>org.apache.abdera</groupId> <artifactId>abdera-client</artifactId> <version>1.1.1</version> </dependency>检索资源(GET)
Abdera abdera = new Abdera();AbderaClient client = new AbderaClient(abdera);ClientResponse resp = client.get("http://localhost:8080/abdera-server-example/employee");if (resp.getType() == ResponseType.SUCCESS) { Document<Feed> doc = resp.getDocument();} else { // there was an error}如果资源不是XML 文档,ClientResponse提供了inputStream
InputStream in = resp.getInputStream();resp.getContentType();ClientResponse提供范围headers的方法,比如ETag ,Last-Modified
System.out.println(resp.getEntityTag());System.out.println(resp.getLastModified());System.out.println(resp.getContentLocation());System.out.println(resp.getSlug())客户端解析Atom Document并且打印entry titles
Abdera abdera = new Abdera();Parser parser = abdera.getParser(); URL url = new URL("http://intertwingly.net/blog/index.atom");Document<Feed> doc = parser.parse(url.openStream(),url.toString());Feed feed = doc.getRoot();System.out.println(feed.getTitle());for (Entry entry : feed.getEntries()) { System.out.println("\t" + entry.getTitle());}System.out.println (feed.getAuthor());创建资源(POST)
AbderaClient client = new AbderaClient(abdera); Entry entry = abdera.newEntry(); entry.setId(...);entry.setTitle(...);entry.setUpdated(...);entry.setContent(...);//... ClientResponse resp = client.post("http://localhost:8080/abdera-server-example/employee",entry); if (resp.getType() == ResponseType.SUCCESS) { // success} else { // there was an error}
更新资源(PUT)
AbderaClient client = new AbderaClient(abdera); Entry entry = abdera.newEntry();// ... ClientResponse resp = client.put("http://www.example.org/collection",entry); if (resp.getType() == ResponseType.SUCCESS) { // success} else { // there was an error}删除资源
AbderaClient client = new AbderaClient(abdera); ClientResponse resp = client.delete("http://www.example.org/collection"); if (resp.getType() == ResponseType.SUCCESS) { // success} else { // there was an error}使用传统的HTTP方法
Abdera abdera = Abdera.getInstance();AbderaClient client = new AbderaClient(abdera); RequestEntity entity = ...client.execute("PATCH", "http://example.org/foo", entity, null); if (resp.getType() == ResponseType.SUCCESS) { // success} else { // there was an error}
请求选项
RequestOptions options = client.getDefaultRequestOptions();options.setIfMatch(new EntityTag("foo"));options.setNoCache(true); ClientResponse resp = client.get("http://example.org/foo", options); if (resp.getType() == ResponseType.SUCCESS) { // success} else { // there was an error}使用SSL
Abdera abdera = new Abdera();AbderaClient client = new AbderaClient(abdera); // Default trust manager provider registered for port 443AbderaClient.registerTrustManager(); client.get("https://localhost:9080/foo");
未完待续。。。
参考:
https://cwiki.apache.org/confluence/display/ABDERA/AtomPub+Client
http://abdera.apache.org/index.html
0 0
- REST:Atom的开源框架Apache Abdera
- Apache Abdera:Atom,AtomPub和Java
- 认识 Atom 发布协议,第 3 部分: Apache Abdera 项目简介
- Atom的view框架SpacePen
- REST:Atom标准
- 开源框架:Apache的DBUtils框架
- 开源框架:Apache的DBUtils框架
- REST框架的理解
- atom,一款开源的代码编辑器
- Atom的view框架2-SpacePenViews
- Apache+PHP 实现基于Slim的REST框架 调用系统命令或自己开发的程序
- Apache CXF Rest与Spring 3.0 mvc 的异常处理框架总结
- 【通信框架】Apache的开源通信框架thrift概述
- 支持REST的Java框架
- Java的REST框架 SerfJ
- REST的Java框架对比
- Apache Came组件rest的使用
- Apache Camel配置SSL的rest
- 历史上最牛的演讲----甲骨文总裁拉里.埃里森(Larry Ellison)在耶鲁大学的演讲
- 高并发网站架构与正态分布的前生今世
- JavaScript实现拖拽预览,AJAX小文件上传
- JS计时器,setTimeout与setInterval
- php 的each()输出内容空白问题
- REST:Atom的开源框架Apache Abdera
- Codeforces Round #369 (Div. 2) C. Coloring Trees
- 获取定位授权和注意事项
- 旋转特效-鼠标经过
- easy UI简单使用介绍
- Unity3D深入浅出 - 动画系统(Mecanim)
- HashMap的实现原理
- Android官方培训课程学习(一): 兼容不同设备
- PhpExcel中文帮助手册|PhpExcel使用方法