For some reason, I haven't found any normal way to do the following:
I want to Post a json object, and add additional parameters to the call (in this case, an authentication token). This is a simple RESTful server in myUrl/server, which should give access to different resources of a "person" in the url myUrl/server/person/personCode/resourceName.
GET is easy, and requires no object, only parameters. The problem arrises when I get to POST - how do I attach the JSON, and keep the other parameters as well?
The class (much has been removed for clarity and proprietary reasons...):
//Handles the person's resources
@Path("/person/{personCode}/{resourceName}")
public class PersonResourceProvider {
@GET
@Produces("application/json")
public String getPersonResource(@PathParam("personCode") String personCode, @PathParam("resourceName") String resourceName, @DefaultValue("") @QueryParam("auth_token") String auth_token) throws UnhandledResourceException, UnauthorizedAccessException {
//Authenticates the user in some way, throwing an exception when needed...
authenticate(personCode, auth_token, resourceName);
//Returns the resource somehow...
}
@POST
@Produces("application/json")
public String postPersonResource(@PathParam("personCode") String personCode, @PathParam("resourceName") String resourceName, @DefaultValue("") @QueryParam("resourceData") String resourceData, @DefaultValue("") @QueryParam("auth_token") String auth_token) throws UnhandledResourceException, UnauthorizedAccessException {
//Again, authenticating
authenticate(personCode, auth_token, resourceName);
//Post the given resource
}
}
Now, the GET method works perfectly, when you go to myUrl/person/personCode/resourceName, it gives me the correct resource. The auth_token is used with every single call to the server (for now, authentication is done by comparing with a predefined string), so it's needed. All the other parameters are provided through the path, except for the authentication token, which should not be in the path as it does not relate to the identity of the required resource.
When I get to POST, it's a problem. I know there's a way to tell the method it consumes a JSON, but in that case, what will happen to the other parameters (auth_token is one of them)? Should I use Multipart?
Another related question, this is the first time I've designed such a server, is this design correct?
Thanks!