Skip to content

Commit

Permalink
save work #7529
Browse files Browse the repository at this point in the history
  • Loading branch information
rymsha committed Oct 16, 2019
1 parent 54f2f61 commit e51e860
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.apache.ignite.configuration.AddressResolver;
import org.apache.ignite.configuration.BasicAddressResolver;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.marshaller.optimized.OptimizedMarshaller;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -45,7 +44,6 @@ public IgniteConfiguration execute()
config.setConsistentId( clusterConfig.name().toString() );
config.setIgniteHome( resolveIgniteHome() );
config.setAddressResolver( getAddressResolver() );
config.setMarshaller( new OptimizedMarshaller( true ) );

config.setDataStorageConfiguration( DataStorageConfigFactory.create( this.igniteSettings ) );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,29 @@ final class SessionWrapper
{
private final HttpServletRequest request;

private HttpSession session;

SessionWrapper( final HttpServletRequest request )
{
this.request = request;
this.session = this.request.getSession( false );
}

private void createSessionIfNeeded()
{
if ( this.session != null )
{
return;
}

this.session = this.request.getSession( true );
}

@Override
public SessionKey getKey()
{
createSessionIfNeeded();
return SessionKey.from( this.session.getId() );
return SessionKey.from( request.getSession().getId() );
}

@Override
public Object getAttribute( final String key )
{
if ( this.session == null )
HttpSession session = request.getSession( false );
if ( session == null )
{
return null;
}

try
{
return this.session.getAttribute( key );
return session.getAttribute( key );
}
catch ( IllegalStateException e )
{
Expand All @@ -69,8 +56,8 @@ public <T> T getAttribute( final Class<T> type )
@Override
public void setAttribute( final String key, final Object value )
{
createSessionIfNeeded();
this.session.setAttribute( key, value );
HttpSession session = request.getSession( true );
session.setAttribute( key, value );
}

@Override
Expand All @@ -82,12 +69,13 @@ public <T> void setAttribute( final T value )
@Override
public void removeAttribute( final String key )
{
if ( this.session == null )
HttpSession session = request.getSession( false );
if ( session == null )
{
return;
}

this.session.removeAttribute( key );
session.removeAttribute( key );
}

@Override
Expand All @@ -99,18 +87,19 @@ public <T> void removeAttribute( final Class<T> type )
@Override
public Map<String, Object> getAttributes()
{
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
if ( this.session == null )
HttpSession session = request.getSession( false );

if ( session == null )
{
return builder.build();
return ImmutableMap.of();
}

final Enumeration<String> names = this.session.getAttributeNames();
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
final Enumeration<String> names = session.getAttributeNames();

while ( names.hasMoreElements() )
{
final String key = names.nextElement();
builder.put( key, this.session.getAttribute( key ) );
builder.put( key, session.getAttribute( key ) );
}

return builder.build();
Expand All @@ -119,11 +108,12 @@ public Map<String, Object> getAttributes()
@Override
public void invalidate()
{
if ( this.session == null )
HttpSession session = request.getSession( false );
if ( session == null )
{
return;
}

this.session.invalidate();
session.invalidate();
}
}
2 changes: 1 addition & 1 deletion modules/web/web-jetty/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ dependencies {
jar {
bnd( 'Bundle-Name': 'Enonic XP Web - Jetty',
'Export-Package': 'org.eclipse.jetty.*, javax.servlet.*;-split-package:=merge-first, javax.websocket.*;-split-package:=merge-first',
'Import-Package': '*;resolution:=optional',
'Import-Package': '*;resolution:=optional, com.enonic.xp.security.auth.*;resolution:=optional',
'X-Jetty-Version': jettyVersion )
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import javax.servlet.ServletContext;

import org.eclipse.jetty.server.session.SessionDataStore;
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
Expand All @@ -18,7 +18,6 @@
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;

import com.enonic.xp.cluster.ClusterConfig;
import com.enonic.xp.status.StatusReporter;
Expand All @@ -39,16 +38,11 @@ public final class JettyActivator

private ServiceRegistration statusReporterReg;

private List<DispatchServlet> dispatchServlets;
private List<DispatchServlet> dispatchServlets = new ArrayList<>();

private ClusterConfig clusterConfig;

private SessionDataStore sessionDataStore;

public JettyActivator()
{
this.dispatchServlets = new ArrayList<>();
}
private SessionDataStoreFactory sessionDataStoreFactory;

@Activate
public void activate( final BundleContext context, final JettyConfig config )
Expand All @@ -61,9 +55,9 @@ public void activate( final BundleContext context, final JettyConfig config )
this.service = new JettyService();
this.service.config = this.config;
this.service.workerName = clusterConfig.name().toString();
if ( clusterConfig.isSessionReplicationEnabled() )
//if ( clusterConfig.isSessionReplicationEnabled() )
{
this.service.sessionDataStore = sessionDataStore;
this.service.sessionDataStoreFactory = sessionDataStoreFactory;
}

this.service.dispatcherServlets = this.dispatchServlets;
Expand Down Expand Up @@ -122,7 +116,7 @@ private void publishThreadPoolInfo()
this.statusReporterReg = this.context.registerService( ThreadPoolInfo.class, threadPoolInfo, new Hashtable<>() );
}

@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
@Reference(cardinality = ReferenceCardinality.AT_LEAST_ONE)
public void addDispatchServlet( final DispatchServlet dispatchServlet )
{
this.dispatchServlets.add( dispatchServlet );
Expand All @@ -140,8 +134,8 @@ public void setClusterConfig( final ClusterConfig clusterConfig )
}

@Reference
public void setSessionDataStore( final SessionDataStore sessionDataStore )
public void setSessionDataStore( final SessionDataStoreFactory sessionDataStoreFactory )
{
this.sessionDataStore = sessionDataStore;
this.sessionDataStoreFactory = sessionDataStoreFactory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.session.DefaultSessionIdManager;
import org.eclipse.jetty.server.session.NullSessionCache;
import org.eclipse.jetty.server.session.SessionDataStore;
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
Expand Down Expand Up @@ -38,7 +38,7 @@ final class JettyService

protected String workerName;

protected SessionDataStore sessionDataStore;
protected SessionDataStoreFactory sessionDataStoreFactory;

public void start()
{
Expand Down Expand Up @@ -113,13 +113,20 @@ private ServletContextHandler initServletContextHandler( final DispatchServlet s
new GZipConfigurator().configure( this.config, context );
new MultipartConfigurator().configure( this.config, holder );

if ( sessionDataStore != null )
if ( sessionDataStoreFactory != null )
{
final NullSessionCache sessionCache = new NullSessionCache( sessionHandler );
sessionCache.setSaveOnCreate( true );
sessionCache.setSaveOnInactiveEviction( true );
sessionCache.setRemoveUnloadableSessions( true );
sessionCache.setSessionDataStore( sessionDataStore );
try
{
sessionCache.setSessionDataStore( sessionDataStoreFactory.getSessionDataStore( sessionHandler ) );
}
catch ( Exception e )
{
throw new RuntimeException( e );
}
sessionHandler.setSessionCache( sessionCache );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class JettyActivatorTest
Expand Down Expand Up @@ -93,7 +92,6 @@ public void testSessionReplicationEnabled()

this.activator.activate( this.bundleContext, this.config );

assertEquals( this.sessionDataStore, this.activator.service.sessionDataStore );
}

@Test
Expand All @@ -105,7 +103,6 @@ public void testSessionReplicationDisabled()

this.activator.activate( this.bundleContext, this.config );

assertNull( this.activator.service.sessionDataStore );
}

@Test
Expand All @@ -116,7 +113,6 @@ public void testClusterDisabled()

this.activator.activate( this.bundleContext, this.config );

assertNull( this.activator.service.sessionDataStore );
}

private Object defaultAnswer( final InvocationOnMock invocation )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.cache.CacheWriteSynchronizationMode;
import org.apache.ignite.configuration.CacheConfiguration;
import org.eclipse.jetty.server.session.SessionData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SessionCacheConfigFactory
{
private final static Logger LOG = LoggerFactory.getLogger( SessionCacheConfigFactory.class );

public static CacheConfiguration<String, SessionData> create( final String cacheName, final WebSessionConfig config )
public static <T> CacheConfiguration<String, T> create( final String cacheName, final WebSessionConfig config )
{
final CacheConfiguration<String, SessionData> cacheConfig = new CacheConfiguration<>();
final CacheConfiguration<String, T> cacheConfig = new CacheConfiguration<>();

cacheConfig.setAtomicityMode( CacheAtomicityMode.ATOMIC );
cacheConfig.setWriteSynchronizationMode( getWriteSyncMode( config.write_sync_mode() ) );
Expand Down Expand Up @@ -42,7 +41,7 @@ private static CacheWriteSynchronizationMode getWriteSyncMode( final String writ
}
}

private static void setCacheMode( final WebSessionConfig config, final CacheConfiguration<String, SessionData> cacheConfig )
private static void setCacheMode( final WebSessionConfig config, final CacheConfiguration<String, ?> cacheConfig )
{
switch ( config.cache_mode().toLowerCase() )
{
Expand Down
Loading

0 comments on commit e51e860

Please sign in to comment.