You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Pere Torrodellas <pt...@fihoca.com> on 2001/04/02 16:28:48 UTC

RE: Parameters in File Upload request

Hello,

Today I was able to dig into the Turbine code, and I found out what's
wrong (I think :-)

TurbineUploadService.parseRequest() gets an OutputStream from each
FileItem created, and passes it to the MultipartStream to store the data
(see code below). The problem is that this OutputStream is never closed
after MultipartStream does its job, so the following FileItem.get()
tries to read from something still open, possibly pointing to the end of
the data, and gets nothing (not shure of the internal details).
Replacing in TurbineUploadService.parseRequest():

// A form field.
FileItem item = createItem(path, requestSize);
multi.readBodyData(item.getOutputStream());
String fieldData = new String(item.get());
params.append(getFieldName(), new String(item.get()));

...with:

// A form field.
FileItem item = createItem(path, requestSize);
OutputStream os = item.getOutputStream();
multi.readBodyData(os);
os.close();
params.append(getFieldName(), new String(item.get()));

...solved the problem and the parameter values are now available in the
ParameterParser.

What I don't understand is why the file itself was processed all right,
because the potential problem seems to be the same.

Can someone with more knowledge verify this, and correct it if I'm
right? Thanks.

Incidentally, ParameterParser.append() is supposed to get a FileItem as
the value... how comes that it works with a String and javac doesn't
complain?

Pere Torrodellas

----- Mensaje original -----
De: Pere Torrodellas <pt...@fihoca.com>
Para: <tu...@jakarta.apache.org>
Enviado: viernes 30 de marzo de 2001 19:07
Asunto: Parameters in File Upload request


