jersey annotations
参照:
http://blog.csdn.net/a19881029/article/details/43056429
@Path
用来为资源类或方法定义URI,当然除了静态URI也支持动态URI
@Path("service")
public class MyResource {
@Path("{sub_path}")
@GET
public String getResource(@PathParam("sub_path") String resourceName) {
......
如果此时客户端请求的URI为http://127.0.0.1:10000/service/sean,则sub_path的值为sean
@PathParam用来将请求URI的一部分作为方法参数传入方法中
对URI的动态部分,可以自定义校验正则表达式,如果请求参数校验失败,容器返回404 Not Found
@Path("{sub_path:[A-Z]*}")
@GET
表明被注解的方法响应HTTP GET请求,@POST、@PUT和@DELETE同理
@Consumes
定义请求的媒体类型,如果不指定,则容器默认可接受任意媒体类型,容器负责确认被调用的方法可接受HTTP请求的媒体类型,否则返回415 Unsupported Media Type
方法级注解将覆盖类级注解
@Produces
定义响应媒体类型,如果不指定,则容器默认可接受任意媒体类型,容器负责确认被调用的方法可返回HTTP请求可以接受媒体类型,否则返回406 Not Acceptable
方法级注解将覆盖类级注解
@QueryParam
public String getResource(
@DefaultValue("Just a test!") @QueryParam("desc") String description) {
......
}
如果请求URI中包含desc参数,例如:http://127.0.0.1:10000/service/sean?desc=123456,则desc参数的值将会赋给方法的参数description,否则方法参数description的值将为@DefaultValue注解定义的默认值
@Context
将信息注入请求或响应相关的类,可注入的类有:Application,UriInfo,Request,HttpHeaders和SecurityContext
@Singleton和@PerRequest
默认情况下,资源类的生命周期是per-request,也就是系统会为每个匹配资源类URI的请求创建一个实例,这样的效率很低,可以对资源类使用@Singleton注解,这样在应用范围内,只会创建资源类的一个实例
jersey annotations的更多相关文章
- 【转】 Build a RESTful Web service using Jersey and Apache Tomcat 2009
Build a RESTful Web service using Jersey and Apache Tomcat Yi Ming Huang with Dong Fei Wu, Qing GuoP ...
- Jersey(1.19.1) - Root Resource Classes
Root resource classes are POJOs (Plain Old Java Objects) that are annotated with @Path have at least ...
- Jersey(1.19.1) - Life-cycle of Root Resource Classes
By default the life-cycle of root resource classes is per-request, namely that a new instance of a r ...
- Jersey(1.19.1) - XML Support
As you probably already know, Jersey uses MessageBodyWriters and MessageBodyReaders to parse incomin ...
- Jersey(1.19.1) - JSON Support
Jersey JSON support comes as a set of JAX-RS MessageBodyReader<T> and MessageBodyWriter<T&g ...
- 用jersey + spring 实现rest服务及单元测试
jersey提供了强大的rest功能,可以通过简洁的标注和编码实现业务的需求,架构会透明的把你的pojo对象转化为客户端可以接受的json/xml文件模式,当然也可以用它做一些基于ajax的表单提交和 ...
- 使用jersey 注解包扫描类PackageNamesScanner
Jersey 中自带一个包扫描,可以是包,或者具体类名 ,扫描的类型是自己定注解类型,实现功能更加大,可以是jar 包 可以是虚拟地址下的 Jersey 主要用来扫描Path Provider 类中同 ...
- JERSEY中文翻译(第三章、JAX-RS Application, Resources and Sub-Resources)
JAX-RS Application Resource and Sub-Resource 本章要介绍的是JAX-RS的核心概念——Resouce.Sub-Resource JAX-RS的2.0的jav ...
- Jersey 入门与Javabean
Jersey是JAX-RS(JSR311)开源参考实现用于构建RESTful Web service,它包含三个部分: 核心服务器(Core Server) 通过提供JSR 311中标准化的注释和AP ...
随机推荐
- jetty tutorial
http://www.eclipse.org/jetty/documentation/current/embedding-jetty.html#d0e18726 Version: 9.2.2-SNAP ...
- 一些使用的linux库
1.curl网络库 apt-get install libcurl4-openssl-dev sudo apt-get install curl 2.jsoncpp库 sudo apt-get ins ...
- [SoapUI] 通过Groovy脚本获取project所在的路径或者直接用${projectDir}
import com.eviware.soapui.support.GroovyUtils def groovyUtils = new GroovyUtils( context ) def proje ...
- [Selenium]等待元素出现之后再消失,界面上的loading icon都属于这种类型,之前的方法总是卡死,换这种方法目前还好用的
等待元素出现之后再消失,界面上的loading icon都属于这种类型,之前的方法总是卡死,换这种方法目前还好用的 /** * Check if the element present with cu ...
- TableLayout 里的TextView等组的LayoutParams参数问题
TableLayout 里的TextView等组的LayoutParams参数不能是LinearLayout.LayoutParams这样来定义, 只能是用TableRow.LayoutParams ...
- 跟微软保持适当距离--Hessian + .net 实现RPC体系的企业应用
同在一个产业链园区的XX厂因为5台Window2003服务器收到了律师函并且被迫下了12万$的采购单,虽然100万对XXX厂来数不是大数目,但是总有种被打劫的感觉. 在企业ERP应用中服务层一般都是做 ...
- os.path等os模块函数
os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...
- thinkphp 调用wsdl接口实例化SoapClient抛出异常
异常:Message:SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://*****?wsdl' : failed to load externa ...
- linux每天一小步---alias命令详解
1 命令功能 alias命令用来设置指令的别名,alias命令设置的别名只限于该次登陆操作,若要每次登入即自动设好别名,可在/etc/profile或自己的~/.bashrc中设定指令的别名. ...
- 20145233《网络对抗》Exp9 Web安全基础实践
20145233<网络对抗>Exp9 Web安全基础实践 实验问题思考 SQL注入攻击原理,如何防御? SQL注入攻击就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符 ...