jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edgarp...@apache.org
Subject svn commit: r478012 - in /jackrabbit/trunk/contrib/jcr-browser/src/main: java/org/apache/jackrabbit/browser/ webapp/WEB-INF/
Date Wed, 22 Nov 2006 02:08:23 GMT
Author: edgarpoce
Date: Tue Nov 21 18:08:22 2006
New Revision: 478012

URL: http://svn.apache.org/viewvc?view=rev&rev=478012
Log:
synchronize session as proposed by jukka
rename login filter to jcrloginfilter.

Added:
    jackrabbit/trunk/contrib/jcr-browser/src/main/java/org/apache/jackrabbit/browser/JcrLoginFilter.java
      - copied, changed from r477390, jackrabbit/trunk/contrib/jcr-browser/src/main/java/org/apache/jackrabbit/browser/LoginFilter.java
Removed:
    jackrabbit/trunk/contrib/jcr-browser/src/main/java/org/apache/jackrabbit/browser/LoginFilter.java
Modified:
    jackrabbit/trunk/contrib/jcr-browser/src/main/java/org/apache/jackrabbit/browser/JcrSessionListener.java
    jackrabbit/trunk/contrib/jcr-browser/src/main/webapp/WEB-INF/web.xml

Copied: jackrabbit/trunk/contrib/jcr-browser/src/main/java/org/apache/jackrabbit/browser/JcrLoginFilter.java
(from r477390, jackrabbit/trunk/contrib/jcr-browser/src/main/java/org/apache/jackrabbit/browser/LoginFilter.java)
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jcr-browser/src/main/java/org/apache/jackrabbit/browser/JcrLoginFilter.java?view=diff&rev=478012&p1=jackrabbit/trunk/contrib/jcr-browser/src/main/java/org/apache/jackrabbit/browser/LoginFilter.java&r1=477390&p2=jackrabbit/trunk/contrib/jcr-browser/src/main/java/org/apache/jackrabbit/browser/JcrLoginFilter.java&r2=478012
==============================================================================
--- jackrabbit/trunk/contrib/jcr-browser/src/main/java/org/apache/jackrabbit/browser/LoginFilter.java
(original)
+++ jackrabbit/trunk/contrib/jcr-browser/src/main/java/org/apache/jackrabbit/browser/JcrLoginFilter.java
Tue Nov 21 18:08:22 2006
@@ -16,8 +16,13 @@
  */
 package org.apache.jackrabbit.browser;
 
+import java.io.ByteArrayInputStream;
+import java.util.Properties;
+
+import javax.jcr.Repository;
 import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
+import javax.naming.InitialContext;
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
 import javax.servlet.FilterConfig;
@@ -29,9 +34,11 @@
 import org.apache.jackrabbit.command.CommandHelper;
 
 /**
- * Filter that binds the jcr session to http session
+ * Filter stores the jcr session in http session. It also synchronizes
  */
