You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2011/01/21 12:47:42 UTC

svn commit: r1061764 - in /incubator/chemistry/opencmis/trunk: chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ chemistry-opencmis-client/chemistry-opencmis-client-bin...

Author: fmui
Date: Fri Jan 21 11:47:41 2011
New Revision: 1061764

URL: http://svn.apache.org/viewvc?rev=1061764&view=rev
Log:
CMIS-296: added compression to the AtomPub binding, Web Services binding and the CMIS Workbench
(compression is turned off by default)

Modified:
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/HttpUtils.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/PortProvider.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/SessionParameter.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoginDialog.java
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientSession.java

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/HttpUtils.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/HttpUtils.java?rev=1061764&r1=1061763&r2=1061764&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/HttpUtils.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/HttpUtils.java Fri Jan 21 11:47:41 2011
@@ -30,10 +30,14 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.Inflater;
+import java.util.zip.InflaterInputStream;
 
 import org.apache.chemistry.opencmis.client.bindings.impl.CmisBindingsHelper;
 import org.apache.chemistry.opencmis.client.bindings.spi.AbstractAuthenticationProvider;
 import org.apache.chemistry.opencmis.client.bindings.spi.Session;
+import org.apache.chemistry.opencmis.commons.SessionParameter;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException;
 import org.apache.chemistry.opencmis.commons.impl.Base64;
 import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
