Basically what we're trying to do is POST some data to our tapestry webapp
from an external application.
Our initial thought was to do exactly as Igor suggested, make a page object,
inject the HttpServletRequest and then read the post data from it.
The implementation looked something like this

public class TestPage {

  public static final Logger log =
Logger.getLogger(TestPage.class.getName());

  @Inject
  private HttpServletRequest request;

  public void onActivate() throws IOException {
    if (request != null) {
      log.info("Got request of type " + request.getMethod());
      if (request.getMethod().equalsIgnoreCase("POST")) {
        InputStream input = request.getInputStream();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        byte[] buffer = new byte[2048];
        int read = input.read(buffer);
        while (read > 0) {
          bos.write(buffer, 0, read);
          read = input.read(buffer);
        }
        log.info(bos.toByteArray().length);
      }
    } else {
      log.info("Request not yet bound!");
    }
  }

}


However we found experimentally that whenever we tried to read off the input
stream it would always return "-1" bytes read.
Our guess was that at the point in the request processing chain where
"onActivate" is called that Tapestry had already read all of the request
contents in order to attempt to do it's own binding to the page object
properties.  Thus we were wondering if there was an event earlier on in the
chain that we could hook onto in order to be able to see the raw unprocessed
POST contents.
We also tried PageAttached but had the same problem.
If we make a standard servlet and configure tapestry to ignore the servlet
URL then we can access the POST contents no problem, but we miss out on all
of the other tapestry IOC goodness.
So, to make a long story short, can anyone suggest a way to get at the raw
POST data?

Thanks,

Mike T

On Thu, Sep 2, 2010 at 4:55 PM, Thiago H. de Paula Figueiredo <
thiag...@gmail.com> wrote:

> On Thu, 02 Sep 2010 17:23:51 -0300, Christian Gruber <cgru...@google.com>
> wrote:
>
>  Hey,
>>
>
> Hi!
>
>
>      We have a "page" we want to use roughly in place of writing a separate
>> servlet that needs access to the request and all its raw data before
>> processing for binding
>>
>
> What do you mean by "before processing for binding" here?
>
>
> - is there a proper event at which we can
>
>> do this?  Would @PageAttached be appropriate for this?
>>
>
> Remember that @PageAttached and @PageDetached are ignored in Tapestry 5.2,
> as it doesn't use a page pool anymore.
>
>
>  Can we get the Request at this point?  We're about to try it, but if
>> there's a better one, I'd love to know about it.
>>
>
> Why not onActivate()?
>
>
>      On a related note - is there anywhere that lists every known event
>> that a page goes through (or component) in the order of such, with
>> indications of what changes happen at these steps?  That would be some
>> crazy-useful documentation. :)
>>
>
> There are page lifecycle events:
> http://tapestry.apache.org/tapestry5.1/guide/lifecycle.html or
> http://tapestry.apache.org/tapestry5.1/guide/lifecycle.html, depending on
> the version you're using. They're not triggered in component classes. Both
> pages and components (and pages are components) have render events,
> described in http://tapestry.apache.org/tapestry5.1/guide/rendering.html.
>
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and instructor
> Owner, Ars Machina Tecnologia da Informação Ltda.
> http://www.arsmachina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

Reply via email to