setting base URL / tomcat web.xml filter

3,123 views
Skip to first unread message

Felix Terkhorn

unread,
Aug 9, 2011, 12:43:17 PM8/9/11
to lif...@googlegroups.com
Hi all,

  I'm trying to set the base URL for my lift application to /mywebapp/l.  I have the constraint of needing to deploy an additional servlet within my web application.  So, I ultimately want to be able to access that other servlet via /mywebapp/ready, and all lift pages via /mywebapp/l/*

  For some reason, when I visit https://myserver.com:8443/mywebapp/l/ , I get the message that "The Requested URL /webapp/l/ was not found on this server ".  However, when I visit /mywebapp, I see a "broken" version of my standard lift home page:  the body seems to render without any of the surrounding content such as menus, styling, etc. 

  My sitemap definition in Boot may be wrong:

    def sitemap() = SiteMap(
      Menu("Home") / "index" >> User.AddUserMenusAfter, // Simple menu form
      // Menu with special Link
      Menu(Loc("Static", Link(List("static"), true, "/static/index"),
               "Static Content")))

  I've also tried the following, which had similar behavior:

    def sitemap() = SiteMap(
      Menu("Home") / "l/index" >> User.AddUserMenusAfter, // Simple menu form
      // Menu with special Link
      Menu(Loc("Static", Link(List("static"), true, "/static/index"),
               "Static Content")))

   def sitemap() = SiteMap(
      Menu("Home") / "l" / "index" >> User.AddUserMenusAfter, // Simple menu form
      // Menu with special Link
      Menu(Loc("Static", Link(List("static"), true, "/static/index"),
               "Static Content")))


   My web.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">

    <display-name>Additional servlet</display-name>

    <servlet>
        <description>Additional servlet</description>
        <servlet-name>ready</servlet-name>
        <servlet-class>my.additional.servlet.Class</servlet-class>  <!-- mangled as i'm pretty sure this isn't causing adverse effects -->
        <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>ready</servlet-name>
        <url-pattern>/ready</url-pattern>
    </servlet-mapping>

    <!--
       The security constraints below are required by my additional servlet.
    -->

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>portalSecurity</web-resource-name>
            <url-pattern>/*</url-pattern>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
        </web-resource-collection>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>setupPages</web-resource-name>
            <url-pattern>*.jsp</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>web-admin</role-name>
        </auth-constraint>
    </security-constraint>

    <security-role>
        <description>
            The role that is required to configure the servlet. This must be added to tomcat-users.xml
        </description>
        <role-name>web-admin</role-name>
    </security-role>

    <login-config>
        <auth-method>BASIC</auth-method>
    </login-config>
 
   
   
    <filter>
     <filter-name>LiftFilter</filter-name>
     <display-name>Lift Filter</display-name>
     <description>The Filter that intercepts lift calls</description>
     <filter-class>net.liftweb.http.LiftFilter</filter-class>
    </filter>
 
    <filter-mapping>
     <filter-name>LiftFilter</filter-name>
     <url-pattern>/l/*</url-pattern>
    </filter-mapping>

</web-app>


   I would note that accessing the other servlet at /mywebapp/ready does work. 

   Am I completely missing something like doing the following in Boot?

  LiftRules.urlDecorate.append {
      case original => "/l/" + original
    }

   Thanks for dealing with my extreme newbieness!

-Felix

--
Felix Terkhorn, M.S.
Research Technologist
Indiana University Data to Insight Center

Diego Medina

unread,
Aug 9, 2011, 4:28:06 PM8/9/11
to lif...@googlegroups.com

HI,

While I don't have a direct answer to your problem, I do have some comments, please see them below:

On Tue, Aug 9, 2011 at 12:43 PM, Felix Terkhorn <terk...@gmail.com> wrote:
> Hi all,
>
>   I'm trying to set the base URL for my lift application to /mywebapp/l.  I
> have the constraint of needing to deploy an additional servlet within my web
> application.  So, I ultimately want to be able to access that other servlet
> via /mywebapp/ready, and all lift pages via /mywebapp/l/*
>
>   For some reason, when I visit https://myserver.com:8443/mywebapp/l/ , I
> get the message that "The Requested URL /webapp/l/ was not found on this
> server ".  However, when I visit /mywebapp, I see a "broken" version of my
> standard lift home page:  the body seems to render without any of the
> surrounding content such as menus, styling, etc. 
>
>   My sitemap definition in Boot may be wrong:
>
>     def sitemap() = SiteMap(
>       Menu("Home") / "index" >> User.AddUserMenusAfter, // Simple menu form
>       // Menu with special Link
>       Menu(Loc("Static", Link(List("static"), true, "/static/index"),
>                "Static Content")))
>
>   I've also tried the following, which had similar behavior:
>

This one does not do what you want having "i/index" will look for a HTML file called I/index.[html|xhtml|...]

So during your testing, stick to the 3rd option (the first one where you just have index may work, I haven't used the LiftRule to add a "fake" subfolder to the site)

Just for debugging purposes, could you remove this section, the one about the security?

Also, try to just have lift serve your app under /myamm/I/ and then add the other stuff

Regards

Diego

>
>    Thanks for dealing with my extreme newbieness!

>fffffffffffffffff


> -Felix
>
> --
> Felix Terkhorn, M.S.
> Research Technologist
> Indiana University Data to Insight Center
>

> --
> You received this message because you are subscribed to the Google Groups
> "Lift" group.
> To post to this group, send email to lif...@googlegroups.com.
> To unsubscribe from this group, send email to
> liftweb+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/liftweb?hl=en.
>

--
Diego Medina
Web Developer
(305) 788-4954
di...@fmpwizard.com
http://www.fmpwizard.com

Felix

unread,
Aug 10, 2011, 9:47:14 AM8/10/11
to Lift
Hi Diego,

Thanks for taking the time to respond. It looks like commenting the
security portions of the web.xml don't seem to have an effect.

I set the sitemap function as such:

def sitemap() = SiteMap(
Menu("Home") / "l" / "index" >> User.AddUserMenusAfter, //
Simple menu
form
// Menu with special Link
Menu(Loc("Static", Link(List("static"), true, "/static/index"),
"Static Content")))

And with the LiftFilter url-pattern of "/l/*" in place, when I visit
the front page of my site (http://mysite.edu/webapp/), I still see a
broken home page as defined in my Lift framework. When I visit what I
*think* should be the front page of my lift site (http://mysite.edu/
webapp/l or http://mysite.edu/webapp/l/index), I still receive the
Lift error message "The Requested URL /htrc_portal/l was not found on
this server"

-f


On Aug 9, 4:28 pm, Diego Medina <di...@fmpwizard.com> wrote:
> HI,
>
> While I don't have a direct answer to your problem, I do have some comments,
> please see them below:
>
>
>
>
>
>
>
>
>
>
>
> On Tue, Aug 9, 2011 at 12:43 PM, Felix Terkhorn <terkh...@gmail.com> wrote:
> > Hi all,
>
> >   I'm trying to set the base URL for my lift application to /mywebapp/l.
> I
> > have the constraint of needing to deploy an additional servlet within my
> web
> > application.  So, I ultimately want to be able to access that other
> servlet
> > via /mywebapp/ready, and all lift pages via /mywebapp/l/*
>
> >   For some reason, when I visithttps://myserver.com:8443/mywebapp/l/, I

Diego Medina

unread,
Aug 10, 2011, 10:04:32 AM8/10/11
to lif...@googlegroups.com
On Wed, Aug 10, 2011 at 9:47 AM, Felix <terk...@gmail.com> wrote:
> Hi Diego,
>
>  Thanks for taking the time to respond.  It looks like commenting the
> security portions of the web.xml don't seem to have an effect.
>
>  I set the sitemap function as such:
>
> def sitemap() = SiteMap(
>      Menu("Home") / "l" / "index" >> User.AddUserMenusAfter, //
> Simple menu
> form
>      // Menu with special Link
>      Menu(Loc("Static", Link(List("static"), true, "/static/index"),
>               "Static Content")))
>
>  And with the LiftFilter url-pattern of "/l/*" in place, when I visit
> the front page of my site (http://mysite.edu/webapp/), I still see a
> broken home page as defined in my Lift framework.  When I visit what I
> *think* should be the front page of my lift site (http://mysite.edu/
> webapp/l   or http://mysite.edu/webapp/l/index), I still receive the
> Lift error message "The Requested URL /htrc_portal/l was not found on
> this server"


alright, let's see, when you say that the front page is broken, do you
mean that it looks as if the css files and images are missing ? if
this is the case, right click on the page on your browser and look at
the source. See what is the url that the css files are pointing to.

Also , can you change this:

LiftRules.urlDecorate.append {
case original => "I" + original
}
for

LiftRules.urlDecorate.append {
case original => println("DEBUG: =====> " + original) ; "I" + original
}


just to make sure it is being called.

Regards,

Diego

Felix

unread,
Aug 10, 2011, 10:49:03 AM8/10/11
to Lift
I can confirm now that urlDecorate is NOT being called. I'm presently
trying to use Locs to see if I can correctly set the URL in Lift.

Indeed, the css files and images are missing. The HTML source
generated ends up looking like the below when this starts to break
down:

<div class="lift:surround?with=default;at=content">
<h2>Welcome to your project!</h2>
<p>
<div class="lift:helloWorld.howdy">
Welcome to mywebapp at <span id="time">The current time</span>
</div>

<div>Click this button to log in to the site.
</div>

<div>
<form class="lift:StartDelegation?form=post">
<input type="submit" value="Submit"/>
</form>
</div>
</p>
</div>

When I take away the LiftFilter url-pattern restriction (/l/*) and
return it to its default value of /*, the HTML source ends up looking
like this (the standard Hello World lift formatting):


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:lift="http://liftweb.net/" xmlns="http://www.w3.org/1999/
xhtml">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-
type" />
<meta content="" name="description" />
<meta content="" name="keywords" />

<title>edu.indiana.d2i.htrc.portal:mywebapp:1.0</title>

<!-- css <link> items snipped -->
<script type="text/javascript" src="/mywebapp/classpath/jquery.js"
id="jquery"></script>
<script type="text/javascript" src="/mywebapp/classpath/json.js"
id="json"></script>
<style type="text/css"> <!-- snipped -->
</style>


</head>
<body>
<div class="container">
<div style="text-align: right" class="column span-12 last">
<h1 class="alt">mywebapp<img src="/mywebapp/images/ajax-
loader.gif" style="display:none; margin-bottom: 0px; margin-left: 5px"
id="ajax-loader" alt="" /></h1>
</div>

<hr />

<div class="column span-6 colborder sidebar">
<hr class="space" />
<ul><li> <span>Home</span></li><li> <a href="/mywebapp/
user_mgt/login">Login</a></li><li> <a href="/mywebapp/user_mgt/
sign_up">Sign Up</a></li><li> <a href="/mywebapp/user_mgt/
lost_password">Lost Password</a></li><li> <a href="/mywebapp/static/
index">Static Content</a></li></ul>
<div>
<div id="lift__noticesContainer__"></div>
<hr class="space" />
</div>
</div>

<div class="column span-17 last">
<div>
<h2>Welcome to your project!</h2>
<p>
<div>
Welcome to mywebapp at <span id="time">Wed Aug 10 10:23:43 EDT
2011</span>
</div>

<div>Click this button to log in to the site.
</div>

<div>
<form action="/mywebapp/" method="post">
<input name="F950150339046VJJJN1" value="Submit" type="submit" />
</form>
</div>
</p>
</div>
</div>

<hr />
<div style="text-align: center" class="column span-23 last">
<h4 class="alt">
<a href="http://www.liftweb.net"><i>Lift</i></a>
is Copyright 2007-2010 WorldWide Conferencing, LLC.
Distributed under an Apache 2.0 License.</h4>
</div>

</div>
<script type="text/javascript"> <!-- js snipped -->
</script></body>
</html>




On Aug 10, 10:04 am, Diego Medina <di...@fmpwizard.com> wrote:
> On Wed, Aug 10, 2011 at 9:47 AM, Felix <terkh...@gmail.com> wrote:
> > Hi Diego,
>
> >  Thanks for taking the time to respond.  It looks like commenting the
> > security portions of the web.xml don't seem to have an effect.
>
> >  I set the sitemap function as such:
>
> > def sitemap() = SiteMap(
> >      Menu("Home") / "l" / "index" >> User.AddUserMenusAfter, //
> > Simple menu
> > form
> >      // Menu with special Link
> >      Menu(Loc("Static", Link(List("static"), true, "/static/index"),
> >               "Static Content")))
>
> >  And with the LiftFilter url-pattern of "/l/*" in place, when I visit
> > the front page of my site (http://mysite.edu/webapp/), I still see a
> > broken home page as defined in my Lift framework.  When I visit what I
> > *think* should be the front page of my lift site (http://mysite.edu/
> > webapp/l   orhttp://mysite.edu/webapp/l/index), I still receive the
> > Lift error message "The Requested URL /mywebapp/l was not found on
> > For more options, visit this group athttp://groups.google.com/group/liftweb?hl=en.

Felix

unread,
Aug 10, 2011, 11:13:07 AM8/10/11
to Lift
This is likely WAY too much information, but at least you can't fault
me for not being thorough. ;) I've tried all these variations with
the SiteMap set as below, and I'm still coming up with a blank on the
answer to a basic question -- how do I set my default page to be /
mywebapp/l/index or /mywebapp/l instead of simply /mywebapp, and
how to I get this to play nicely with the tomcat-level LiftFilter
defined in web.xml?

def optionOneSitemap() = SiteMap(
Menu("Home") / "index" >> User.AddUserMenusAfter, // Simple menu
form
// delete me -- Menu("Request Credential") / "reqcred" >>
User.AddUserMenusAfter,
// three entries below shouldn't be necessary as they are REST
URLs?
/*
Menu("Ready URL") / "ready" >> User.AddUserMenusAfter,
Menu("Success URL") / "success" >> User.AddUserMenusAfter,
Menu("Failure URL") / "failure" >> User.AddUserMenusAfter,
*/
// Menu with special Link
Menu(Loc("Static", Link(List("static"), true, "/static/index"),
"Static Content")))

