zoukankan      html  css  js  c++  java
  • Jersey(1.19.1)

    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.

  • 相关阅读:
    黑产江湖
    FW/IDS/IPS/WAF等安全设备部署方式及优缺点
    SOAPA来临,SIEM时代终结?
    美国爱因斯坦计划4
    零基础如何学好安卓开发
    协同办公系统能为企业带来怎样的影响?
    阿里腾讯开撕,钉钉的广告打到腾讯的地盘了
    bug管理工具为开发者工作带来哪些改变?
    开发人员必备的几款bug管理工具
    教你玩转产品管理系统iClap(PC端功能篇)
  • 原文地址:https://www.cnblogs.com/huey/p/5399662.html
Copyright © 2011-2022 走看看