svn commit: r481189 - in /jakarta/slide/trunk: WHATSNEW contributors.xml webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/HttpRequestBodyMethodBase.java

[email protected]
Newsgroups gmane.comp.jakarta.slide.devel
Message-ID <[email protected]>
Author: antoine
Date: Fri Dec  1 00:56:45 2006
New Revision: 481189

URL: http://svn.apache.org/viewvc?view=rev&rev=481189
Log:
HttpClient 3.0 support, Bugzilla 35213, contributed by Eric Van

Added:
    jakarta/slide/trunk/contributors.xml
Modified:
    jakarta/slide/trunk/WHATSNEW
    jakarta/slide/trunk/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/HttpRequestBodyMethodBase.java

Modified: jakarta/slide/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/jakarta/slide/trunk/WHATSNEW?view=diff&rev=481189&r1=481188&r2=481189
==============================================================================
--- jakarta/slide/trunk/WHATSNEW (original)
+++ jakarta/slide/trunk/WHATSNEW Fri Dec  1 00:56:45 2006
@@ -15,5 +15,8 @@
 Other changes:
 --------------
 
+* Patch allowing Slide to work with httpclient version 3.0
+  Bugzilla 35213.
+
 
 

Added: jakarta/slide/trunk/contributors.xml
URL: http://svn.apache.org/viewvc/jakarta/slide/trunk/contributors.xml?view=auto&rev=481189
==============================================================================
--- jakarta/slide/trunk/contributors.xml (added)
+++ jakarta/slide/trunk/contributors.xml Fri Dec  1 00:56:45 2006
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE contributors
+[
+<!ELEMENT name (first?, middle?, last)>
+<!ELEMENT contributors (introduction, name+)>
+<!ELEMENT first (#PCDATA)>
+<!ELEMENT introduction (#PCDATA)>
+<!ELEMENT middle (#PCDATA)>
+<!ELEMENT last (#PCDATA)>
+]
+>
+
+<contributors>
+  <introduction>
+  These are some of the many people who have helped Slide become so successful.
+  </introduction>
+  <name>
+    <first>Eric</first>
+    <last>Van</last>
+  </name>
+</contributors>
+

Modified: jakarta/slide/trunk/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/HttpRequestBodyMethodBase.java
URL: http://svn.apache.org/viewvc/jakarta/slide/trunk/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/HttpRequestBodyMethodBase.java?view=diff&rev=481189&r1=481188&r2=481189
==============================================================================
--- jakarta/slide/trunk/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/HttpRequestBodyMethodBase.java (original)
+++ jakarta/slide/trunk/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/HttpRequestBodyMethodBase.java Fri Dec  1 00:56:45 2006
@@ -29,6 +29,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.lang.reflect.Method;
 import java.net.URL;
 import org.apache.commons.httpclient.ChunkedOutputStream;
 import org.apache.commons.httpclient.HttpConnection;
@@ -48,6 +49,8 @@
 public abstract class HttpRequestBodyMethodBase extends HttpMethodBase {
 
 
+    private static Method chunkedOutputStreamFinish;
+
     // ----------------------------------------------------------- Constructors
 
 
@@ -191,7 +194,7 @@
     protected boolean writeRequestBody(HttpState state, HttpConnection conn)
         throws IOException, HttpException {
         OutputStream out = conn.getRequestOutputStream();
-        if (isHttp11() && (null == getRequestHeader("Content-Length"))) {
+        if (isHttp11() && getRequestContentLength() == -1) {
             out = new ChunkedOutputStream(out);
         }
 
@@ -215,10 +218,41 @@
             }
             out.write(buffer, 0, nb);
         }
+
+        // httpclient 3.0 support
+        if(out instanceof ChunkedOutputStream){
+          try{
+            if(chunkedOutputStreamFinish == null){
+              chunkedOutputStreamFinish = out.getClass().getMethod("finish", null);
+            }
+            chunkedOutputStreamFinish.invoke(out, null);
+          }catch(NoSuchMethodException nsme){
+            // must be httpclient 2.0.x
+          }catch(Exception e){
+            throw new HttpException(e.getClass() + ": " + e.getMessage());
+          }
+        }
         out.flush();
         return true;
     }
 
+    /**
+     * In httpclient 3.0, setting Content-Length was moved to
+     * EntityEnclosingMethod class.
+     */
+    protected void addRequestHeaders(HttpState state, HttpConnection conn)
+    throws IOException, HttpException {
+        super.addRequestHeaders(state, conn);
+        if ((getRequestHeader("content-length") == null)
+            && (getRequestHeader("Transfer-Encoding") == null)) {
+            long len = getRequestContentLength();
+            if (len >= 0) {
+                addRequestHeader("Content-Length", String.valueOf(len));
+            } else if ((len == -1) && isHttp11()) {
+                addRequestHeader("Transfer-Encoding", "chunked");
+            }
+        }
+    }
     /**
      * Override the method of {@link HttpMethodBase}
      * to return the appropriate content length.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.