Error 500 (Internal Server Error), how much do I try to create a session

0

I'm trying to create a session for a login using Java, vRaptor, Hibernate, AngularJS. But when the session is going to be created I get this exception ( 500 (Internal Server Error )).

This is my session class using vRaptor:

@SessionScoped

@Any public class LoginModel implements Serializable {     private admin admin;

public static void LoginModel(String[] arg) {

}

public void login(Administrador administrador) {
    this.administrador = administrador;
}



public boolean isLogado() {
    return administrador != null;
}

public Administrador getLogado() {
    return administrador;
}

public void setLogado(Administrador administrador) {
    this.administrador = administrador;
}

public void logout() {
    this.administrador = null;
}

And in my controler I have the method that checks and creates the session:

 @Consumes("application/json")
@Post("/verifica-login")
public void verificaLogin(String email, String senha) {
    try {
        Administrador administrador;
        administrador = administradorRepository.login(email, senha);

       //Até essa parte esta tudo certo, o administrador ja foi validado
      // e já foi carregado no objeto administrador, mas quando o comando
      // abaixo (if) é executado eu recebo a exceção. 

        if (administrador != null) {
            loginModel.login(administrador);
        }
        result.use(Results.json()).withoutRoot().from(administrador).serialize();
    } catch (Exception e) {
        result.use(Results.json()).withoutRoot().from(e.getMessage()).serialize();
    }

}

I would like to know what I'm doing, because I've read some documentation and followed some tutorials and apparently it's right, but my lack of experience does not help in those KKK hours. I was following an example from Caelum.

Obs :. I do not know what this @Any annotation is for, but I was asking her or @Default to work, in the Caelum tutorial she asks to add the annotation @Component, but this annotation has no import from vraptor or something like that.     

asked by anonymous 06.07.2016 / 14:31

1 answer

0

The error was due to non-initialization of the LoginModel class, which also caused a null object return error, in the end my class stayed like this.

@Consumes("application/json")
@Post("/verifica-login")
public void verificaLogin(String email, String senha) {
    try {
        Administrador administrador = administradorRepository.login(email, senha);
        LoginModel loginModel = new LoginModel();
        if (administrador != null) {
            loginModel.login(administrador);
        }
        result.use(Results.json()).withoutRoot().from(administrador).serialize();
    } catch (Exception e) {
        result.use(Results.json()).withoutRoot().from(e.getMessage()).serialize();
    }

}

This solved the problem of creating the session.

    
06.07.2016 / 19:28