You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Christian Gruber <cg...@google.com> on 2010/09/02 22:23:51 UTC

Event before which request data is processed.

Hey,

     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 - is there a proper event at which we can do this?  Would @PageAttached be appropriate for this?  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.  

     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. :)

cheers,
Christian.
		
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Event before which request data is processed.

Posted by Igor Drobiazko <ig...@gmail.com>.
Just inject the Request [1] or HttpServletRequest (both are per-thread
services) into your page and use it.

[1]
http://tapestry.apache.org/tapestry5.1/apidocs/org/apache/tapestry5/services/Request.html

On Thu, Sep 2, 2010 at 10:23 PM, Christian Gruber <cg...@google.com>wrote:

> Hey,
>
>     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 - is there a proper event at which we can do this?
>  Would @PageAttached be appropriate for this?  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.
>
>     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. :)
>
> cheers,
> Christian.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Best regards,

Igor Drobiazko
http://tapestry5.de

Re: Event before which request data is processed.

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Hi, guys!

I stand corrected. :)

On Thu, 02 Sep 2010 18:13:44 -0300, Howard Lewis Ship <hl...@gmail.com>  
wrote:

> Thank you for pointing that out.  I guess that the meaning has
> changed, it's more like "the page's persistent fields have been
> attached to the page instance for this thread/request".
>
> On Thu, Sep 2, 2010 at 2:07 PM, Igor Drobiazko  
> <ig...@gmail.com> wrote:
>> On Thu, Sep 2, 2010 at 10:55 PM, Thiago H. de Paula Figueiredo <
>> thiagohp@gmail.com> wrote:
>>
>>
>>> @PageDetached are ignored in Tapestry 5.2, as it doesn't use a page  
>>> pool
>>> anymore.
>>>
>>>
>> That's not correct. The life cycle of a page is still the same: the  
>> page is
>> attached to the request and detached when the request is served.
>>
>>
>> --
>> Best regards,
>>
>> Igor Drobiazko
>> http://tapestry5.de
>>
>
>
>


-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
Consultor, desenvolvedor e instrutor em Java, Tapestry e Hibernate
Coordenador e professor da Especialização em Engenharia de Software com  
Ênfase em Java da Faculdade Pitágoras
http://www.arsmachina.com.br

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


Re: Event before which request data is processed.

Posted by Howard Lewis Ship <hl...@gmail.com>.
Thank you for pointing that out.  I guess that the meaning has
changed, it's more like "the page's persistent fields have been
attached to the page instance for this thread/request".

On Thu, Sep 2, 2010 at 2:07 PM, Igor Drobiazko <ig...@gmail.com> wrote:
> On Thu, Sep 2, 2010 at 10:55 PM, Thiago H. de Paula Figueiredo <
> thiagohp@gmail.com> wrote:
>
>
>> @PageDetached are ignored in Tapestry 5.2, as it doesn't use a page pool
>> anymore.
>>
>>
> That's not correct. The life cycle of a page is still the same: the page is
> attached to the request and detached when the request is served.
>
>
> --
> Best regards,
>
> Igor Drobiazko
> http://tapestry5.de
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

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


Re: Event before which request data is processed.

Posted by Igor Drobiazko <ig...@gmail.com>.
On Thu, Sep 2, 2010 at 10:55 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:


> @PageDetached are ignored in Tapestry 5.2, as it doesn't use a page pool
> anymore.
>
>
That's not correct. The life cycle of a page is still the same: the page is
attached to the request and detached when the request is served.


-- 
Best regards,

Igor Drobiazko
http://tapestry5.de

Re: Event before which request data is processed.

Posted by Michael Taylor <mi...@google.com>.
Yes thanks.  I think that's exactly what I was looking for.

On Fri, Sep 3, 2010 at 11:04 AM, Christian Gruber <
christianedwardgruber@gmail.com> wrote:

> Good answer!  Thanks Thiago.  Hadn't considered that.
>
> Christian.
>
> On Sep 3, 2010, at 10:02 AM, Thiago H. de Paula Figueiredo wrote:
>
> > On Fri, 03 Sep 2010 10:36:23 -0300, Michael Taylor <
> miketaylor@google.com> wrote:
> >
> >> Basically what we're trying to do is POST some data to our tapestry
> webapp from an external application.
> >
> > What do you do after receiving the post? If it's just processing it then
> redirecting to another page, why don't you use a Dispatcher instead? It's
> inside Tapestry, so you can use all the IoC goodness. :)
> >
> > --
> > 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-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Event before which request data is processed.

Posted by Christian Gruber <ch...@gmail.com>.
Good answer!  Thanks Thiago.  Hadn't considered that.

Christian.

On Sep 3, 2010, at 10:02 AM, Thiago H. de Paula Figueiredo wrote:

> On Fri, 03 Sep 2010 10:36:23 -0300, Michael Taylor <mi...@google.com> wrote:
> 
>> Basically what we're trying to do is POST some data to our tapestry webapp from an external application.
> 
> What do you do after receiving the post? If it's just processing it then redirecting to another page, why don't you use a Dispatcher instead? It's inside Tapestry, so you can use all the IoC goodness. :)
> 
> -- 
> 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-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


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


Re: Event before which request data is processed.

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Fri, 03 Sep 2010 10:36:23 -0300, Michael Taylor <mi...@google.com>  
wrote:

> Basically what we're trying to do is POST some data to our tapestry  
> webapp from an external application.

What do you do after receiving the post? If it's just processing it then  
redirecting to another page, why don't you use a Dispatcher instead? It's  
inside Tapestry, so you can use all the IoC goodness. :)

-- 
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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Event before which request data is processed.

Posted by Michael Taylor <mi...@google.com>.
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 <
thiagohp@gmail.com> wrote:

> On Thu, 02 Sep 2010 17:23:51 -0300, Christian Gruber <cg...@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-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Event before which request data is processed.

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Thu, 02 Sep 2010 17:23:51 -0300, Christian Gruber <cg...@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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org