I want to first say that I am a newbie to Android and java (to a lesser extent). I have a client-server application, the client is an Android app and the server is running Tomcat. Considering I am new at this I am a little confused about the POST request. The Client has a couple text fields, the user enters information and hits a button that calls on a method that well does a POST task. I can see that the server receives the data from the POST form in the client but my question is where does that information (from the form) go? It is supposed to create a new resource (in this case a Person resource)…Here is the code from the PersonResource class that does the POST.
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
public Person postPerson(MultivaluedMap<String, String> personParams) {
String firstName = personParams.getFirst(FIRST_NAME);
String lastName = personParams.getFirst(LAST_NAME);
String email = personParams.getFirst(EMAIL);
System.out.println ("System storing: " + firstName + " " + lastName + " " + email);
person.setFirstName(firstName);
person.setLastName(lastName);
person.setEmail(email);
System.out.println ("person info: " + person.getFirstName() + " " + person.getLastName() + " " + person.getEmail() + " " + person.getId());
return person;
}
It returns a person resource but ultimately where does that person resource go? I am sorry if I have not provided all required information needed to solve this problem. If more information is needed I will be happy to provide it. I truly appreciate any help given. Thank you.
I am not sure I fully understand the question, but here is an overview that might be helpful:
The client POST sends an HTTP request to the server. The server must have some sort of web service framework (e.g. Jersey or CXF or …) that processes the request. The JAX-RS annotations on your class (@POST and @Consume), instruct the web service framework to route the request to the postPerson method of your class. It sounds like this much is working, yes?
Your method then constructs a Person object based upon the contents of the form, i.e. the user input. Your method returns this Person to the web service framework.
So what happens to this person? The @Produces annotation you have provided, instructs the web service framework to generate a JSON representation of the person and include this in the body of the HTTP response that is sent back to the client. The response might look something like this:
Is this what you were looking for?