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 2016/01/07 14:36:05 UTC

svn commit: r1723539 - 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...

Author: fmui
Date: Thu Jan  7 13:36:05 2016
New Revision: 1723539

URL: http://svn.apache.org/viewvc?rev=1723539&view=rev
Log:
CMIS-965: Web Services client: added session parameters to control temp files 

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/spi/webservices/CXFPortProvider.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-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/CmisWebServicesServlet.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=1723539&r1=1723538&r2=1723539&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 Thu Jan  7 13:36:05 2016
@@ -172,6 +172,25 @@ public class SessionParameterMap extends
     }
 
     /**
+     * Sets the Web Service temp directory.
+     * 
+     * @param tempDir
+     *            path of the temp directory
+     * @param encrypt
+     *            {@code true} if temp files should be encrypted, {@code false}
+     *            otherwise
+     */
+    public void setWebServicesMemoryTempDirectory(String tempDir, boolean encrypt) {
+        if (tempDir == null) {
+            remove(SessionParameter.WEBSERVICES_TEMP_DIRECTORY);
+            remove(SessionParameter.WEBSERVICES_TEMP_ENCRYPT);
+        } else {
+            put(SessionParameter.WEBSERVICES_TEMP_DIRECTORY, tempDir);
+            put(SessionParameter.WEBSERVICES_TEMP_ENCRYPT, encrypt);
+        }
+    }
+
+    /**
      * Sets the Browser URL and sets the binding to Browser.
      * 
      * @param url

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/CXFPortProvider.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/CXFPortProvider.java?rev=1723539&r1=1723538&r2=1723539&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/CXFPortProvider.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/CXFPortProvider.java Thu Jan  7 13:36:05 2016
@@ -22,6 +22,8 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.SSLSocketFactory;
 import javax.xml.namespace.QName;
 import javax.xml.ws.Binding;
 import javax.xml.ws.BindingProvider;
@@ -29,10 +31,13 @@ import javax.xml.ws.soap.MTOMFeature;
 import javax.xml.ws.soap.SOAPBinding;
 
 import org.apache.chemistry.opencmis.client.bindings.impl.CmisBindingsHelper;
+import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
 import org.apache.chemistry.opencmis.commons.SessionParameter;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException;
 import org.apache.chemistry.opencmis.commons.spi.AuthenticationProvider;
+import org.apache.cxf.Bus;
+import org.apache.cxf.configuration.jsse.TLSClientParameters;
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.frontend.ClientProxy;
 import org.apache.cxf.headers.Header;
@@ -48,6 +53,21 @@ import org.w3c.dom.Element;
 public class CXFPortProvider extends AbstractPortProvider {
     private static final Logger LOG = LoggerFactory.getLogger(CXFPortProvider.class);
 
+    private int contentThreshold;
+    private int responseThreshold;
+
+    @Override
+    public void setSession(BindingSession session) {
+        super.setSession(session);
+
+        contentThreshold = session.get(SessionParameter.WEBSERVICES_MEMORY_THRESHOLD, 4 * 1024 * 1024);
+        responseThreshold = session.get(SessionParameter.WEBSERVICES_REPSONSE_MEMORY_THRESHOLD, -1);
+
+        if (responseThreshold > contentThreshold) {
+            contentThreshold = responseThreshold;
+        }
+    }
+
     /**
      * Creates a port object.
      */
@@ -65,6 +85,31 @@ public class CXFPortProvider extends Abs
             Binding binding = portObject.getBinding();
             ((SOAPBinding) binding).setMTOMEnabled(true);
 
+            Client client = ClientProxy.getClient(portObject);
+            HTTPConduit http = (HTTPConduit) client.getConduit();
+            HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
+            httpClientPolicy.setAllowChunking(true);
+
+            // temp files and large stream handlding
+            Bus bus = client.getBus();
+
+            Object tempDir = getSession().get(SessionParameter.WEBSERVICES_TEMP_DIRECTORY);
+            if (tempDir != null) {
+                bus.setProperty("bus.io.CachedOutputStream.OutputDirectory", tempDir.toString());
+            }
+
+            if (serviceHolder.getService().handlesContent()) {
+                bus.setProperty("bus.io.CachedOutputStream.Threshold", String.valueOf(contentThreshold));
+            } else if (responseThreshold > -1) {
+                bus.setProperty("bus.io.CachedOutputStream.Threshold", String.valueOf(responseThreshold));
+            }
+
+            bus.setProperty("bus.io.CachedOutputStream.MaxSize", "-1");
+
+            if (getSession().get(SessionParameter.WEBSERVICES_TEMP_ENCRYPT, false)) {
+                bus.setProperty("bus.io.CachedOutputStream.CipherTransformation", "AES/CTR/PKCS5Padding");
+            }
+
             // add SOAP and HTTP authentication headers
             AuthenticationProvider authProvider = CmisBindingsHelper.getAuthenticationProvider(getSession());
             Map<String, List<String>> httpHeaders = null;
@@ -82,6 +127,20 @@ public class CXFPortProvider extends Abs
                 String url = (serviceHolder.getEndpointUrl() != null ? serviceHolder.getEndpointUrl().toString()
                         : serviceHolder.getServiceObject().getWSDLDocumentLocation().toString());
                 httpHeaders = authProvider.getHTTPHeaders(url);
