Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nubes session error #74

Open
yunho1017 opened this issue Jun 21, 2017 · 9 comments
Open

nubes session error #74

yunho1017 opened this issue Jun 21, 2017 · 9 comments

Comments

@yunho1017
Copy link

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

@yunho1017
Copy link
Author

exception of sessionCheck : java.lang.reflect.InvocationTargetException

@aesteve
Copy link
Owner

aesteve commented Jun 22, 2017

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 !

@yunho1017
Copy link
Author

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());
	}
}

}
`

@yunho1017
Copy link
Author

Here is sessionCheck

@yunho1017
Copy link
Author

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());
	}
}

}
`

@aesteve
Copy link
Owner

aesteve commented Jun 22, 2017

Seems related to #57 #67

@aesteve
Copy link
Owner

aesteve commented Jun 22, 2017

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.

@yunho1017
Copy link
Author

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.

@yunho1017
Copy link
Author

yunho1017 commented Jun 22, 2017

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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants