Error 500 (Internal Server Error), when I try to create a session

Asked

Viewed 302 times

0

I am trying to create a session for a login using Java, vRaptor, Hibernate, Angularjs. But when the session will 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 administrator;

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 controller 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 am doing because I read some documentation and followed some tutorials and apparently it is right, but my lack of experience does not help in these KKK hours. I was following an example of Caelum.

Obs. I don’t know what this @Any annotation is for, but I was asking it or @Default to work, the Caelum tutorial asks to add the @Component annotation, but this annotation does not have any import of vraptor or anything like that.

1 answer

0


The error was due to not initializing the Loginmodel class, which also caused a null return error of object, at the end my class was 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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.