Loading...

tapestry-user@jakarta.apache.org

[Prev] Thread [Next]  |  [Prev] Date [Next]

RE: Is HttpServletRequest cached? Noam Solomon Tue Nov 29 10:23:40 2005

I'm trying to find a way to get at the correct IP address for the user,
but am running into this problem: I always get the same value for
getRemoteAddr(), and this value is wherever the first request comes
from.  I've seen one exception to this, and it looked like it was
related to expired sessions, but the effect was just to reset the
"constant" IP address.

I wonder if this is related to the problem "Getting the IP Address of a
request" from the lists on November 15.

I haven't tried this with annotations, but I've tried with a property
injected from a page specification, and have now resorted to using the
deprecated getRequestCycle().getRequestcontext().getRequest().  I've had
the same result in both cases.

I'm using tapestry 4 beta 13, and running the application in jetty.

I can probably wait until 4.1 to resolve this if it's a bug, but it
seems more likely that I'm making a mistake somewhere.

In my file Login.page, I have:

    <inject property="remoteAddr"
object="service-property:tapestry.globals.HttpServletRequest:remoteAddr"
/>

In the abstract page class Login.java, I have:

        public abstract String getRemoteAddr();

And elsewhere (in a widely shared base class), I have:

        public String getRemoteAddr() {
                String remoteAddr =
getRequestCycle().getRequestContext().getRequest().getRemoteAddr();
                logger.info("getRemoteAddr: " + remoteAddr);
                return remoteAddr;
        }


-----Original Message-----
From: Howard Lewis Ship [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 18, 2005 2:21 PM
To: Tapestry users
Subject: Re: Is HttpServletRequest cached?

@InsertObject evaulates its value using HiveMind, which results in a
string value, obtained from the current HttpServletRequest service's
remoteHost property. This value is stored internally as is (it is NOT
re-evaluated again) and is injected into each new instance of your
page or component.

The key thing is that with @InjectObject, the evaluation happens just
once. This makes sense in terms of injecting services and
configurations, since those types of values are invariant.

It would be possible to create another type of injection, let's call
it @InjectLive, where the value is recalculated on each access to the
property.

On 11/18/05, hv @ Fashion Content <[EMAIL PROTECTED]> wrote:
> Could it be that the value injected is cached under the
service-property...
> expression, and not recognised as derived from a threaded object.
>
> <[EMAIL PROTECTED]> skrev i en meddelelse
> news:[EMAIL PROTECTED]
> >> Hi,
> >>
> >>   I am trying to get the remote host ip by using:
> >>
> >>
> >>
@InjectObject("service-property:tapestry.globals.HttpServletRequest:remo
teHost")
> >>  public abstract String getRemoteHost();
> >>
> >>   If I connect to the server from two different pc's, the second pc
will
> >> show
> >> the first one's ip address. Is the HttpServletRequest cached?
Someone
> >> earlier
> >> had asked a similar question but I did not see a solution.
> >
> > Indeed, it doesn't work this way - and I thought it would :(
> >
> > Anyway, inject the HttpServletRequest
> > and do a getHttpServletRequest().getRemoteHost()
> >
> > The HttpServletRequest isn't cached, it's stored in a treadlocal, so
the
> > above
> > will work.
> > But I don't actually know why the direct injection of the remotehost
> > doesn't
> > work...I'll have to look into it :)
> >
> >
> >
> >>
> >>   Thanks,
> >>   Amir
> >>
> >
> >
> > --
> >
> >
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail:
[EMAIL PROTECTED]
> >
> >
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


--
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]