chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1004193 - in /incubator/chemistry/opencmis/trunk: chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/ chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/j...
Date Mon, 04 Oct 2010 10:45:45 GMT
Author: fmui
Date: Mon Oct  4 10:45:45 2010
New Revision: 1004193

URL: http://svn.apache.org/viewvc?rev=1004193&view=rev
Log:
- moved classes and code to support browser binding development

Added:
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/BasicAuthCallContextHandler.java
  (with props)
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/CallContextHandler.java
  (with props)
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java
  (with props)
Removed:
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/BasicAuthCallContextHandler.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CallContextHandler.java
Modified:
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CallContext.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/webapp/WEB-INF/web.xml

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CallContext.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CallContext.java?rev=1004193&r1=1004192&r2=1004193&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CallContext.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/server/CallContext.java
Mon Oct  4 10:45:45 2010
@@ -25,6 +25,7 @@ public interface CallContext {
 
     String BINDING_ATOMPUB = "atompub";
     String BINDING_WEBSERVICES = "webservices";
+    String BINDING_BROWSER = "browser";
     String BINDING_LOCAL = "local";
 
     String REPOSITORY_ID = "repositoryId";
@@ -36,8 +37,9 @@ public interface CallContext {
 
     /**
      * Returns the binding. Usually it returns
-     * {@link CallContext#BINDING_ATOMPUB} or
-     * {@link CallContext#BINDING_WEBSERVICES}.
+     * {@link CallContext#BINDING_ATOMPUB},
+     * {@link CallContext#BINDING_WEBSERVICES},
+     * {@link CallContext#BINDING_BROWSER} or {@link CallContext#BINDING_LOCAL}.
      */
     String getBinding();
 

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java?rev=1004193&r1=1004192&r2=1004193&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/CmisAtomPubServlet.java
Mon Oct  4 10:45:45 2010
@@ -19,8 +19,6 @@
 package org.apache.chemistry.opencmis.server.impl.atompub;
 
 import java.io.IOException;
-import java.math.BigInteger;
-import java.util.Map;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
@@ -45,8 +43,9 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.server.CallContext;
 import org.apache.chemistry.opencmis.commons.server.CmisService;
 import org.apache.chemistry.opencmis.commons.server.CmisServiceFactory;
-import org.apache.chemistry.opencmis.server.impl.CallContextImpl;
 import org.apache.chemistry.opencmis.server.impl.CmisRepositoryContextListener;
+import org.apache.chemistry.opencmis.server.shared.CallContextHandler;
+import org.apache.chemistry.opencmis.server.shared.HttpUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -149,7 +148,7 @@ public class CmisAtomPubServlet extends 
         // create a context object, dispatch and handle exceptions
         CallContext context = null;
         try {
-            context = createContext(request);
+            context = HttpUtils.createContext(request, CallContext.BINDING_ATOMPUB, callContextHandler);
             dispatch(context, request, response);
         } catch (Exception e) {
             if (e instanceof CmisPermissionDeniedException) {
@@ -194,7 +193,7 @@ public class CmisAtomPubServlet extends 
             service = factory.getService(context);
 
             // analyze the path
-            String[] pathFragments = splitPath(request);
+            String[] pathFragments = HttpUtils.splitPath(request);
 
             if (pathFragments.length < 2) {
                 // root -> service document
@@ -223,79 +222,6 @@ public class CmisAtomPubServlet extends 
     }
 
     /**
-     * Decodes basic auth and creates a {@link CallContext} object.
-     */
-    protected CallContext createContext(HttpServletRequest request) {
-        String[] pathFragments = splitPath(request);
-
-        String repositoryId = null;
-        if (pathFragments.length > 0) {
-            repositoryId = pathFragments[0];
-        }
-
-        CallContextImpl context = new CallContextImpl(CallContext.BINDING_ATOMPUB, repositoryId,
true);
-
-        // call call context handler
-        if (callContextHandler != null) {
-            Map<String, String> callContextMap = callContextHandler.getCallContextMap(request);
-            if (callContextMap != null) {
-                for (Map.Entry<String, String> e : callContextMap.entrySet()) {
-                    context.put(e.getKey(), e.getValue());
-                }
-            }
-        }
-
-        // decode range
-        String rangeHeader = request.getHeader("Range");
-        if (rangeHeader != null) {
-            rangeHeader = rangeHeader.trim();
-            BigInteger offset = null;
-            BigInteger length = null;
-
-            int eq = rangeHeader.indexOf('=');
-            int ds = rangeHeader.indexOf('-');
-            if ((eq > 0) && (ds > eq)) {
-                String offsetStr = rangeHeader.substring(eq + 1, ds).trim();
-                if (offsetStr.length() > 0) {
-                    offset = new BigInteger(offsetStr);
-                }
-
-                if (ds < rangeHeader.length()) {
-                    String lengthStr = rangeHeader.substring(ds + 1).trim();
-                    if (lengthStr.length() > 0) {
-                        if (offset == null) {
-                            length = new BigInteger(lengthStr);
-                        } else {
-                            length = (new BigInteger(lengthStr)).subtract(offset);
-                        }
-                    }
-
-                    if (offset != null) {
-                        context.put(CallContext.OFFSET, offset.toString());
-                    }
-                    if (length != null) {
-                        context.put(CallContext.LENGTH, length.toString());
-                    }
-                }
-            }
-        }
-
-        return context;
-    }
-
-    /**
-     * Splits the path into its fragments.
-     */
-    private String[] splitPath(HttpServletRequest request) {
-        String p = request.getPathInfo();
-        if (p == null) {
-            return new String[0];
-        }
-
-        return p.substring(1).split("/");
-    }
-
-    /**
      * Translates an exception in an appropriate HTTP error code.
      */
     private int getErrorCode(CmisBaseException ex) {

Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/BasicAuthCallContextHandler.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/BasicAuthCallContextHandler.java?rev=1004193&view=auto
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/BasicAuthCallContextHandler.java
(added)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/BasicAuthCallContextHandler.java
Mon Oct  4 10:45:45 2010
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.chemistry.opencmis.server.shared;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.chemistry.opencmis.commons.server.CallContext;
+import org.apache.commons.codec.binary.Base64;
+
+/**
+ * Call Context handler that handles basic authentication.
+ */
+public class BasicAuthCallContextHandler implements CallContextHandler {
+
+    /**
+     * Constructor.
+     */
+    public BasicAuthCallContextHandler() {
+    }
+
+    public Map<String, String> getCallContextMap(HttpServletRequest request) {
+        Map<String, String> result = null;
+
+        String authHeader = request.getHeader("Authorization");
+        if ((authHeader != null) && (authHeader.trim().toLowerCase().startsWith("basic
"))) {
+            int x = authHeader.lastIndexOf(' ');
+            if (x == -1) {
+                return result;
+            }
+
+            String credentials = null;
+            try {
+                credentials = new String(Base64.decodeBase64(authHeader.substring(x + 1).getBytes("ISO-8859-1")),
+                        "ISO-8859-1");
+            } catch (Exception e) {
+                return result;
+            }
+
+            x = credentials.indexOf(':');
+            if (x == -1) {
+                return result;
+            }
+
+            // extract user and password and add them to map
+            result = new HashMap<String, String>();
+            result.put(CallContext.USERNAME, credentials.substring(0, x));
+            result.put(CallContext.PASSWORD, credentials.substring(x + 1));
+        }
+
+        return result;
+    }
+}

Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/BasicAuthCallContextHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/CallContextHandler.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/CallContextHandler.java?rev=1004193&view=auto
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/CallContextHandler.java
(added)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/CallContextHandler.java
Mon Oct  4 10:45:45 2010
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.chemistry.opencmis.server.shared;
+
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.chemistry.opencmis.commons.server.CallContext;
+
+/**
+ * Call Context handler interface.
+ */
+public interface CallContextHandler {
+
+    /**
+     * Returns key-value pairs that will be added to the {@link CallContext}.
+     */
+    Map<String, String> getCallContextMap(HttpServletRequest request);
+}

Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/CallContextHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java?rev=1004193&view=auto
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java
(added)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java
Mon Oct  4 10:45:45 2010
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.chemistry.opencmis.server.shared;
+
+import java.math.BigInteger;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.chemistry.opencmis.commons.server.CallContext;
+import org.apache.chemistry.opencmis.server.impl.CallContextImpl;
+
+/**
+ * Utility methods that are used by the AtomPub and Browser binding.
+ */
+public class HttpUtils {
+
+    /**
+     * Creates a {@link CallContext} object from a servlet request.
+     */
+    public static CallContext createContext(HttpServletRequest request, String binding,
+            CallContextHandler callContextHandler) {
+        String[] pathFragments = splitPath(request);
+
+        String repositoryId = null;
+        if (pathFragments.length > 0) {
+            repositoryId = pathFragments[0];
+        }
+
+        CallContextImpl context = new CallContextImpl(binding, repositoryId, true);
+
+        // call call context handler
+        if (callContextHandler != null) {
+            Map<String, String> callContextMap = callContextHandler.getCallContextMap(request);
+            if (callContextMap != null) {
+                for (Map.Entry<String, String> e : callContextMap.entrySet()) {
+                    context.put(e.getKey(), e.getValue());
+                }
+            }
+        }
+
+        // decode range
+        String rangeHeader = request.getHeader("Range");
+        if (rangeHeader != null) {
+            rangeHeader = rangeHeader.trim();
+            BigInteger offset = null;
+            BigInteger length = null;
+
+            int eq = rangeHeader.indexOf('=');
+            int ds = rangeHeader.indexOf('-');
+            if ((eq > 0) && (ds > eq)) {
+                String offsetStr = rangeHeader.substring(eq + 1, ds).trim();
+                if (offsetStr.length() > 0) {
+                    offset = new BigInteger(offsetStr);
+                }
+
+                if (ds < rangeHeader.length()) {
+                    String lengthStr = rangeHeader.substring(ds + 1).trim();
+                    if (lengthStr.length() > 0) {
+                        if (offset == null) {
+                            length = new BigInteger(lengthStr);
+                        } else {
+                            length = (new BigInteger(lengthStr)).subtract(offset);
+                        }
+                    }
+
+                    if (offset != null) {
+                        context.put(CallContext.OFFSET, offset.toString());
+                    }
+                    if (length != null) {
+                        context.put(CallContext.LENGTH, length.toString());
+                    }
+                }
+            }
+        }
+
+        return context;
+    }
+
+    /**
+     * Splits the path into its fragments.
+     */
+    public static String[] splitPath(HttpServletRequest request) {
+        String p = request.getPathInfo();
+        if (p == null) {
+            return new String[0];
+        }
+
+        return p.substring(1).split("/");
+    }
+}

Propchange: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/HttpUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/webapp/WEB-INF/web.xml?rev=1004193&r1=1004192&r2=1004193&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/webapp/WEB-INF/web.xml
(original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/webapp/WEB-INF/web.xml
Mon Oct  4 10:45:45 2010
@@ -46,7 +46,7 @@
 		<servlet-class>org.apache.chemistry.opencmis.server.impl.atompub.CmisAtomPubServlet</servlet-class>
 		<init-param>
 			<param-name>callContextHandler</param-name>
-			<param-value>org.apache.chemistry.opencmis.server.impl.atompub.BasicAuthCallContextHandler</param-value>
+			<param-value>org.apache.chemistry.opencmis.server.shared.BasicAuthCallContextHandler</param-value>
 		</init-param>
 		<load-on-startup>2</load-on-startup>
 	</servlet>



Mime
View raw message