HttpRequest conversion

1,771 views
Skip to first unread message

Mario Scappaticci

unread,
Jul 12, 2012, 3:50:59 PM7/12/12
to lif...@googlegroups.com
Hi lifters,
i would know if there's a way to convert a S.request object in a java HttpRequest.

thanks in advance

Mario

Jeppe Nejsum Madsen

unread,
Jul 12, 2012, 4:07:11 PM7/12/12
to lif...@googlegroups.com
You should get S.request.request. This is a HTTPRequest which is
normally an instance of HTTPRequestServlet which has a req field that
contains the original HttpServletRequest.

/Jeppe

Mario Scappaticci

unread,
Jul 13, 2012, 3:12:15 AM7/13/12
to lif...@googlegroups.com
thanks jeppe,but i need a cast.
My application use a function with the following signature:

function(param:javax.servlet.http.httpservletrequest)

how can i pass my S.request.request object to this function?

thanks


Il giorno giovedì 12 luglio 2012 22:07:11 UTC+2, Jeppe Nejsum Madsen ha scritto:
On Thu, Jul 12, 2012 at 9:50 PM, Mario Scappaticci

Jeppe Nejsum Madsen

unread,
Jul 13, 2012, 4:25:29 AM7/13/12
to lif...@googlegroups.com
On Fri, Jul 13, 2012 at 9:12 AM, Mario Scappaticci
<mario.sc...@gmail.com> wrote:
> thanks jeppe,but i need a cast.
> My application use a function with the following signature:
>
> function(param:javax.servlet.http.httpservletrequest)
>
> how can i pass my S.request.request object to this function?

val r :Box[javax.servlet.http.HttpServletRequest] = for {
lr <- S.request
sr <- Box.isA(lr.request, classOf[provider.servlet.HTTPRequestServlet])
} yield sr.req

r.foreach(r => function(r))

/Jeppe

>
> thanks
>
> Il giorno giovedì 12 luglio 2012 22:07:11 UTC+2, Jeppe Nejsum Madsen ha
> scritto:
>>
>> On Thu, Jul 12, 2012 at 9:50 PM, Mario Scappaticci
>> > Hi lifters,
>> > i would know if there's a way to convert a S.request object in a java
>> > HttpRequest.
>> >
>> > thanks in advance
>>
>> You should get S.request.request. This is a HTTPRequest which is
>> normally an instance of HTTPRequestServlet which has a req field that
>> contains the original HttpServletRequest.
>>
>> /Jeppe
>
> --
> Lift, the simply functional web framework: http://liftweb.net
> Code: http://github.com/lift
> Discussion: http://groups.google.com/group/liftweb
> Stuck? Help us help you:
> https://www.assembla.com/wiki/show/liftweb/Posting_example_code

David Pollak

unread,
Jul 16, 2012, 4:37:13 PM7/16/12
to lif...@googlegroups.com
On Thu, Jul 12, 2012 at 12:50 PM, Mario Scappaticci <mario.sc...@gmail.com> wrote:
Hi lifters,
i would know if there's a way to convert a S.request object in a java HttpRequest.

  val servletRequest: Box[HttpServletRequest] =
    for {
    req <- S.request
    inner <- Box.asA[HTTPRequestServlet](req.request)
  } yield inner.req
 

thanks in advance

Mario

--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code



--
Telegram, Simply Beautiful CMS https://telegr.am
Lift, the simply functional web framework http://liftweb.net


Diego Medina

unread,
Feb 7, 2013, 3:31:43 AM2/7/13
to Lift
SO, did you try the code David posted and you get an Empty box? what
jetty version are you using?

On Thu, Feb 7, 2013 at 12:54 AM, Phaedrus <srir...@gmail.com> wrote:
> Hi,
> I am using Lift 2.5.M2 and am running a web app using the Jetty
> container in sbt. Turns out, the S.request.get.request object is of type
> net.liftweb.http.provider.servlet.OfflineRequestSnapshot and cannot be cast
> to HttpServletRequest. Is there really any way to get to the underlying
> HttpServletRequest object? I am near my wits' end....any help appreciated.
>
> Cheers
> Phaedrus
> --
> --
> Lift, the simply functional web framework: http://liftweb.net
> Code: http://github.com/lift
> Discussion: http://groups.google.com/group/liftweb
> Stuck? Help us help you:
> https://www.assembla.com/wiki/show/liftweb/Posting_example_code
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Lift" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to liftweb+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://fmpwizard.telegr.am

Jeppe Nejsum Madsen

unread,
Feb 7, 2013, 4:08:29 AM2/7/13
to lif...@googlegroups.com
Phaedrus <srir...@gmail.com> writes:

> Hi,
> I am using Lift 2.5.M2 and am running a web app using the Jetty
> container in sbt. Turns out, the S.request.get.request object is of type
> net.liftweb.http.provider.servlet.OfflineRequestSnapshot and cannot be cast
> to HttpServletRequest. Is there really any way to get to the underlying
> HttpServletRequest object? I am near my wits' end....any help appreciated.
>
> Cheers
> Phaedrus

Is this inside a CometActor? If so you're not seeing the
HttpServletRequest but the OfflineRequestSnapshot since you're running
outside the original request cycle. But the original request is
available from the OfflineRequestSnapshot.req value. See the source for
details :-)

/Jeppe

Phaedrus

unread,
Feb 7, 2013, 7:01:05 PM2/7/13
to lif...@googlegroups.com
Hi All,
    I finally found out why it wasn't working. My snippet was being lazy loaded. I removed lazy loading and the conversion to HttpServletRequest works. Thanks everyone for your pointers.

Cheers

On Thursday, February 7, 2013 9:06:24 PM UTC+8, Phaedrus wrote:
Hi,
   I tried the posted code before posing my question and it doesn't work. Also I did have a look at the source code for OfflineRequestSnapshot before posting and it doesn't expose a "req" or "request" field. Is there any workable way of getting access to the HttpServletRequest object?

Thanks
Phaedrus

Jeppe Nejsum Madsen

unread,
Feb 8, 2013, 4:34:31 AM2/8/13
to lif...@googlegroups.com
Phaedrus <srir...@gmail.com> writes:

> Hi,
> I tried the posted code before posing my question and it doesn't work.
> Also I did have a look at the source code for OfflineRequestSnapshot before
> posting and it doesn't expose a "req" or "request" field. Is there any
> workable way of getting access to the HttpServletRequest object?

Aahh you're right of course. First off the OfflineRequestSnapshot class
is private and the req field is not exposed. Sorry, my bad.

The question is then: Why do you need the HttpServletRequest? Much of
what you can do is not available in the context of an
OfflineRequestSnapshot (since you're not running the original request) and most (all?) info is exposed on the
HTTPRequest.

/Jeppe
Reply all
Reply to author
Forward
0 new messages