You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Euphreme Rinfrett <eu...@yahoo.ca> on 2008/03/11 21:52:53 UTC

"stream" result type

Hi all,

    I'm trying to use to "stream" result type to get some images to 
display within a portal.

Based on the wiki page: http://struts.apache.org/2.x/docs/stream-result.html

I did my own action that gets an image and puts it into a model.

This is the struts configuration:

        <action name="displayExerciceImageAction" 
class="displayExerciceAction">
            <result name="success" type="stream">
              <param name="contentType">${model.imageContentType}</param>
              <param name="inputName">${model.image}</param>
              <param 
name="contentDisposition">filename="${model.name}_img"</param>
              <param name="bufferSize">${model.image.length}</param>
            </result>
        </action>

image being an array of bytes.

While getting called, I'm getting the following error:
NoSuchMethodException: setBufferSize(java.lang.String)

My first though was that the image was null, but it's not the case, the 
size should be 12345.

Any clue ?

Thanks,
- Pascal


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


Re: [Bulk] Re: [struts] "stream" result type

Posted by Euphreme Rinfrett <eu...@yahoo.ca>.
Excellent, this is great and made everything work.

Thank you very much for the quick response.

- Pascal

Dale Newfield wrote:
> Euphreme Rinfrett wrote:
>>    I'm trying to use to "stream" result type to get some images to 
>> display within a portal.
>
>>        <action name="displayExerciceImageAction" 
>> class="displayExerciceAction">
>>            <result name="success" type="stream">
>>              <param name="contentType">${model.imageContentType}</param>
>>              <param name="inputName">${model.image}</param>
>>              <param 
>> name="contentDisposition">filename="${model.name}_img"</param>
>>              <param name="bufferSize">${model.image.length}</param>
>>            </result>
>>        </action>
>
>> image being an array of bytes.
>
> You've got a mixup between "contentLength" and "bufferSize"
> bufferSize is simply the size chunks sent out along the wire 
> (something simple like 1024 or 2048), "contentLength" is the size of 
> the image you're trying to send.  (And if you don't provide it, your 
> content will be fetched twice, once to find the size, again to send it.)
> your "contentDisposition" is invalid (as is the example you reference, 
> BTW).  You want that to read inline;filename="${model.name}_img". 
> Lastly, you've got the actual content wrong.  "inputName" does not 
> accept OGNL, but rather a property name on your action for which there 
> should be a getter that returns an InputStream (not an array of bytes, 
> and not the same InputStream each time it's called but rather a new 
> one each time).
>
> Here's an example from my current app:
>
> <result name="success" type="stream">
>   <param name="contentType">${media.mimetype}</param>
>   <param name="inputName">mediaFileStream</param>
>   <param 
> name="contentDisposition">inline;filename="${media.code}.${media.suffix}"</param> 
>
>   <param name="bufferSize">1024</param>
>   <param name="contentLength">${mediaFileLength}</param>
> </result>
>
> -Dale
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



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


Re: [struts] "stream" result type

Posted by Dale Newfield <Da...@Newfield.org>.
Euphreme Rinfrett wrote:
>    I'm trying to use to "stream" result type to get some images to 
> display within a portal.

>        <action name="displayExerciceImageAction" 
> class="displayExerciceAction">
>            <result name="success" type="stream">
>              <param name="contentType">${model.imageContentType}</param>
>              <param name="inputName">${model.image}</param>
>              <param 
> name="contentDisposition">filename="${model.name}_img"</param>
>              <param name="bufferSize">${model.image.length}</param>
>            </result>
>        </action>

> image being an array of bytes.

You've got a mixup between "contentLength" and "bufferSize"
bufferSize is simply the size chunks sent out along the wire (something 
simple like 1024 or 2048), "contentLength" is the size of the image 
you're trying to send.  (And if you don't provide it, your content will 
be fetched twice, once to find the size, again to send it.)
your "contentDisposition" is invalid (as is the example you reference, 
BTW).  You want that to read inline;filename="${model.name}_img". 
Lastly, you've got the actual content wrong.  "inputName" does not 
accept OGNL, but rather a property name on your action for which there 
should be a getter that returns an InputStream (not an array of bytes, 
and not the same InputStream each time it's called but rather a new one 
each time).

Here's an example from my current app:

<result name="success" type="stream">
   <param name="contentType">${media.mimetype}</param>
   <param name="inputName">mediaFileStream</param>
   <param 
name="contentDisposition">inline;filename="${media.code}.${media.suffix}"</param>
   <param name="bufferSize">1024</param>
   <param name="contentLength">${mediaFileLength}</param>
</result>

-Dale

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


Re: "stream" result type

Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
I assume that you're talking about a Struts 2 portlet since you're
saying "within a portal"? If not, just disregard my response.

A (jsr168)portlet can't render binary content (some jsr168 portlet
containers have proprietary extensions to do this, but it's not
supported by the framework), so you need to access your image
rendering action as a regular Struts 2 servlet application. The
easiest way to do this is to create a new package in struts.xml that
extends struts-default and put your action there. Then create the url
to the image "manually" (use the "value" attribute of the url tag, or
just create it by hand). You also need the FilterDispatcher in the
web.xml file if it's not there already.

This also means that if you're sharing session values between the
actions in the portlet and the actions creating the image, you have to
put them in the application scope of the portlet session.

Luckily, this is directly supported in the new portlet 2.0 secification.

Nils-H

On Tue, Mar 11, 2008 at 9:52 PM, Euphreme Rinfrett
<eu...@yahoo.ca> wrote:
> Hi all,
>
>     I'm trying to use to "stream" result type to get some images to
>  display within a portal.
>
>  Based on the wiki page: http://struts.apache.org/2.x/docs/stream-result.html
>
>  I did my own action that gets an image and puts it into a model.
>
>  This is the struts configuration:
>
>         <action name="displayExerciceImageAction"
>  class="displayExerciceAction">
>             <result name="success" type="stream">
>               <param name="contentType">${model.imageContentType}</param>
>               <param name="inputName">${model.image}</param>
>               <param
>  name="contentDisposition">filename="${model.name}_img"</param>
>               <param name="bufferSize">${model.image.length}</param>
>             </result>
>         </action>
>
>  image being an array of bytes.
>
>  While getting called, I'm getting the following error:
>  NoSuchMethodException: setBufferSize(java.lang.String)
>
>  My first though was that the image was null, but it's not the case, the
>  size should be 12345.
>
>  Any clue ?
>
>  Thanks,
>  - Pascal
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>  For additional commands, e-mail: user-help@struts.apache.org
>
>

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