Does Menu.param allow relative paths? (i.e. varying context roots)

73 views
Skip to first unread message

opyate

unread,
Apr 6, 2011, 9:07:45 AM4/6/11
to lif...@googlegroups.com
Hi Lifters,

I built https://github.com/dpp/simply_lift/tree/master/samples/shopwithme and it runs perfectly with Jetty, but when deployed to Tomcat it now has a different context root, and the links don't work:

This works (with sbt jetty):

This doesn't work (deployed to Tomcat -- note the context):

Naftoli mentioned rewriting the context here: https://groups.google.com/d/msg/liftweb/MJLP-F32fsQ/dVqb6oq6jqQJ
...but the context may vary a lot in my case (e.g. example.com/app and example.com/app-beta and example.com/some-random-shop-name)

Does the code from the shopwithme example allow relative paths?

def menu = Menu.param[Item]("Item", Loc.LinkText(i => Text(i.name)),
                              Item.find _, _.id) / "item" / *

I've had success in the past with Menu.i and LiftRules.setSiteMap but the code above uses Menu.param and LiftRules.setSiteMapFunc 

Thanks,
Juan

PS The issue of context root is not new, but these pose solutions not suited to my needs, or have unanswered questions:

David Pollak

unread,
Apr 6, 2011, 9:34:18 AM4/6/11
to lif...@googlegroups.com
Lift correctly supports different context paths.  Lift correctly rewrite URLs relative to the context path.

If you are seeing an example of this not happening, please put together a reproducible example and we'll look at it.

--
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.



--
Lift, the simply functional web framework http://liftweb.net

opyate

unread,
Apr 6, 2011, 10:15:08 AM4/6/11
to lif...@googlegroups.com
On Wednesday, April 6, 2011 2:34:18 PM UTC+1, David Pollak wrote:
Lift correctly supports different context paths.  Lift correctly rewrite URLs relative to the context path.

If you are seeing an example of this not happening, please put together a reproducible example and we'll look at it.

I just used your example, David:

Then:

sbt package
Deploy to Tomcat.
Works fine, but click on "Item" in the left-side menu... 

E.g.
[15:13:26] juanuys:~ $ curl -X GET http://localhost:8080/shop-with-me_2.8.1-0.1/item/
<!DOCTYPE html>
<html> <body>The Requested URL /shop-with-me_2.8.1-0.1/item/ was not found on this server</body> </html>  
  %                                                                                                                                                                                                              [15:13:32] juanuys:~ $

Thanks,
Juan

David Pollak

unread,
Apr 6, 2011, 12:33:29 PM4/6/11
to lif...@googlegroups.com
On Wed, Apr 6, 2011 at 7:15 AM, opyate <opy...@gmail.com> wrote:
On Wednesday, April 6, 2011 2:34:18 PM UTC+1, David Pollak wrote:
Lift correctly supports different context paths.  Lift correctly rewrite URLs relative to the context path.

If you are seeing an example of this not happening, please put together a reproducible example and we'll look at it.

I just used your example, David:
Then:

sbt package
Deploy to Tomcat.
Works fine, but click on "Item" in the left-side menu... 

E.g.
[15:13:26] juanuys:~ $ curl -X GET http://localhost:8080/shop-with-me_2.8.1-0.1/item/
<!DOCTYPE html>
<html> <body>The Requested URL /shop-with-me_2.8.1-0.1/item/ was not found on this server</body> </html>  
  %                                                                                                                                                                                                              [15:13:32] juanuys:~ $


First, http://localhost:8080/shop-with-me_2.8.1-0.1/item/ is not a legal URL for the application.  It should be http://localhost:8080/shop-with-me_2.8.1-0.1/item (note the lack of trailing slash).

I just tried it with Jetty 7 and it worked for me (although I called the file shop.war).

Please try deploying the app with a name that does not contain '.' characters.  Please also try on Jetty 7.

opyate

unread,
Apr 6, 2011, 4:41:44 PM4/6/11
to lif...@googlegroups.com


First, http://localhost:8080/shop-with-me_2.8.1-0.1/item/ is not a legal URL for the application.  It should be http://localhost:8080/shop-with-me_2.8.1-0.1/item (note the lack of trailing slash).

I just tried it with Jetty 7 and it worked for me (although I called the file shop.war).

Please try deploying the app with a name that does not contain '.' characters.  Please also try on Jetty 7.

OK, very strange situation indeed. When I hover over the "Item" link in my browser, I can clearly see the link WITHOUT the trailing slash, but when I click on it, the browser adds the trailing slash. I tried with both (latest) Chrome and Firefox on Mac OS X. I deployed the WAR both in it's original form, and as swm.war
Even when I try to correct the URL in the browser (i.e. Ctrl-L, backspace once to remove the trailing slash) it rewrites with the trailing slash.

I hope someone else can reproduce this issue or perhaps shed some light as to why it is happening.


David Pollak

unread,
Apr 6, 2011, 5:43:04 PM4/6/11
to lif...@googlegroups.com

Okay... It's got nothing to do with the context path, it's a bug in Tomcat.

There's a directory named "item" as well as a file named "item.html"  For some reason, Tomcat is sending a 302 when the /shop/item path is accessed:

dpp@raptor:~$ telnet localhost 8080
Trying ::1...
Connected to localhost.
Escape character is '^]'.
GET /shop/item HTTP/1.0

HTTP/1.1 302 Moved Temporarily
Server: Apache-Coyote/1.1
Location: http://localhost:8080/shop/item/
Date: Wed, 06 Apr 2011 21:40:50 GMT
Connection: close

Connection closed by foreign host.

That's why the browser appears to append the / to /shop/item... the server it telling it to redirect.

Yet another reason not to use Tomcat.

 


--
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.

opyate

unread,
Apr 7, 2011, 7:02:08 AM4/7/11
to lif...@googlegroups.com

Yet another reason not to use Tomcat.



Thank so much for your time, David. I tested with Resin 4.0.16 too, and it works as perfectly as Jetty.

I'm going to give Tomcat the boot, but I'm still curious if someone out there knows what the issue with Tomcat is from the top of their head:
I just don't have time to dig through the Catalina sources right now.

Sander Mak

unread,
Apr 7, 2011, 7:23:18 AM4/7/11
to lif...@googlegroups.com
On Thu, Apr 7, 2011 at 1:02 PM, opyate <opy...@gmail.com> wrote:

> I just don't have time to dig through the Catalina sources right now.

Somebody seems to have done the digging for Tomcat 6:
http://stackoverflow.com/questions/2815986/where-does-tomcat-append-to-directory-paths

opyate

unread,
Apr 7, 2011, 7:35:14 AM4/7/11
to lif...@googlegroups.com
That's it! Brilliant -- thanks, Sander :-) 

Jeppe Nejsum Madsen

unread,
Apr 7, 2011, 7:36:40 AM4/7/11
to lif...@googlegroups.com
On Thu, Apr 7, 2011 at 1:02 PM, opyate <opy...@gmail.com> wrote:
>>

Seems to be a known issue that will not be fixed:
https://issues.apache.org/bugzilla/show_bug.cgi?id=32424

(Not sure if anything has changed for 6.x but it seems not :-)

/Jeppe

tain

unread,
Apr 30, 2011, 1:03:07 PM4/30/11
to Lift
Impacted same problem, just rename item.html -> items.html and in
AllItemsPage.scala item -> items,

finally it works perfectly in Tomcat :)
Reply all
Reply to author
Forward
0 new messages