Jersey (1.19.1)-Conditional GETs and returning 304 (not Modified) responses

Source: Internet
Author: User

Conditional GETs is a great a-to-reduce bandwidth, and potentially server-side performance, depending on how the inform Ation 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:

 PublicSparklinesresource (@QueryParam ("D") integerlist data, @DefaultValue ("0,100") @QueryParam ("Limits")) Interval limits, @Context request request, @Context Uriinfo UI) {if(Data = =NULL)        Throw NewWebapplicationexception (400);  This. data =data;  This. Limits =limits; if(!limits.contains (data))Throw NewWebapplicationexception (400);  This. Tag =Computeentitytag (Ui.getrequesturi ()); if(Request.getmethod (). Equals ("GET") {Response.responsebuilder RB=request.evaluatepreconditions (tag); if(RB! =NULL)            Throw Newwebapplicationexception (Rb.build ()); }}

The constructor of the SparklinesResouce root resource class computes an entity tag from the request URI and then calls the Request.ev Aluatepreconditions with that entity tag. If A client request contains an If-None-Match header with a value that contains the same entity tag that is calculated then the E Valuatepreconditionsreturns a pre-filled out response, with the 304 status code and entity tag set, which may be built and Returned. Otherwise, Evaluatepreconditions returns and the null normal response can be returned.

Notice That's example the constructor of a resource class can be used perform actions which may otherwise has to be Duplicated to invoked for each resource method.

Jersey (1.19.1)-Conditional GETs and returning 304 (not Modified) responses

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.