I need to implement a webservice that uses the first query parameter to identify the operation, i.e. the client call would be something like: http://localhost:8080/ws/oper
I see this is already answered, but I had a similar problem and achieved a solution using sub-resources.
package com.example.ws;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
@Path("/")
public class Operation {
@Path("/")
public Object sub(@QueryParam("operation") String operation)
{
if ("info".equals(operation))
return new InfoOp();
if ("create".equals(operation))
return new CreateOp();
//handle via error code
}
public class InfoOp {
@GET
public String info() {
return "info";
}
}
public class CreateOp {
@GET
public String create(@QueryParam("name") String name) {
return "create: " + name;
}
}
}