You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Kaspar Fischer <fi...@inf.ethz.ch> on 2008/03/07 12:19:32 UTC

RequestCycle.get() in WebResource

How can I get hold of the current request cycle in a subclass of  
WebResource?
In

   public final class RepositoryFileResource extends WebResource
   {
     /* ... */

     public IResourceStream getResourceStream()
     {
       RequestCycle cycle = RequestCycle.get();

cycle is null.

P.S. I am registering my resource in my application's init()

     getSharedResources().add("repo", new RepositoryFileResource());


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


Re: RequestCycle.get() in WebResource

Posted by Johan Compagner <jc...@gmail.com>.
yes
there is not request cycle when doing resources
why do you need it?

johan



On Fri, Mar 7, 2008 at 1:06 PM, Kaspar Fischer <fi...@inf.ethz.ch> wrote:

> On 07.03.2008, at 13:01, lars vonk wrote:
>
> > I guess you can't. Since you are in the Application init method I
> > don't think there is a requestcycle available (request cycles
> > represents the processing of a request).
>
> I am not trying to get the request cycle inside my application's init(),
> but in getResourceStream().
>
> Still, I think your explanation applies again: getResourceStream()
> is apparently called (why?) even when the web server is doing a
> HEAD request, in which case there is (?) no request cycle either.
> Could this be the case?
>
> > On Fri, Mar 7, 2008 at 12:19 PM, Kaspar Fischer
> > <fi...@inf.ethz.ch> wrote:
> >> How can I get hold of the current request cycle in a subclass of
> >> WebResource?
> >> In
> >>
> >>   public final class RepositoryFileResource extends WebResource
> >>   {
> >>     /* ... */
> >>
> >>     public IResourceStream getResourceStream()
> >>     {
> >>       RequestCycle cycle = RequestCycle.get();
> >>
> >> cycle is null.
> >>
> >> P.S. I am registering my resource in my application's init()
> >>
> >>     getSharedResources().add("repo", new RepositoryFileResource());
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: How to enclode WebResource requests in transaction (Was: RequestCycle.get() in WebResource)

Posted by Johan Compagner <jc...@gmail.com>.
do you need a transaction around the resource when only the
lastModifiedTimeStamp is ask for?
is your resource really cachable?

johan



On Fri, Mar 7, 2008 at 2:15 PM, Kaspar Fischer <fi...@inf.ethz.ch> wrote:

> I have a general question on how to wrap transaction boundaries around
> requests
> to a WebResource. As discussed in the thread
>
>   http://markmail.org/message/tbpg65xd5x26v7xf
>
> there are two possible requests: an ordinary web request (with a
> RequestCycle)
> and a HEAD request (where no RequestCycle exists). If an application
> needs to
> wrap transaction boundaries around such requests, how should it do this?
>
> The former kind of request can wrapped by listening to WebRequestCycle's
> onBeginRequest and onEndRequest methods, but the latter needs *another*
> way, it seems. Is there a way that handles both cases?
>
> Thanks a lot for any hint!
> Kaspar
>
> On 07.03.2008, at 13:06, Kaspar Fischer wrote:
>
> > On 07.03.2008, at 13:01, lars vonk wrote:
> >
> >> I guess you can't. Since you are in the Application init method I
> >> don't think there is a requestcycle available (request cycles
> >> represents the processing of a request).
> >
> > I am not trying to get the request cycle inside my application's
> > init(),
> > but in getResourceStream().
> >
> > Still, I think your explanation applies again: getResourceStream()
> > is apparently called (why?) even when the web server is doing a
> > HEAD request, in which case there is (?) no request cycle either.
> > Could this be the case?
> >
> >> On Fri, Mar 7, 2008 at 12:19 PM, Kaspar Fischer
> >> <fi...@inf.ethz.ch> wrote:
> >>> How can I get hold of the current request cycle in a subclass of
> >>> WebResource?
> >>> In
> >>>
> >>>  public final class RepositoryFileResource extends WebResource
> >>>  {
> >>>    /* ... */
> >>>
> >>>    public IResourceStream getResourceStream()
> >>>    {
> >>>      RequestCycle cycle = RequestCycle.get();
> >>>
> >>> cycle is null.
> >>>
> >>> P.S. I am registering my resource in my application's init()
> >>>
> >>>    getSharedResources().add("repo", new RepositoryFileResource());
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

How to enclode WebResource requests in transaction (Was: RequestCycle.get() in WebResource)

Posted by Kaspar Fischer <fi...@inf.ethz.ch>.
I have a general question on how to wrap transaction boundaries around  
requests
to a WebResource. As discussed in the thread

   http://markmail.org/message/tbpg65xd5x26v7xf

there are two possible requests: an ordinary web request (with a  
RequestCycle)
and a HEAD request (where no RequestCycle exists). If an application  
needs to
wrap transaction boundaries around such requests, how should it do this?

The former kind of request can wrapped by listening to WebRequestCycle's
onBeginRequest and onEndRequest methods, but the latter needs *another*
way, it seems. Is there a way that handles both cases?

Thanks a lot for any hint!
Kaspar

On 07.03.2008, at 13:06, Kaspar Fischer wrote:

> On 07.03.2008, at 13:01, lars vonk wrote:
>
>> I guess you can't. Since you are in the Application init method I
>> don't think there is a requestcycle available (request cycles
>> represents the processing of a request).
>
> I am not trying to get the request cycle inside my application's  
> init(),
> but in getResourceStream().
>
> Still, I think your explanation applies again: getResourceStream()
> is apparently called (why?) even when the web server is doing a
> HEAD request, in which case there is (?) no request cycle either.
> Could this be the case?
>
>> On Fri, Mar 7, 2008 at 12:19 PM, Kaspar Fischer  
>> <fi...@inf.ethz.ch> wrote:
>>> How can I get hold of the current request cycle in a subclass of
>>> WebResource?
>>> In
>>>
>>>  public final class RepositoryFileResource extends WebResource
>>>  {
>>>    /* ... */
>>>
>>>    public IResourceStream getResourceStream()
>>>    {
>>>      RequestCycle cycle = RequestCycle.get();
>>>
>>> cycle is null.
>>>
>>> P.S. I am registering my resource in my application's init()
>>>
>>>    getSharedResources().add("repo", new RepositoryFileResource());

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


Re: RequestCycle.get() in WebResource

Posted by Kaspar Fischer <fi...@inf.ethz.ch>.
On 07.03.2008, at 13:01, lars vonk wrote:

> I guess you can't. Since you are in the Application init method I
> don't think there is a requestcycle available (request cycles
> represents the processing of a request).

I am not trying to get the request cycle inside my application's init(),
but in getResourceStream().

Still, I think your explanation applies again: getResourceStream()
is apparently called (why?) even when the web server is doing a
HEAD request, in which case there is (?) no request cycle either.
Could this be the case?

> On Fri, Mar 7, 2008 at 12:19 PM, Kaspar Fischer  
> <fi...@inf.ethz.ch> wrote:
>> How can I get hold of the current request cycle in a subclass of
>> WebResource?
>> In
>>
>>   public final class RepositoryFileResource extends WebResource
>>   {
>>     /* ... */
>>
>>     public IResourceStream getResourceStream()
>>     {
>>       RequestCycle cycle = RequestCycle.get();
>>
>> cycle is null.
>>
>> P.S. I am registering my resource in my application's init()
>>
>>     getSharedResources().add("repo", new RepositoryFileResource());
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


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


Re: RequestCycle.get() in WebResource

Posted by lars vonk <la...@gmail.com>.
I guess you can't. Since you are in the Application init method I
don't think there is a requestcycle available (request cycles
represents the processing of a request).

Lars

On Fri, Mar 7, 2008 at 12:19 PM, Kaspar Fischer <fi...@inf.ethz.ch> wrote:
> How can I get hold of the current request cycle in a subclass of
>  WebResource?
>  In
>
>    public final class RepositoryFileResource extends WebResource
>    {
>      /* ... */
>
>      public IResourceStream getResourceStream()
>      {
>        RequestCycle cycle = RequestCycle.get();
>
>  cycle is null.
>
>  P.S. I am registering my resource in my application's init()
>
>      getSharedResources().add("repo", new RepositoryFileResource());
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>  For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: RequestCycle.get() in WebResource

Posted by Johan Compagner <jc...@gmail.com>.
see for example Image
that one can old an Resource directly to make a session relative resource so
yes resources can be serialized

On Fri, Mar 7, 2008 at 5:31 PM, Kaspar Fischer <fi...@inf.ethz.ch> wrote:

> Johan, thanks a lot for your explanations!
>
> On 07.03.2008, at 15:47, Johan Compagner wrote:
>
> > do you need a transaction around the resource when only the
> > lastModifiedTimeStamp is ask for?
>
> Yes, unfortunately.
>
> > is your resource really cachable?
>
> I am writing a WebResource that returns files from an external content
> repository. So yes: the resource should be cached by the browser and
> yes, I do have a lastModifiedTimeStamp.
>
> Or did you ask because I am using WebResource and not
> DynamicWebResource?
> I thought I am going to use WebResource as the content repository
> (Alfresco,
> in my case) probably already does some (server-side) caching and
> DynamicWebResource would add another level of server-side caching
> (right?).
>
> > head request must be really fast because the happen a lot
> > and you should not be loading so much then
> >
> > So you just have to see if you can create a resourcestream that only
> > has the
> > right timestamp
>
> Okay, got it.
>
> Btw, is there a reason why WebResources are serializable? Are they
> ever serialized?
>
> Thanks,
> Kaspar
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: RequestCycle.get() in WebResource

Posted by Kaspar Fischer <fi...@inf.ethz.ch>.
Johan, thanks a lot for your explanations!

On 07.03.2008, at 15:47, Johan Compagner wrote:

> do you need a transaction around the resource when only the
> lastModifiedTimeStamp is ask for?

Yes, unfortunately.

> is your resource really cachable?

I am writing a WebResource that returns files from an external content
repository. So yes: the resource should be cached by the browser and
yes, I do have a lastModifiedTimeStamp.

Or did you ask because I am using WebResource and not  
DynamicWebResource?
I thought I am going to use WebResource as the content repository  
(Alfresco,
in my case) probably already does some (server-side) caching and
DynamicWebResource would add another level of server-side caching  
(right?).

> head request must be really fast because the happen a lot
> and you should not be loading so much then
>
> So you just have to see if you can create a resourcestream that only  
> has the
> right timestamp

Okay, got it.

Btw, is there a reason why WebResources are serializable? Are they
ever serialized?

Thanks,
Kaspar

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


Re: RequestCycle.get() in WebResource

Posted by Johan Compagner <jc...@gmail.com>.
head request must be really fast because the happen a lot
and you should not be loading so much then

So you just have to see if you can create a resourcestream that only has the
right timestamp

johan



On Fri, Mar 7, 2008 at 12:31 PM, Kaspar Fischer <fi...@inf.ethz.ch>
wrote:

> I should add that I want the cycle in order to access the context
> of my external content repository. I am setting up this context
> as described in http://markmail.org/message/varxr2or2ba6tr7g .
>
> On 07.03.2008, at 12:19, Kaspar Fischer wrote:
>
> > How can I get hold of the current request cycle in a subclass of
> > WebResource?
> > In
> >
> >  public final class RepositoryFileResource extends WebResource
> >  {
> >    /* ... */
> >
> >    public IResourceStream getResourceStream()
> >    {
> >      RequestCycle cycle = RequestCycle.get();
> >
> > cycle is null.
> >
> > P.S. I am registering my resource in my application's init()
> >
> >    getSharedResources().add("repo", new RepositoryFileResource());
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: RequestCycle.get() in WebResource

Posted by Kaspar Fischer <fi...@inf.ethz.ch>.
I should add that I want the cycle in order to access the context
of my external content repository. I am setting up this context
as described in http://markmail.org/message/varxr2or2ba6tr7g .

On 07.03.2008, at 12:19, Kaspar Fischer wrote:

> How can I get hold of the current request cycle in a subclass of  
> WebResource?
> In
>
>  public final class RepositoryFileResource extends WebResource
>  {
>    /* ... */
>
>    public IResourceStream getResourceStream()
>    {
>      RequestCycle cycle = RequestCycle.get();
>
> cycle is null.
>
> P.S. I am registering my resource in my application's init()
>
>    getSharedResources().add("repo", new RepositoryFileResource());
>


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