You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Lionel Crine <cr...@4dconcept.fr> on 2003/05/27 11:05:09 UTC

Need to use getInputStream() from HttpRequest !!!

How can I do that.

I have a ClassCastException from Here:

HttpRequest httpRequest 
=(HttpRequest)this.objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT);

But If you have any answer to use get a ServletInputStream from
Request request = ObjectModelHelper.getRequest(objectModel);


This ServletInputStream is used to read  new bytes[request.getContentLength()];


Help me.

Thanks.


Lionel CRINE
Société : 4DConcept
22 rue Etienne de Jouy 78353 JOUY EN JOSAS
Tel : 01.34.58.70.70 Fax : 01.39.58.70.70


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


AW: Need to use getInputStream() from HttpRequest !!!

Posted by Marco Rolappe <m_...@web.de>.
as upayavira said, have a look at the StreamGenerator to see how you can do
it (use PostInputStream).

> -----Ursprüngliche Nachricht-----
> Von: cocoon-users-return-51119-m_rolappe=web.de@xml.apache.org
> [mailto:cocoon-users-return-51119-m_rolappe=web.de@xml.apache.org]Im
> Auftrag von Lionel Crine
> Gesendet: Dienstag, 27. Mai 2003 13:12
> An: cocoon-users@xml.apache.org
> Betreff: Re: Need to use getInputStream() from HttpRequest !!!
>
>
> The Stream generator only read XML data and I need exactly the same
> generator to read image files from POST
>
> I precise : I use Cocoon 2.0.4.
>
>
>
> At 10:50 27/05/2003 +0100, you wrote:
> >Lionel,
> >
> >Why do you want to do this? Can't you just use the StreamGenerator? If
> >not, then
> >look at the code for the StreamGenerator. Maybe that'll tell you
> how to do it.
> >
> >Regards, Upayavira
> >
> >On 27 May 2003 at 11:05, Lionel Crine wrote:
> >
> > > How can I do that.
> > >
> > > I have a ClassCastException from Here:
> > >
> > > HttpRequest httpRequest
> > > =(HttpRequest)this.objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT
> > > );
> > >
> > > But If you have any answer to use get a ServletInputStream from
> > > Request request = ObjectModelHelper.getRequest(objectModel);
> > >
> > >
> > > This ServletInputStream is used to read  new
> > > bytes[request.getContentLength()];
> > >
> > >
> > > Help me.
> > >
> > > Thanks.
> > >
> > >
> > > Lionel CRINE
> > > Société : 4DConcept
> > > 22 rue Etienne de Jouy 78353 JOUY EN JOSAS
> > > Tel : 01.34.58.70.70 Fax : 01.39.58.70.70
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org For
> > > additional commands, e-mail: cocoon-users-help@xml.apache.org
> > >
> > >
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> >For additional commands, e-mail: cocoon-users-help@xml.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Re: Need to use getInputStream() from HttpRequest !!!

Posted by Lionel Crine <cr...@4dconcept.fr>.
The Stream generator only read XML data and I need exactly the same 
generator to read image files from POST

I precise : I use Cocoon 2.0.4.



At 10:50 27/05/2003 +0100, you wrote:
>Lionel,
>
>Why do you want to do this? Can't you just use the StreamGenerator? If 
>not, then
>look at the code for the StreamGenerator. Maybe that'll tell you how to do it.
>
>Regards, Upayavira
>
>On 27 May 2003 at 11:05, Lionel Crine wrote:
>
> > How can I do that.
> >
> > I have a ClassCastException from Here:
> >
> > HttpRequest httpRequest
> > =(HttpRequest)this.objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT
> > );
> >
> > But If you have any answer to use get a ServletInputStream from
> > Request request = ObjectModelHelper.getRequest(objectModel);
> >
> >
> > This ServletInputStream is used to read  new
> > bytes[request.getContentLength()];
> >
> >
> > Help me.
> >
> > Thanks.
> >
> >
> > Lionel CRINE
> > Société : 4DConcept
> > 22 rue Etienne de Jouy 78353 JOUY EN JOSAS
> > Tel : 01.34.58.70.70 Fax : 01.39.58.70.70
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org For
> > additional commands, e-mail: cocoon-users-help@xml.apache.org
> >
> >
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
>For additional commands, e-mail: cocoon-users-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


[SOLUTION]Re: Need to use getInputStream() from HttpRequest !!!

Posted by Lionel Crine <cr...@4dconcept.fr>.
Ok, I find the error.