-public class LoginFilter implements Filter {
+public class JcrLoginFilter implements Filter {
+
+	private static Repository repository;
 
 	public void destroy() {
 
@@ -40,13 +47,13 @@
 	public void doFilter(ServletRequest request, ServletResponse response,
 			FilterChain chain) throws java.io.IOException, ServletException {
 
-		chain.doFilter(request, response);
+		HttpServletRequest httpRequest = (HttpServletRequest) request;
 
+		// Create the jcr session if necessary
 		try {
-			HttpServletRequest httpRequest = (HttpServletRequest) request;
 			if (httpRequest.getSession()
 					.getAttribute(CommandHelper.SESSION_KEY) == null) {
-				Session s = JcrSessionListener.getRepository().login(
+				Session s = getRepository().login(
 						new SimpleCredentials(httpRequest.getRemoteUser(), ""
 								.toCharArray()));
 				httpRequest.getSession().setAttribute(
@@ -56,10 +63,41 @@
 			throw new ServletException(
 					"unable to bind jcr session to http session", e);
 		}
+
+		// get the session from the http session
+		Object session = httpRequest.getSession().getAttribute(
+				CommandHelper.SESSION_KEY);
+
+		// Synchronize request
+		synchronized (session) {
+			chain.doFilter(request, response);
+		}
+
 	}
 
 	public void init(FilterConfig cfg) throws ServletException {
 
+	}
+
+	public static Repository getRepository() {
+		if (repository == null) {
+			try {
+				InitialContext ctx = new InitialContext();
+				String jndiAddress = (String) ctx
+						.lookup("java:comp/env/jcr/jndi/address");
+				String jndiProperties = (String) ctx
+						.lookup("java:comp/env/jcr/jndi/properties");
+				Properties properties = new Properties();
+				properties.load(new ByteArrayInputStream(jndiProperties
+						.getBytes()));
+				InitialContext repoCtx = new InitialContext(properties);
+				repository = (Repository) repoCtx.lookup(jndiAddress);
+			} catch (Exception e) {
+				throw new IllegalStateException(
+						"unable to retrieve repository. ", e);
+			}
+		}
+		return repository;
 	}
 
 }

Modified: jackrabbit/trunk/contrib/jcr-browser/src/main/java/org/apache/jackrabbit/browser/JcrSessionListener.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jcr-browser/src/main/java/org/apache/jackrabbit/browser/JcrSessionListener.java?view=diff&rev=478012&r1=478011&r2=478012
==============================================================================
--- jackrabbit/trunk/contrib/jcr-browser/src/main/java/org/apache/jackrabbit/browser/JcrSessionListener.java
(original)
+++ jackrabbit/trunk/contrib/jcr-browser/src/main/java/org/apache/jackrabbit/browser/JcrSessionListener.java
Tue Nov 21 18:08:22 2006
@@ -16,12 +16,7 @@
  */
 package org.apache.jackrabbit.browser;
 
-import java.io.ByteArrayInputStream;
-import java.util.Properties;
-
-import javax.jcr.Repository;
 import javax.jcr.Session;
-import javax.naming.InitialContext;
 import javax.servlet.http.HttpSessionEvent;
 import javax.servlet.http.HttpSessionListener;
 
@@ -29,8 +24,6 @@
 
 public class JcrSessionListener implements HttpSessionListener {
 
-	private static Repository repository;
-
 	public void sessionCreated(HttpSessionEvent evt) {
 
 	}
@@ -41,27 +34,6 @@
 		if (s!=null) {
 			s.logout();
 		}
-	}
-
-	public static Repository getRepository() {
-		if (repository == null) {
-			try {
-				InitialContext ctx = new InitialContext();
-				String jndiAddress = (String) ctx
-						.lookup("java:comp/env/jcr/jndi/address");
-				String jndiProperties = (String) ctx
-						.lookup("java:comp/env/jcr/jndi/properties");
-				Properties properties = new Properties();
-				properties.load(new ByteArrayInputStream(jndiProperties
-						.getBytes()));
-				InitialContext repoCtx = new InitialContext(properties);
-				repository = (Repository) repoCtx.lookup(jndiAddress);
-			} catch (Exception e) {
-				throw new IllegalStateException(
-						"unable to retrieve repository. ", e);
-			}
-		}
-		return repository;
 	}
 
 }

Modified: jackrabbit/trunk/contrib/jcr-browser/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jcr-browser/src/main/webapp/WEB-INF/web.xml?view=diff&rev=478012&r1=478011&r2=478012
==============================================================================
--- jackrabbit/trunk/contrib/jcr-browser/src/main/webapp/WEB-INF/web.xml (original)
+++ jackrabbit/trunk/contrib/jcr-browser/src/main/webapp/WEB-INF/web.xml Tue Nov 21 18:08:22
2006
@@ -26,7 +26,7 @@
 
 	<filter>
 		<filter-name>loginFilter</filter-name>
-		<filter-class>org.apache.jackrabbit.browser.LoginFilter</filter-class>
+		<filter-class>org.apache.jackrabbit.browser.JcrLoginFilter</filter-class>
 	</filter>
 	
 	<filter>



Mime
View raw message