@@ -85,6 +89,7 @@ public class HttpUtils {
             conn.setRequestMethod(method);
             conn.setDoInput(true);
             conn.setDoOutput(writer != null);
+            conn.setRequestProperty("User-Agent", "Apache Chemistry OpenCMIS");
 
             // set content type
             if (contentType != null) {
@@ -124,6 +129,15 @@ public class HttpUtils {
                 conn.setRequestProperty("Range", sb.toString());
             }
 
+            // compression
+            if ((session.get(SessionParameter.COMPRESSION) instanceof String)
+                    && (Boolean.parseBoolean((String) session.get(SessionParameter.COMPRESSION)))) {
+                conn.setRequestProperty("Accept-Encoding", "gzip");
+            } else if ((session.get(SessionParameter.COMPRESSION) instanceof Boolean)
+                    && ((Boolean) session.get(SessionParameter.COMPRESSION)).booleanValue()) {
+                conn.setRequestProperty("Accept-Encoding", "gzip");
+            }
+
             // send data
             if (writer != null) {
                 conn.setChunkedStreamingMode(BUFFER_SIZE);
@@ -219,10 +233,31 @@ public class HttpUtils {
                 }
             }
 
-            // if the stream is base64 encoded, decode it
             if (stream != null) {
-                String encoding = getContentTransferEncoding();
-                if ((encoding != null) && (encoding.toLowerCase().trim().equals("base64"))) {
+                String encoding = getContentEncoding();
+                if (encoding != null) {
+                    if (encoding.toLowerCase().trim().equals("gzip")) {
+                        // if the stream is gzip encoded, decode it
+                        length = null;
+                        try {
+                            this.stream = new GZIPInputStream(stream, 4096);
+                        } catch (IOException e) {
+                            errorContent = e.getMessage();
+                            try {
+                                stream.close();
+                            } catch (IOException ec) {
+                            }
+                        }
+                    } else if (encoding.toLowerCase().trim().equals("deflate")) {
+                        // if the stream is deflate encoded, decode it
+                        length = null;
+                        this.stream = new InflaterInputStream(stream, new Inflater(true), 4096);
+                    }
+                }
+
+                String transferEncoding = getContentTransferEncoding();
+                if ((transferEncoding != null) && (transferEncoding.toLowerCase().trim().equals("base64"))) {
+                    // if the stream is base64 encoded, decode it
                     length = null;
                     this.stream = new Base64.InputStream(stream);
                 }
@@ -279,6 +314,10 @@ public class HttpUtils {
             return getHeader("Content-Transfer-Encoding");
         }
 
+        public String getContentEncoding() {
+            return getHeader("Content-Encoding");
+        }
+
         public BigInteger getContentLength() {
             return length;
         }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/PortProvider.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/PortProvider.java?rev=1061764&r1=1061763&r2=1061764&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/PortProvider.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/PortProvider.java Fri Jan 21 11:47:41 2011
@@ -18,6 +18,8 @@
  */
 package org.apache.chemistry.opencmis.client.bindings.spi.webservices;
 
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -58,11 +60,23 @@ public class PortProvider extends Abstra
 
     private static Log log = LogFactory.getLog(PortProvider.class);
 
+    private boolean useCompression;
+
     /**
      * Constructor.
      */
     public PortProvider(Session session) {
         this.session = session;
+
+        useCompression = false;
+        if ((session.get(SessionParameter.COMPRESSION) instanceof String)
+                && (Boolean.parseBoolean((String) session.get(SessionParameter.COMPRESSION)))) {
+            useCompression = true;
+        }
+        if ((session.get(SessionParameter.COMPRESSION) instanceof Boolean)
+                && ((Boolean) session.get(SessionParameter.COMPRESSION)).booleanValue()) {
+            useCompression = true;
+        }
     }
 
     /**
@@ -109,6 +123,7 @@ public class PortProvider extends Abstra
 
             // add SOAP and HTTP authentication headers
             AbstractAuthenticationProvider authProvider = CmisBindingsHelper.getAuthenticationProvider(session);
+            Map<String, List<String>> httpHeaders = null;
             if (authProvider != null) {
                 // SOAP header
                 Element soapHeader = authProvider.getSOAPHeaders(portObject);
@@ -117,13 +132,21 @@ public class PortProvider extends Abstra
                 }
 
                 // HTTP header
-                Map<String, List<String>> httpHeaders = authProvider.getHTTPHeaders(service.getWSDLDocumentLocation()
-                        .toString());
-                if (httpHeaders != null) {
-                    ((BindingProvider) portObject).getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS,
-                            httpHeaders);
+                httpHeaders = authProvider.getHTTPHeaders(service.getWSDLDocumentLocation().toString());
+            }
+
+            if (useCompression) {
+                if (httpHeaders == null) {
+                    httpHeaders = new HashMap<String, List<String>>();
                 }
+                httpHeaders.put("Accept-Encoding", Collections.singletonList("gzip"));
+            }
+
+            if (httpHeaders != null) {
+                ((BindingProvider) portObject).getRequestContext()
+                        .put(MessageContext.HTTP_REQUEST_HEADERS, httpHeaders);
             }
+
         } catch (CmisBaseException ce) {
             throw ce;
         } catch (Exception e) {

Modified: incubator/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/incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/SessionParameter.java?rev=1061764&r1=1061763&r2=1061764&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/SessionParameter.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/SessionParameter.java Fri Jan 21 11:47:41 2011
@@ -71,6 +71,8 @@ public final class SessionParameter {
      */
     public static final String AUTH_SOAP_USERNAMETOKEN = "org.apache.chemistry.opencmis.binding.auth.soap.usernametoken";
 
+    public static final String COMPRESSION = "org.apache.chemistry.opencmis.binding.compression";
+    
     public static final String CACHE_SIZE_OBJECTS = "org.apache.chemistry.opencmis.cache.objects.size";
     public static final String CACHE_TTL_OBJECTS = "org.apache.chemistry.opencmis.cache.objects.ttl";
     public static final String CACHE_SIZE_PATHTOID = "org.apache.chemistry.opencmis.cache.pathtoid.size";

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoginDialog.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoginDialog.java?rev=1061764&r1=1061763&r2=1061764&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoginDialog.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoginDialog.java Fri Jan 21 11:47:41 2011
@@ -67,6 +67,7 @@ public class LoginDialog extends JDialog
     public static final String SYSPROP_URL = ClientSession.WORKBENCH_PREFIX + "url";
     public static final String SYSPROP_BINDING = ClientSession.WORKBENCH_PREFIX + "binding";
     public static final String SYSPROP_AUTHENTICATION = ClientSession.WORKBENCH_PREFIX + "authentication";
+    public static final String SYSPROP_COMPRESSION = ClientSession.WORKBENCH_PREFIX + "compression";
     public static final String SYSPROP_USER = ClientSession.WORKBENCH_PREFIX + "user";
     public static final String SYSPROP_PASSWORD = ClientSession.WORKBENCH_PREFIX + "password";
 
@@ -84,6 +85,8 @@ public class LoginDialog extends JDialog
     private JRadioButton authenticationNoneButton;
     private JRadioButton authenticationStandardButton;
     private JRadioButton authenticationNTLMButton;
+    private JRadioButton compressionOnButton;
+    private JRadioButton compressionOffButton;
     private JTextArea sessionParameterTextArea;
     private JButton loadRepositoryButton;
     private JButton loginButton;
@@ -128,7 +131,9 @@ public class LoginDialog extends JDialog
 
         createAuthenticationButtons(basicPanel);
 
-        makeCompactGrid(basicPanel, 5, 2, 5, 10, 5, 5);
+        createCompressionButtons(basicPanel);
+
+        makeCompactGrid(basicPanel, 6, 2, 5, 10, 5, 5);
 
         loginTabs.addTab("Basic", basicPanel);
 
@@ -322,6 +327,24 @@ public class LoginDialog extends JDialog
         pane.add(authenticationContainer);
     }
 
+    private void createCompressionButtons(Container pane) {
+        JPanel compressionContainer = new JPanel();
+        compressionContainer.setLayout(new BoxLayout(compressionContainer, BoxLayout.LINE_AXIS));
+        boolean compression = (System.getProperty(SYSPROP_BINDING, "compression").equalsIgnoreCase("on"));
+        compressionOnButton = new JRadioButton("On", compression);
+        compressionOffButton = new JRadioButton("Off", !compression);
+        ButtonGroup compressionGroup = new ButtonGroup();
+        compressionGroup.add(compressionOnButton);
+        compressionGroup.add(compressionOffButton);
+        compressionContainer.add(compressionOnButton);
+        compressionContainer.add(Box.createRigidArea(new Dimension(10, 0)));
+        compressionContainer.add(compressionOffButton);
+        JLabel compressionLabel = new JLabel("Compression:", JLabel.TRAILING);
+
+        pane.add(compressionLabel);
+        pane.add(compressionContainer);
+    }
+
     private JButton createButton(String title) {
         JButton button = new JButton(title);
         button.setPreferredSize(new Dimension(Short.MAX_VALUE, 30));
@@ -394,7 +417,8 @@ public class LoginDialog extends JDialog
             authentication = ClientSession.Authentication.NTLM;
         }
 
-        return ClientSession.createSessionParameters(url, binding, username, password, authentication);
+        return ClientSession.createSessionParameters(url, binding, username, password, authentication,
+                compressionOnButton.isSelected());
     }
 
     private Map<String, String> createExpertSessionParameters() {

Modified: incubator/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/incubator/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientSession.java?rev=1061764&r1=1061763&r2=1061764&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientSession.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientSession.java Fri Jan 21 11:47:41 2011
@@ -86,7 +86,7 @@ public class ClientSession {
     }
 
     public static Map<String, String> createSessionParameters(String url, BindingType binding, String username,
-            String password, Authentication authentication) {
+            String password, Authentication authentication, boolean compression) {
         Map<String, String> parameters = new LinkedHashMap<String, String>();
 
         if (binding == BindingType.WEBSERVICES) {
@@ -118,6 +118,10 @@ public class ClientSession {
             break;
         }
 
+        if (compression) {
+            parameters.put(SessionParameter.COMPRESSION, "true");
+        }
+
         // get additional workbench properties from system properties
         Properties sysProps = System.getProperties();
         for (String key : sysProps.stringPropertyNames()) {