You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by 928572663 <92...@cox.net> on 2008/10/07 02:47:36 UTC

Returning text/html InputStream using Zero Configuration annotations

I am trying to rewrite this sample code from the FAQ using zero 
configuration annoations:

http://struts.apache.org/2.1.2/docs/how-can-we-return-a-text-string-as-the-response.html

and I came up with this:


import java.io.InputStream;
import java.io.StringBufferInputStream;

import org.apache.struts2.config.Result;
import org.apache.struts2.dispatcher.StreamResult;

import com.opensymphony.xwork2.ActionSupport;

@Result(value = "", type = StreamResult.class, params =
{
    "contentType",
    "text/html",
    "inputName",
    "inputStream" })
public class TextResult extends ActionSupport
{
    private InputStream inputStream;

    public InputStream getInputStream()
    {
       return inputStream;
    }

    public String execute() throws Exception
    {
       inputStream = new StringBufferInputStream(
          "Hello World! This is a text string response from a Struts 2 
Action.");
       return SUCCESS;
    }
}

But when I run it I get this exception:

ERROR dispatcher.StreamResult  - Can not find a java.io.InputStream with 
the name [] in the invocation stack. Check the <param name="inputName"> 
tag specified for this action.

The first thing I wondered about is the "value" parameter in @Result. 
It is required, but I wasn't sure what to pass.

Any help to get this sample code to work using annotations would be 
appreciated.

Thanks,  John


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


Re: Returning text/html InputStream using Zero Configuration annotations

Posted by 928572663 <92...@cox.net>.
Awesome it's working now!   Thanks to you both for your help.

For posterity's sake,  here is the working code:


import java.io.InputStream;
import java.io.StringBufferInputStream;

import org.apache.struts2.config.Result;
import org.apache.struts2.dispatcher.StreamResult;

import com.opensymphony.xwork2.ActionSupport;

@Result(name = ActionSupport.SUCCESS, value = "inputStream", type = 
StreamResult.class, params =
{
    "contentType",
    "text/html",
    "inputName",
    "inputStream"
})
public class TextResult extends ActionSupport
{
    private InputStream inputStream;

    public InputStream getInputStream()
    {
       return inputStream;
    }

    public String execute() throws Exception
    {
       inputStream = new StringBufferInputStream(
          "Hello World! This is a text string response from a Struts 2 
Action.");
       return SUCCESS;
    }
}



Thanks,
John

Laurie Harper wrote:
> Lukasz Lenart wrote:
>> 2008/10/7 928572663 <92...@cox.net>:
>>> Sorry I forgot to add this:
>>>
>>> If I change the value="" to value="John",  the error message changes to
>>> this:
>>
>> try value="inputName"
> 
> Based on the code in the original post, that should be value="inputStream".
> 
> L.
> 
> 
> ---------------------------------------------------------------------
> 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: Returning text/html InputStream using Zero Configuration annotations

Posted by Laurie Harper <la...@holoweb.net>.
Lukasz Lenart wrote:
> 2008/10/7 928572663 <92...@cox.net>:
>> Sorry I forgot to add this:
>>
>> If I change the value="" to value="John",  the error message changes to
>> this:
> 
> try value="inputName"

Based on the code in the original post, that should be value="inputStream".

L.


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


Re: Returning text/html InputStream using Zero Configuration annotations

Posted by Lukasz Lenart <lu...@googlemail.com>.
2008/10/7 928572663 <92...@cox.net>:
> Sorry I forgot to add this:
>
> If I change the value="" to value="John",  the error message changes to
> this:

try value="inputName"


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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


Re: Returning text/html InputStream using Zero Configuration annotations

Posted by 928572663 <92...@cox.net>.
Sorry I forgot to add this:

If I change the value="" to value="John",  the error message changes to 
this:

ERROR dispatcher.StreamResult  - Can not find a java.io.InputStream with 
the name [John] in the invocation stack. Check the <param 
name="inputName"> tag specified for this action.

It appears that it is attempting to process the forward,  but is not 
able to locate the stream.  Does it need an OGNL trick in the "value" 
field to help it call my getInputStream() accessor?


Thanks,
John

928572663 wrote:
> Lukasz,
> 
> Thank you for your reply.
> 
> I tried adding the name="success"  (or ActionSupport.SUCCESS) and I get 
> the same error.   Here is the annotation now:
> 
> @Result(name="success", value = "", type = StreamResult.class, params =
> {
>    "contentType",
>    "text/html",
>    "inputName",
>    "inputStream" })
> 
> also tried:
> 
> @Result(name=ActionSupport.SUCCESS, value = "", type = 
> StreamResult.class, params =
> {
>    "contentType",
>    "text/html",
>    "inputName",
>    "inputStream" })
> 
> and received the same error:
> 
> ERROR dispatcher.StreamResult  - Can not find a java.io.InputStream with 
> the name [] in the invocation stack. Check the <param name="inputName"> 
> tag specified for this action.
> 
> Any other ideas?
> 
> Thanks,
> John
> 
> 


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


Re: Returning text/html InputStream using Zero Configuration annotations

Posted by 928572663 <92...@cox.net>.
Lukasz,

Thank you for your reply.

I tried adding the name="success"  (or ActionSupport.SUCCESS) and I get 
the same error.   Here is the annotation now:

@Result(name="success", value = "", type = StreamResult.class, params =
{
    "contentType",
    "text/html",
    "inputName",
    "inputStream" })

also tried:

@Result(name=ActionSupport.SUCCESS, value = "", type = 
StreamResult.class, params =
{
    "contentType",
    "text/html",
    "inputName",
    "inputStream" })

and received the same error:

ERROR dispatcher.StreamResult  - Can not find a java.io.InputStream with 
the name [] in the invocation stack. Check the <param name="inputName"> 
tag specified for this action.

Any other ideas?

Thanks,
John


Lukasz Lenart wrote:
>> @Result(value = "", type = StreamResult.class, params =
> 
> You are missing Result Name, please specify it as a *success*
> 
> http://struts.apache.org/2.0.11.2/docs/result-annotation.html
> 
> 
> Regards


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


Re: Returning text/html InputStream using Zero Configuration annotations

Posted by Lukasz Lenart <lu...@googlemail.com>.
> @Result(value = "", type = StreamResult.class, params =

You are missing Result Name, please specify it as a *success*

http://struts.apache.org/2.0.11.2/docs/result-annotation.html


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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