chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1720140 - in /chemistry/opencmis/trunk: chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/ chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemi...
Date Tue, 15 Dec 2015 12:28:15 GMT
Author: fmui
Date: Tue Dec 15 12:28:15 2015
New Revision: 1720140

URL: http://svn.apache.org/viewvc?rev=1720140&view=rev
Log:
OpenCMIS client: allow applications setting the user agent

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/SessionParameterMap.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/impl/ClientVersion.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/OAuthAuthenticationProvider.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/AbstractApacheClientHttpInvoker.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/AbstractPortProvider.java
    chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/SessionParameter.java
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientSession.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/SessionParameterMap.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/SessionParameterMap.java?rev=1720140&r1=1720139&r2=1720140&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/SessionParameterMap.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/SessionParameterMap.java
Tue Dec 15 12:28:15 2015
@@ -602,6 +602,20 @@ public class SessionParameterMap extends
     }
 
     /**
+     * Sets the user agent string.
+     * 
+     * @param userAgent
+     *            the user agent string
+     */
+    public void setUserAgent(String userAgent) {
+        if (userAgent != null) {
+            put(SessionParameter.USER_AGENT, userAgent);
+        } else {
+            remove(SessionParameter.USER_AGENT);
+        }
+    }
+
+    /**
      * Sets whether requests to the server should be compressed or not.
      * 
      * @param compression

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/impl/ClientVersion.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/impl/ClientVersion.java?rev=1720140&r1=1720139&r2=1720140&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/impl/ClientVersion.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/impl/ClientVersion.java
Tue Dec 15 12:28:15 2015
@@ -22,16 +22,22 @@ public final class ClientVersion {
 
     public static final String OPENCMIS_VERSION;
     public static final String OPENCMIS_CLIENT;
+    public static final String OPENCMIS_USER_AGENT;
 
     static {
         Package p = Package.getPackage("org.apache.chemistry.opencmis.client.bindings.impl");
         if (p == null) {
             OPENCMIS_VERSION = "?";
-            OPENCMIS_CLIENT = "Apache Chemistry OpenCMIS";
+            OPENCMIS_CLIENT = "Apache-Chemistry-OpenCMIS";
         } else {
             OPENCMIS_VERSION = p.getImplementationVersion();
-            OPENCMIS_CLIENT = "Apache Chemistry OpenCMIS/" + (OPENCMIS_VERSION == null ?
"?" : OPENCMIS_VERSION);
+            OPENCMIS_CLIENT = "Apache-Chemistry-OpenCMIS/" + (OPENCMIS_VERSION == null ?
"?" : OPENCMIS_VERSION);
         }
+
+        String java = "Java " + System.getProperty("java.version");
+        String os = System.getProperty("os.name") + " " + System.getProperty("os.version");
+
+        OPENCMIS_USER_AGENT = OPENCMIS_CLIENT + " (" + java + "; " + os + ")";
     }
 
     private ClientVersion() {

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/OAuthAuthenticationProvider.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/OAuthAuthenticationProvider.java?rev=1720140&r1=1720139&r2=1720140&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/OAuthAuthenticationProvider.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/OAuthAuthenticationProvider.java
Tue Dec 15 12:28:15 2015
@@ -364,7 +364,8 @@ public class OAuthAuthenticationProvider
         conn.setDoOutput(true);
         conn.setAllowUserInteraction(false);
         conn.setUseCaches(false);
-        conn.setRequestProperty("User-Agent", ClientVersion.OPENCMIS_CLIENT);
+        conn.setRequestProperty("User-Agent",
+                (String) getSession().get(SessionParameter.USER_AGENT, ClientVersion.OPENCMIS_USER_AGENT));
         conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
 
         // compile request

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/AbstractApacheClientHttpInvoker.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/http/AbstractApacheClientHttpInvoker.java?rev=1720140&r1=1720139&r2=1720140&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/AbstractApacheClientHttpInvoker.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/AbstractApacheClientHttpInvoker.java
Tue Dec 15 12:28:15 2015
@@ -328,7 +328,8 @@ public abstract class AbstractApacheClie
         HttpParams params = new BasicHttpParams();
 
         HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
-        HttpProtocolParams.setUserAgent(params, ClientVersion.OPENCMIS_CLIENT);
+        HttpProtocolParams.setUserAgent(params,
+                (String) session.get(SessionParameter.USER_AGENT, ClientVersion.OPENCMIS_USER_AGENT));
         HttpProtocolParams.setContentCharset(params, IOUtils.UTF8);
         HttpProtocolParams.setUseExpectContinue(params, true);
 

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.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/http/DefaultHttpInvoker.java?rev=1720140&r1=1720139&r2=1720140&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java
Tue Dec 15 12:28:15 2015
@@ -96,7 +96,9 @@ public class DefaultHttpInvoker implemen
             conn.setDoOutput(writer != null);
             conn.setAllowUserInteraction(false);
             conn.setUseCaches(false);
-            conn.setRequestProperty("User-Agent", ClientVersion.OPENCMIS_CLIENT);
+
+            conn.setRequestProperty("User-Agent",
+                    (String) session.get(SessionParameter.USER_AGENT, ClientVersion.OPENCMIS_USER_AGENT));
 
             // timeouts
             int connectTimeout = session.get(SessionParameter.CONNECT_TIMEOUT, -1);

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/AbstractPortProvider.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/webservices/AbstractPortProvider.java?rev=1720140&r1=1720139&r2=1720140&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/AbstractPortProvider.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/AbstractPortProvider.java
Tue Dec 15 12:28:15 2015
@@ -647,7 +647,8 @@ public abstract class AbstractPortProvid
         }
 
         // CMIS client header
-        httpHeaders.put("X-CMIS-Client", Collections.singletonList(ClientVersion.OPENCMIS_CLIENT));
+        httpHeaders.put("X-CMIS-Client", Collections.singletonList((String) session.get(SessionParameter.USER_AGENT,
+                ClientVersion.OPENCMIS_USER_AGENT)));
 
         // compression
         if (useCompression) {

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=1720140&r1=1720139&r2=1720140&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
Tue Dec 15 12:28:15 2015
@@ -181,6 +181,14 @@ package org.apache.chemistry.opencmis.co
  * <td>no</td>
  * <td>-</td>
  * </tr>
+  * <tr>
+ * <td>{@link #USER_AGENT}</td>
+ * <td>User agent header</td>
+ * <td>AtomPub, Web Services, Browser</td>
+ * <td>user agent string</td>
+ * <td>no</td>
+ * <td>-</td>
+ * </tr>
  * <tr>
  * <td>{@link #PROXY_USER}</td>
  * <td>Proxy user (used by the standard authentication provider)</td>
@@ -688,6 +696,8 @@ public final class SessionParameter {
 
     public static final String CSRF_HEADER = "org.apache.chemistry.opencmis.binding.csrfheader";
 
+    public static final String USER_AGENT = "org.apache.chemistry.opencmis.binding.useragent";
+
     // --- cache ---
 
     public static final String CACHE_SIZE_OBJECTS = "org.apache.chemistry.opencmis.cache.objects.size";

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientSession.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientSession.java?rev=1720140&r1=1720139&r2=1720140&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientSession.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientSession.java
Tue Dec 15 12:28:15 2015
@@ -42,6 +42,7 @@ import org.apache.chemistry.opencmis.cli
 import org.apache.chemistry.opencmis.client.api.Repository;
 import org.apache.chemistry.opencmis.client.api.Session;
 import org.apache.chemistry.opencmis.client.bindings.cache.TypeDefinitionCache;
+import org.apache.chemistry.opencmis.client.bindings.impl.ClientVersion;
 import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
 import org.apache.chemistry.opencmis.client.runtime.cache.Cache;
 import org.apache.chemistry.opencmis.commons.PropertyIds;
@@ -60,6 +61,10 @@ public class ClientSession {
 
     private static final Logger LOG = LoggerFactory.getLogger(ClientSession.class);
 
+    public static final String WORKBENCH_USER_AGENT = "OpenCMIS-Workbench/"
+            + (ClientVersion.OPENCMIS_VERSION == null ? "?" : ClientVersion.OPENCMIS_VERSION)
+ " "
+            + ClientVersion.OPENCMIS_USER_AGENT;
+
     public static final String WORKBENCH_PREFIX = "cmis.workbench.";
     public static final String OBJECT_PREFIX = WORKBENCH_PREFIX + "object.";
     public static final String FOLDER_PREFIX = WORKBENCH_PREFIX + "folder.";
@@ -152,6 +157,8 @@ public class ClientSession {
             parameters.setNoAuthentication();
         }
 
+        parameters.setUserAgent(WORKBENCH_USER_AGENT);
+
         parameters.setCompression(compression);
         parameters.setClientCompression(clientCompression);
 



Mime
View raw message