def optionTwoSitemap() = SiteMap(
Menu("Home") / "l/index" >> User.AddUserMenusAfter, // Simple
menu form
// Menu with special Link
Menu(Loc("Static", Link(List("static"), true, "/static/index"),
"Static Content")))

def optionThreeSitemap() = SiteMap(
Menu("Home") / "l" / "index" >> User.AddUserMenusAfter, //
Simple menu form
// Menu with special Link
// Menu with special Link
Menu(Loc("Static", Link(List("static"), true, "/static/index"),
"Static Content")))

// DONE: Tested options one, two, and three above with LiftFilter url-
pattern defined as "/l/*"
// DONE: Tested against base URLs of: /, /l, /l/index, /static/
index, /l/static/index

def optionFourSitemapWithLoc() = SiteMap(
//Menu("Home") / "l" / "index" >> User.AddUserMenusAfter,
Menu(Loc("Home", Link(List("index"), true, "/l/index"),
"Home")),
// Menu with special Link
// Menu with special Link
Menu(Loc("Static", Link(List("static"), true, "/l/static/
index"),
"Static Content")))

def optionFiveSitemapWithLoc() = SiteMap(
//Menu("Home") / "l" / "index" >> User.AddUserMenusAfter,
Menu(Loc("Home", Link(List("index"), true, "/index"), "Home")),
// Menu with special Link
// Menu with special Link
Menu(Loc("Static", Link(List("static"), true, "/static/index"),
"Static Content")))

// DONE: Tested options Four and Five with Loc instead of Menu

def optionSixSitemapWithMenu() = SiteMap(
Menu.i("Home") / "index" >> User.AddUserMenusAfter,
// Menu with special Link
// Menu with special Link
Menu(Loc("Static", Link(List("static"), true, "/static/index"),
"Static Content")))

def optionSevenSitemapWithMenu() = SiteMap(
Menu.i("Home") / "l" / "index" >> User.AddUserMenusAfter,
// Menu with special Link
// Menu with special Link
Menu(Loc("Static", Link(List("static"), true, "/static/index"),
"Static Content")))

def optionEightSitemapWithMenu() = SiteMap(
Menu.i("Home") / "l/index" >> User.AddUserMenusAfter,
// Menu with special Link
// Menu with special Link
Menu(Loc("Static", Link(List("static"), true, "/static/index"),
"Static Content")))

// DONE: Test with Menu.i:
// mywebapp/static WORKS for options Six, Seven
// Option Eight untested but it's a bad option anyway

// DONE for OptionOne: Test with LiftFilter off for behavior check on
Menu --


// See exploring lift index-7 (Loc Link) for more about getting Loc
Link correct

def optionNineSitemapWithLoc() = SiteMap(
Menu(Loc("Home", new Link("l" :: "index" :: Nil, false), "Home
page")),
// Menu with special Link
Menu(Loc("Static", Link(List("static"), true, "/l/static/
index"),
"Static Content")))

// DONE: Tested option nine, doesn't work

def optionTenSitemapSingleMenuWithLocs() = {
// TESTED: This option causes a crash when surfing to any /l/
// URL.... "javax.servlet.ServletException: Filter execution
threw an exception
// root cause: net.liftweb.sitemap.SiteMapException: Location
Login defined
// twice Loc(Login,...)

// Still see broken HTML at /mywebapp/
logger.info("defining Loc, Menu, and Sitemap")
val myLoc = Loc("Home", new Link("l" :: "index" :: Nil, false),
"Index")
val myMenu = Menu(myLoc)
val allMenus = myMenu :: User.menus
SiteMap(allMenus: _*)
}

def optionElevenSitemapSingleMenuWithLocs() = {
// TESTED: Accessing URLs with base /mywebapp/l/ does not
// cause the SiteMapException shown in #10 as the User menu was
// removed. However, visiting the front page is still showing
// the wrong HTML output.

logger.info("defining Loc, Menu, and Sitemap")
val myLoc = Loc("Home", new Link("l" :: "index" :: Nil, false),
"Index")
val myMenu = Menu(myLoc)
val allMenus = myMenu :: Nil
SiteMap(allMenus: _*)
> ...
>
> read more »

Felix

unread,
Aug 10, 2011, 11:35:08 AM8/10/11
to Lift
Hi Diego,

Again -- big thanks for taking a look at this. Now, line up and get
ready to throw your brick at me. *grin*

I did some RTFM and found that I didn't have a webapps/l/index.html
defined at any point during this little exercise. As soon as I did
that, access to /mywebapp/l/index.html resolved.

I'm working with the SiteMap now to get it cleaned up, but I think
the worst is over.

Cheers,
Felix
> ...
>
> read more »

Diego Medina

unread,
Aug 10, 2011, 11:36:20 AM8/10/11
to lif...@googlegroups.com
Ok, how about on your lift app, go a create a folder I and have all
your files inside there? I know it is not ideal, but just to see if it
works. It is weird that the Liftrule is not being called.

And that the soround template does not show on your original try at
http://host/I/index

Diego Medina

unread,
Aug 10, 2011, 11:37:53 AM8/10/11
to lif...@googlegroups.com
On Wed, Aug 10, 2011 at 11:35 AM, Felix <terk...@gmail.com> wrote:
> Hi Diego,
>
>  Again -- big thanks for taking a look at this.  Now, line up and get
> ready to throw your brick at me.  *grin*
>

I'm glad it is all working now, good luck on your project and don't
worry, I have done mistakes like that and worse many times :)

Regards,

Diego

P.S. It was nice to see that you *really* tried different things to
solve your issue

Reply all
Reply to author
Forward
0 new messages