My vertx server is in Java and when i want to create a Session with Js my browser doesn't have a cookie with the key. But when I create a session directly with the URL, my browser has a cookie. My server:
router.route().handler(CookieHandler.create());
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx));
router.get("/log/:name/:password").handler(this::verifId);
public void verifId(RoutingContext routingContext) {
HttpServerRequest request = routingContext.request();
HttpServerResponse response = routingContext.response();
try {
Session s = routingContext.session();
DataBase.connect();
String name = request.getParam("name");
String password = request.getParam("password");
Boolean returnValue = DataBase.exist(name, password);
DataBase.disconnect();
if (returnValue) {
s.put("user", request.getParam("name"));
System.out.println(s.id());
response.end(Json.encodePrettily(s.id().toString()));
} else {
s.destroy();
response.end("null");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
And My Js code:
function tryToLogin(login, password){
var urlBuilder = 'https://localhost:8090/log/' + login + '/' + password;
$.ajax({
url : urlBuilder,
type: 'get',
dataType: 'json',
success : function(code_json, statut){
console.log(" il a repondu " + code_json);
}
});
}
The only cookie Vertx sets that way is "vertx-web.session". You're not setting any other cookies in your example.
To check that the cookie is valid you can use the following code:
And JS client:
You'll get:
And :
In JavaScript console