chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1330798 - in /chemistry/opencmis/trunk: chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/ chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/o...
Date Thu, 26 Apr 2012 12:10:24 GMT
Author: fmui
Date: Thu Apr 26 12:10:24 2012
New Revision: 1330798

URL: http://svn.apache.org/viewvc?rev=1330798&view=rev
Log:
StandardAuthenticationProvider:
- compile HTTP headers once and reuse them
- added capability to add HTTP headers via session parameters

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/StandardAuthenticationProvider.java
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/SessionParameter.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/StandardAuthenticationProvider.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/StandardAuthenticationProvider.java?rev=1330798&r1=1330797&r2=1330798&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/StandardAuthenticationProvider.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/StandardAuthenticationProvider.java
Thu Apr 26 12:10:24 2012
@@ -20,6 +20,7 @@ package org.apache.chemistry.opencmis.cl
 
 import java.io.UnsupportedEncodingException;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -51,6 +52,7 @@ public class StandardAuthenticationProvi
     private boolean sendBasicAuth;
     private boolean sendUsernameToken;
     private CmisCookieManager cookieManager;
+    private Map<String, List<String>> fixedHeaders = new HashMap<String, List<String>>();
 
     @Override
     public void setSession(BindingSession session) {
@@ -62,11 +64,6 @@ public class StandardAuthenticationProvi
         if (isTrue(SessionParameter.COOKIES)) {
             cookieManager = new CmisCookieManager();
         }
-    }
-
-    @Override
-    public Map<String, List<String>> getHTTPHeaders(String url) {
-        Map<String, List<String>> result = new HashMap<String, List<String>>();
 
         // authentication
         if (sendBasicAuth) {
@@ -76,7 +73,7 @@ public class StandardAuthenticationProvi
 
             // if no user is set, don't set basic auth header
             if (user != null) {
-                result.put("Authorization", createBasicAuthHeaderValue(user, password));
+                fixedHeaders.put("Authorization", createBasicAuthHeaderValue(user, password));
             }
 
             // get proxy user and password
@@ -85,10 +82,38 @@ public class StandardAuthenticationProvi
 
             // if no proxy user is set, don't set basic auth header
             if (proxyUser != null) {
-                result.put("Proxy-Authorization", createBasicAuthHeaderValue(proxyUser, proxyPassword));
+                fixedHeaders.put("Proxy-Authorization", createBasicAuthHeaderValue(proxyUser,
proxyPassword));
             }
         }
 
+        // other headers
+        int x = 0;
+        Object headerParam;
+        while ((headerParam = getSession().get(SessionParameter.HEADER + "." + x)) != null)
{
+            String header = headerParam.toString();
+            int colon = header.indexOf(':');
+            if (colon > -1) {
+                String key = header.substring(0, colon).trim();
+                if (key.length() > 0) {
+                    String value = header.substring(colon + 1).trim();
+                    List<String> values = fixedHeaders.get(key);
+                    if (values == null) {
+                        fixedHeaders.put(key, Collections.singletonList(value));
+                    } else {
+                        List<String> newValues = new ArrayList<String>(values);
+                        newValues.add(value);
+                        fixedHeaders.put(key, newValues);
+                    }
+                }
+            }
+            x++;
+        }
+    }
+
+    @Override
+    public Map<String, List<String>> getHTTPHeaders(String url) {
+        Map<String, List<String>> result = new HashMap<String, List<String>>(fixedHeaders);
+
         // cookies
         if (cookieManager != null) {
             Map<String, List<String>> cookies = cookieManager.get(url, result);
@@ -177,6 +202,14 @@ public class StandardAuthenticationProvi
     }
 
     /**
+     * Returns the HTTP headers that are sent with all requests. The returned
+     * map is mutable but not synchronized!
+     */
+    protected Map<String, List<String>> getFixedHeaders() {
+        return fixedHeaders;
+    }
+
+    /**
      * Creates a basic authentication header value from a username and a
      * password.
      */

Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/SessionParameter.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/SessionParameter.java?rev=1330798&r1=1330797&r2=1330798&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/SessionParameter.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/SessionParameter.java
Thu Apr 26 12:10:24 2012
@@ -82,6 +82,8 @@ public final class SessionParameter {
     public static final String CLIENT_COMPRESSION = "org.apache.chemistry.opencmis.binding.clientcompression";
 
     public static final String COOKIES = "org.apache.chemistry.opencmis.binding.cookies";
+    
+    public static final String HEADER = "org.apache.chemistry.opencmis.binding.header";
 
     public static final String CONNECT_TIMEOUT = "org.apache.chemistry.opencmis.binding.connecttimeout";
     public static final String READ_TIMEOUT = "org.apache.chemistry.opencmis.binding.readtimeout";



Mime
View raw message