rest - Jax-rs http header range -


i want use http header 'range' in jax-rs application, can define unit this? example, number of records.

what want implement limit number of records returned in response maximum value of 'range'

for parsing more complex parameters can implement paramconverter:

@provider public class rangeheaderconverter implements paramconverter<rangeheader> {      @override     public rangeheader fromstring(string value) {         return rangeheader.fromvalue(value);     }      @override     public string tostring(rangeheader value) {         return value.tostring();     }  } 

the implementation of rangeheader might this:

public class rangeheader {      public static enum unit {         bytes;     }      private unit unit;      private long from;      private long to;      public rangeheader(unit unit, long from, long to) {         this.unit = unit;         this.from = from;         this.to = to;     }      public unit getunit() {         return unit;     }      public long getfrom() {         return from;     }      public long getto() {         return to;     }      public static rangeheader fromvalue(string range) {         if (range == null) {             return null;         }         string[] tokens = range.replace("range: ", "").split("=");         unit unit = unit.valueof(tokens[0].touppercase());         string[] fromto = tokens[1].split("-");         long = long.valueof(fromto[0]);         long = long.valueof(fromto[1]);         return new rangeheader(unit, from, to);     }      public string tostring() {         return string.format("range: %s=%d-%d", unit.name().tolowercase(), from, to);     }  } 

you can use class this:

public response get(@headerparam("range") rangeheader range) {     // } 

note: quick+dirty implementation , doesn't handle special values or errors.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -