[Lift] Re: Catch file upload exceptions?
Have you tried using in boot LiftRules.exceptionHandler.prepend (...) ? Br's, Marius On Dec 21, 11:43 pm, tiro wrote: > Hi, > > just wondering if anybody knows of a handy way to properly handle the > exceptions that are thrown when a user uploads a file that exceeds the > size limit (or who knows what else can happen)? > > The stack trace that I see in such a case is as follows -- and apart > from trying S.addAround I don't see a any place where one could insert > some exception handling: > > Message: org.apache.commons.fileupload.FileUploadBase > $SizeLimitExceededException: the request was rejected because its size > (7385713) exceeds the configured maximum (6291456) > org.apache.commons.fileupload.FileUploadBase > $FileItemIteratorImpl.(FileUploadBase.java:914) > org.apache.commons.fileupload.FileUploadBase.getItemIterator > (FileUploadBase.java:331) > > org.apache.commons.fileupload.servlet.ServletFileUpload.getItemIterator > (ServletFileUpload.java:148) > net.liftweb.http.provider.servlet.HTTPRequestServlet$$anon$1. > (HTTPRequestServlet.scala:110) > net.liftweb.http.provider.servlet.HTTPRequestServlet.extractFiles > (HTTPRequestServlet.scala:100) > net.liftweb.http.Req$$anonfun$5.apply(Req.scala:182) > net.liftweb.http.Req$$anonfun$5.apply(Req.scala:156) > net.liftweb.http.Req.x$17(Req.scala:351) > net.liftweb.http.Req.uploadedFiles(Req.scala:350) > net.liftweb.http.LiftSession.runParams(LiftSession.scala:306) > net.liftweb.http.LiftSession.processRequest(LiftSession.scala:492) > net.liftweb.http.LiftServlet.net$liftweb$http$LiftServlet$ > $dispatchStatefulRequest(LiftServlet.scala:261) > net.liftweb.http.LiftServlet$$anonfun$3.apply(LiftServlet.scala:171) > net.liftweb.http.LiftServlet$$anonfun$3.apply(LiftServlet.scala:171) > net.liftweb.http.S$.net$liftweb$http$S$$wrapQuery(S.scala:974) > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_nest2InnerInit$1$ > $anonfun$apply$25.apply(S.scala:1114) > net.liftweb.http.S$.net$liftweb$http$S$$doAround(S.scala:911) > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_nest2InnerInit > $1.apply(S.scala:1112) > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > net.liftweb.http.S$.net$liftweb$http$S$$_nest2InnerInit(S.scala:) > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_innerInit$1$$anonfun > $apply$28$$anonfun$apply$29$$anonfun$apply$30$$anonfun$apply$31.apply > (S.scala:1133) > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_innerInit$1$$anonfun > $apply$28$$anonfun$apply$29$$anonfun$apply$30.apply(S.scala:1132) > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_innerInit$1$$anonfun > $apply$28$$anonfun$apply$29.apply(S.scala:1131) > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_innerInit$1$$anonfun > $apply$28.apply(S.scala:1130) > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_innerInit$1.apply > (S.scala:1129) > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > net.liftweb.http.S$.net$liftweb$http$S$$_innerInit(S.scala:1128) > net.liftweb.http.S$$anonfun$_init$1$$anonfun$apply$38$$anonfun$apply > $39$$anonfun$apply$40$$anonfun$apply$41$$anonfun$apply$42.apply > (S.scala:1175) > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > net.liftweb.http.S$$anonfun$_init$1$$anonfun$apply$38$$anonfun$apply > $39$$anonfun$apply$40$$anonfun$apply$41.apply(S.scala:1174) > net.liftweb.http.CoreRequestVarHandler$class.apply(Vars.scala:325) > net.liftweb.http.RequestVarHandler$.apply(Vars.scala:248) > net.liftweb.http.S$$anonfun$_init$1$$anonfun$apply$38$$anonfun$apply > $39$$anonfun$apply$40.apply(S.scala:1173) > net.liftweb.http.CoreRequestVarHandler$class.apply(Vars.scala:325) > net.liftweb.http.TransientRequestVarHandler$.apply(Vars.scala:252) > net.liftweb.http.S$$anonfun$_init$1$$anonfun$apply$38$$anonfun$apply > $39.apply(S.scala:1172) > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > net.liftweb.http.S$$anonfun$_init$1$$anonfun$apply$38.apply(S.scala: > 1171) > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > net.liftweb.http.S$$anonfun$_init$1.apply(S.scala:1170) > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > net.liftweb.http.S$._init(S.scala:1169) > net.liftweb.http.S$.init(S.scala:825) > net.liftweb.http.LiftServlet.doService(LiftServlet.scala:170) > net.liftweb.http.LiftServlet$$anonfun$doIt$1$1.apply > (LiftServlet.scala:72) > net.liftw
[Lift] Re: Catch file upload exceptions?
I'm not sure that is what the OP is after - it would work, but that's not what he is asking IMHO I'll take a look tomorrow and see what could be done cheers, Tim On Dec 21, 9:52 pm, Marius wrote: > Have you tried using in boot LiftRules.exceptionHandler.prepend > (...) ? > > Br's, > Marius > > On Dec 21, 11:43 pm, tiro wrote: > > > > > Hi, > > > just wondering if anybody knows of a handy way to properly handle the > > exceptions that are thrown when a user uploads a file that exceeds the > > size limit (or who knows what else can happen)? > > > The stack trace that I see in such a case is as follows -- and apart > > from trying S.addAround I don't see a any place where one could insert > > some exception handling: > > > Message: org.apache.commons.fileupload.FileUploadBase > > $SizeLimitExceededException: the request was rejected because its size > >(7385713) exceeds the configured maximum(6291456) > > org.apache.commons.fileupload.FileUploadBase > > $FileItemIteratorImpl.(FileUploadBase.java:914) > > org.apache.commons.fileupload.FileUploadBase.getItemIterator > > (FileUploadBase.java:331) > > > org.apache.commons.fileupload.servlet.ServletFileUpload.getItemIterator > > (ServletFileUpload.java:148) > > net.liftweb.http.provider.servlet.HTTPRequestServlet$$anon$1. > > (HTTPRequestServlet.scala:110) > > net.liftweb.http.provider.servlet.HTTPRequestServlet.extractFiles > > (HTTPRequestServlet.scala:100) > > net.liftweb.http.Req$$anonfun$5.apply(Req.scala:182) > > net.liftweb.http.Req$$anonfun$5.apply(Req.scala:156) > > net.liftweb.http.Req.x$17(Req.scala:351) > > net.liftweb.http.Req.uploadedFiles(Req.scala:350) > > net.liftweb.http.LiftSession.runParams(LiftSession.scala:306) > > net.liftweb.http.LiftSession.processRequest(LiftSession.scala:492) > > net.liftweb.http.LiftServlet.net$liftweb$http$LiftServlet$ > > $dispatchStatefulRequest(LiftServlet.scala:261) > > net.liftweb.http.LiftServlet$$anonfun$3.apply(LiftServlet.scala:171) > > net.liftweb.http.LiftServlet$$anonfun$3.apply(LiftServlet.scala:171) > > net.liftweb.http.S$.net$liftweb$http$S$$wrapQuery(S.scala:974) > > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_nest2InnerInit$1$ > > $anonfun$apply$25.apply(S.scala:1114) > > net.liftweb.http.S$.net$liftweb$http$S$$doAround(S.scala:911) > > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_nest2InnerInit > > $1.apply(S.scala:1112) > > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > > > > net.liftweb.http.S$.net$liftweb$http$S$$_nest2InnerInit(S.scala:) > > > > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_innerInit$1$$anonfun > > $apply$28$$anonfun$apply$29$$anonfun$apply$30$$anonfun$apply$31.apply > > (S.scala:1133) > > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > > > > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_innerInit$1$$anonfun > > $apply$28$$anonfun$apply$29$$anonfun$apply$30.apply(S.scala:1132) > > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > > > > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_innerInit$1$$anonfun > > $apply$28$$anonfun$apply$29.apply(S.scala:1131) > > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > > > > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_innerInit$1$$anonfun > > $apply$28.apply(S.scala:1130) > > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_innerInit$1.apply > > (S.scala:1129) > > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > > net.liftweb.http.S$.net$liftweb$http$S$$_innerInit(S.scala:1128) > > net.liftweb.http.S$$anonfun$_init$1$$anonfun$apply$38$$anonfun$apply > > $39$$anonfun$apply$40$$anonfun$apply$41$$anonfun$apply$42.apply > > (S.scala:1175) > > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > > net.liftweb.http.S$$anonfun$_init$1$$anonfun$apply$38$$anonfun$apply > > $39$$anonfun$apply$40$$anonfun$apply$41.apply(S.scala:1174) > > net.liftweb.http.CoreRequestVarHandler$class.apply(Vars.scala:325) > > net.liftweb.http.RequestVarHandler$.apply(Vars.scala:248) > > net.liftweb.http.S$$anonfun$_init$1$$anonfun$apply$38$$anonfun$apply > > $39$$anonfun$apply$40.apply(S.scala:1173) > > net.liftweb.http.CoreRequestVarHandler$class.apply(Vars.scala:325) > > net.liftweb.http.TransientRequestVarHandler$.apply(Vars.scala:252) > > net.liftweb.http.S$$anonfun$_init$1$$anonfun$apply$38$$anonfun$apply > > $39.apply(S.scala:1172) > > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > > net.liftweb.http.S$$anonfun$_init$1$$anonfun$apply$38.apply(S.scala: > > 1171) > > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > > net.liftweb.ht
[Lift] Re: Catch file upload exceptions?
Well LiftRules.exceptionHandler was new to me so thanks. Great way to deal with the really unexpected (like OutOfMemory). Would do in the short run. However, the other Tim is correct in that I (and probably other people) really want to handle this like similarly to a validation error on any other field. LiftRules.exceptionHandler catches so far outside, as far as I understand, that the only way to get back into the workflow would be to kindly ask the user to press the Back button. -- You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
[Lift] Re: Catch file upload exceptions?
Yes, your pretty much right. Can you post your code thus far? (or a cut down version). If you box the upload holder you should be ok (I think) private object theUpload extends RequestVar[Box[FileParamHolder]] (Empty) SHtml.fileUpload(ul => theUpload(tryo(ul))) That is, if your upload fails, tryo will stuff it into a Failure instance. Thoughts? Cheers, Tim On Dec 22, 8:28 am, tiro wrote: > Well LiftRules.exceptionHandler was new to me so thanks. Great way to > deal with the really unexpected (like OutOfMemory). Would do in the > short run. > However, the other Tim is correct in that I (and probably other > people) really want to handle this like similarly to a validation > error on any other field. LiftRules.exceptionHandler catches so far > outside, as far as I understand, that the only way to get back into > the workflow would be to kindly ask the user to press the Back button. -- You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
[Lift] Re: Catch file upload exceptions?
Catching OutOfMemory won't do you much good. You're already in an inconsistent state and at that point your app should be restarted. Yes LiftRules.exceptionHandler won't get you back in your upload work flow. It is a mean for graceful degradation when unrecoverable errors occur. Thus you can redirect to error pages, returning Ajax responses in case the exception was thrown from an Ajax function etc. Br's, Marius On Dec 22, 10:28 am, tiro wrote: > Well LiftRules.exceptionHandler was new to me so thanks. Great way to > deal with the really unexpected (like OutOfMemory). Would do in the > short run. > However, the other Tim is correct in that I (and probably other > people) really want to handle this like similarly to a validation > error on any other field. LiftRules.exceptionHandler catches so far > outside, as far as I understand, that the only way to get back into > the workflow would be to kindly ask the user to press the Back button. -- You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
[Lift] Re: Catch file upload exceptions?
Hi Tim, thanks for raising this, I did wrap the whole thing like so: LiftRules.maxMimeSize = 6 * 1024 * 1024 LiftRules.maxMimeFileSize = 5 * 1024 * 1024 LiftRules.handleMimeFile = (fieldName, contentType, fileName, inputStream) => { try { OnDiskFileParamHolder(fieldName, contentType, fileName, inputStream) } catch { case e:Exception => S.error("Failure in upload (file too large?). Details: " + e.toString) new InMemFileParamHolder("", "", "", null) case _ => new InMemFileParamHolder("", "", "", null) } } and now I remember that I did manage to catch an exception once when I set the maxMimeFileSize to very low. Then I set it back to where it was and tested with a 7MB file. I think I understand now: The above will catch based on maxMimeFileSize. It will not work when the file you upload also exceeds the maxMimeSize, which is when you get the stack trace at the beginning of my post. So I suppose the solution is to set the maxMimeSize to "Infinity". Marius, thanks for the hint. Was just a quick idea how to keep face with users in such a case, since I'm running on a virtual server, but it's clear such conditions should really be avoided by proper configuration and load testing. Best wishes, Tim -- You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to lift...@googlegroups.com. To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.
Re: [Lift] Re: Catch file upload exceptions?
It's good way to handle exception. And I think it's better that it could pop dialog to tell users what's wrong. http://www.mail-archive.com/liftweb@googlegroups.com/msg03001.html http://wiki.liftweb.net/index.php/HowTo_use_error_pages On Tue, Dec 22, 2009 at 5:52 AM, Marius wrote: > Have you tried using in boot LiftRules.exceptionHandler.prepend > (...) ? > > Br's, > Marius > > On Dec 21, 11:43 pm, tiro wrote: > > Hi, > > > > just wondering if anybody knows of a handy way to properly handle the > > exceptions that are thrown when a user uploads a file that exceeds the > > size limit (or who knows what else can happen)? > > > > The stack trace that I see in such a case is as follows -- and apart > > from trying S.addAround I don't see a any place where one could insert > > some exception handling: > > > > Message: org.apache.commons.fileupload.FileUploadBase > > $SizeLimitExceededException: the request was rejected because its size > > (7385713) exceeds the configured maximum (6291456) > > org.apache.commons.fileupload.FileUploadBase > > $FileItemIteratorImpl.(FileUploadBase.java:914) > > org.apache.commons.fileupload.FileUploadBase.getItemIterator > > (FileUploadBase.java:331) > > > > org.apache.commons.fileupload.servlet.ServletFileUpload.getItemIterator > > (ServletFileUpload.java:148) > > > net.liftweb.http.provider.servlet.HTTPRequestServlet$$anon$1. > > (HTTPRequestServlet.scala:110) > > net.liftweb.http.provider.servlet.HTTPRequestServlet.extractFiles > > (HTTPRequestServlet.scala:100) > > net.liftweb.http.Req$$anonfun$5.apply(Req.scala:182) > > net.liftweb.http.Req$$anonfun$5.apply(Req.scala:156) > > net.liftweb.http.Req.x$17(Req.scala:351) > > net.liftweb.http.Req.uploadedFiles(Req.scala:350) > > net.liftweb.http.LiftSession.runParams(LiftSession.scala:306) > > > net.liftweb.http.LiftSession.processRequest(LiftSession.scala:492) > > net.liftweb.http.LiftServlet.net$liftweb$http$LiftServlet$ > > $dispatchStatefulRequest(LiftServlet.scala:261) > > > net.liftweb.http.LiftServlet$$anonfun$3.apply(LiftServlet.scala:171) > > > net.liftweb.http.LiftServlet$$anonfun$3.apply(LiftServlet.scala:171) > > net.liftweb.http.S$.net$liftweb$http$S$$wrapQuery(S.scala:974) > > > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_nest2InnerInit$1$ > > $anonfun$apply$25.apply(S.scala:1114) > > net.liftweb.http.S$.net$liftweb$http$S$$doAround(S.scala:911) > > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_nest2InnerInit > > $1.apply(S.scala:1112) > > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > > > net.liftweb.http.S$.net$liftweb$http$S$$_nest2InnerInit(S.scala:) > > > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_innerInit$1$$anonfun > > $apply$28$$anonfun$apply$29$$anonfun$apply$30$$anonfun$apply$31.apply > > (S.scala:1133) > > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > > > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_innerInit$1$$anonfun > > $apply$28$$anonfun$apply$29$$anonfun$apply$30.apply(S.scala:1132) > > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > > > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_innerInit$1$$anonfun > > $apply$28$$anonfun$apply$29.apply(S.scala:1131) > > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > > > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_innerInit$1$$anonfun > > $apply$28.apply(S.scala:1130) > > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > > > net.liftweb.http.S$$anonfun$net$liftweb$http$S$$_innerInit$1.apply > > (S.scala:1129) > > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > > net.liftweb.http.S$.net$liftweb$http$S$$_innerInit(S.scala:1128) > > > net.liftweb.http.S$$anonfun$_init$1$$anonfun$apply$38$$anonfun$apply > > $39$$anonfun$apply$40$$anonfun$apply$41$$anonfun$apply$42.apply > > (S.scala:1175) > > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > > > net.liftweb.http.S$$anonfun$_init$1$$anonfun$apply$38$$anonfun$apply > > $39$$anonfun$apply$40$$anonfun$apply$41.apply(S.scala:1174) > > > net.liftweb.http.CoreRequestVarHandler$class.apply(Vars.scala:325) > > net.liftweb.http.RequestVarHandler$.apply(Vars.scala:248) > > > net.liftweb.http.S$$anonfun$_init$1$$anonfun$apply$38$$anonfun$apply > > $39$$anonfun$apply$40.apply(S.scala:1173) > > > net.liftweb.http.CoreRequestVarHandler$class.apply(Vars.scala:325) > > > net.liftweb.http.TransientRequestVarHandler$.apply(Vars.scala:252) > > > net.liftweb.http.S$$anonfun$_init$1$$anonfun$apply$38$$anonfun$apply > > $39.apply(S.scala:1172) > > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > > > net.liftweb.http.S$$anonfun$_init$1$$anonfun$apply$38.apply(S.scala: > > 1171) > > net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:67) > > net.liftweb.http.S$$anonfun$_init$1.apply(S.scala:1170) > >