I'm developing an application where a POST to /operations will create a new
Operation, a GET to /operations/{code} will either return the Operation in XML
or in JSON, depending on the Header parameter Accept.
In order to achieve the path, I had to use @Path("operations") in the class
declaration and @Path("{code}") in the GET methods.
Using @Get or @Post (from org.restlet) didn't work at all. But when I changed
it to @GET and @POST (from javax.ws) it worked as expected.
So I have three questions:
1- Is it possible to use @Get and @Post with @Path?
2- What are the differences between: @Get and @GET; and between @Post and @POST
(because it seems using @GET and @POST I can do more things)?
3- If they have different purposes, then am I supposed to annotate my methods
with both @Get and @GET?
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2730188package br.org.bmnds.restlet.thirdapplication;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.restlet.data.Form;
@Path("operations")
public class OperationServerResource {
private static OperationDAO operationDAO = new OperationDAO();
@GET
@Path("{code}")
@Produces({"text/xml","application/json"})
public Operation retrieveXML(@PathParam("code") String code) {
return operationDAO.find(code);
}
@POST
public void handlePostJAXRS(Form form) {
String code = form.getFirstValue("code");
String name = form.getFirstValue("name");
String type = form.getFirstValue("type");
Operation operation = new Operation(code, name, OperationType.valueOf(type));
operationDAO.save(operation);
}
}