public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
Matcher m = null;
String uri = URLDecoder.decode(request.getRequestURI(), ENCODING);
AbstractApiRequest apiRequest = null;
/*
* /legislation/(api/(1.0/)?[format]/)?[type]/[id]
*
* ex. /legislation/api/html/bill/s1234-2011
*/
if(apiRequest == null && (m = SINGLE_PATTERN.matcher(uri)) != null && m.find()) {
apiRequest = new SingleViewRequest( request,
response,
m.group(SINGLE_FORMAT),
m.group(SINGLE_TYPE),
m.group(SINGLE_ID));
}
/*
* /legislation/(api/(1.0/)?)?[type](/[page number](/[page size]))?
*
* ex. legislation/bills/1/20 (first page, 20 bills a page)
*/
if(apiRequest == null && (m = MULTI_PATTERN.matcher(uri)) != null && m.find()) {
apiRequest = new MultiViewRequest( request,
response,
m.group(MULTI_FORMAT),
m.group(MULTI_TYPE),
m.group(MULTI_PAGE_NUMBER),
m.group(MULTI_PAGE_SIZE));
}
/*
* /legislation/(api/(1.0/)?)?[key]/[value](/[page number](/[page size]))?
*
* ex. /legislation/api/committee/finance
*/
if(apiRequest == null && (m = KEY_VALUE_PATTERN.matcher(uri)) != null && m.find()) {
logger.info(TextFormatter.append("Key value request: ", uri));
apiRequest = new KeyValueViewRequest( request,
response,
m.group(KEY_VALUE_FORMAT),
m.group(KEY_VALUE_KEY),
m.group(KEY_VALUE_VALUE),
m.group(KEY_VALUE_PAGE_NUMBER),
m.group(KEY_VALUE_PAGE_SIZE));
}
if(apiRequest == null && (m = SEARCH_PATTERN.matcher(uri)) != null && m.find()) {
apiRequest = new SearchRequest( request,
response,
m.group(SEARCH_FORMAT),
m.group(SEARCH_KEY),
m.group(SEARCH_VALUE),
m.group(SEARCH_PAGE_NUMBER),
m.group(SEARCH_PAGE_SIZE));
}
try {
if(apiRequest == null)
throw new ApiRequestException(TextFormatter.append("Failed to route request: ", uri));
apiRequest.execute();
}
catch(ApiRequestException e) {
logger.error(e);
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}