Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
src
README.md
pom.xml

README.md

Pippo Session MongoDB

MongoDB Session Manager integration for Pippo

Sample code

First we must add in src/main/resources/conf/application.properties:

# List of hosts of the form "mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]"
mongodb.hosts = mongodb://localhost:27017

Add the following code sniped in your application:

public class MyApplication extends Application {

    private MongoClient client;

    @Override
    protected void onInit() {
        this.client = MongoDBFactory.create(getPippoSettings());
        // add routes here
    }

    @Override
    protected RequestResponseFactory createRequestResponseFactory() {
        SessionDataStorage sessionDataStorage = new MongoDBSessionDataStorage(this.client.getDatabase("database"));
        SessionManager sessionManager = new SessionManager(sessionDataStorage);

        return new SessionRequestResponseFactory(this, sessionManager);
    }

    @Override
    protected void onDestroy() {
        this.client.close();
    }
}

TTL Index

The idle time of the session is manage with a TTL Index, read the MongoDB Documentation for more information