> Hi,
>
> I am testing the TurbineUpload service with tdk 1.1a12 and ran into a
> problem that I've been unable to debug so far: I get the file all
right,
> but I can't get the request parameters.
>
> I know that they have been received and stored because a file is
created
> in the temp path for each one. These files are not discarded later
like
> the file containing the file sent (shouldn't they be also discarded
?),
> so I can edit them and see that the values are there.
>
> But when I request them with:
>
> for(Enumeration en = pp.keys(); en.hasMoreElements(); ) {
>    param = (String)en.nextElement();
>    o = pp.getObject(param);
>    if(o instanceof String) {
>       System.out.println(param + " = " + (String)o);
>    } else {
>       if(o instanceof FileItem) {
>          // get and save file
>           ...................
>       } else {
>           // Should not get there. Do nothing...
>       }
>    }
>
> the parameter names are printed OK, but the values are null.
>
> I've looked into TurbineUploadService and noticed the following:
>
> // A form field.
> FileItem item = createItem(path, requestSize);
> multi.readBodyData(item.getOutputStream());
> String fieldData = new String(item.get());
> params.append(getFieldName(), new String(item.get()));
>
> The contents of the FileItem is requested twice (fieldData is not used
> later, so It's not needed). Althogh It doesn't seem so by looking at
> FileItem, is it possible that the first item.get() "empties" the
> contents, so the second gets nothing?
>
> Thanks for any suggestion to solve this!
>
> Pere Torrodellas
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org


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


Re: Parameters in File Upload request

Posted by Rafal Krzewski <Ra...@e-point.pl>.
Pere Torrodellas wrote:

> Just guessing... if the OutputStream is flushed but not closed, I wonder
> if it will be possible to rename the temp file to save it, as was hinted
> here some time ago, i.e.:
> 
> myFileItem.getStoreLocation().renameTo(new File(newName));
> 
> In my experience, a renameTo() usually fails if the file is not
> completely closed...

AFAIK, there are people who use it this way, so this stream is being
closed
somehow. It's great that you found the bug and we can fix it at the very 
source now.

Rafal

--
Rafal Krzewski
Senior Internet Developer
mailto:Rafal.Krzewski@e-point.pl
+48 22 8534830 http://e-point.pl

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


RE: Parameters in File Upload request

Posted by Pere Torrodellas <pt...@fihoca.com>.
----- Mensaje original -----
De: Rafal Krzewski <Ra...@e-point.pl>
Para: <tu...@jakarta.apache.org>
Enviado: lunes 2 de abril de 2001 17:00
Asunto: Re: Parameters in File Upload request


> Right. The contents of the stream was not flushed. Really, I'd prefer
to
> fix it by adding a flush() before the end of
> MulitpartStream.readBodyData().
>
>I cannot acces the CVS @ apache.org at the moment, but will check in a
>fix to the MultipartStream ASAP.

Thanks, Rafal.

Just guessing... if the OutputStream is flushed but not closed, I wonder
if it will be possible to rename the temp file to save it, as was hinted
here some time ago, i.e.:

myFileItem.getStoreLocation().renameTo(new File(newName));

In my experience, a renameTo() usually fails if the file is not
completely closed...

Pere Torrodellas








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


Re: Parameters in File Upload request

Posted by Rafal Krzewski <Ra...@e-point.pl>.
Pere Torrodellas wrote:
> Today I was able to dig into the Turbine code, and I found out what's
> wrong (I think :-)

Great! Congratulations...

> // A form field.
> FileItem item = createItem(path, requestSize);
> OutputStream os = item.getOutputStream();
> multi.readBodyData(os);
> os.close();
> params.append(getFieldName(), new String(item.get()));
> 
> ...solved the problem and the parameter values are now available in the
> ParameterParser.

Right. The contents of the stream was not flushed. Really, I'd prefer to
fix it by adding a flush() before the end of
MulitpartStream.readBodyData().

> What I don't understand is why the file itself was processed all right,
> because the potential problem seems to be the same.

No idea. I guess we just have been being lucky... 

> Incidentally, ParameterParser.append() is supposed to get a FileItem as
> the value... how comes that it works with a String and javac doesn't
> complain?

append(String,String) comes from ValueParser superclass.

I cannot acces the CVS @ apache.org at the moment, but will check in a
fix
to the MultipartStream ASAP.

Rafal

--
Rafal Krzewski
Senior Internet Developer
mailto:Rafal.Krzewski@e-point.pl
+48 22 8534830 http://e-point.pl

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


Re: Parameters in File Upload request

Posted by Sean Legassick <se...@informage.net>.
In message <3A...@e-point.pl>, Rafal Krzewski 
<Ra...@e-point.pl> writes
>Hey, I like the javax.activation.DataSource addtion! It wasn't much
>intrusive
>on the FileItem itself, and allows easy creation of email messages
>with attachments, wich is way cool.

Yeah, it allows my server to the best thing possible with uploaded Word 
files - email them straight to someone else to deal with their viruses!

>A side note - are you sure that the sources you commited didn't contain
>tabs? They looked suspicious in my mailer in a couple of places...

Ah yes, dealt with (and I've now slapped Kawa's preferences into 
shape...)

-- 
Sean Legassick
sean@informage.net
         Je suis un homme: rien d'humain en m'est étranger

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


Re: Parameters in File Upload request

Posted by Rafal Krzewski <Ra...@e-point.pl>.
Sean Legassick wrote:

> I just had the same problem as you with getting other field contents,
> and your fix seems to do the job. Rafal - any problem you can see with
> the change I just committed?

No problem at all. Sorry for not getting to that earlier, my I had
some connectivity problmes, and then I just forgot.

Hey, I like the javax.activation.DataSource addtion! It wasn't much
intrusive
on the FileItem itself, and allows easy creation of email messages
with attachments, wich is way cool.

A side note - are you sure that the sources you commited didn't contain
tabs? They looked suspicious in my mailer in a couple of places...

Rafal

--
Rafal Krzewski
Senior Internet Developer
mailto:Rafal.Krzewski@e-point.pl
+48 22 8534830 http://e-point.pl

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


Re: Parameters in File Upload request

Posted by Sean Legassick <se...@informage.net>.
In message <00...@fihoca.int>, Pere Torrodellas 
<pt...@fihoca.com> writes
>All in all, I still think that in addition to flushing the Outpu
>tStream's in MultipartStream, they should be closed in TurbineUp
>loadService.parseRequest() when everything needed has been put there.

I just had the same problem as you with getting other field contents, 
and your fix seems to do the job. Rafal - any problem you can see with 
the change I just committed?

-- 
Sean Legassick
sean@informage.net
         Soy un hombre: nada humano me es extrano

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


RE: Parameters in File Upload request

Posted by Pere Torrodellas <pt...@fihoca.com>.
I tried to drop the last Turbine nightly build (06-Apr-2001 03:13) that
includes the fix into my TDK 1.1a12 webapp, but it didn't work because
some Turbine classes have had their packages changed (for instance
org.apache.turbine.util.assemblerbroker.java.JavaActionFactory).

Keeping a TDK up to date by using Turbine nightly builds seems a hard
path to follow :-(

So, I extracted MultipartStream from the new Turbine jar and replaced
the old version in TDK 1.1a12 with it. I expected the fix to be limited
to this class because the CVS web interface says that TurbineUpl
oadService has not been changed lately. The result is that the upload
parameters disappeared again. Should I have updated some other classes?

All in all, I still think that in addition to flushing the Outpu
tStream's in MultipartStream, they should be closed in TurbineUp
loadService.parseRequest() when everything needed has been put there.

Pere Torrodellas

----- Mensaje original -----
De: Rafal Krzewski <Ra...@e-point.pl>
Para: <tu...@jakarta.apache.org>
Enviado: jueves 5 de abril de 2001 15:53
Asunto: Re: Parameters in File Upload request


> Pere Torrodellas wrote:
>
> > TurbineUploadService.parseRequest() gets an OutputStream from each
> > FileItem created, and passes it to the MultipartStream to store the
data
> > (see code below). The problem is that this OutputStream is never
closed
> > after MultipartStream does its job, so the following FileItem.get()
> > tries to read from something still open, possibly pointing to the
end of
> > the data, and gets nothing (not shure of the internal details).
>
> I just checked in the fix into the MulitpartStream code.
> Could you please upldate your snapshot and verify if it works
correctly?
>
> Thank for help,
> Rafal
>
> --
> Rafal Krzewski
> Senior Internet Developer
> mailto:Rafal.Krzewski@e-point.pl
> +48 22 8534830 http://e-point.pl
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org


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


Re: Parameters in File Upload request

Posted by Rafal Krzewski <Ra...@e-point.pl>.
Pere Torrodellas wrote:

> TurbineUploadService.parseRequest() gets an OutputStream from each
> FileItem created, and passes it to the MultipartStream to store the data
> (see code below). The problem is that this OutputStream is never closed
> after MultipartStream does its job, so the following FileItem.get()
> tries to read from something still open, possibly pointing to the end of
> the data, and gets nothing (not shure of the internal details).

I just checked in the fix into the MulitpartStream code.
Could you please upldate your snapshot and verify if it works correctly?

Thank for help,
Rafal

--
Rafal Krzewski
Senior Internet Developer
mailto:Rafal.Krzewski@e-point.pl
+48 22 8534830 http://e-point.pl

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