You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by re...@locus.apache.org on 2000/07/03 06:49:54 UTC
cvs commit: jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods PutMethod.java WebdavMethod.java WebdavMethodBase.java
remm 00/07/02 21:49:54
Modified: src/clients/webdav/src/org/apache/webdav/lib
RequestOutputStream.java WebdavClient.java
src/clients/webdav/src/org/apache/webdav/lib/methods
PutMethod.java WebdavMethod.java
WebdavMethodBase.java
Log:
- Use streaming + chunking with the PUT method.
- The WebdavClient now wraps the socket output stream using
the RequestOutputStream class.
- Recycling related bug fix.
Revision Changes Path
1.2 +27 -9 jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/RequestOutputStream.java
Index: RequestOutputStream.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/RequestOutputStream.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RequestOutputStream.java 2000/06/26 22:37:50 1.1
+++ RequestOutputStream.java 2000/07/03 04:49:49 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/RequestOutputStream.java,v 1.1 2000/06/26 22:37:50 remm Exp $
- * $Revision: 1.1 $
- * $Date: 2000/06/26 22:37:50 $
+ * $Header: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/RequestOutputStream.java,v 1.2 2000/07/03 04:49:49 remm Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/07/03 04:49:49 $
*
* ====================================================================
*
@@ -74,7 +74,7 @@
* Socket output stream wrapper.
*
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
- * @version $Revision: 1.1 $ $Date: 2000/06/26 22:37:50 $
+ * @version $Revision: 1.2 $ $Date: 2000/07/03 04:49:49 $
*/
public class RequestOutputStream
@@ -88,9 +88,8 @@
* Construct an output stream associated with the specified headers.
*
* @param stream Wrapped input stream
- * @param requestHeaders Headers used in the request
*/
- public RequestOutputStream(OutputStream stream, Hashtable requestHeaders) {
+ public RequestOutputStream(OutputStream stream) {
super();
@@ -117,18 +116,37 @@
/**
* True if chunking is allowed.
*/
- private boolean useChunking;
+ private boolean useChunking = false;
/**
* True if printing a chunk.
*/
- private boolean writingChunk;
+ private boolean writingChunk = false;
+ // ------------------------------------------------------------- Properties
+
+
+ /**
+ * Use chunking flag setter.
+ */
+ public void setUseChunking(boolean useChunking) {
+ this.useChunking = useChunking;
+ }
+
+
+ /**
+ * Use chunking flag getter.
+ */
+ public boolean isUseChunking() {
+ return useChunking;
+ }
+
+
// --------------------------------------------------------- Public Methods
-
-
+
+
/**
* Writes a <code>String</code> to the client,
* without a carriage return-line feed (CRLF)
1.6 +17 -8 jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/WebdavClient.java
Index: WebdavClient.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/WebdavClient.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- WebdavClient.java 2000/06/28 17:02:33 1.5
+++ WebdavClient.java 2000/07/03 04:49:50 1.6
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/WebdavClient.java,v 1.5 2000/06/28 17:02:33 remm Exp $
- * $Revision: 1.5 $
- * $Date: 2000/06/28 17:02:33 $
+ * $Header: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/WebdavClient.java,v 1.6 2000/07/03 04:49:50 remm Exp $
+ * $Revision: 1.6 $
+ * $Date: 2000/07/03 04:49:50 $
*
* ====================================================================
*
@@ -202,6 +202,8 @@
new ResponseInputStream(input, responseHeaders);
method.parseResponse(responseInputStream);
+ method.setUsed();
+
responseInputStream.close();
}
@@ -279,6 +281,9 @@
query = new String();
output.write(("Content-Length: "
+ query.length() + "\r\n").getBytes());
+ } else {
+ // Chunking
+ output.write(("Transfer-Encoding: chunked\r\n").getBytes());
}
if (state.getAuthenticateToken() != null) {
@@ -300,14 +305,18 @@
// Writing request body
+ RequestOutputStream requestOutputStream =
+ new RequestOutputStream(output);
+
if (method.isStreamedQuery()) {
- // TODO : Streamed query
- // Requires chunking on output
- InputStream queryStream = method.streamQuery();
-
+ requestOutputStream.setUseChunking(true);
+ method.streamQuery(requestOutputStream);
} else {
- output.write(query.getBytes());
+ requestOutputStream.write(query.getBytes());
}
+
+ // Closing wrapped output stream
+ requestOutputStream.close();
}
1.3 +62 -6 jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/PutMethod.java
Index: PutMethod.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/PutMethod.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PutMethod.java 2000/06/27 06:44:02 1.2
+++ PutMethod.java 2000/07/03 04:49:52 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/PutMethod.java,v 1.2 2000/06/27 06:44:02 remm Exp $
- * $Revision: 1.2 $
- * $Date: 2000/06/27 06:44:02 $
+ * $Header: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/PutMethod.java,v 1.3 2000/07/03 04:49:52 remm Exp $
+ * $Revision: 1.3 $
+ * $Date: 2000/07/03 04:49:52 $
*
* ====================================================================
*
@@ -108,9 +108,15 @@
* on input to work on the server side (it doesn't - Catalina doesn't
* handle that yet).
*/
- private byte[] data;
+ private byte[] data = null;
+ /**
+ * Input stream to the data.
+ */
+ private InputStream is = null;
+
+
// --------------------------------------------------------- Public Methods
@@ -120,6 +126,7 @@
public void sendData(File file)
throws IOException {
sendData(new FileInputStream(file));
+ setHeader("Content-Length", new Long(file.length()).toString());
}
@@ -144,7 +151,7 @@
*/
public void sendData(InputStream is)
throws IOException {
-
+ /*
byte[] buffer = new byte[4096];
ByteArrayOutputStream os = new ByteArrayOutputStream();
int nb = 0;
@@ -155,7 +162,8 @@
os.write(buffer, 0, nb);
}
data = os.toByteArray();
-
+ */
+ this.is = is;
}
@@ -163,6 +171,35 @@
/**
+ * Is the query body submitted through an InputStream of with a String.
+ * If an InputStream is available, it's used.
+ *
+ * @return boolean True if the content is avalable in an InputStream
+ */
+ public boolean isStreamedQuery() {
+ return (is != null);
+ }
+
+
+ /**
+ * Recycle the method object, so that it can be reused again. Any attempt
+ * to reuse an object without recycling it will throw a WebdavException.
+ */
+ public void recycle() {
+ super.recycle();
+ data = null;
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ is = null;
+ }
+
+
+ /**
* Generate the query body.
*
* @return String query
@@ -172,6 +209,25 @@
return "";
else
return new String(data);
+ }
+
+
+ /**
+ * Stream the body of the query. This function should be used to send large
+ * request bodies.
+ */
+ public void streamQuery(OutputStream out)
+ throws IOException {
+
+ byte[] buffer = new byte[4096];
+ int nb = 0;
+ while (true) {
+ nb = is.read(buffer);
+ if (nb == -1)
+ break;
+ out.write(buffer, 0, nb);
+ }
+
}
1.5 +11 -6 jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/WebdavMethod.java
Index: WebdavMethod.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/WebdavMethod.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- WebdavMethod.java 2000/06/28 17:02:41 1.4
+++ WebdavMethod.java 2000/07/03 04:49:52 1.5
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/WebdavMethod.java,v 1.4 2000/06/28 17:02:41 remm Exp $
- * $Revision: 1.4 $
- * $Date: 2000/06/28 17:02:41 $
+ * $Header: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/WebdavMethod.java,v 1.5 2000/07/03 04:49:52 remm Exp $
+ * $Revision: 1.5 $
+ * $Date: 2000/07/03 04:49:52 $
*
* ====================================================================
*
@@ -103,6 +103,12 @@
/**
+ * Set the method as used.
+ */
+ public void setUsed();
+
+
+ /**
* Status code property setter.
*
* @param int Status code
@@ -240,10 +246,9 @@
/**
* Stream the body of the query. This function should be used to send large
* request bodies.
- *
- * @return InputStream Body of the query
*/
- public InputStream streamQuery();
+ public void streamQuery(OutputStream out)
+ throws IOException ;
/**
1.5 +14 -8 jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/WebdavMethodBase.java
Index: WebdavMethodBase.java
===================================================================
RCS file: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/WebdavMethodBase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- WebdavMethodBase.java 2000/06/28 17:02:43 1.4
+++ WebdavMethodBase.java 2000/07/03 04:49:52 1.5
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/WebdavMethodBase.java,v 1.4 2000/06/28 17:02:43 remm Exp $
- * $Revision: 1.4 $
- * $Date: 2000/06/28 17:02:43 $
+ * $Header: /home/cvs/jakarta-slide/src/clients/webdav/src/org/apache/webdav/lib/methods/WebdavMethodBase.java,v 1.5 2000/07/03 04:49:52 remm Exp $
+ * $Revision: 1.5 $
+ * $Date: 2000/07/03 04:49:52 $
*
* ====================================================================
*
@@ -267,6 +267,14 @@
/**
+ * Set the method as used.
+ */
+ public void setUsed() {
+ used = true;
+ }
+
+
+ /**
* Ensures the correctness of the request according to criterions which are
* method dependent.
*
@@ -340,11 +348,10 @@
/**
* Stream the body of the query. This function should be used to send large
* request bodies.
- *
- * @return InputStream Body of the query
*/
- public InputStream streamQuery() {
- return null;
+ public void streamQuery(OutputStream out)
+ throws IOException {
+
}
@@ -388,7 +395,6 @@
*/
public final String generateRequestLine() {
- used = true;
return (name + " " + path + " " + PROTOCOL + "\r\n");
}