Reputation: 5351
I have a login Mobile Application in Android, here peoples can Login by adding username and password. After the "LOGIN" button click, i send an User Object to my server with only email(username) and password filled. that's my object:
@Entity
@Table(name="utente")
public class Utente implements Serializable {
@Id
@Column(name = "id")
private Integer id;
@Column(name = "nome")
private String nome;
@Column(name = "cognome")
private String cognome;
@Column(name = "email")
private String eMail;
@Column(name = "password")
private String password;
@Column(name = "ultimo_accesso")
private Date ultimoAccesso;
public Utente(){
}
(That's my java side of the object) with getters and setter below.
my code is the following:
@POST
@Path("login/docente")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public Response loginDocente(Utente utente){
// Utente utente = utenteJson.getValue();JAXBElement<Utente> utenteJson
try{
UtenteController utenteController = new UtenteController(entityManager);
Docente docente = utenteController.loginDocente(utente.geteMail(), utente.getPassword());
if (docente == null) {
return Response.noContent().build();}
else{
docente.getUtente().setUltimoAccesso(new Date());
return Response.ok().entity(docente).build();
}
}catch(Exception e){
return Response.status(Status.FORBIDDEN).entity(e).build();
}
}
but every times i write this code:
{
"eMail":"MyEmail",
"password":"MyPsw"
}
with Advanced Rest Client Application, i got this error:
Status
500 Internal Server Error Show explanation Loading time: 1482
Request headers
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36
Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo
Content-Type: application/json
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4
Response headers
Server: GlassFish Server Open Source Edition 4.1
X-Powered-By: Servlet/3.1 JSP/2.3 (GlassFish Server Open Source Edition 4.1 Java/Oracle Corporation/1.7)
Content-Language:
Content-Type: text/html
Date: Sun, 22 Mar 2015 20:33:00 GMT
Connection: close
Content-Length: 1154
i don't really know how to solve this, any ideas?
@Edit: i tryed to add an exception catcher, but my problem is that the request doesn't reach my server, it's stopped by rest client so my server doesn't neither get an input
Upvotes: 0
Views: 500
Reputation: 6073
You can create an exception mapper which could tell you the exact problem. I had the same kind of problems and since by default you dont see exceptions regarding parsing and servlet exceptions it can be very annoying.
Just add a class to the package like:
@Provider
public class GenericExceptionMapper implements ExceptionMapper<Throwable> {
@Override
public Response toResponse(Throwable ex) {
ex.printStackTrace();
}
}
This catches all exceptions so it might help you
Upvotes: 1