Form parameter data will only be present when you submit ... form data. Change the @Consumes
type for your resource to multipart/form-data
.
@PUT
@Path("/login")
@Produces({ "application/json", "text/plain" })
@Consumes("multipart/form-data")
public String login(@FormParam("login") String login,
@FormParam("password") String password) {
String response = null;
response = new UserManager().login(login, password);
return response;
}
Then on your client side, set:
- Content-Type: multipart/form-data
- Add form variables for
login
and password
On a side note, assuming this isn't for learning, you will want to secure your login endpoint with SSL, and hash the password before sending it across the wire.
EDIT
Based on your comment, I am including an example of sending a client request with the required form data:
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost post = new HttpPost(BASE_URI + "/services/users/login");
// Setup form data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("login", "blive1"));
nameValuePairs.add(new BasicNameValuePair("password",
"d30a62033c24df68bb091a958a68a169"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute request
HttpResponse response = httpclient.execute(post);
// Check response status and read data
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
String data = EntityUtils.toString(response.getEntity());
}
} catch (Exception e) {
System.out.println(e);
}