+
+                // SSL factory and hostname verifier
+                SSLSocketFactory sslSocketFactory = authProvider.getSSLSocketFactory();
+                HostnameVerifier hostnameVerifier = authProvider.getHostnameVerifier();
+                if (sslSocketFactory != null || hostnameVerifier != null) {
+                    TLSClientParameters tlsCP = new TLSClientParameters();
+                    if (sslSocketFactory != null) {
+                        tlsCP.setSSLSocketFactory(sslSocketFactory);
+                    }
+                    if (hostnameVerifier != null) {
+                        tlsCP.setHostnameVerifier(hostnameVerifier);
+                    }
+                    http.setTlsClientParameters(tlsCP);
+                }
             }
 
             // set HTTP headers
@@ -90,11 +149,6 @@ public class CXFPortProvider extends Abs
             // set endpoint URL
             setEndpointUrl(portObject, serviceHolder.getEndpointUrl());
 
-            Client client = ClientProxy.getClient(portObject);
-            HTTPConduit http = (HTTPConduit) client.getConduit();
-            HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
-            httpClientPolicy.setAllowChunking(true);
-
             // timeouts
             int connectTimeout = getSession().get(SessionParameter.CONNECT_TIMEOUT, -1);
             if (connectTimeout >= 0) {

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=1723539&r1=1723538&r2=1723539&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 Jan  7 13:36:05 2016
@@ -181,7 +181,7 @@ package org.apache.chemistry.opencmis.co
  * <td>no</td>
  * <td>-</td>
  * </tr>
-  * <tr>
+ * <tr>
  * <td>{@link #USER_AGENT}</td>
  * <td>User agent header</td>
  * <td>AtomPub, Web Services, Browser</td>
@@ -509,6 +509,22 @@ package org.apache.chemistry.opencmis.co
  * <td>(JAX-WS implementation default)</td>
  * </tr>
  * <tr>
+ * <td>{@link #WEBSERVICES_TEMP_DIRECTORY}</td>
+ * <td>Sets the path for temp files to an existing directory</td>
+ * <td>Web Services</td>
+ * <td>path to temp directory</td>
+ * <td>no</td>
+ * <td>(JAX-WS implementation default)</td>
+ * </tr>
+ * <tr>
+ * <td>{@link #WEBSERVICES_TEMP_ENCRYPT}</td>
+ * <td>Defines whether temp files should be encrypted or not</td>
+ * <td>Web Services</td>
+ * <td>"true", "false"</td>
+ * <td>no</td>
+ * <td>"false"</td>
+ * </tr>
+ * <tr>
  * <td colspan="6"><b>Browser Binding</b></td>
  * </tr>
  * <tr>
@@ -628,6 +644,9 @@ public final class SessionParameter {
     public static final String WEBSERVICES_MEMORY_THRESHOLD = "org.apache.chemistry.opencmis.binding.webservices.memoryThreshold";
     public static final String WEBSERVICES_REPSONSE_MEMORY_THRESHOLD = "org.apache.chemistry.opencmis.binding.webservices.responseMemoryThreshold";
 
+    public static final String WEBSERVICES_TEMP_DIRECTORY = "org.apache.chemistry.opencmis.binding.webservices.tempDirectory";
+    public static final String WEBSERVICES_TEMP_ENCRYPT = "org.apache.chemistry.opencmis.binding.webservices.tempEncrypt";
+
     public static final String WEBSERVICES_PORT_PROVIDER_CLASS = "org.apache.chemistry.opencmis.binding.webservices.portprovider.classname";
 
     public static final String WEBSERVICES_JAXWS_IMPL = "org.apache.chemistry.opencmis.binding.webservices.jaxws.impl";

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/CmisWebServicesServlet.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/CmisWebServicesServlet.java?rev=1723539&r1=1723538&r2=1723539&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/CmisWebServicesServlet.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/CmisWebServicesServlet.java Thu Jan  7 13:36:05 2016
@@ -264,8 +264,12 @@ public class CmisWebServicesServlet exte
 
         Bus bus = getBus();
         BusFactory.setDefaultBus(bus);
-        bus.setProperty("bus.io.CachedOutputStream.OutputDirectory", factory.getTempDirectory().getAbsolutePath());
-        bus.setProperty("bus.io.CachedOutputStream.Threshold", String.valueOf(factory.getMemoryThreshold()));
+        if (factory.getTempDirectory() != null) {
+            bus.setProperty("bus.io.CachedOutputStream.OutputDirectory", factory.getTempDirectory().getAbsolutePath());
+        }
+        if (factory.getMemoryThreshold() >= 0) {
+            bus.setProperty("bus.io.CachedOutputStream.Threshold", String.valueOf(factory.getMemoryThreshold()));
+        }
         bus.setProperty("bus.io.CachedOutputStream.MaxSize", "-1");
         if (factory.encryptTempFiles()) {
             bus.setProperty("bus.io.CachedOutputStream.CipherTransformation", "AES/CTR/PKCS5Padding");