The example is not worinkg for me. The example is either false or it's only me.
I used the example on the book. "Developer's handbook".

So finally, it's working as I expected.

Lionel


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Re: Need to use getInputStream() from HttpRequest !!!

Posted by Geoff Howard <co...@leverageweb.com>.
What version are you using? (there could be more changes
necessary if you use 2.1)

     <init-param>
       <param-name>autosave-uploads</param-name>
       <param-value>false</param-value>
     </init-param>

that should be true if you want to use FilePartFile.  Both
FilePartFile and FilePartArray are subclasses of FilePart,
which exposes getInputStream() - so you can cast to FilePart
instead and use getInputStream() no matter what you have
configured.  But if you want to use File and getFile() you
need to autosave-uploads to be true.

Actually I'm surprised you got a null pointer instead of a
class cast exception.  That may mean that you are not using
the same key in request.get() as you are in your <input
type="file" name="XXX"...> Can you check that?  Send your
sitemap snippet where you call the action if you're not sure
what I mean.

Geoff

At 09:14 AM 5/27/2003, you wrote:
>I saw these examples but when I try to use fileUploadAction :
>
>I get a nullPointerException when I try to get the File. --->
>  File file = ((FilePartFile)filePart).getFile(); IS NOT WORKING.
>The filePart is Empty.
>
>Strange.
>My web.xml is :
>
>     <init-param>
>       <param-name>upload-directory</param-name>
>       <param-value>WEB-INF/work/upload-dir</param-value>
>     </init-param>
>
>
>     <!--
>       Causes all files in multipart requests to be saved to upload-dir.
>       Default is true.  Unsupported values will be interpreted as false.
>     -->
>     <init-param>
>       <param-name>autosave-uploads</param-name>
>       <param-value>false</param-value>
>     </init-param>
>
>     <!--
>       Specify handling of name conflicts when saving uploaded files
>       to disk.  Acceptable values are deny, allow, rename (default).
>       Files are renamed x_filename where x is an integer value incremented
>       to make the new filename unique.
>     -->
>     <init-param>
>       <param-name>overwrite-uploads</param-name>
>       <param-value>acceptable</param-value>
>     </init-param>
>
>that would be helpful if you find my mistake.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
>For additional commands, e-mail: cocoon-users-help@xml.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Re: Need to use getInputStream() from HttpRequest !!!

Posted by Lionel Crine <cr...@4dconcept.fr>.
I saw these examples but when I try to use fileUploadAction :

I get a nullPointerException when I try to get the File. --->
  File file = ((FilePartFile)filePart).getFile(); IS NOT WORKING.
The filePart is Empty.

Strange.
My web.xml is :

     <init-param>
       <param-name>upload-directory</param-name>
       <param-value>WEB-INF/work/upload-dir</param-value>
     </init-param>


     <!--
       Causes all files in multipart requests to be saved to upload-dir.
       Default is true.  Unsupported values will be interpreted as false.
     -->
     <init-param>
       <param-name>autosave-uploads</param-name>
       <param-value>false</param-value>
     </init-param>

     <!--
       Specify handling of name conflicts when saving uploaded files
       to disk.  Acceptable values are deny, allow, rename (default).
       Files are renamed x_filename where x is an integer value incremented
       to make the new filename unique.
     -->
     <init-param>
       <param-name>overwrite-uploads</param-name>
       <param-value>acceptable</param-value>
     </init-param>

that would be helpful if you find my mistake.


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Re: [SOLUTION]Re: Need to use getInputStream() from HttpRequest !!!

Posted by Lionel Crine <cr...@4dconcept.fr>.
Yes, it is.

The example in the book use an enumeration to get the document.
It test if the file is a filepartfile or a filepartarray.

I've decided to work with filepartArray.


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Re: [SOLUTION]Re: Need to use getInputStream() from HttpRequest !!!

Posted by Geoff Howard <co...@leverageweb.com>.
The example at the wiki assumes you are working with FilePartFile -
the example in the book probably doesn't make that assumption.

At 09:30 AM 5/27/2003, you wrote:
>Ok, I find the error.
>
>The example is not worinkg for me. The example is either false or it's 
>only me.
>I used the example on the book. "Developer's handbook".
>
>So finally, it's working as I expected.
>
>Lionel


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Re: Need to use getInputStream() from HttpRequest !!!

