This is what i did make add this code to your DropwizardApplication.java:

  @Override
    public void run(MyConfiguration configuration, Environment environment)
    {
        

        addSessionHandler(configuration, environment);
        .
        .
        .
    }
 
 private void addSessionHandler(final MyConfiguration configuration, final 
Environment env)
    {
        env.lifecycle().addLifeCycleListener(new AbstractLifeCycleListener()
        {
            @Override
            public void lifeCycleStarting(LifeCycle event)
            {
                if (!(event instanceof Server))
                {
                    return;
                }

                Server server = (Server) event;
                DataSourceFactory dataSourceFactory = 
configuration.getDataSourceFactory();
                JDBCSessionManager sessionManager = new 
JDBCSessionManager();
                JDBCSessionIdManager sessionIdManager = new 
JDBCSessionIdManager(server);

                sessionIdManager.setDriverInfo(
                    dataSourceFactory.getDriverClass(),
                    dataSourceFactory.getUrl()
                    + ";user=" + dataSourceFactory.getUser()
                    + ";password=" + dataSourceFactory.getPassword());

                sessionIdManager.setWorkerName(NetworkChecksum.getValue());
                // JDBCSessionManager cannot determine the blob type for 
sql server
                // blob type should be provided for sqlserver
                
sessionIdManager.getDbAdaptor().setBlobType("varbinary(MAX)");
                sessionManager.setSessionIdManager(sessionIdManager);
                // Session expires after 2 hours
                sessionManager.setMaxInactiveInterval(7200);
                sessionManager.setSessionCookie("MY_SESSION");
                sessionManager.setHttpOnly(true);

                env.servlets().setSessionHandler(new 
SessionHandler(sessionManager));
            }
        });
    }

hope this solves your problem

On Friday, September 26, 2014 at 2:37:46 AM UTC-5, Alex wrote:
>
> Hello,
>
> I need a way to share the session across different dropwizard web 
> services. In Jetty there is a way to do it by using JDBCSessionIdManager 
> and JDBCSessionManager (
> http://wiki.eclipse.org/Jetty/Tutorial/Session_Clustering). 
>
> The problem is that dropwizard does not expose the 
> org.eclipse.jetty.server.Server that is needed so there is no obvious way 
> to do change the SessionManager and the SessionIdManager. 
> I've seen that the Server is created 
> in io.dropwizard.cli.ServerCommand:run through a 
>  io.dropwizard.ServerFactory but the reference in 
> io.dropwizard.cli.ServerCommand:run is local so I can't even use reflection 
> to get the reference that I want.
>
> What should I do in dropwizard to change SessionManager and the 
> SessionIdManager?
>
> Thanks,
> Alex
>

-- 
You received this message because you are subscribed to the Google Groups 
"dropwizard-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dropwizard-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to