Open yunho1017 opened 7 years ago
exception of sessionCheck : java.lang.reflect.InvocationTargetException
Hello,
Sorry but the issue doesn't sound very very clear to me.
Could you please push, on a minimalist GitHub project, a small case that reproduces the issue.
For example, just a Main class with a single controller using the session.
This way, I can reproduce the bug, add an automatic test case failing reproducing your issue, then fix it (and watch that indeed, the test case passes after the fix).
Thanks a lot !
Sorry T.T `@Controller("/session") public class SessionController { String sessionKey; Statement statement; ResultSet resultSet;
@POST("/check")
public void sessionCheck(RoutingContext ctx) {
JsonObject jo = new JsonObject();
Session session = ctx.session();
String sessionKey = session.get("sessionKey").toString();
try {
statement = DataBase.DBconnection();
resultSet = statement.executeQuery("select count(*) from session where sessionKey='" + sessionKey + "';");
if (resultSet.next() && resultSet.getInt(1) > 0) {
jo.put("session", true);
ctx.response().putHeader("content-type", "application/json; charset=utf-8").setStatusCode(200)
.end(jo.toString());
ctx.response().close();
} else {
jo.put("session", false);
ctx.response().putHeader("content-type", "application/json; charset=utf-8").setStatusCode(400)
.end(jo.toString());
ctx.response().close();
}
} catch (SQLException e) {
jo.put("success", false);
ctx.response().putHeader("content-type", "application/json; charset=utf-8").setStatusCode(500)
.end(jo.toString());
ctx.response().close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
} `
Here is sessionCheck
and here is account `@Controller("/account") public class AccountController { Statement statement; ResultSet resultSet;
@POST("/login")
public void login(RoutingContext ctx, Session session) {
String id = ctx.request().getFormAttribute("id");
String password = ctx.request().getFormAttribute("password");
JsonObject jo = new JsonObject();
try {
statement = DataBase.DBconnection();
resultSet = statement.executeQuery(
"select count(*) from account where id= '" + id + "' and password='" + password + "';");
if (resultSet.next() && resultSet.getInt(1) >= 0) {
String sessionKey;
int count = 1;
do {
UUID key = UUID.randomUUID();
sessionKey = key.toString();
resultSet = statement
.executeQuery("select count(*) from session where sessionKey='" + sessionKey + "';");
if (resultSet.next())
count = resultSet.getInt(1);
} while (count != 0);
int result = statement.executeUpdate(
"insert into session values('" + sessionKey + "','" + id + "','" + password + "');");
if (result == 1) {
session.put("sessionKey", sessionKey);
ctx.setSession(session);
jo.put("success", true);
ctx.response().putHeader("content-type", "application/json; charset=utf-8").setStatusCode(201)
.end(jo.toString());
ctx.response().close();
} else {
jo.put("success", false);
ctx.response().putHeader("content-type", "application/json; charset=utf-8").setStatusCode(400)
.end(jo.toString());
ctx.response().close();
}
} else {
jo.put("success", false);
ctx.response().putHeader("content-type", "application/json; charset=utf-8").setStatusCode(400)
.end(jo.toString());
ctx.response().close();
}
} catch (SQLException e) {
jo.put("success", false);
ctx.response().putHeader("content-type", "application/json; charset=utf-8").setStatusCode(500)
.end(jo.toString());
ctx.response().close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
@POST("/register")
public void signUp(RoutingContext ctx) {
String id = ctx.request().getFormAttribute("id");
String password = ctx.request().getFormAttribute("password");
JsonObject jo = new JsonObject();
System.out.println(id + " " + password);
try {
statement = DataBase.DBconnection();
System.out.println("DataBase connection");
int result = statement.executeUpdate("insert into account values('" + id + "','" + password + "');");
if (result == 1) {
jo.put("success", true);
ctx.response().putHeader("content-type", "application/json; charset=utf-8").setStatusCode(200)
.end(jo.toString());
ctx.response().close();
} else {
jo.put("success", false);
ctx.response().putHeader("content-type", "application/json; charset=utf-8").setStatusCode(400)
.end(jo.toString());
ctx.response().close();
}
} catch (SQLException e) {
jo.put("success", false);
ctx.response().putHeader("content-type", "application/json; charset=utf-8").setStatusCode(500)
.end(jo.toString());
ctx.response().close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
} `
Seems related to #57 #67
Thanks for the source code, but I can't make it work without all the rest of your application.
A "reproducer" is a very simple, standalone project (means : that works on its own, without anything else needed) running and showing the bug in action.
Here I see some DataBase
access I don't have any access to, etc.
Please understand that reproducing issues from other people is very hard, and it helps alot to have a very simple test case (the most minimal as possible) showing the issue, without any "noise" (i.e. some code that is not involved in the bug).
But please note, as mentionned in #67 that using (Session session)
as parameter of your method should work.
Thanks.
oh i use '(RoutingContext ctx, Session session)' in sessionCheck but result is not differentT.T and i debug, session in login and session in sessionCheck are different id.
i tried get sessonKey in the session in sessionCheck . String sesionKey was null,,,
@POST("/check") public void sessionCheck(RoutingContext ctx, Session session) { JsonObject jo = new JsonObject(); String sessionKey = session.get("sessionKey").toString();
i make server with nubes. but i can't use SessionHandler. when i route sessionHandler, server didn't work. then i saw a issue, use this code '(RoutingContext routingContext,Session session)'. i try contain session. so i write this code 'session.put("sessionKey",sessionKey);'. it worked! but i make method sessionCheck. so i write this code (RoutingContext routingContext,Session session). but it didn't work!!T.T i do debug this code. so i think session of login method and session of sessionCheck are different object. please slove this problem T.T