chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1490206 - in /chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi: browser/ObjectServiceImpl.java http/Response.java
Date Thu, 06 Jun 2013 09:06:27 GMT
Author: fmui
Date: Thu Jun  6 09:06:27 2013
New Revision: 1490206

URL: http://svn.apache.org/r1490206
Log:
CMIS-666: detect empty response streams

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/ObjectServiceImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/Response.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/ObjectServiceImpl.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/browser/ObjectServiceImpl.java?rev=1490206&r1=1490205&r2=1490206&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/ObjectServiceImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/ObjectServiceImpl.java
Thu Jun  6 09:06:27 2013
@@ -499,7 +499,7 @@ public class ObjectServiceImpl extends A
             }
         });
 
-        if (!BigInteger.ZERO.equals(resp.getContentLength())) {
+        if (resp.hasResponseStream()) {
             Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset());
             return JSONConverter.convertFailedToDelete(json);
         }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/Response.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/Response.java?rev=1490206&r1=1490205&r2=1490206&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/Response.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/Response.java
Thu Jun  6 09:06:27 2013
@@ -18,6 +18,7 @@
  */
 package org.apache.chemistry.opencmis.client.bindings.spi.http;
 
+import java.io.BufferedInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -30,6 +31,7 @@ import java.util.zip.GZIPInputStream;
 import java.util.zip.Inflater;
 import java.util.zip.InflaterInputStream;
 
+import org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException;
 import org.apache.chemistry.opencmis.commons.impl.Base64;
 
 /**
@@ -43,12 +45,14 @@ public class Response {
     private String errorContent;
     private BigInteger length;
     private String charset;
+    private boolean hasResponseStream;
 
     public Response(int responseCode, String responseMessage, Map<String, List<String>>
headers,
             InputStream responseStream, InputStream errorStream) {
         this.responseCode = responseCode;
         this.responseMessage = responseMessage;
-        stream = responseStream;
+        this.stream = responseStream;
+        this.hasResponseStream = (stream != null);
 
         this.headers = new HashMap<String, List<String>>();
         if (headers != null) {
@@ -133,35 +137,52 @@ public class Response {
             }
         }
 
-        if (stream != null) {
-            String encoding = getContentEncoding();
-            if (encoding != null) {
-                if (encoding.toLowerCase().trim().equals("gzip")) {
-                    // if the stream is gzip encoded, decode it
-                    length = null;
-                    try {
-                        stream = new GZIPInputStream(stream, 4096);
-                    } catch (IOException e) {
-                        errorContent = e.getMessage();
-                        stream = null;
+        if (stream == null || BigInteger.ZERO.equals(length) || responseCode == 204) {
+            hasResponseStream = false;
+        } else {
+            stream = new BufferedInputStream(stream, 64 * 1024);
+            try {
+                stream.mark(2);
+                if (stream.read() == -1) {
+                    hasResponseStream = false;
+                } else {
+                    stream.reset();
+                    hasResponseStream = true;
+                }
+            } catch (IOException ioe) {
+                throw new CmisConnectionException("IO exception!", ioe);
+            }
+
+            if (hasResponseStream) {
+                String encoding = getContentEncoding();
+                if (encoding != null) {
+                    if (encoding.toLowerCase().trim().equals("gzip")) {
+                        // if the stream is gzip encoded, decode it
+                        length = null;
                         try {
-                            responseStream.close();
-                        } catch (IOException ec) {
+                            stream = new GZIPInputStream(stream, 4096);
+                        } catch (IOException e) {
+                            errorContent = e.getMessage();
+                            stream = null;
+                            try {
+                                responseStream.close();
+                            } catch (IOException ec) {
+                            }
                         }
+                    } else if (encoding.toLowerCase().trim().equals("deflate")) {
+                        // if the stream is deflate encoded, decode it
+                        length = null;
+                        stream = new InflaterInputStream(stream, new Inflater(true), 4096);
                     }
-                } else if (encoding.toLowerCase().trim().equals("deflate")) {
-                    // if the stream is deflate encoded, decode it
-                    length = null;
-                    stream = new InflaterInputStream(stream, new Inflater(true), 4096);
                 }
-            }
 
-            String transferEncoding = getContentTransferEncoding();
-            if ((stream != null) && (transferEncoding != null)
-                    && (transferEncoding.toLowerCase().trim().equals("base64")))
{
-                // if the stream is base64 encoded, decode it
-                length = null;
-                stream = new Base64.InputStream(stream);
+                String transferEncoding = getContentTransferEncoding();
+                if ((stream != null) && (transferEncoding != null)
+                        && (transferEncoding.toLowerCase().trim().equals("base64")))
{
+                    // if the stream is base64 encoded, decode it
+                    length = null;
+                    stream = new Base64.InputStream(stream);
+                }
             }
         }
     }
@@ -228,6 +249,10 @@ public class Response {
         return length;
     }
 
+    public boolean hasResponseStream() {
+        return hasResponseStream;
+    }
+
     public InputStream getStream() {
         return stream;
     }



Mime
View raw message