Reputation: 3
I started learning Play this week. Now I am trying to write a Code that creates a session, when a user logs in. Sorry, but the post looks a bit messy because I am new user, who is not allowed to post pictures.
I am using Java play 2.3.8 and eclipse 4.4.1 (and I already tried the other tips i saw here)
At the moment I always get this errormessage:
play.api.Application$$anon$1: Execution exception[[RuntimeException: java.lang.reflect.InvocationTargetException]] at play.api.Application$class.handleError(Application.scala:296) ~[play_2.11-2.3.6.jar:2.3.6] at play.api.DefaultApplication.handleError(Application.scala:402) [play_2.11-2.3.6.jar:2.3.6] at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$4.apply(PlayDefaultUpstreamHandler.scala:320) [play_2.11-2.3.6.jar:2.3.6] at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$4.apply(PlayDefaultUpstreamHandler.scala:320) [play_2.11-2.3.6.jar:2.3.6] at scala.Option.map(Option.scala:145) [scala-library-2.11.1.jar:na] Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at play.data.Form.bind(Form.java:394) ~[play-java_2.11-2.3.6.jar:2.3.6] at play.data.Form.bindFromRequest(Form.java:221) ~[play-java_2.11-2.3.6.jar:2.3.6] at controllers.Application.authenticate(Application.java:70) ~[classes/:na] at Routes$$anonfun$routes$1$$anonfun$applyOrElse$11$$anonfun$apply$11.apply(routes_routing.scala:209) ~[classes/:na] at Routes$$anonfun$routes$1$$anonfun$applyOrElse$11$$anonfun$apply$11.apply(routes_routing.scala:209) ~[classes/:na] Caused by: java.lang.reflect.InvocationTargetException: null at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_31] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_31] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_31] at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_31] at play.data.Form.bind(Form.java:391) ~[play-java_2.11-2.3.6.jar:2.3.6] Caused by: java.lang.RuntimeException: DataSource user is null? at com.avaje.ebeaninternal.server.lib.sql.DataSourcePool.(DataSourcePool.java:204) ~[avaje-ebeanorm-3.3.4.jar:na] at com.avaje.ebeaninternal.server.core.DefaultServerFactory.getDataSourceFromConfig(DefaultServerFactory.java:419) ~[avaje-ebeanorm-3.3.4.jar:na] at com.avaje.ebeaninternal.server.core.DefaultServerFactory.setDataSource(DefaultServerFactory.java:385) ~[avaje-ebeanorm-3.3.4.jar:na] at com.avaje.ebeaninternal.server.core.DefaultServerFactory.createServer(DefaultServerFactory.java:163) ~[avaje-ebeanorm-3.3.4.jar:na] at com.avaje.ebeaninternal.server.core.DefaultServerFactory.createServer(DefaultServerFactory.java:125) ~[avaje-ebeanorm-3.3.4.jar:na]
This is my method, that is called:
public static Result authenticate() {
Form<Login> loginForm = Form.form(Login.class);
Login loginUser = loginForm.bindFromRequest().get();
if (!usersList.getUsers().contains(loginForm)) {
return ok(login.render("test"));
} else {
session().clear();
session("email", loginForm.get().email);
System.out.println("ich bin hier");
return redirect(routes.Application.login());
}
}
This is the model (getters and setters are there, too):
public class Login {
public Login(){
}
public String email;
public String password;
public Login(String email, String password){
this.email=email;
this.password=password;
}
public String validate() {
if (Users.authenticate(email, password) == null) {
return "Invalid user or password";
}
return null;
}
public static Finder<String,Login> find = new Finder<String,Login>(
String.class, Login.class
);
And here the scala.html document:
<div class="Login">
<br>
<br>
<br>
<br>
<h1>Login</h1>
<form action="@routes.Application.authenticate()" method="post">
<p><input type="email" name="email" placeholder="Email" value=""></p>
<p><input type="password" name="password" placeholder="Password" value=""></p>
<p class="submit"><input type="submit" name="Login" value="Login"></p>
</form>
And last but not least the error message in my browser says the exception is thrown in line 70:
[RuntimeException: java.lang.reflect.InvocationTargetException]
System.out.println("nach loginform"); 68 69 //System.out.println(loginForm.bindFromRequest().toString()); 70 Login loginUser = loginForm.bindFromRequest().get(); 71 72 System.out.println(loginForm.toString()); 73// Form loginForm = form(Login.class).bindFromRequest(); 74
75 if (!usersList.getUsers().contains(loginForm)) {
thanks in advance for helping me with this issue
Upvotes: 0
Views: 1594
Reputation: 7919
Are you missing something
@Entity
public class Login extends Model {
and also check if ebean.default="models.*"
line is uncommented in application.conf
Upvotes: 2