I'm trying to use Jersey to develop a REST web service. My requirement is for me to be able to access the web service and return data, based on the passed PatParam parameters. My web service so far is as follows:
@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes({ "application/xml", "application/json", "application/x-www-form-urlencoded" })
@Path("/1.0/people{extension:(.json)*}/{personId:([^/]+?)?}{entityExtension:(.json)*}")
public String getLocation(@PathParam("extension") String extension, @PathParam("personId") String personId,@PathParam("entityExtension") String entityExtension)
{
if ((personId==null ||personId.equals("")) && (extension == null || extension.equals("")))
return "No Id, and no extension";
else
return "personId= "+personId + ", extension= " + extension+", entityExtension= "+entityExtension;
}
With the above code in mind, what I'm trying to achieve is the following:
http://localhost:8080/Jersey/RestService/1.0/people.json
Should return the list of all people in the "json" format (Hence the .json extension)
Now, I want to be able to get the information for a particular person by simply putting the person's ID, and return the person's information in json/xml based on the extension:
http://localhost:8080/Jersey/RestService/1.0/people/Mouhammed89.json
With the above URL, I should be returning the information for the personId: Mouhammed89, and returning the information in the json format.
I know that my problem is with the regular expressions that I'm using, so I would really appreciate the help in creating them.