jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r349905 - in /incubator/jackrabbit/trunk/contrib/jcr-server: server/src/java/org/apache/jackrabbit/server/ server/src/java/org/apache/jackrabbit/server/io/ server/src/java/org/apache/jackrabbit/webdav/jcr/ server/src/java/org/apache/jackrab...
Date Wed, 30 Nov 2005 07:52:44 GMT
Author: angela
Date: Tue Nov 29 23:52:30 2005
New Revision: 349905

URL: http://svn.apache.org/viewcvs?rev=349905&view=rev
Log:
webapp: adding some better error reporting  (tobi)
webapp: adding support for late repository retrieval (tobi)
server: workspace not passed to Repository.login in webdav/simple/DavSessionProviderImpl
JCR-280 - IllegalArgumentException when retrieving DateHeader 
JCR-282 - respect maximal value for timeout
JCR-276 - SimpleWebdavServlet: avoid 404 on the root collection after successful connection
to it.

Added:
    incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/util/HttpDateFormat.java
  (with props)
Modified:
    incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/AbstractWebdavServlet.java
    incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/DefaultHandler.java
    incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/AbstractResource.java
    incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java
    incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/DavSessionProviderImpl.java
    incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/ResourceFactoryImpl.java
    incubator/jackrabbit/trunk/contrib/jcr-server/webapp/src/java/org/apache/jackrabbit/j2ee/JCRWebdavServerServlet.java
    incubator/jackrabbit/trunk/contrib/jcr-server/webapp/src/java/org/apache/jackrabbit/j2ee/RepositoryAccessServlet.java
    incubator/jackrabbit/trunk/contrib/jcr-server/webapp/src/java/org/apache/jackrabbit/j2ee/SimpleWebdavServlet.java
    incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavConstants.java
    incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/util/XmlUtil.java

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/AbstractWebdavServlet.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/AbstractWebdavServlet.java?rev=349905&r1=349904&r2=349905&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/AbstractWebdavServlet.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/AbstractWebdavServlet.java
Tue Nov 29 23:52:30 2005
@@ -362,9 +362,10 @@
 
         long modSince = request.getDateHeader("If-Modified-Since");
         if (modSince > IOUtil.UNDEFINED_TIME) {
-            // test if resource has been modified
         long modTime = resource.getModificationTime();
-            if (modTime != IOUtil.UNDEFINED_TIME && modTime <= modSince) {
+            // test if resource has been modified. note that formatted modification
+            // time lost the milli-second precision
+            if (modTime != IOUtil.UNDEFINED_TIME && (modTime / 1000 * 1000) <=
modSince) {
             // resource has not been modified since the time indicated in the
             // 'If-Modified-Since' header.
             response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/DefaultHandler.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/DefaultHandler.java?rev=349905&r1=349904&r2=349905&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/DefaultHandler.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/server/io/DefaultHandler.java
Tue Nov 29 23:52:30 2005
@@ -181,9 +181,12 @@
     protected boolean importData(ImportContext context, boolean isCollection, Node contentNode)
throws IOException, RepositoryException {
         InputStream in = context.getInputStream();
         if (in != null) {
+            // NOTE: with the default folder-nodetype (nt:folder) no inputstream
+            // is allowed. setting the property would therefore fail.
+            if (isCollection) {
+                return false;
+            }
             try {
-                // NOTE: with the default folder-nodetype (nt:folder) no inputstream
-                // is allowed. setting the property will therefore fail.
                 contentNode.setProperty(JcrConstants.JCR_DATA, in);
             } finally {
                 in.close();

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/AbstractResource.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/AbstractResource.java?rev=349905&r1=349904&r2=349905&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/AbstractResource.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/jcr/AbstractResource.java
Tue Nov 29 23:52:30 2005
@@ -63,7 +63,7 @@
     private TxLockManagerImpl txMgr;
     private String transactionId;
 
-    private long modificationTime = new Date().getTime();
+    private long modificationTime = IOUtil.UNDEFINED_TIME;
 
     protected boolean initedProps;
     protected DavPropertySet properties = new DavPropertySet();
@@ -122,15 +122,16 @@
     }
 
     /**
-     * Set the modificationTime field and adds the {@link DavPropertyName.GETLASTMODIFIED}
+     * Set the modificationTime field and adds the {@link DavPropertyName#GETLASTMODIFIED}
      * property to the set of properties.
+     *
      * @param modificationTime
      */
     void setModificationTime(long modificationTime) {
+        if (modificationTime > IOUtil.UNDEFINED_TIME) {
         this.modificationTime = modificationTime;
-        if (this.modificationTime >= 0) {
-            properties.add(new DefaultDavProperty(DavPropertyName.GETLASTMODIFIED,
-                    DavConstants.modificationDateFormat.format(new Date(modificationTime))));
+            String lastModified = IOUtil.getLastModified(modificationTime);
+            properties.add(new DefaultDavProperty(DavPropertyName.GETLASTMODIFIED, lastModified));
         }
     }
 

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java?rev=349905&r1=349904&r2=349905&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/DavResourceImpl.java
Tue Nov 29 23:52:30 2005
@@ -70,11 +70,12 @@
     private DavPropertySet properties = new DavPropertySet();
     private boolean inited = false;
     private boolean isCollection = true;
-    private long modificationTime = IOUtil.UNDEFINED_TIME;
 
     private ResourceFilter filter;
     private IOManager ioManager;
 
+    private long modificationTime = IOUtil.UNDEFINED_TIME;
+
     /**
      * Create a new {@link DavResource}.
      *
@@ -83,7 +84,7 @@
      * @param session
      */
     public DavResourceImpl(DavResourceLocator locator, DavResourceFactory factory,
-                           DavSession session, ResourceConfig config) throws RepositoryException
{
+                           DavSession session, ResourceConfig config) throws RepositoryException,
DavException {
         this.session = session;
         this.factory = factory;
         this.locator = locator;
@@ -101,6 +102,8 @@
             } catch (PathNotFoundException e) {
                 // ignore: exists field evaluates to false
             }
+        } else {
+            throw new DavException(DavServletResponse.SC_NOT_FOUND);
         }
     }
 
@@ -490,11 +493,9 @@
         try {
             ImportContext ctx = getImportContext(inputContext, Text.getName(member.getLocator().getJcrPath()));
             if (!ioManager.importContent(ctx, member)) {
-                // undo all changes
-                node.refresh(false);
+                // any changes should have been reverted in the importer
                 throw new DavException(DavServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
             }
-
             // persist changes after successful import
             node.save();
         } catch (RepositoryException e) {
@@ -953,7 +954,7 @@
         }
 
         public void setModificationTime(long modTime) {
-            if (modificationTime <= IOUtil.UNDEFINED_TIME) {
+            if (modTime <= IOUtil.UNDEFINED_TIME) {
                 modificationTime = new Date().getTime();
             } else {
                 modificationTime = modTime;

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/DavSessionProviderImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/DavSessionProviderImpl.java?rev=349905&r1=349904&r2=349905&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/DavSessionProviderImpl.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/DavSessionProviderImpl.java
Tue Nov 29 23:52:30 2005
@@ -66,8 +66,14 @@
      */
     public boolean attachSession(WebdavRequest request) throws DavException {
         try {
+            // retrieve the workspace name
+            String workspaceName = request.getRequestLocator().getWorkspaceName();
+            // empty workspaceName rather means default -> must be 'null'
+            if (workspaceName != null && "".equals(workspaceName)) {
+                workspaceName = null;
+            }
             // login to repository
-            Session repSession = sesProvider.getSession(request, repository, null);
+            Session repSession = sesProvider.getSession(request, repository, workspaceName);
             if (repSession == null) {
                 log.debug("Could not to retrieve a repository session.");
                 return false;
@@ -76,8 +82,10 @@
             log.debug("Attaching session '"+ ds + "' to request '" + request + "'");
             request.setDavSession(ds);
             return true;
-        } catch (LoginException e) {
-	    throw new JcrDavException(e);
+        } catch (NoSuchWorkspaceException e) {
+            // the default error-code for NoSuchWorkspaceException is 409 conflict
+            // which seems not appropriate here
+            throw new JcrDavException(e, DavServletResponse.SC_NOT_FOUND);
         } catch (RepositoryException e) {
 	    throw new JcrDavException(e);
 	} catch (ServletException e) {

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/ResourceFactoryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/ResourceFactoryImpl.java?rev=349905&r1=349904&r2=349905&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/ResourceFactoryImpl.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/server/src/java/org/apache/jackrabbit/webdav/simple/ResourceFactoryImpl.java
Tue Nov 29 23:52:30 2005
@@ -16,9 +16,16 @@
 
 package org.apache.jackrabbit.webdav.simple;
 
-import org.apache.jackrabbit.webdav.*;
 import org.apache.jackrabbit.webdav.jcr.JcrDavException;
 import org.apache.jackrabbit.webdav.lock.LockManager;
+import org.apache.jackrabbit.webdav.DavResourceFactory;
+import org.apache.jackrabbit.webdav.DavResource;
+import org.apache.jackrabbit.webdav.DavMethods;
+import org.apache.jackrabbit.webdav.DavException;
+import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.apache.jackrabbit.webdav.DavServletRequest;
+import org.apache.jackrabbit.webdav.DavResourceLocator;
+import org.apache.jackrabbit.webdav.DavSession;
 
 import javax.jcr.RepositoryException;
 
@@ -31,8 +38,8 @@
     private final ResourceConfig resourceConfig;
 
     /**
-     * Create a new <code>ResourceFactory</code> that uses the given lock manager
-     * and the default {@link DefaultResourceFilter resource filter}.
+     * Create a new <code>ResourceFactory</code> that uses the given lock
+     * manager and the default {@link DefaultResourceFilter resource filter}.
      *
      * @param lockMgr
      */
@@ -42,8 +49,8 @@
     }
 
     /**
-     * Create a new <code>ResourceFactory</code> that uses the given lock manager
-     * and resource filter.
+     * Create a new <code>ResourceFactory</code> that uses the given lock
+     * manager and resource filter.
      *
      * @param lockMgr
      * @param resourceConfig
@@ -54,14 +61,16 @@
     }
 
     /**
-     * Create a new <code>DavResource</code> from the given locator and request.
+     * Create a new <code>DavResource</code> from the given locator and
+     * request.
      *
      * @param locator
      * @param request
      * @param response
      * @return
      * @throws DavException
-     * @see DavResourceFactory#createResource(DavResourceLocator, DavServletRequest, DavServletResponse)
+     * @see DavResourceFactory#createResource(DavResourceLocator,
+     *      DavServletRequest, DavServletResponse)
      */
     public DavResource createResource(DavResourceLocator locator, DavServletRequest request,
                                       DavServletResponse response) throws DavException {

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webapp/src/java/org/apache/jackrabbit/j2ee/JCRWebdavServerServlet.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webapp/src/java/org/apache/jackrabbit/j2ee/JCRWebdavServerServlet.java?rev=349905&r1=349904&r2=349905&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webapp/src/java/org/apache/jackrabbit/j2ee/JCRWebdavServerServlet.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webapp/src/java/org/apache/jackrabbit/j2ee/JCRWebdavServerServlet.java
Tue Nov 29 23:52:30 2005
@@ -15,20 +15,25 @@
  */
 package org.apache.jackrabbit.j2ee;
 
-import org.apache.log4j.Logger;
-import org.apache.jackrabbit.webdav.*;
-import org.apache.jackrabbit.webdav.observation.*;
-import org.apache.jackrabbit.webdav.jcr.*;
-import org.apache.jackrabbit.webdav.jcr.observation.SubscriptionManagerImpl;
-import org.apache.jackrabbit.webdav.jcr.transaction.TxLockManagerImpl;
-import org.apache.jackrabbit.server.jcr.JCRWebdavServer;
-import org.apache.jackrabbit.server.SessionProviderImpl;
 import org.apache.jackrabbit.server.AbstractWebdavServlet;
 import org.apache.jackrabbit.server.BasicCredentialsProvider;
+import org.apache.jackrabbit.server.SessionProviderImpl;
+import org.apache.jackrabbit.server.jcr.JCRWebdavServer;
+import org.apache.jackrabbit.webdav.DavConstants;
+import org.apache.jackrabbit.webdav.DavLocatorFactory;
+import org.apache.jackrabbit.webdav.DavResource;
+import org.apache.jackrabbit.webdav.DavResourceFactory;
+import org.apache.jackrabbit.webdav.DavSessionProvider;
+import org.apache.jackrabbit.webdav.WebdavRequest;
+import org.apache.jackrabbit.webdav.jcr.DavLocatorFactoryImpl;
+import org.apache.jackrabbit.webdav.jcr.DavResourceFactoryImpl;
+import org.apache.jackrabbit.webdav.jcr.observation.SubscriptionManagerImpl;
+import org.apache.jackrabbit.webdav.jcr.transaction.TxLockManagerImpl;
+import org.apache.jackrabbit.webdav.observation.SubscriptionManager;
+import org.apache.log4j.Logger;
 
-import javax.servlet.ServletException;
-import javax.servlet.ServletContext;
 import javax.jcr.Repository;
+import javax.servlet.ServletException;
 
 /**
  * JCRWebdavServerServlet provides request/response handling for the JCRWebdavServer.
@@ -71,16 +76,6 @@
 	pathPrefix = getInitParameter(INIT_PARAM_PREFIX);
 	log.debug(INIT_PARAM_PREFIX + " = " + pathPrefix);
 
-        final ServletContext ctx = getServletContext();
-
-	Repository repository = RepositoryAccessServlet.getRepository(ctx);
-	if (repository == null) {
-	    throw new ServletException("Repository could not be retrieved. Check config of 'RepositoryAccessServlet'.");
-	}
-	server = new JCRWebdavServer(repository, new SessionProviderImpl(
-                new BasicCredentialsProvider(
-                        getInitParameter(INIT_PARAM_MISSING_AUTH_MAPPING)))
-        );
         txMgr = new TxLockManagerImpl();
         subscriptionMgr = new SubscriptionManagerImpl();
 
@@ -114,11 +109,7 @@
 
         // make sure, the TransactionId header is valid
         String txId = request.getTransactionId();
-        if (txId != null && !txMgr.hasLock(txId, resource)) {
-           return false;
-        }
-
-        return true;
+        return txId == null || txMgr.hasLock(txId, resource);
     }
 
     /**
@@ -128,6 +119,13 @@
      * @see AbstractWebdavServlet#getDavSessionProvider()
      */
     public DavSessionProvider getDavSessionProvider() {
+        if (server == null) {
+            Repository repository = RepositoryAccessServlet.getRepository(getServletContext());
+            server = new JCRWebdavServer(repository, new SessionProviderImpl(
+                    new BasicCredentialsProvider(
+                            getInitParameter(INIT_PARAM_MISSING_AUTH_MAPPING)))
+            );
+        }
         return server;
     }
 

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webapp/src/java/org/apache/jackrabbit/j2ee/RepositoryAccessServlet.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webapp/src/java/org/apache/jackrabbit/j2ee/RepositoryAccessServlet.java?rev=349905&r1=349904&r2=349905&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webapp/src/java/org/apache/jackrabbit/j2ee/RepositoryAccessServlet.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webapp/src/java/org/apache/jackrabbit/j2ee/RepositoryAccessServlet.java
Tue Nov 29 23:52:30 2005
@@ -40,9 +40,6 @@
     /** default logger */
     private static final Logger log = Logger.getLogger(RepositoryAccessServlet.class);
 
-    // todo: implement correctly
-    public final static String INIT_PARAM_LOG4J_CONFIG = "log4j-config";
-
     /** the 'repository-name' init parameter */
     public final static String INIT_PARAM_REPOSITORY_NAME = "repository-name";
 
@@ -50,11 +47,15 @@
     public final static String INIT_PARAM_RMI_URI = "rmi-uri";
 
     /** the 'missing-auth-mapping' init parameter */
-    public final static String INIT_PARAM_MISSING_AUTH_MAPPING = "missing-auth-mapping";
+    //public final static String INIT_PARAM_MISSING_AUTH_MAPPING = "missing-auth-mapping";
 
     private static final String CTX_ATTR_REPOSITORY = "jcr.repository";
 
-    private String repositoryName;
+    private static final String CTX_ATTR_REPOSITORY_NAME = "jcr.repository.name";
+
+    private static final String CTX_ATTR_REPOSITORY_RMI_URI = "jcr.repository.rmiURI";
+
+    private static final String CTX_ATTR_REPOSITORY_JNDI_CONTEXT = "jcr.repository.jndiContext";
 
     /**
      * Initializes this servlet
@@ -63,38 +64,23 @@
      */
     public void init() throws ServletException {
 	log.info("RepositoryAccessServlet initializing...");
-        repositoryName = getServletConfig().getInitParameter(INIT_PARAM_REPOSITORY_NAME);
+        // fetching the name
+        String repositoryName = getServletConfig().getInitParameter(INIT_PARAM_REPOSITORY_NAME);
         if (repositoryName==null) {
             repositoryName="default";
         }
-        Repository repository = null;
+        getServletContext().setAttribute(CTX_ATTR_REPOSITORY_NAME, repositoryName);
 
-        // try to retrieve via rmi
-        if (repository == null) {
-            String rmiURI = getRMIUri();
-            if (rmiURI != null) {
-                repository = getRepositoryByRMI(rmiURI);
-            }
-        }
-        // try to retrieve via jndi
-        if (repository == null) {
-            InitialContext context = getInitialContext();
-            if (context != null) {
-                repository = getRepositoryByJNDI(context);
-            }
-        }
-        // error
-        if (repository == null) {
-            log.error("Unable to retrieve repository");
-            throw new ServletException("Unable to retrieve repository");
-        }
-        getServletContext().setAttribute(CTX_ATTR_REPOSITORY, repository);
-        log.info(repository.getDescriptor(Repository.REP_NAME_DESC) + " v" + repository.getDescriptor(Repository.REP_VERSION_DESC));
+        // fetching the rmiuri
+        getServletContext().setAttribute(CTX_ATTR_REPOSITORY_RMI_URI, getRMIUri());
+
+        // setup initial context
+        getServletContext().setAttribute(CTX_ATTR_REPOSITORY_JNDI_CONTEXT, getInitialContext());
 
 	log.info("RepositoryAccessServlet initialized.");
     }
 
-    private InitialContext getInitialContext() throws ServletException {
+    private InitialContext getInitialContext() {
 	// retrieve JNDI Context environment
 	try {
 	    Properties env = new Properties();
@@ -109,7 +95,7 @@
 	    return new InitialContext(env);
 	} catch (NamingException e) {
 	    log.error("Create initial context: " + e.toString());
-	    throw new ServletException(e);
+	    return null;
 	}
     }
 
@@ -121,8 +107,13 @@
     /**
      * tries to retrieve the repository using RMI
      */
-    private Repository getRepositoryByJNDI(InitialContext jndiContext) {
+    private static Repository getRepositoryByJNDI(ServletContext ctx) {
         // acquire via JNDI
+        String repositoryName = (String) ctx.getAttribute(CTX_ATTR_REPOSITORY_NAME);
+        InitialContext jndiContext = (InitialContext) ctx.getAttribute(CTX_ATTR_REPOSITORY_JNDI_CONTEXT);
+        if (jndiContext == null) {
+            return null;
+        }
         try {
             Repository r = (Repository) jndiContext.lookup(repositoryName);
             log.info("Acquired repository via JNDI.");
@@ -136,8 +127,12 @@
     /**
      * tries to retrieve the repository using RMI
      */
-    private Repository getRepositoryByRMI(String rmiURI) {
+    private static Repository getRepositoryByRMI(ServletContext ctx) {
         // acquire via RMI
+        String rmiURI = (String) ctx.getAttribute(CTX_ATTR_REPOSITORY_RMI_URI);
+        if (rmiURI == null) {
+            return null;
+        }
         log.info("  trying to retrieve repository using rmi. uri=" + rmiURI);
         ClientFactoryDelegater cfd;
         try {
@@ -165,9 +160,28 @@
      * Returns the JSR170 repository
      *
      * @return a jsr170 repository
+     * @throws IllegalStateException if the repository is not available in the context.
      */
     public static Repository getRepository(ServletContext ctx) {
-	return (Repository) ctx.getAttribute(CTX_ATTR_REPOSITORY);
+        Repository repository = (Repository) ctx.getAttribute(CTX_ATTR_REPOSITORY);
+        if (repository != null) {
+            return repository;
+        } else {
+            repository = getRepositoryByRMI(ctx);
+        }
+        // try to retrieve via jndi
+        if (repository == null) {
+            repository = getRepositoryByJNDI(ctx);
+        }
+        // error
+        if (repository == null) {
+            log.fatal("The repository is not available. Check config of 'RepositoryAccessServlet'.");
+            throw new IllegalStateException("The repository is not available.");
+        } else {
+            ctx.setAttribute(CTX_ATTR_REPOSITORY, repository);
+            log.info(repository.getDescriptor(Repository.REP_NAME_DESC) + " v" + repository.getDescriptor(Repository.REP_VERSION_DESC));
+            return repository;
+        }
     }
 }
 

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webapp/src/java/org/apache/jackrabbit/j2ee/SimpleWebdavServlet.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webapp/src/java/org/apache/jackrabbit/j2ee/SimpleWebdavServlet.java?rev=349905&r1=349904&r2=349905&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webapp/src/java/org/apache/jackrabbit/j2ee/SimpleWebdavServlet.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webapp/src/java/org/apache/jackrabbit/j2ee/SimpleWebdavServlet.java
Tue Nov 29 23:52:30 2005
@@ -400,7 +400,7 @@
     /**
      * Returns the resource configuration to be applied
      *
-     * @return
+     * @return the resource configuration.
      */
     public ResourceConfig getResourceConfig() {
         // fallback if no config present
@@ -430,9 +430,6 @@
     public Repository getRepository() {
         if (repository == null) {
             repository = RepositoryAccessServlet.getRepository(getServletContext());
-            if (repository == null) {
-                throw new IllegalStateException("Repository could not be retrieved. Check
config of 'RepositoryAccessServlet'.");
-            }
         }
         return repository;
     }

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavConstants.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavConstants.java?rev=349905&r1=349904&r2=349905&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavConstants.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/DavConstants.java
Tue Nov 29 23:52:30 2005
@@ -16,8 +16,9 @@
 package org.apache.jackrabbit.webdav;
 
 import org.jdom.Namespace;
+import org.apache.jackrabbit.webdav.util.HttpDateFormat;
 
-import java.text.SimpleDateFormat;
+import java.text.DateFormat;
 
 /**
  * <code>DavConstants</code> provide constants for request and response
@@ -48,8 +49,9 @@
     //------------------------------------------------------- Timeout header ---
     public static final String HEADER_TIMEOUT = "Timeout";
     public static final String TIMEOUT_INFINITE = "Infinite";
-    public static final long INFINITE_TIMEOUT = Long.MAX_VALUE;
-    public static final long UNDEFINED_TIMEOUT = Long.MIN_VALUE;
+    // RFC 2518: timeout value for TimeType "Second" MUST NOT be greater than 2^32-1
+    public static final long INFINITE_TIMEOUT = Integer.MAX_VALUE;
+    public static final long UNDEFINED_TIMEOUT = Integer.MIN_VALUE;
     
     //----------------------------------------------------- Overwrite header ---
     public static final String HEADER_OVERWRITE = "Overwrite";
@@ -135,10 +137,10 @@
     /**
      * modificationDate date format per RFC 1123
      */
-    public static SimpleDateFormat modificationDateFormat = new SimpleDateFormat("EEE, dd
MMM yyyy HH:mm:ss zzz");
+    public static DateFormat modificationDateFormat = new HttpDateFormat("EEE, dd MMM yyyy
HH:mm:ss z");
 
     /**
      * Simple date format for the creation date ISO representation (partial).
      */
-    public static SimpleDateFormat creationDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+    public static DateFormat creationDateFormat = new HttpDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
 }

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/util/HttpDateFormat.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/util/HttpDateFormat.java?rev=349905&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/util/HttpDateFormat.java
(added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/util/HttpDateFormat.java
Tue Nov 29 23:52:30 2005
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.webdav.util;
+
+import org.apache.log4j.Logger;
+
+import java.text.SimpleDateFormat;
+import java.text.DateFormatSymbols;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * <code>HttpDateFormat</code>...
+ */
+public class HttpDateFormat extends SimpleDateFormat {
+
+    private static Logger log = Logger.getLogger(HttpDateFormat.class);
+    private static final TimeZone GMT_TIMEZONE = TimeZone.getTimeZone("GMT");
+
+    public HttpDateFormat() {
+        super();
+        super.setTimeZone(GMT_TIMEZONE);
+    }
+
+    public HttpDateFormat(String pattern) {
+        super(pattern);
+        super.setTimeZone(GMT_TIMEZONE);
+    }
+
+    public HttpDateFormat(String pattern, DateFormatSymbols formatSymbols) {
+        super(pattern, formatSymbols);
+        super.setTimeZone(GMT_TIMEZONE);
+    }
+
+    public HttpDateFormat(String pattern, Locale locale) {
+        super(pattern, locale);
+        super.setTimeZone(GMT_TIMEZONE);
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/util/HttpDateFormat.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/util/HttpDateFormat.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/util/XmlUtil.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/util/XmlUtil.java?rev=349905&r1=349904&r2=349905&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/util/XmlUtil.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/util/XmlUtil.java
Tue Nov 29 23:52:30 2005
@@ -30,17 +30,19 @@
     /**
      * Converts the given timeout (long value defining the number of milli-
      * second until timeout is reached) to its Xml representation as defined
-     * by RTF 2518.
+     * by RTF 2518.<br>
+     * Note, that {@link #INFINITE_TIMEOUT} is not represented by the String
+     * {@link #TIMEOUT_INFINITE 'Infinite'} defined by RFC 2518, due to a known
+     * issue with Microsoft Office that opens the document "read only" and
+     * never unlocks the resource if the timeout is missing or 'Infinite'.
      *
      * @param timeout number of milli-seconds until timeout is reached.
      * @return 'timeout' JDOM element
      */
     public static Element timeoutToXml(long timeout) {
-        // TODO: check if 'infinite' would be better to return for infinite timeout.
-        String expString = "Second-"+ timeout/1000;
-        Element exp = new Element(XML_TIMEOUT, NAMESPACE);
-        exp.setText(expString);
-        return exp;
+        Element el = new Element(XML_TIMEOUT, NAMESPACE);
+        el.setText("Second-"+ timeout/1000);
+        return el;
     }
 
     /**



Mime
View raw message