Sometimes it is necessary to return additional information in response to a HTTP request. Such information may be built and returned using Response and Response.ResponseBuilder. For example, a common RESTful pattern for the creation of a new resource is to support a POST request that returns a 201 (Created) status code and a Location header whose value is the URI to the newly created resource. This may be achieved as follows:

@POST
@Consumes("application/xml")
public Response post(String content) {
URI createdUri = ...
create(content);
return Response.created(createdUri).build();
}

In the above no representation produced is returned, this can be achieved by building an entity as part of the response as follows:

@POST
@Consumes("application/xml")
public Response post(String content) {
URI createdUri = ...
String createdContent = create(content);
return Response.created(createdUri).entity(createdContent).build();
}

Response building provides other functionality such as setting the entity tag and last modified date of the representation.

Jersey(1.19.1) - Building Responses的更多相关文章

  1. Jersey(1.19.1) - Building URIs

    A very important aspects of REST is hyperlinks, URIs, in representations that clients can use to tra ...

  2. Jersey(1.19.1) - WebApplicationException and Mapping Exceptions to Responses

    Previous sections have shown how to return HTTP responses and it is possible to return HTTP errors u ...

  3. Jersey(1.19.1) - Conditional GETs and Returning 304 (Not Modified) Responses

    Conditional GETs are a great way to reduce bandwidth, and potentially server-side performance, depen ...

  4. Jersey(1.19.1) - Client API, Overview of the API

    To utilize the client API it is first necessary to create an instance of a Client, for example: Clie ...

  5. Jersey(1.19.1) - Client API, Using filters

    Filtering requests and responses can provide useful functionality that is hidden from the applicatio ...

  6. Jersey(1.19.1) - Hello World, Get started with Jersey using the embedded Grizzly server

    Maven Dependencies The following Maven dependencies need to be added to the pom: <dependency> ...

  7. Jersey(1.19.1) - Hello World, Get started with a Web application

    1. Maven Dependency <properties> <jersey.version>1.19.1</jersey.version> </prop ...

  8. Jersey(1.19.1) - Client API, Uniform Interface Constraint

    The Jersey client API is a high-level Java based API for interoperating with RESTful Web services. I ...

  9. Jersey(1.19.1) - Client API, Ease of use and reusing JAX-RS artifacts

    Since a resource is represented as a Java type it makes it easy to configure, pass around and inject ...

随机推荐

  1. UIButton上使用UIEdgeInsetsMake让title跟图片对齐

    UIButton上使用UIEdgeInsetsMake让title跟图片对齐 默认情况下,不设置的效果,都使居中现实,button为150*150 使用以下设置后:   [self setTitleE ...

  2. [转]directsound抓取麦克风PCM数据封装类

    网上有很多方法从麦克风读取PCM数据,不想一一举例.只是在这里发布一个我自己写的directsound的麦克风PCM数据采集类,通过它,可以很方便的利用directsound技术把麦克风的数据采集到, ...

  3. POJ 2763 Housewife Wind (树链剖分 有修改单边权)

    题目链接:http://poj.org/problem?id=2763 n个节点的树上知道了每条边权,然后有两种操作:0操作是输出 当前节点到 x节点的最短距离,并移动到 x 节点位置:1操作是第i条 ...

  4. HDU 4052 Adding New Machine (线段树+离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4052 初始给你w*h的矩阵,给你n个矩形(互不相交),按这些矩形尺寸把初始的矩形扣掉,形成一个新的'矩 ...

  5. SQLite的37个核心函数

    转载:http://www.feiesoft.com/00012/ abs(X) abs(X)返回 X 的绝对值. Abs(X) returns NULL if X is NULL. Abs(X) r ...

  6. 关于Python中的self

    虽然我现在写过一些Python代码,但实际上几乎还没用过Class,而且一直觉得一个很别扭的事情是,Class中的函数都要写个参数self,虽然实例化调用的时候不需要. 当然,一开始就知道Python ...

  7. pjsip视频通信开发(上层应用)之拨号键盘下部份拨号和删除功能

    我们开发的是视频电话,所以既可以视频通话,可以只有音频的通话,所以底部含有两个按钮,最后一个就是删除功能,如果输入错误,我们可以删除输入的内容. 这里我们要通过重写LinearLayout来实现这部份 ...

  8. SDWebImage内存性能优化

    // 清除已过期图片 [[SDImageCache sharedImageCache] cleanDisk]; // 设置最多缓存7天时间 [[SDImageCache sharedImageCach ...

  9. 个人对maven pom.xml文件的理解

    如:一个项目可能需要引用另外两个项目的类.. 如 项目cswebbefore  需要引用cswebservice 和reports 这三个项目都有各自的pom.xml文件 cswebservice 项 ...

  10. 2.目录:疯子讲iOS课程

    目录:疯子讲iOS课程 写这个目录让我纠结好几天,一是我在考虑要不要从Objective-c基础开始讲,是否要使用ARC的方式讲,二是本人的游戏这几天正在封测,时间也比较紧张.纠结于有些朋友可能还不了 ...