Gregory,
I experiment your XSP file (in Cocoon 2.1.8) that handles file uploads from
client using the cocoon file upload support, and I remark that we can't detect
in the code if the size file is greater than the maximum size authorised. But
there is a way, by using a <map:handle-errors> construct in the pipeline :
<map:pipeline>
<map:match pattern="FileUpload">
<map:generate type="serverpages" src="fileupload.xsp"/>
<map:transform src="fileupload.xsl"/>
<map:serialize/>
</map:match>
<map:handle-errors>
<!-- problably a too large file -->
...
</map:handle-errors>
</map:pipeline>
Does anyone see another way ?
-----Message d'origine-----
De : Rob Gregory [mailto:[EMAIL PROTECTED]
Envoyé : mercredi 18 janvier 2006 22:57
À : [email protected]; [EMAIL PROTECTED]
Objet : RE: Content length exceeds maximum upload size.
Are you uploading to an XSP or action or what?
I have a couple of XSP examples that might shed some light for you and I have
pasted these here.
Hope this helps mate.
Rob.
FIRST EXAMPLE
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
@application File Upload - handles file uploads from client using
the commons file upload support
The html form requires an enctype="multipart/form-data"
and a
method="post" for it to contain <input name="myFile"
type="file"/>
elements.
@author Rob Gregory
@version 05.00.00/037
-->
<!-- Define the namespaces for any logic sheets we will be using --> <xsp:page
language="java"
xmlns:xsp="http://apache.org/xsp"
xmlns:xsp-request="http://apache.org/xsp/request/2.0"
xmlns:esql="http://apache.org/cocoon/SQL/v2"
xmlns:session="http://apache.org/xsp/session/2.0" create-session="false"
>
<xsp:structure>
<xsp:include>javax.servlet.http.*</xsp:include>
<xsp:include>java.io.File</xsp:include>
<xsp:include>org.apache.commons.fileupload.*</xsp:include>
<xsp:include>org.apache.cocoon.environment.http.HttpRequest</xsp:include>
<xsp:include>org.apache.cocoon.environment.ObjectModelHelper</xsp:include>
<xsp:include>org.apache.cocoon.environment.http.HttpEnvironment</xsp:include
>
<xsp:include>org.apache.commons.logging.Log</xsp:include>
<xsp:include>org.apache.commons.logging.LogFactory</xsp:include>
</xsp:structure>
<xsp:logic>
// Create a log attribute to allow access to log files
private static Log log = LogFactory.getLog("upload_commons_xsp");
</xsp:logic>
<page>
<content>
<xsp:logic>
// get the httpservletrequest from Cocoon
HttpServletRequest objRequest =
(HttpServletRequest)objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT);
// define some constants
long lMaxSize = 10000000; // (10 Mb)
int iSizeThreshold = 4096; // bytes to hold in memory before writing to
temp location
String strPath = "C:/tmp"; // temp location
// create the uploader
DiskFileUpload objFileUploads = new DiskFileUpload();
// maximum size that will be stored in memory
objFileUploads.setSizeThreshold(iSizeThreshold);
// the temp location for saving data that is larger than
getSizeThreshold()
objFileUploads.setRepositoryPath(strPath);
try {
List fileItems = objFileUploads.parseRequest(objRequest,
iSizeThreshold, lMaxSize, strPath);
System.out.println("Number of Files : " + fileItems.size());
Iterator it = fileItems.iterator();
for (int i = 0; i < fileItems.size(); i++) {
FileItem fi = (FileItem) it.next();
// write the file to the disk
System.out.println("File " + fi.getName() + " field " +
fi.getFieldName() + " size " + fi.getSize());
File file = new File(strPath + "/" + i + ".test");
file.createNewFile();
// write the incomming file (fi) to the disk file created above
fi.write(file);
}
} catch (FileUploadException fue) {
fue.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
</xsp:logic>
<file_upload>Rob Test</file_upload>
</content>
</page>
</xsp:page>
SECOND EXAMPLE
Another approach is this:-
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
@application File Upload - handles file uploads from client using
the cocoon file upload support
The html form requires an enctype="multipart/form-data"
and a
method="post" for it to contain <input name="myFile"
type="file"/>
elements.
@author Rob Gregory
@version 05.00.00/037
-->
<!-- Define the namespaces for any logic sheets we will be using --> <xsp:page
language="java"
xmlns:xsp="http://apache.org/xsp"
xmlns:xsp-request="http://apache.org/xsp/request/2.0"
xmlns:esql="http://apache.org/cocoon/SQL/v2"
xmlns:session="http://apache.org/xsp/session/2.0" create-session="false"
>
<xsp:structure>
<xsp:include>org.apache.cocoon.components.language.markup.xsp.XSPUtil</xsp:i
nclude>
<xsp:include>org.apache.avalon.framework.context.ContextException</xsp:inclu
de>
<xsp:include>org.apache.cocoon.servlet.multipart.PartOnDisk</xsp:include>
<xsp:include>org.apache.commons.logging.Log</xsp:include>
<xsp:include>org.apache.commons.logging.LogFactory</xsp:include>
</xsp:structure>
<xsp:logic>
// Create a log attribute to allow access to log files
private static Log log = LogFactory.getLog("upload_cocoon_xsp");
</xsp:logic>
<xsp:logic>
<!-- determine the temp upload location from the web.xml -->
File uploadDir = null;
public void contextualize(Context context) throws ContextException {
uploadDir = (File) context.get(Constants.CONTEXT_UPLOAD_DIR);
}
</xsp:logic>
<page>
<content>
<xsp:logic>
PartOnDisk filePart = null;
<!-- try to obtain the file todo enumerate all files -->
if (request.getParameter("uploaded_file1") != null) {
filePart = (PartOnDisk) request.get("uploaded_file1");
} else if (request.getContentType()!=null &&
request.getContentType().indexOf("multipart/form-data") != -1) {
log.debug("Either uploads are turned off, or you submitted a blank
form");
}
<!-- list the files within the upload-dir -->
log.debug("Dir=" + uploadDir);
String[] filelist = uploadDir.list();
log.debug("List=" + filelist.length);
for (int i = 0; i < filelist.length; i++) {
log.debug("File [" + i + "]=" + filelist[i]);
}
<!-- Process the file here as upload directory is emptied following
request -->
System.out.println("FileName " + filePart.getFileName());
<!--System.out.println("File " + filePart.getFile()); also see
getInputStream() -->
System.out.println("Size " + filePart.getSize());
</xsp:logic>
<title>Cocoon Upload Test</title>
<filesize><xsp:expr>filePart.getSize()</xsp:expr></filesize>
<filename><xsp:expr>filePart.getFileName()</xsp:expr></filename>
</content>
</page>
</xsp:page>
-----Original Message-----
From: Maik Zygan [mailto:[EMAIL PROTECTED]
Sent: 18 January 2006 13:48
To: [email protected]
Subject: Content length exceeds maximum upload size.
Hi,
Everytime I try to upload a file that's larger then the configured upload size
I get the following exception.
<map:handle-errors> Does'nt work, the problem looks like this exception is
handled by the servlet itself.
Does enyone know how I get Cocoon not to display this exception?
I'm using Apache 2.1.7
Problem in creating the Request
Message: Content length exceeds maximum upload size.
Description: java.io.IOException: Content length exceeds maximum upload size.
Sender: org.apache.cocoon.servlet.CocoonServlet
Source: Cocoon Servlet
cause
java.io.IOException: Content length exceeds maximum upload size.
request-uri
/platform/ebp/pk/ebp-portlets
full exception chain stacktrace
java.io.IOException: Content length exceeds maximum upload size.
at
org.apache.cocoon.servlet.multipart.RequestFactory.getServletRequest(Request
Factory.java:78)
at
org.apache.cocoon.servlet.CocoonServlet.service(CocoonServlet.java:1029)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(Servle
tStubImpl.java:1006)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:419)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:315)
at
weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(W
ebAppServletContext.java:6718)
at
weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubjec
t.java:321)
at
weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at
weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletCo
ntext.java:3764)
at
weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java
:2644)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
stacktrace
java.io.IOException: Content length exceeds maximum upload size.
at
org.apache.cocoon.servlet.multipart.RequestFactory.getServletRequest(Request
Factory.java:78)
at
org.apache.cocoon.servlet.CocoonServlet.service(CocoonServlet.java:1029)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(Servle
tStubImpl.java:1006)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:419)
at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:315)
at
weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(W
ebAppServletContext.java:6718)
at
weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubjec
t.java:321)
at
weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at
weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletCo
ntext.java:3764)
at
weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java
:2644)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
Apache Cocoon 2.1.7
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]