Add lift to existing servlet web application.

26 views
Skip to first unread message

Vagif Verdi

unread,
Dec 10, 2007, 7:08:27 PM12/10/07
to liftweb
Is it possible to start adding new functionality (new pages, new
modules) with lift, into existing servlet java application ? Will the
session be shared ?

David Pollak

unread,
Dec 10, 2007, 8:22:13 PM12/10/07
to lif...@googlegroups.com
lift is implemented as a Filter. It only handles Servlet requests
that it's "supposed" to.

"supposed" is defined in LiftServlet.isLiftRequest_? (it's a partial
function. If it's defined, it returns true or false).

If lift doesn't handle the request, it's passed on in the Filter
chain (thanks to Viktor for recommending this strategy.)

lift interoperates with everything else in the servlet container.

So, all you'd have to do is define the isLiftRequest_? partial
function to tell lift to deal with certain URLs and your existing
Servlet would deal with the rest and both lift and your other servlet
would share the same Servlet Context.

Long way of saying "yes".

--
David Pollak
http://blog.lostlake.org

Viktor Klang

unread,
Dec 11, 2007, 7:05:04 AM12/11/07
to lif...@googlegroups.com
Hey Vagif (or Verdi) :),
 
David's right on the spot!
 
Since /lift/ is implemented as a Filter, intercepting calls/URLs, you could simply add a test to isLiftRequest_? and have a Servlet, JSP, whatever cool stuff you want behind it. :)
 
 
David: perhaps it'd be nice to have a simple way of doing this, as perhaps people want to integrate their servlets?

Cheers,
-- Viktor
_____________________________________
/                                                                 \
        /lift/ committer (www.liftweb.net)
      SGS member (Scala Group Sweden)
  SEJUG member (Swedish Java User Group)
            Coffee drinker (Skånerost)
\_____________________________________/
 

David Pollak

unread,
Dec 11, 2007, 7:09:20 AM12/11/07
to lif...@googlegroups.com
On Dec 11, 2007, at 4:05 AM, Viktor Klang wrote:

Hey Vagif (or Verdi) :),
 
David's right on the spot!
 
Since /lift/ is implemented as a Filter, intercepting calls/URLs, you could simply add a test to isLiftRequest_? and have a Servlet, JSP, whatever cool stuff you want behind it. :)
 
 
David: perhaps it'd be nice to have a simple way of doing this, as perhaps people want to integrate their servlets?

I agree.  Perhaps you could write up an example of the web.xml and tell me what the directory lift stuff with be served from and I'll write up the partial function.

Viktor Klang

unread,
Dec 11, 2007, 7:33:51 AM12/11/07
to lif...@googlegroups.com


On 12/11/07, David Pollak <d...@athena.com> wrote:

On Dec 11, 2007, at 4:05 AM, Viktor Klang wrote:

Hey Vagif (or Verdi) :),
 
David's right on the spot!
 
Since /lift/ is implemented as a Filter, intercepting calls/URLs, you could simply add a test to isLiftRequest_? and have a Servlet, JSP, whatever cool stuff you want behind it. :)
 
 
David: perhaps it'd be nice to have a simple way of doing this, as perhaps people want to integrate their servlets?

 
I agree.  Perhaps you could write up an example of the web.xml and tell me what the directory lift stuff with be served from and I'll write up the partial function.
 
David: just write a sample-class that inherits from HttpServlet, then add this to you web-xml:
<web-inf>
[...]
<servlet>
    <servlet-name>MyCoolName</servlet-name>
    <display-name>MyCoolServlet</display-name>
    <servlet-class>qualifiedClassName</servlet-class>   
  </servlet>
  <servlet-mapping>
    <servlet-name>MyCoolName</servlet-name>
    <url-pattern>/myDir/myName</url-pattern>
  </servlet-mapping>
[...]
</web-inf>
 
Example (Apache AXIS Servlet definition):
 
<servlet>
    <servlet-name>AxisServlet</servlet-name>
    <display-name>Apache-Axis Servlet</display-name>
    <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>   
  </servlet>
  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/servlet/AxisServlet</url-pattern>
  </servlet-mapping>
 
So, to call the AXIS servlet, you'd write: http://<myhttpserver>:<myport>/<my webapp>/servlet/AxisServlet
 
 
Do I make any sense? :)
 
Cheers,
-Viktor

Vagif Verdi

unread,
Dec 11, 2007, 6:34:11 PM12/11/07
to liftweb
Thank you all. I'll try it on weekend and will report the outcome :)

David Pollak

unread,
Dec 13, 2007, 9:00:14 AM12/13/07
to lif...@googlegroups.com
In Boot, do something like:

LiftServlet.addLiftRequest{
  case r if (r.path.path match {case "lift" :: _ => false case _ => true}) => false
}

This will pass /lift/* to the lift Filter and pass everything else down the servlet chain.

The way it works is we test r.path.path (a list of path elements on the request).  If the request starts with /lift/, then the pattern match fails and the code falls through (to allow lift to service the request), otherwise the pattern match succeeds and returns false (don't let the lift Filter process the request.)  It's a double-negative.

Thanks,

David
Reply all
Reply to author
Forward
0 new messages