[kune-commits] r1408 - in trunk/src/main: java/cc/kune/core/server java/cc/kune/core/server/auth java/cc/kune/core/server/rack resources/META-INF

Vicente J. Ruiz Jurado vjrj_ at ourproject.org
Thu Jun 16 19:48:38 CEST 2011


Author: vjrj_
Date: 2011-06-16 19:48:38 +0200 (Thu, 16 Jun 2011)
New Revision: 1408

Modified:
   trunk/src/main/java/cc/kune/core/server/KunePersistenceService.java
   trunk/src/main/java/cc/kune/core/server/auth/AuthenticatedMethodInterceptor.java
   trunk/src/main/java/cc/kune/core/server/rack/RackServletFilter.java
   trunk/src/main/resources/META-INF/persistence.xml
Log:
Some guice persist tunning

Modified: trunk/src/main/java/cc/kune/core/server/KunePersistenceService.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/KunePersistenceService.java	2011-06-16 16:47:28 UTC (rev 1407)
+++ trunk/src/main/java/cc/kune/core/server/KunePersistenceService.java	2011-06-16 17:48:38 UTC (rev 1408)
@@ -19,7 +19,6 @@
  */
 package cc.kune.core.server;
 
-
 import cc.kune.core.server.init.DatabaseInitializer;
 
 import com.google.inject.Inject;
