Conditional GETs are a great way to reduce bandwidth, and potentially server-side performance, depending on how the information used to determine conditions is calculated. A well-designed web site may return 304 (Not Modified) responses for the many of the static images it serves.

JAX-RS provides support for conditional GETs using the contextual interface Request.

The following example shows conditional GET support from the sparklines sample:

public SparklinesResource(
@QueryParam("d") IntegerList data,
@DefaultValue("0,100") @QueryParam("limits") Interval limits,
@Context Request request,
@Context UriInfo ui) { if (data == null)
throw new WebApplicationException(400); this.data = data; this.limits = limits; if (!limits.contains(data))
throw new WebApplicationException(400); this.tag = computeEntityTag(ui.getRequestUri());
if (request.getMethod().equals("GET")) {
Response.ResponseBuilder rb = request.evaluatePreconditions(tag);
if (rb != null)
throw new WebApplicationException(rb.build());
}
}

The constructor of the SparklinesResouce root resource class computes an entity tag from the request URI and then calls the request.evaluatePreconditions with that entity tag. If a client request contains an If-None-Match header with a value that contains the same entity tag that was calculated then the evaluatePreconditionsreturns a pre-filled out response, with the 304 status code and entity tag set, that may be built and returned. Otherwise, evaluatePreconditions returns null and the normal response can be returned.

Notice that in this example the constructor of a resource class can be used perform actions that may otherwise have to be duplicated to invoked for each resource method.

最新文章

  1. php模拟http请求的方法
  2. 腾讯信鸽推送Android SDK快速指南
  3. 有一种算法叫做“Union-Find”?
  4. Class org.apache.struts2.json.JSONWriter can not access a member of class org.springframework.aop.TruePointcut with modifiers "public"
  5. CodeForces 705A(训练水题)
  6. **IOS:xib文件解析(xib和storyboard的比较,一个轻量级一个重量级)
  7. WWDC2014之iOS使用动态库
  8. 转一篇NGINX+UWSGI+PYTHON+DJANGO部署文档
  9. ZOJ2112--Dynamic Rankings (动态区间第k大)
  10. 浏览器文档播放Shockwave Flash 插件问题
  11. display:block;inline;inline-block大总结
  12. 归并排序(非递归,Java实现)
  13. raw_input与input
  14. Kubernetes 笔记 06 豌豆荚之旅(一)
  15. codeforces 985B Switches and Lamps
  16. CSS3背景色透明(兼容IE8)
  17. SQL——将表中的最大ID+1插入新的ID中------Insert into 表 MAX(表id) +1
  18. [企业化NET]Window Server 2008 R2[1]-服务器基本安装即问题解决记录
  19. 在ios上时间无法parse返回 "Invalid Date"
  20. kernel下nand flash的文件系统总结

热门文章

  1. 关于session更新的问题
  2. 开源原生JavaScript插件-CJPCD(省市区联动)
  3. python函数介绍
  4. C# WinForm控件、自定义控件整理(大全)
  5. 方法javaJVM学习笔记-内存处理
  6. Codeforces Round #327 (Div. 2) C. Median Smoothing 找规律
  7. Linux內核中常用的一些延時方法
  8. [Mapreduce]eclipse下写wordcount
  9. ViewGroup源码部分解析
  10. xtrabackup进行物理备份、恢复、在线克隆从库、在线重做主从