-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mongodb session store doesn't work fix #590
- Loading branch information
Showing
4 changed files
with
301 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package apps; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import org.jooby.Jooby; | ||
import org.jooby.Session; | ||
import org.jooby.mongodb.MongoSessionStore; | ||
import org.jooby.mongodb.Mongodb; | ||
|
||
import com.typesafe.config.ConfigFactory; | ||
import com.typesafe.config.ConfigValueFactory; | ||
|
||
public class MongodbApp extends Jooby { | ||
|
||
{ | ||
use(ConfigFactory.empty() | ||
.withValue("db", ConfigValueFactory.fromAnyRef("mongodb://localhost/mongodbapp")) | ||
.withValue("session.timeout", ConfigValueFactory.fromAnyRef("2m"))); | ||
|
||
use(new Mongodb()); | ||
|
||
AtomicInteger inc = new AtomicInteger(0); | ||
session(MongoSessionStore.class); | ||
|
||
get("/", req -> { | ||
Session session = req.ifSession().orElseGet(() -> { | ||
Session newSession = req.session(); | ||
int next = newSession.get("inc").intValue(inc.getAndIncrement()); | ||
newSession.set("inc", next); | ||
return newSession; | ||
}); | ||
return session.get("inc"); | ||
}); | ||
|
||
} | ||
|
||
public static void main(final String[] args) { | ||
run(MongodbApp::new, args); | ||
} | ||
} |
Oops, something went wrong.