@@ -28,18 +27,18 @@
 
 @Singleton
 public class KunePersistenceService {
-    @Inject
-    DatabaseInitializer databaseInitializer;
-    @Inject
-    PersistService persistenceService;
+  @Inject
+  DatabaseInitializer databaseInitializer;
+  @Inject
+  PersistService persistenceService;
 
-    public void start() {
-        try {
-            persistenceService.start();
-            databaseInitializer.initConditional();
-        } catch (final Exception e) {
-            throw new ServerException("Error starting persistence service", e);
-        }
+  public void start() {
+    try {
+      persistenceService.start();
+      databaseInitializer.initConditional();
+    } catch (final Exception e) {
+      throw new ServerException("Error starting persistence service", e);
     }
+  }
 
 }

Modified: trunk/src/main/java/cc/kune/core/server/auth/AuthenticatedMethodInterceptor.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/auth/AuthenticatedMethodInterceptor.java	2011-06-16 16:47:28 UTC (rev 1407)
+++ trunk/src/main/java/cc/kune/core/server/auth/AuthenticatedMethodInterceptor.java	2011-06-16 17:48:38 UTC (rev 1408)
@@ -32,57 +32,70 @@
 
 import com.google.inject.Inject;
 import com.google.inject.Provider;
+import com.google.inject.persist.UnitOfWork;
 
 public class AuthenticatedMethodInterceptor implements MethodInterceptor {
 
-    public static final Log LOG = LogFactory.getLog(AuthenticatedMethodInterceptor.class);
+  public static final Log LOG = LogFactory.getLog(AuthenticatedMethodInterceptor.class);
 
-    @Inject
-    Provider<HttpServletRequest> requestProvider;
+  @Inject
+  Provider<HttpServletRequest> requestProvider;
 
-    @Inject
-    Provider<SessionService> sessionServiceProvider;
+  @Inject
+  Provider<SessionService> sessionServiceProvider;
 
-    @Inject
-    Provider<UserSession> userSessionProvider;
+  @Inject
+  private UnitOfWork unitOfWork;
 
-    @Override
-    public Object invoke(final MethodInvocation invocation) throws Throwable {
-        final Object[] arguments = invocation.getArguments();
-        // Some browsers getCookie returns "null" as String instead of null
-        final String userHash = arguments[0] == null || arguments[0].equals("null") ? null : (String) arguments[0];
+  @Inject
+  Provider<UserSession> userSessionProvider;
 
-        LOG.info("Method: " + invocation.getMethod().getName());
-        LOG.info("Userhash received: " + userHash);
-        LOG.info("--------------------------------------------------------------------------------");
-        final UserSession userSession = userSessionProvider.get();
-        // final SessionService sessionService = sessionServiceProvider.get();
+  @Override
+  public Object invoke(final MethodInvocation invocation) throws Throwable {
+    unitOfWork.begin();
 
-        final Authenticated authAnnotation = invocation.getStaticPart().getAnnotation(Authenticated.class);
-        final boolean mandatory = authAnnotation.mandatory();
+    final Object[] arguments = invocation.getArguments();
+    // Some browsers getCookie returns "null" as String instead of null
+    final String userHash = arguments[0] == null || arguments[0].equals("null") ? null
+        : (String) arguments[0];
 
-        if (userHash == null && mandatory) {
-            // sessionService.getNewSession();
-            throw new UserMustBeLoggedException();
-        } else if (userSession.isUserNotLoggedIn() && mandatory) {
-            // sessionService.getNewSession();
-            LOG.info("Session expired (not logged in server and mandatory)");
-            throw new SessionExpiredException();
-        } else if (userSession.isUserNotLoggedIn() && userHash == null) {
-            // Ok, do nothing
-        } else if (userSession.isUserNotLoggedIn() && userHash != null) {
-            // sessionService.getNewSession();
-            LOG.info("Session expired (not logged in server)");
-            throw new SessionExpiredException();
-        } else if (!userSession.getHash().equals(userHash)) {
-            final String serverHash = userSession.getHash();
-            userSession.logout();
-            // sessionService.getNewSession();
-            LOG.info("Session expired (userHash: " + userHash + " different from server hash: " + serverHash + ")");
-            throw new SessionExpiredException();
-        }
-        final Object result = invocation.proceed();
-        return result;
+    LOG.info("Method: " + invocation.getMethod().getName());
+    LOG.info("Userhash received: " + userHash);
+    LOG.info("--------------------------------------------------------------------------------");
+    final UserSession userSession = userSessionProvider.get();
+    // final SessionService sessionService = sessionServiceProvider.get();
+
+    final Authenticated authAnnotation = invocation.getStaticPart().getAnnotation(Authenticated.class);
+    final boolean mandatory = authAnnotation.mandatory();
+
+    if (userHash == null && mandatory) {
+      // sessionService.getNewSession();
+      unitOfWork.end();
+      throw new UserMustBeLoggedException();
+    } else if (userSession.isUserNotLoggedIn() && mandatory) {
+      // sessionService.getNewSession();
+      LOG.info("Session expired (not logged in server and mandatory)");
+      unitOfWork.end();
+      throw new SessionExpiredException();
+    } else if (userSession.isUserNotLoggedIn() && userHash == null) {
+      // Ok, do nothing
+    } else if (userSession.isUserNotLoggedIn() && userHash != null) {
+      // sessionService.getNewSession();
+      LOG.info("Session expired (not logged in server)");
+      unitOfWork.end();
+      throw new SessionExpiredException();
+    } else if (!userSession.getHash().equals(userHash)) {
+      final String serverHash = userSession.getHash();
+      userSession.logout();
+      // sessionService.getNewSession();
+      LOG.info("Session expired (userHash: " + userHash + " different from server hash: " + serverHash
+          + ")");
+      unitOfWork.end();
+      throw new SessionExpiredException();
     }
+    final Object result = invocation.proceed();
+    unitOfWork.end();
+    return result;
+  }
 
 }

Modified: trunk/src/main/java/cc/kune/core/server/rack/RackServletFilter.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/rack/RackServletFilter.java	2011-06-16 16:47:28 UTC (rev 1407)
+++ trunk/src/main/java/cc/kune/core/server/rack/RackServletFilter.java	2011-06-16 17:48:38 UTC (rev 1408)
@@ -41,144 +41,145 @@
 import com.google.inject.Injector;
 
 public class RackServletFilter implements Filter {
-    public static class DockChain implements FilterChain {
-        private final Iterator<Dock> iterator;
+  public static class DockChain implements FilterChain {
+    private final Iterator<Dock> iterator;
 
-        public DockChain(final Iterator<Dock> iterator) {
-            this.iterator = iterator;
-        }
+    public DockChain(final Iterator<Dock> iterator) {
+      this.iterator = iterator;
+    }
 
-        @Override
-        public void doFilter(final ServletRequest request, final ServletResponse response) throws IOException,
-                ServletException {
-            Dock dock = null;
-            boolean matched = false;
+    @Override
+    public void doFilter(final ServletRequest request, final ServletResponse response)
+        throws IOException, ServletException {
+      Dock dock = null;
+      boolean matched = false;
 
-            final String relative = RackHelper.getRelativeURL(request);
-            while (!matched && iterator.hasNext()) {
-                dock = iterator.next();
-                matched = dock.matches(relative);
-            }
-            if (matched) {
-                execute(dock.getFilter(), request, response);
-            }
-        }
+      final String relative = RackHelper.getRelativeURL(request);
+      while (!matched && iterator.hasNext()) {
+        dock = iterator.next();
+        matched = dock.matches(relative);
+      }
+      if (matched) {
+        execute(dock.getFilter(), request, response);
+      }
+    }
 
-        private void execute(final Filter filter, final ServletRequest request, final ServletResponse response)
-                throws IOException, ServletException {
-            // log.debug("RACK FILTER: " + filter.getClass().getSimpleName());
-            filter.doFilter(request, response, this);
-        }
+    private void execute(final Filter filter, final ServletRequest request,
+        final ServletResponse response) throws IOException, ServletException {
+      // log.debug("RACK FILTER: " + filter.getClass().getSimpleName());
+      filter.doFilter(request, response, this);
     }
+  }
 
-    public static final String INJECTOR_ATTRIBUTE = Injector.class.getName() + "Child";
-    public static final String INJECTOR_PARENT_ATTRIBUTE = ServerRpcProvider.INJECTOR_ATTRIBUTE;
-    private static final Log LOG = LogFactory.getLog(RackServletFilter.class);
-    private static final String MODULE_PARAMETER = RackModule.class.getName();
-    private List<Dock> docks;
+  public static final String INJECTOR_ATTRIBUTE = Injector.class.getName() + "Child";
+  public static final String INJECTOR_PARENT_ATTRIBUTE = ServerRpcProvider.INJECTOR_ATTRIBUTE;
+  private static final Log LOG = LogFactory.getLog(RackServletFilter.class);
+  private static final String MODULE_PARAMETER = RackModule.class.getName();
+  private List<Dock> docks;
 
-    private List<RequestMatcher> excludes;
-    private Injector injector;
-    private Rack rack;
+  private List<RequestMatcher> excludes;
+  private Injector injector;
+  private Rack rack;
 
-    @Override
-    public void destroy() {
-        for (final Dock dock : docks) {
-            dock.getFilter().destroy();
-        }
+  @Override
+  public void destroy() {
+    for (final Dock dock : docks) {
+      dock.getFilter().destroy();
     }
+  }
 
-    @Override
-    public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
-            throws IOException, ServletException {
+  @Override
+  public void doFilter(final ServletRequest request, final ServletResponse response,
+      final FilterChain chain) throws IOException, ServletException {
 
-        final String relative = RackHelper.getRelativeURL(request);
-        for (final RequestMatcher matcher : excludes) {
-            if (matcher.matches(relative)) {
-                LOG.info("Excluded (from Guice): " + relative);
-                chain.doFilter(request, response);
-                return;
-            }
-        }
-        LOG.debug("REQUEST: " + relative);
-        final FilterChain newChain = new DockChain(docks.iterator());
-        newChain.doFilter(request, response);
+    final String relative = RackHelper.getRelativeURL(request);
+    for (final RequestMatcher matcher : excludes) {
+      if (matcher.matches(relative)) {
+        LOG.info("Excluded (from Guice): " + relative);
+        chain.doFilter(request, response);
+        return;
+      }
     }
+    LOG.debug("REQUEST: " + relative);
+    final FilterChain newChain = new DockChain(docks.iterator());
+    newChain.doFilter(request, response);
+  }
 
-    @Override
-    protected void finalize() throws Throwable {
-        super.finalize();
-        stopContainerListeners(rack.getListeners(), injector);
-    }
+  @Override
+  protected void finalize() throws Throwable {
+    super.finalize();
+    stopContainerListeners(rack.getListeners(), injector);
+  }
 
-    private RackModule getModule(final FilterConfig filterConfig) {
-        final String moduleName = getModuleName(filterConfig);
-        try {
-            final Class<?> clazz = Class.forName(moduleName);
-            final RackModule module = (RackModule) clazz.newInstance();
-            return module;
-        } catch (final Exception e) {
-            throw new ServerException("couldn't instantiate the rack module", e);
-        }
+  private RackModule getModule(final FilterConfig filterConfig) {
+    final String moduleName = getModuleName(filterConfig);
+    try {
+      final Class<?> clazz = Class.forName(moduleName);
+      final RackModule module = (RackModule) clazz.newInstance();
+      return module;
+    } catch (final Exception e) {
+      throw new ServerException("couldn't instantiate the rack module", e);
     }
+  }
 
-    private String getModuleName(final FilterConfig filterConfig) {
-        final String moduleName = filterConfig.getInitParameter(MODULE_PARAMETER);
-        if (moduleName == null) {
-            throw new ServerException("Rack module name can't be null!");
-        }
-        return moduleName;
+  private String getModuleName(final FilterConfig filterConfig) {
+    final String moduleName = filterConfig.getInitParameter(MODULE_PARAMETER);
+    if (moduleName == null) {
+      throw new ServerException("Rack module name can't be null!");
     }
+    return moduleName;
+  }
 
-    @Override
-    public void init(final FilterConfig filterConfig) throws ServletException {
-        LOG.debug("INITIALIZING RackServletFilter...");
-        final RackModule module = getModule(filterConfig);
-        final RackBuilder builder = new RackBuilder();
-        module.configure(builder);
-        rack = builder.getRack();
-        // final WaveStarter waveStarter = new WaveStarter();
-        // final Injector waveChildInjector = waveStarter.runMain();
-        injector = (Injector) filterConfig.getServletContext().getAttribute(INJECTOR_PARENT_ATTRIBUTE);
-        final Injector kuneChildInjector = installInjector(filterConfig, rack, injector);
-        startContainerListeners(rack.getListeners(), kuneChildInjector);
-        docks = rack.getDocks();
-        excludes = rack.getExcludes();
-        initFilters(filterConfig);
-        LOG.debug("INITIALIZATION DONE!");
-    }
+  @Override
+  public void init(final FilterConfig filterConfig) throws ServletException {
+    LOG.debug("INITIALIZING RackServletFilter...");
+    final RackModule module = getModule(filterConfig);
+    final RackBuilder builder = new RackBuilder();
+    module.configure(builder);
+    rack = builder.getRack();
+    // final WaveStarter waveStarter = new WaveStarter();
+    // final Injector waveChildInjector = waveStarter.runMain();
+    injector = (Injector) filterConfig.getServletContext().getAttribute(INJECTOR_PARENT_ATTRIBUTE);
+    final Injector kuneChildInjector = installInjector(filterConfig, rack, injector);
+    startContainerListeners(rack.getListeners(), kuneChildInjector);
+    docks = rack.getDocks();
+    excludes = rack.getExcludes();
+    initFilters(filterConfig);
+    LOG.debug("INITIALIZATION DONE!");
+  }
 
-    private void initFilters(final FilterConfig filterConfig) throws ServletException {
-        for (final Dock dock : docks) {
-            dock.getFilter().init(filterConfig);
-        }
+  private void initFilters(final FilterConfig filterConfig) throws ServletException {
+    for (final Dock dock : docks) {
+      dock.getFilter().init(filterConfig);
     }
+  }
 
-    private Injector installInjector(final FilterConfig filterConfig, final Rack rack, final Injector waveChildInjector) {
-        // final Injector injector = Guice.createInjector();
-        final Injector childInjector = waveChildInjector.createChildInjector(rack.getGuiceModules());
-        filterConfig.getServletContext().setAttribute(INJECTOR_ATTRIBUTE, childInjector);
-        return childInjector;
-    }
+  private Injector installInjector(final FilterConfig filterConfig, final Rack rack,
+      final Injector waveChildInjector) {
+    // final Injector injector = Guice.createInjector();
+    final Injector childInjector = waveChildInjector.createChildInjector(rack.getGuiceModules());
+    filterConfig.getServletContext().setAttribute(INJECTOR_ATTRIBUTE, childInjector);
+    return childInjector;
+  }
 
-    private void startContainerListeners(final List<Class<? extends ContainerListener>> listenerClasses,
-            final Injector injector) {
-        LOG.debug("STARTING CONTAINER LISTENERS...");
-        for (final Class<? extends ContainerListener> listenerClass : listenerClasses) {
-            final ContainerListener listener = injector.getInstance(listenerClass);
-            listener.start();
-        }
+  private void startContainerListeners(final List<Class<? extends ContainerListener>> listenerClasses,
+      final Injector injector) {
+    LOG.debug("STARTING CONTAINER LISTENERS...");
+    for (final Class<? extends ContainerListener> listenerClass : listenerClasses) {
+      final ContainerListener listener = injector.getInstance(listenerClass);
+      listener.start();
     }
+  }
 
-    // FIXME: Dani, never used this:
-    @SuppressWarnings("unused")
-    private void stopContainerListeners(final List<Class<? extends ContainerListener>> listenerClasses,
-            final Injector injector) {
-        LOG.debug("STOPING CONTAINER LISTENERS...");
-        for (final Class<? extends ContainerListener> listenerClass : listenerClasses) {
-            final ContainerListener listener = injector.getInstance(listenerClass);
-            listener.stop();
-        }
+  // FIXME: Dani, never used this:
+  @SuppressWarnings("unused")
+  private void stopContainerListeners(final List<Class<? extends ContainerListener>> listenerClasses,
+      final Injector injector) {
+    LOG.debug("STOPING CONTAINER LISTENERS...");
+    for (final Class<? extends ContainerListener> listenerClass : listenerClasses) {
+      final ContainerListener listener = injector.getInstance(listenerClass);
+      listener.stop();
     }
+  }
 
 }

Modified: trunk/src/main/resources/META-INF/persistence.xml
===================================================================
--- trunk/src/main/resources/META-INF/persistence.xml	2011-06-16 16:47:28 UTC (rev 1407)
+++ trunk/src/main/resources/META-INF/persistence.xml	2011-06-16 17:48:38 UTC (rev 1408)
@@ -8,7 +8,8 @@
     transaction-type="RESOURCE_LOCAL">
     <provider>org.hibernate.ejb.HibernatePersistence</provider>
     <!-- JPA entities must be registered here -->
-    <!-- src/main/java/cc/kune/domain$ ls -1 *.java | sed 's/.java/<\/class>/g' | sed 's/^/<class>cc.kune.domain./g' -->
+    <!-- src/main/java/cc/kune/domain$ ls -1 *.java | sed 's/.java/<\/class>/g'
+      | sed 's/^/<class>cc.kune.domain./g' -->
     <class>cc.kune.domain.AccessLists</class>
     <class>cc.kune.domain.BasicMimeType</class>
     <class>cc.kune.domain.Container</class>




More information about the kune-commits mailing list