I have a problem with my web service.
GETrequests are executed correctly and correctly, but the mail request receives HTTP status 415.
The project I'm working on is a JAX-RS RESTful API that will need to communicate with the Android mobile application. I can get information from the instructions GET.
This is the code of my object LoginFormat:
@XmlRootElement
public class LoginFormat {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
Here you can see a sample of POSTmy class CoCreationService:
@Path("/User")
public class CoCreationService {
@POST
@Path("/testLogin")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response parseTerm(LoginFormat login) {
return Response.status(200).entity(login.getUsername() + login.getPassword()).build();
}
}
I tried so much that they confuse me.
I tested the curl of a web service:
curl -i -X POST -H 'Content-Type: application/json' -d '{"username": "testuser", "password": "test"}' http://localhost:8080/CoCreationService/api/User/testLogin
Is there any tweak that needs to be mentioned, or have I made a critical mistake?
PS: I work with NetBeans.
Edit: POST with / plain text works!
@POST
@Path("/testPost")
@Consumes("text/plain")
public Response postClichedMessage(String message) {
return Response.status(200).entity(message).build();
}