Created
September 25, 2011 14:38
-
-
Save whaley/1240657 to your computer and use it in GitHub Desktop.
PlayerService class for JAXRS 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
| package com.jasonwhaley.rest; | |
| import javax.ws.rs.GET; | |
| import javax.ws.rs.Path; | |
| import javax.ws.rs.PathParam; | |
| import javax.ws.rs.Produces; | |
| import javax.ws.rs.QueryParam; | |
| public class PlayerService { | |
| @GET | |
| @Produces("application/xml") | |
| @Path("/player/{nickname}.xml") | |
| public Player getXml(@PathParam(value = "nickname") String nickname, | |
| @QueryParam(value = "playerClass") String playerClass) { | |
| return this.get(nickname, playerClass); | |
| } | |
| @GET | |
| @Produces("application/json") | |
| @Path("/player/{nickname}.json") | |
| public Player getJson(@PathParam(value = "nickname") String nickname, | |
| @QueryParam(value = "playerClass") String playerClass) { | |
| return this.get(nickname, playerClass); | |
| } | |
| @GET | |
| @Produces({"application/json", "application/xml"}) | |
| @Path("/player/{nickname}") | |
| public Player get(@PathParam(value = "nickname") String nickname, | |
| @QueryParam(value = "playerClass") String playerClass) { | |
| Player player = new Player(); | |
| player.setNickname(nickname); | |
| player.setPlayerClass(playerClass); | |
| return player; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment