commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dakota Jack <crackwil...@gmail.com>
Subject Re: FileUpload\Windows 2003 Server\Tomcat
Date Thu, 28 Oct 2004 16:10:29 GMT
I would suggest that you go into FileUploadBase and flesh out the
exceptions so that you can get more information.  Try something like
the following:


/*
    try {*/
      int boundaryIndex = contentType.indexOf("boundary=");
      if (boundaryIndex < 0) {
        throw new FileUploadException(
            "the request was rejected because "
            + "no multipart boundary was found");
      }
      byte[] boundary = contentType.substring(
          boundaryIndex + 9).getBytes();

    InputStream input = null;
    MultipartStream multi = null;
    boolean nextPart = false;

    try {
      input = req.getInputStream();
      multi = new MultipartStream(input, boundary);
      multi.setHeaderEncoding(headerEncoding);
      nextPart = multi.skipPreamble();
    } catch(IOException ioe) {
      YOURLOGGER("log.error","FileUploadBase (88) ioe.getMessage() = "
+ ioe.getMessage());
    }
      while (nextPart) {
        Map headers = null;

        try {
          headers = parseHeaders(multi.readHeaders());
        } catch (MalformedStreamException mse) {
          YOURLOGGER("log.error","FileUploadBase mse.getMessage() = "
+ mse.getMessage());
        }

        String fieldName = getFieldName(headers);
        if (fieldName != null) {
          String subContentType = getHeader(headers, CONTENT_TYPE);
          if (subContentType != null &&
subContentType.startsWith(MULTIPART_MIXED)) {
            // Multiple files.
            byte[] subBoundary =
              subContentType.substring(
                subContentType
                .indexOf("boundary=") + 9).getBytes();
            boolean nextSubPart = false;
            try {
              multi.setBoundary(subBoundary);
              nextSubPart =multi.skipPreamble();
            } catch (MalformedStreamException mse) {
              YOURLOGGER("log.error","FileUploadBase mse.getMessage()
= " + mse.getMessage());
            } catch (IllegalBoundaryException ibe) {
              YOURLOGGER("log.error","FileUploadBase ibe.getMessage()
= " + ibe.getMessage());
            } catch (IOException ioe) {
              YOURLOGGER("log.error","FileUploadBase ioe.getMessage()
= " + ioe.getMessage());
            }

            while (nextSubPart) {
              try {
                headers = parseHeaders(multi.readHeaders());
              } catch (MalformedStreamException mse) {
                YOURLOGGER("log.error","FileUploadBase
mse.getMessage() = " + mse.getMessage());
              }
              if (getFileName(headers) != null) {
                FileItem item =
                    createItem(headers, false);
                OutputStream os = null;

                try {
                  os = item.getOutputStream();
                  multi.readBodyData(os);
                } catch (IOException ioe) {
                  YOURLOGGER("log.error","FileUploadBase
ioe.getMessage() = " + ioe.getMessage());
                } finally {
                  try {
                    os.close();
                  } catch (IOException ioe) {
                    YOURLOGGER("log.error","FileUploadBase
ioe.getMessage() = " + ioe.getMessage());
                  }
                }
                items.add(item);
              } else {
                // Ignore anything but files inside
                // multipart/mixed.
                try {
                  multi.discardBodyData();
                } catch (MalformedStreamException mse) {
                  YOURLOGGER("log.error","FileUploadBase
mse.getMessage() = " + mse.getMessage());
                } catch (IOException ioe) {
                  YOURLOGGER("log.error","FileUploadBase
ioe.getMessage() = " + ioe.getMessage());
                }
              }
              try {
                nextSubPart = multi.readBoundary();
              } catch (MalformedStreamException mse) {
                YOURLOGGER("log.error","FileUploadBase
mse.getMessage() = " + mse.getMessage());
              }
            }
            try {
              multi.setBoundary(boundary);
            } catch (IllegalBoundaryException ibe) {
              YOURLOGGER("log.error","FileUploadBase ibe.getMessage()
= " + ibe.getMessage());
            }
          } else {
            if (getFileName(headers) != null) {
              // A single file.
              FileItem item = createItem(headers, false);
              OutputStream os = null;
              try {
                os = item.getOutputStream();
                multi.readBodyData(os);
              } catch (IOException ioe) {
                YOURLOGGER("log.error","FileUploadBase
ioe.getMessage() = " + ioe.getMessage());
              } finally {
                try {
                  os.close();
                } catch(IOException ioe) {
                  YOURLOGGER("log.error","FileUploadBase
ioe.getMessage() = " + ioe.getMessage());
                }
              }
              items.add(item);
            } else {
              // A form field.
              FileItem item = createItem(headers, true);
              OutputStream os = null;
              try {
                os = item.getOutputStream();
                multi.readBodyData(os);
              } catch(IOException ioe) {
                YOURLOGGER("log.error","FileUploadBase
ioe.getMessage() = " + ioe.getMessage());
              } finally {
                try {
                  os.close();
                } catch (IOException ioe) {
                  YOURLOGGER("log.error","FileUploadBase
ioe.getMessage() = " + ioe.getMessage());
                }
              }
              items.add(item);
            }
          }
        } else {
          // Skip this part.
          try {
            multi.discardBodyData();
          } catch (MalformedStreamException mse) {
            YOURLOGGER("log.error","FileUploadBase mse.getMessage() =
" + mse.getMessage());
          } catch (IOException ioe) {
            YOURLOGGER("log.error","FileUploadBase ioe.getMessage() =
" + ioe.getMessage());
          }
        }

        try {
          nextPart = multi.readBoundary();
        } catch (MalformedStreamException mse) {
          YOURLOGGER("log.error","FileUploadBase mse.getMessage() = "
+ mse.getMessage());
        }
      }
      /*
    } catch (IOException e) {
      throw new FileUploadException(
        "Processing of " + MULTIPART_FORM_DATA
          + " request failed. " + e.getMessage());
    }*/

Seem right?

Jack


On Thu, 28 Oct 2004 10:30:13 -0400, Robert Priest
<robert.priest@bentley.com> wrote:
>  Hello Dakota Jack,
> 
> I am using the latest version of fileupload
> (commons-fileupload-1.1-dev.jar), which is using the latest version of
> commons-io-1.1-dev.jar
> 
> The code for getTempFile() in the latest version of DefaultFileItem,
> looks like this:
> 
> /**
>      * Creates and returns a {@link java.io.File File} representing a
> uniquely
>      * named temporary file in the configured repository path. The
> lifetime of
>      * the file is tied to the lifetime of the <code>FileItem</code>
> instance;
>      * the file will be deleted when the instance is garbage collected.
>      *
>      * @return The {@link java.io.File File} to be used for temporary
> storage.
>      */
>     protected File getTempFile()
>     {
>         File tempDir = repository;
>         if (tempDir == null)
>         {
>             tempDir = new File(System.getProperty("java.io.tmpdir"));
>         }
> 
>         String fileName = "upload_" + getUniqueId() + ".tmp";
> 
>         File f = new File(tempDir, fileName);
>         FileCleaner.track(f, this);
>         return f;
>     }
> 
> That FileCleaner, is out of commons-io-1.1-dev.jar.
> 
> I think you may be on to something with the point about the threshold.
> Another point about this problem is that if the file is 51KB or less, it
> works fine.
> However, If I try it with a file of 52 KB or more, it fails. Any idea?
> 
> I did check the tmpdir, and it has been created.
> Indeed, the 51 KB file is uploaded correctly to the exact same
> directory.
> 
> However 52 KB, fails.
> 
> Here is how I call upload:
> 
>                           // Create a new file upload handler
>                     DiskFileUpload upload = new DiskFileUpload();
>                     // Set upload parameters
>                     upload.setSizeMax(-1); //no limit
>                     upload.setSizeThreshold(4096);
>                     upload.setRepositoryPath(importDir);
>                     upload.setHeaderEncoding("UTF-8");
>                     // Parse the request
>                     List items = null;
>                     try
>                         {
>                         items = upload.parseRequest(hsrRequest);
>                         }
>                     catch(Exception e)
>                         {
>                         mLog.log("Encountered Situation parsing file
> upload request",LogConstants.LEVEL_ERROR,e);
>                         }
> 
> And here is the stack trace I get back when it fails (when filesize > 51
> KB)
> 
> 
> 
> NDC:
> Category:       com.projectwise.web.server.lite.LiteServlet
> Message:                Encountered Situation parsing file upload
> request
> Location:
> Thrown:
> org.apache.commons.fileupload.FileUploadException: Processing of
> multipart/form-data request failed. Stream ended unexpectedly
>         at
> org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase
> .java:364)
>         at
> com.projectwise.web.server.lite.formhandler.FormHandler.arrangeRequest(F
> ormHandler.java:655)
>         at
> com.projectwise.web.server.lite.formhandler.FormHandler.processRequest(F
> ormHandler.java:3856)
>         at
> com.projectwise.web.server.lite.LiteServlet.doGet(LiteServlet.java:470)
>         at
> com.projectwise.web.server.lite.LiteServlet.doPost(LiteServlet.java:527)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>         at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
> tionFilterChain.java:247)
>         at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
> erChain.java:193)
>         at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
> e.java:260)
>         at
> org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
> nvokeNext(StandardPipeline.java:643)
>         at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
> 80)
>         at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
>         at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
> e.java:191)
>         at
> org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
> nvokeNext(StandardPipeline.java:643)
>         at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
> 80)
>         at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
>         at
> org.apache.catalina.core.StandardContext.invoke(StandardContext.java:235
> 0)
>         at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
> :180)
>         at
> org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
> nvokeNext(StandardPipeline.java:643)
>         at
> org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherVa
> lve.java:170)
>         at
> org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
> nvokeNext(StandardPipeline.java:641)
>         at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
> :171)
>         at
> org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
> nvokeNext(StandardPipeline.java:641)
>         at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
> 80)
>         at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
>         at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.
> java:174)
>         at
> org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
> nvokeNext(StandardPipeline.java:643)
>         at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
> 80)
>         at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
>         at
> org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
>         at
> org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:256)
>         at
> org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:361)
>         at
> org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:565)
>         at
> org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:
> 537)
>         at
> org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:640)
>         at
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool
> .java:533)
>         at java.lang.Thread.run(Thread.java:536)
> 
> 
> 
> 
> -----Original Message-----
> From: Dakota Jack [mailto:crackwillow@gmail.com]
> Sent: Wednesday, October 27, 2004 7:53 PM
> To: Jakarta Commons Users List
> Subject: Re: FileUpload\Windows 2003 Server\Tomcat
> 
> What is your code for his, Robert?  And, what is the stack trace of the
> error?  It looks like the problem is in OutputStream os =
> item.getOutputStream();  and this goes back to
> 
>     protected File getTempFile()
>     {
>         File tempDir = repository;
>         if (tempDir == null)
>         {
>             tempDir = new File(System.getProperty("java.io.tmpdir"));
>         }
> 
>         String fileName = "upload_" + getUniqueId() + ".tmp";
> 
>         File f = new File(tempDir, fileName);
>         f.deleteOnExit();
>         return f;
>     }
> 
> Have you checked out your temporary directory?  Or, I think there is
> something about the threshold only being used for certain things.
> 
> Jack
> 
> On Wed, 27 Oct 2004 18:01:11 -0400, Robert Priest
> <robert.priest@bentley.com> wrote:
> > Hello, I am running a version of tomcat 4.1 on Windows 2003 Server and
> 
> > I keep getting the following problem from the
> >
> > DiskFileUpload.parseRequest() call:
> >
> > Date:                   Wed Oct 27 17:23:18 EDT 2004 (1098912198367)
> > Thread:         Thread-11
> > Message #:      274
> > Level:          ERROR
> > NDC:
> > Category:       com.projectwise.web.server.lite.LiteServlet
> > Message:                Encountered Situation parsing file upload
> > request
> > Location:
> > Thrown:
> > org.apache.commons.fileupload.FileUploadException: Processing of
> > multipart/form-data request failed. Stream ended unexpectedly
> >         at
> > org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBa
> > se
> > .java:364)
> >         at
> > com.projectwise.web.server.lite.formhandler.FormHandler.arrangeRequest
> > (F
> > ormHandler.java:655)
> >         ...
> >
> > This code works fine on other machines (w2k, XP, etc). I am only
> > seeing this when I am running on a Windows 2003 Server.
> >
> > It seems to happen when on
> >
> > FileUploadBase line:349
> >
> >                finally
> >                         {
> >      line 349: -->     os.close();
> >                         }
> >
> > the original exception is a
> >
> > org.apache.commons.fileupload.MultipartStream$MalformedStreamException
> > "Stream ended unexpectedly"
> >
> > is anyone else seeing this issue?
> >
> > I am using a version of fileupload which  I compiled today from the
> > cvs repository.
> >
> > it is:  commons-fileupload-1.1-dev.jar
> >
> > Does anyone have any suggestions?
> >
> > I would appreciate the help. Thanks.
> >
> > Robert.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
> >
> 
> --
> "You can't wake a person who is pretending to be asleep."
> 
> ~Native Proverb~
> 
> "Each man is good in His sight. It is not necessary for eagles to be
> crows."
> 
> ~Hunkesni (Sitting Bull), Hunkpapa Sioux~
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> 
> 
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


-- 
"You can't wake a person who is pretending to be asleep."

~Native Proverb~

"Each man is good in His sight. It is not necessary for eagles to be crows."

~Hunkesni (Sitting Bull), Hunkpapa Sioux~

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message