Skadlig
Skadlig

Reputation: 1579

Struts interceptor giving a stream result

I got an interceptor that I'm trying to get to output a stream when a certain action is calling. This is part of my code in the inteceptor:

InputStream inputStream;    

public String intercept(ActionInvocation invocation) throws Exception
{
    if (currAction.contentEquals("actionToTest"))
    {
        String result = "TRUE";
        inputStream = new ByteArrayInputStream(result.getBytes("UTF-8"));
        return "resultToGiveStream";
    }
}

inputStream has got it's own getters and setters.
And in struts.xml:

<global-results>
    <result type="stream" name="resultToGiveStream">
        <param name="contentType">text/plain</param>
        <param name="inputName">inputStream</param>
    </result>
</global-results>

But when I call actionToTest I only receive this in my console:

2011-maj-18 11:19:16 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
ALLVARLIG: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.

Is it a lost cause to get it to output what I want? I haven' found anyone doing anything similar. This code is an atempt for a workaround for my other question.

Upvotes: 2

Views: 4632

Answers (1)

Steven Benitez
Steven Benitez

Reputation: 11055

Struts2 is looking for the getInputStream() method on your action and it isn't finding it.

You could try placing the inputStream on the stack manually from within the interceptor. Something like:

invocation.getInvocationContext().put("inputStream", inputStream);

Upvotes: 4

Related Questions