Author: cmailleux
Date: Thu Aug 9 16:19:19 2007
New Revision: 406
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D406&repname=
=3Desi_server
Log:
Make big files work also with webdav client and not only with post method
Modified:
trunk/src/net/sf/j2ep/requesthandlers/EntityEnclosingRequestHandler.java
Modified: trunk/src/net/sf/j2ep/requesthandlers/EntityEnclosingRequestHandl=
er.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/trunk/src/net/sf/j2ep=
/requesthandlers/EntityEnclosingRequestHandler.java&rev=3D406&repname=3Desi=
_server
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/src/net/sf/j2ep/requesthandlers/EntityEnclosingRequestHandler.jav=
a (original)
+++ trunk/src/net/sf/j2ep/requesthandlers/EntityEnclosingRequestHandler.jav=
a Thu Aug 9 16:19:19 2007
@@ -59,50 +59,16 @@
if (ServletFileUpload.isMultipartContent(servletRequestContext=
)) {
isMultipart =3D true;
method.getParams().setSoTimeout(1000 * 60 * 5);//(1s * 60 =
=3D 1min) * 5 =3D 5 min
- ((PostMethod) method).setRequestEntity(new RequestEntity()=
{
- InputStream content =3D request.getInputStream();
- private long contentLength =3D -2;
- private String contentType =3D request.getContentType(=
);
- private DeferredFileOutputStream dfos;
-
- public boolean isRepeatable() {
- return true;
- }
-
- public void writeRequest(OutputStream out) throws IOEx=
ception {
- dfos.writeTo(out);
- final File file =3D dfos.getFile();
- if (file !=3D null && file.exists()) file.delete();
- }
-
- public long getContentLength() {
- if (contentLength =3D=3D -2) {
- try {
- dfos =3D new DeferredFileOutputStream(1024=
* 1024 * 10,
- File.=
createTempFile("temp", "upload"));
- IOUtils.copy(content, dfos);
- } catch (IOException e) {
- log.error("Error during copy of file", e);
- } finally {
- if (dfos !=3D null) try {
- dfos.close();
- contentLength =3D dfos.getByteCount();
- } catch (IOException e) {
- log.error("Error during closing of fil=
e", e);
- }
- }
- }
- return contentLength;
- }
-
- public String getContentType() {
- return contentType;
- }
- });
+ setRequestEntity((EntityEnclosingMethod) method, request);
}
}
else if (request.getMethod().equalsIgnoreCase("PUT")) {
method =3D new PutMethod(url);
+ if (request.getContentLength() > 0) {
+ isMultipart =3D true;
+ method.getParams().setSoTimeout(1000 * 60 * 5);//(1s * 60 =
=3D 1min) * 5 =3D 5 min
+ setRequestEntity((EntityEnclosingMethod) method, request);
+ }
}
else if (request.getMethod().equalsIgnoreCase("DELETE")) {
method =3D new DeleteMethod(url);
@@ -125,4 +91,46 @@
return method;
=
}
+
+ private void setRequestEntity(EntityEnclosingMethod method, final Http=
ServletRequest request) throws IOException {
+ method.setRequestEntity(new RequestEntity() {
+ InputStream content =3D request.getInputStream();
+ private long contentLength =3D -2;
+ private String contentType =3D request.getContentType();
+ private DeferredFileOutputStream dfos;
+
+ public boolean isRepeatable() {
+ return true;
+ }
+
+ public void writeRequest(OutputStream out) throws IOException {
+ dfos.writeTo(out);
+ final File file =3D dfos.getFile();
+ if (file !=3D null && file.exists()) file.delete();
+ }
+
+ public long getContentLength() {
+ if (contentLength =3D=3D -2) {
+ try {
+ dfos =3D new DeferredFileOutputStream(1024 * 1024 =
* 10, File.createTempFile("temp", "upload"));
+ IOUtils.copy(content, dfos);
+ } catch (IOException e) {
+ log.error("Error during copy of file", e);
+ } finally {
+ if (dfos !=3D null) try {
+ dfos.close();
+ contentLength =3D dfos.getByteCount();
+ } catch (IOException e) {
+ log.error("Error during closing of file", e);
+ }
+ }
+ }
+ return contentLength;
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+ });
+ }
}
_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list