Posted by Geoff Howard <co...@leverageweb.com>.
Then I have good news for you - you don't need to do the file parsing -
Cocoon has already done so for you and placed an object in the request
where you can get the input stream of each file individually, or even
a File object depending on your config.  See the wiki FileUpload** pages
for more info.  Note there have been some changes between 2.0 and 2.1,
and recent changes within 2.1.  Also see the file upload example,
lamentably located under the xsp examples. (lamentable because uploads
have nothing to do with xsp).

Geoff

At 08:27 AM 5/27/2003, you wrote:
>Yes.
>
>Hre is the form :

<form name="request" action="setillus" method="POST"
enctype="multipart/form-data">
<table border="0" width="450">

<tr><td>Illustration au format (.PNG)&nbsp;:&nbsp;</td><td><input
type="file" name="illusPng"></td><tr>
<tr><td>Illustration au format (.TIFF)&nbsp;:&nbsp;</td><td><input
type="file" name="illusTif"></td><tr>
<tr><td align="center" colspan="2"><br><br><input type="submit"
value="valider">&nbsp;<input type="reset" value="annuler"></td><tr>

</table>
</form> 


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Re: Need to use getInputStream() from HttpRequest !!!

Posted by Lionel Crine <cr...@4dconcept.fr>.
Yes.

Hre is the form :

<html>
<body>
<br>
<center>
<h2>ILLUSTRATION</h2>
<br>
<form name="request" action="setillus" method="POST" 
enctype="multipart/form-data">
<table border="0" width="450">

<tr><td>Illustration au format (.PNG)&nbsp;:&nbsp;</td><td><input 
type="file" name="illusPng"></td><tr>
<tr><td>Illustration au format (.TIFF)&nbsp;:&nbsp;</td><td><input 
type="file" name="illusTif"></td><tr>
<tr><td align="center" colspan="2"><br><br><input type="submit" 
value="valider">&nbsp;<input type="reset" value="annuler"></td><tr>

</table>
</form>
<br><br>
</center>
</body></html>


At 07:36 27/05/2003 -0400, you wrote:
>Are you using multipart form with <input type="file">??
>
>Geoff
>
>At 07:11 AM 5/27/2003, you wrote:
>>The Stream generator only read XML data and I need exactly the same 
>>generator to read image files from POST
>>
>>I precise : I use Cocoon 2.0.4.
>>
>>
>>
>>At 10:50 27/05/2003 +0100, you wrote:
>>>Lionel,
>>>
>>>Why do you want to do this? Can't you just use the StreamGenerator? If 
>>>not, then
>>>look at the code for the StreamGenerator. Maybe that'll tell you how to 
>>>do it.
>>>
>>>Regards, Upayavira
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
>For additional commands, e-mail: cocoon-users-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Re: Need to use getInputStream() from HttpRequest !!!

Posted by Geoff Howard <co...@leverageweb.com>.
Are you using multipart form with <input type="file">??

Geoff

At 07:11 AM 5/27/2003, you wrote:
>The Stream generator only read XML data and I need exactly the same 
>generator to read image files from POST
>
>I precise : I use Cocoon 2.0.4.
>
>
>
>At 10:50 27/05/2003 +0100, you wrote:
>>Lionel,
>>
>>Why do you want to do this? Can't you just use the StreamGenerator? If 
>>not, then
>>look at the code for the StreamGenerator. Maybe that'll tell you how to 
>>do it.
>>
>>Regards, Upayavira


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Re: Need to use getInputStream() from HttpRequest !!!

Posted by Upayavira <uv...@upaya.co.uk>.
Lionel,

Why do you want to do this? Can't you just use the StreamGenerator? If not, then 
look at the code for the StreamGenerator. Maybe that'll tell you how to do it.

Regards, Upayavira

On 27 May 2003 at 11:05, Lionel Crine wrote:

> How can I do that.
> 
> I have a ClassCastException from Here:
> 
> HttpRequest httpRequest 
> =(HttpRequest)this.objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT
> );
> 
> But If you have any answer to use get a ServletInputStream from
> Request request = ObjectModelHelper.getRequest(objectModel);
> 
> 
> This ServletInputStream is used to read  new
> bytes[request.getContentLength()];
> 
> 
> Help me.
> 
> Thanks.
> 
> 
> Lionel CRINE
> Société : 4DConcept
> 22 rue Etienne de Jouy 78353 JOUY EN JOSAS
> Tel : 01.34.58.70.70 Fax : 01.39.58.70.70
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org For
> additional commands, e-mail: cocoon-users-help@xml.apache.org
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org