利用Jersey构建REST之入门实例
一、依赖包
1、目录结构如下:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAATcAAAIICAIAAACEhD6AAAAgAElEQVR4nO2dbZQU1b2v+0u+s849a+V4vxBNsg7qiYmgpG3NZK4nR9Rwg5cVciALOb4kFRPjAVRskCFMRlBAja0DSNTADDgjCCJCaFAkw0t4i4pAUObYURhgZGZgcGCYmZqunqn7obqrdtX+73rp16ru37Nqsejq2lW7e/bTe1d17V+HVACAvwmVugIAAAdgKQB+JxtLPz6yd+mfn5++ZcvSPz//8ZG9qqq+9vrbvVf6LJuNemB5HioIQMXj2dKPj+ydvmVL4sMG+dzB6Vu2RLb+/eMje1s/OVL/xzWWLWEpAHnBs6Vrd7SqV06eOLZs3+dPbz3+ypRlb/7n7LVde+f9cfGcWTVLZtUsqXumvrOrWxVaGpdCkVjCzaHcbwlAOePZ0ulbtmz4n0/X7PrT6/G7Vv7pRw/PWzXlv9eql/akFwZYCkBeCKmqOjw8bFnLr9GZvmXL7bvbpjRtnferf5/13zMm/vfbM+c+r17ckV5UdcLv1mlbwlIA8kJo1apV0WhUURR9laIo0Wi0oaGBLPDxkb1TVx769xeOPzBzw88eWPOzB576+Mheteud9MLICUsByAuhaDRaXV2ti6opqq1JpVJkmY+P7H1+3hsP/uKVmkdj2jXe2gVrpz+2Zvpja1RVXb/nxKgHlo96YPmq945SpeNSKBKLSSENKZ5enYhFQpZ17rcEoJwJJZNJXcv+/n6LtC55p21IX9j1v3r0LW7buKTrlYhF0r1lIiZles24lHna/ZYAlDMhlek/x48f71LRrkOr2pomdR1aparqmycG+eXVvRd++Xj8TPslrig7jk3EIsaYlusj3W8JQDmTvsbLDnTd9KJtTZPU1N/bmiapqrr6wyuWpX5758+nv9d29jJVlHIvEYuEMmsTsYiNpfSWAJQzxjcxiqI0NjYmk0nHMl27npNba+8ZFZJba7t2Pa+q6iu7evTlmXWn/8/Pt5w8Qyqq0u4x6xKxiF1fSm8JQDmTzR2CbU2TdEu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Ox9++Pd/7BtIPfz7P15758N9cqpfTm3e+FKejgNLQUGoCEvXr1ve26/09iefXrH+2jsfvtyvXHvnw0+vWN/br/T2K2+tX0aWYqZfMfl+xlpjUho7WZJIGMrATvTM7DEuhSKxOBOqkinNHBqWVjoVYWnTG3/suaL0XFF6riQ1P6+98+GeK0ltzdq1K8hSbORIJBLRtMlIys6gNGcQ8AlDDOliFtX1XYf4GdGwFFSGpavWvNZ9OaktmqJPr1jffXlQW7P69VfpYhlV4lIklohLkVhCTcQiGUnNWKY5m8qbsCQhsbaT/4eloDIsfaWhoatnUFv0vrSrJ6mtWbl6laCc5iTjZzxm6VK57WEpyD8VYemyP71+7uLguYuDmp/nLsqaq9rKFStXiwomYpFIxBjO6uNey3A2LjkmDBkD3Egswa3I7AaWAoqKsDT2yhtnL8jtFwa1a7xnLwxq13jPdstnL8hLX2sSlmS9s2QNiHKf6YSh9Nkom5xnXD2CpcCWirD0+ZffPN0ln+6S27rk0+fl010Dp88PtHXJbecH2rrkF/64ttQVBMCOirB00fINJzsHtOVU58CpzoGTnbL+8Lnlb5a6ggDYURGWPr1049P1GxfWb3x66caFS7V/39ZWPl2/cfHSDaWuIAB2VISlAAQaWAqA3/n/fm1TeuOt4IAAAAAASUVORK5CYII=" alt="" />
2.jery.jar:转json用的工具包,可以随便找一个。
3.对了,还需要引入junit.jar
二、服务端代码
package com.haha.manager; import java.util.concurrent.atomic.AtomicLong; public class User { private static AtomicLong seq = new AtomicLong(0); private Long id; private String name; private String sex; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getSex() {
return sex;
} public void setSex(String sex) {
this.sex = sex;
} User(){
} public User(String name, String sex) {
this.id = seq.incrementAndGet();
this.name = name;
this.sex = sex;
} public Long getId() {
return id;
} public void setId() {
this.id = seq.incrementAndGet();
} }
资源类:
package com.haha.jersey; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType; import com.haha.manager.User;
import com.jery.util.JsonMapper; @Path("user")
public class UserResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("world")
/**
* 测试
* @return
*/
public String say(){
return "helloWorld!";
} @GET
@Produces(MediaType.APPLICATION_JSON)
@Path("hook")
/**
* 测试
* @return
*/
public String hook(){
return "hook!";
} private static Map<Long,User> userMap=new HashMap<Long,User>(); @POST
@Path("add")
@Consumes({MediaType.APPLICATION_FORM_URLENCODED,MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
public String creatUser(@FormParam("name") String name,
@FormParam("sex") String sex){
String rs=null;
try {
User user=new User(name,sex);
userMap.put(user.getId(), user);
rs=JsonMapper.buildNormal().toJson(userMap);
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
return rs;
} @DELETE
@Path("{id}")
public String deleteUser(@PathParam("id")Long id){
String rs=null;
try {
userMap.remove(id);
rs=JsonMapper.buildNormal().toJson(userMap);
} catch (Exception e) {
e.printStackTrace();
}
return rs;
} @PUT
@Path("update")
@Consumes({MediaType.APPLICATION_FORM_URLENCODED,MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})
public String updateUser(@FormParam("id") String id,
@FormParam("name") String name){
String rs=null;
try {
User user=userMap.get(Long.valueOf(id));
user.setName(name);
userMap.put(Long.valueOf(id), user);
rs=JsonMapper.buildNormal().toJson(userMap);
} catch (Exception e) {
e.printStackTrace();
}
return rs;
} @GET
@Path("{id}")
@Produces({MediaType.APPLICATION_XML,MediaType.TEXT_PLAIN,MediaType.APPLICATION_JSON})
public String findUserById(@PathParam("id") Long id){
User user=userMap.get(id);
String str="";
try {
str=JsonMapper.buildNormal().toJson(user);
} catch (Exception e) {
e.printStackTrace();
}
return str;
} @GET
@Produces({MediaType.APPLICATION_XML,MediaType.TEXT_PLAIN,MediaType.APPLICATION_JSON})
public String getUsers(){
List<User> userList=new ArrayList<User>();
userList.addAll(userMap.values());
String str="";
try {
str=JsonMapper.buildNormal().toJson(userList);
} catch (Exception e) {
e.printStackTrace();
}
return str;
} }
配置文件web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>haha</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>
com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.haha.jersey</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
三、 客户端程序:
package com.haha.client; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap; import org.junit.Test; import com.jery.util.JsonMapper;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl; public class UserClient {
private static String uri="http://127.0.0.1:8080/haha/rest"; @Test
public void test_hook(){
WebResource resource=new Client().resource(uri+"/user/hook");
ClientResponse response=resource.accept(MediaType.APPLICATION_JSON)
.get(ClientResponse.class);
System.out.println(response.getStatus());
System.out.println(response.getEntity(String.class));
}
@Test
public void test_hello(){
WebResource resource=new Client().resource(uri+"/user/world");
ClientResponse response=resource.accept(MediaType.TEXT_PLAIN)
.get(ClientResponse.class);
System.out.println(response.getStatus());
System.out.println(response.getEntity(String.class));
} @Test
public void addUser(){
try {
MultivaluedMap form=new MultivaluedMapImpl();
form.add("name", "花和尚");
form.add("sex", "male");
System.out.println("rq:"+JsonMapper.buildNormal().toJson(form));
WebResource resource=new Client().resource(uri+"/user/add");
ClientResponse response = resource.type(MediaType.APPLICATION_FORM_URLENCODED).
post(ClientResponse.class, form);
System.out.println("status"+response.getStatus());
System.out.println("rs:"+response.getEntity(String.class));
} catch (Exception e) {
e.printStackTrace();
}
} @Test
public void delete(){
try {
WebResource resource=new Client().resource(uri).path("user/3");
ClientResponse response=resource
.delete(ClientResponse.class);
System.out.println(response.getStatus());
System.out.println("rs:"+response.getEntity(String.class));
} catch (Exception e) {
e.printStackTrace();
}
} @Test
public void update(){
try {
MultivaluedMap form=new MultivaluedMapImpl();
form.add("id","2");
form.add("name", "戴(●'◡'●)鑫");
form.add("sex", "male");
System.out.println(JsonMapper.buildNormal().toJson(form));
WebResource resource=new Client().resource(uri+"/user/update");
ClientResponse response = resource.type(MediaType.APPLICATION_FORM_URLENCODED)
.put(ClientResponse.class,form);
System.out.println(response.getStatus());
System.out.println("rs:"+response.getEntity(String.class));
} catch (Exception e) {
e.printStackTrace();
}
} @Test
public void findUser(){
WebResource resource=new Client().resource(uri).path("user/2");
ClientResponse response=resource.accept(MediaType.TEXT_PLAIN)
.get(ClientResponse.class);
System.out.println(response.getStatus());
System.out.println(response.getEntity(String.class));
} @Test
public void getUsers(){
WebResource resource=new Client().resource(uri).path("user");
ClientResponse response=resource.accept(MediaType.TEXT_PLAIN)
.get(ClientResponse.class);
System.out.println(response.getStatus());
System.out.println(response.getEntity(String.class));
} }
利用Jersey构建REST之入门实例的更多相关文章
- SoapUI简介和入门实例解析
SoapUI简介 SoapUI是一个开源测试工具,通过soap/http来检查.调用.实现Web Service的功能/负载/符合性测试.该工具既可作为一个单独的测试软件使用,也可利用插件集成到Ecl ...
- 利用node构建本地服务
利用node构建本地服务 首先安装下node.js,地址为https://nodejs.org/en/,然后安装npm. node.js的中文api地址http://nodeapi.ucdok.com ...
- Vue.js2.0从入门到放弃---入门实例
最近,vue.js越来越火.在这样的大浪潮下,我也开始进入vue的学习行列中,在网上也搜了很多教程,按着教程来做,也总会出现这样那样的问题(坑啊,由于网上那些教程都是Vue.js 1.x版本的,现在用 ...
- Spring中IoC的入门实例
Spring中IoC的入门实例 Spring的模块化是很强的,各个功能模块都是独立的,我们可以选择的使用.这一章先从Spring的IoC开始.所谓IoC就是一个用XML来定义生成对象的模式,我们看看如 ...
- Spark+ECLIPSE+JAVA+MAVEN windows开发环境搭建及入门实例【附详细代码】
http://blog.csdn.net/xiefu5hh/article/details/51707529 Spark+ECLIPSE+JAVA+MAVEN windows开发环境搭建及入门实例[附 ...
- mybatis 详解(二)------入门实例(基于XML)
通过上一小节,mybatis 和 jdbc 的区别:http://www.cnblogs.com/ysocean/p/7271600.html,我们对 mybatis有了一个大致的了解,下面我们通过一 ...
- mybatis 详解(三)------入门实例(基于注解)
1.创建MySQL数据库:mybatisDemo和表:user 详情参考:mybatis 详解(二)------入门实例(基于XML) 一致 2.建立一个Java工程,并导入相应的jar包,具体目录如 ...
- [Gradle] 在 Eclipse 下利用 gradle 构建系统
转载自:http://www.ibm.com/developerworks/cn/opensource/os-cn-gradle/ 构建系统时候常常要用到 Ant, Maven 等工具,对于初学者 ...
- EF6CodeFirst+MVC5+Autofac泛型注册 入门实例
贴一个EF6 CodeFirst模式结合MVC5和Autofac(泛型注册)的一个入门实例 网上类似的例子实在太少,最近自己也有用到这一块的知识,总结了一下,不要让后人踩了自己踩过的坑. 1:新建三个 ...
随机推荐
- char与varchar区别-转
1.CHAR的长度是固定的,而VARCHAR2的长度是可以变化的, 比如,存储字符串“abc",对于CHAR (10),表示你存储的字符将占10个字节(包括7个空字符),而同样的VARCHA ...
- mysql row number的实现
CREATE TABLE `test_id` (`id` int(11) NOT NULL DEFAULT 0 ,`name` varchar(255) CHARACTER SET utf8 COLL ...
- HTML 文本格式化
HTML 可定义很多供格式化输出的元素,比如粗体和斜体字. 下面有很多例子,您可以亲自试试: HTML 文本格式化实例 文本格式化 此例演示如何在一个 HTML 文件中对文本进行格式化 预格式文本 此 ...
- 【shell】通配符
‘’与“” [root@andon ~]# name='$date' [root@andon ~]# echo $name $date [root@andon ~]# name=abc [root@a ...
- JavaScript中的继承模式总结
一.总结: //js中的几种继承 //原型链的问题,包含引用类型的原型属性会被实例共享,子类型无法给超类型传递参数 function SuperType() { this.colors = [&quo ...
- HDMI接口与协议
深入了解HDMI接口 一.HDMI接口的工作原理这张图是HDMI接口的架构示意图.从左边的信号源中你可以看到,HDMI接口的信源可以是任何支持HDMI输出的设备,而接入端也可以是任何带有HDMI输 入 ...
- IOS开发之自定义系统弹出键盘上方的view(转载)
这篇文章解决的一个开发中的实际问题就是:当弹出键盘时,自定义键盘上方的view.目前就我的经验来看,有两种解决方法.一个就是利用UITextField或者UITextView的inputAccesso ...
- ASP.NET MVC之从控制器传递数据到视图四种方式
前言 本系列开始着手讲述ASP.NET MVC,也算是自己对基础的回顾以及进一步深入学习,保证每天发表一篇该系列文章,关于基本知识则不再叙述,园子有关文章不胜枚举,这一系列若有叙述不当或错误之处,欢迎 ...
- [Android NDK/JNI-1A]-开发环境搭建
NDK简介 NDK能干什么:NDK使得在android中,java可以调用C 函数库. 1.Android平台从诞生起,就已经支持C.C++开发.众所周知,Android的SDK基于Java实现,这意 ...
- NeHe OpenGL教程 第二十一课:线的游戏
转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...