For pagination purposes, our UI guy is specifying the items ranges in the Http header as follows:
Range: items=0-15
In subsequent requests the ranges from the web can be either
Range: items=16-31
Range: items=32-45
...etc...etc
In my controller SearchRequestController.java, I am trying to extract these ranges so that I can send it over to the Solr server to return the values in the requested chucks by setting the start and the offset.
What I am doing is as follows(In SearchRequestController.java):
@RequestMapping("/billsSearch")
@ResponseBody
public SearchResult searchBills(HttpServletRequest request,@RequestBody SearchRequest searchRequest){
String rangeRequest = request.getHeader("Range");
//(1)Parse the rangeRequest using some mechanism
//(2)Set the start using the first value of the range
//(3) Add the second value to the start to get the offset
searchRequest.setStart(startValue);
searchRequest.setOffset(offsetValue);
return searchHelper(request,searchRequest);
}
There are a couple of questions that I have: Is this the best way to request data in a chunked fashion from the server?
How do I extract the ranges from the request header?
I am assuming the request.getHeader("Range")
will return "items=16-31
".
Is regular expression the best way to grab 16 and 31 from this string?
If I decide to use regular expression, wouldn't the expression break if I change the range header to be billItems=16-31?
I am a regex n00b, so it is quite possible I am thinking of this in a wrong way.
Are there alternatives to regex to parse range information like this from the http headers within SpringMVC?