Created
July 2, 2012 07:18
-
-
Save inancsevinc/3031644 to your computer and use it in GitHub Desktop.
JAX-RS optional path params example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Returns most popular(retrieved using records in portal_log) documents opened using portal. | |
| * This rest service responds all these requests:<br/> | |
| * ../log/top ({p:/?} makes / optional)<br/> | |
| * ../log/top/<br/> | |
| * ../log/top/10 (same as ../log/top)<br/> | |
| * ../log/top/20 (any number is fine)<br/> | |
| * | |
| * @param numberOfItems max number of items, default 10 | |
| * @return list of items containing cuid, rank and viewCount, ordered by viewCount desc | |
| */ | |
| @GET | |
| @Path("/log/top{p:/?}{numberOfItems:([0-9]*)}") | |
| @Produces(MediaType.APPLICATION_JSON) | |
| public Response getTopItems(@PathParam(value = "numberOfItems") int numberOfItems) { | |
| try { | |
| return Response.ok(portalLogDao.getTopItems(numberOfItems==0?10:numberOfItems)).build(); | |
| } catch (Exception e) { | |
| return createExceptionResponse(e); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment