Problem deploying to Tomcat - only getting source code of "not found" page

261 views
Skip to first unread message

zilti

unread,
Oct 30, 2011, 7:05:46 AM10/30/11
to clj-noir
Hi there,
I just started yesterday evening with Noir. I used the server/gen-
handler function to generate handlers for lein-ring, use ring 1.0.0-
RC1 and deploy to a Tomcat 6.
When running the application locally using "lein ring server" it works
great. But as soon as I deploy it as a war generated with "lein ring
uberwar" I get this: http://lyrion.ch/beta (a plain-text html-and-css-
code which is supposed to be the default 404 page I guess).
Is this my fault or is this a bug?

Chris Granger

unread,
Oct 30, 2011, 7:58:36 PM10/30/11
to clj-...@googlegroups.com
When I go to that page, it seems to be doing the right thing. Did you get this fixed?

zilti

unread,
Nov 5, 2011, 9:04:06 AM11/5/11
to clj-...@googlegroups.com
If you call "shows only the error page" "doing the right thing", then, yes, it's fixed. But actually it would be nice if I'd be able to show some content.

Mark Rathwell

unread,
Nov 5, 2011, 10:04:08 AM11/5/11
to clj-...@googlegroups.com
Hi,

Couple questions:

1. Can you describe your Tomcat environment? And do Java servlets run
fine there?
2. Have you ever run a Compojure app in this environment?
3. Last week, at the start of the day the Noir error page was being
returned as text/plain and later in the day it was text/html. What
change did you make for that to happen?
4. Also, last week, at the start of the day, your root url path was
returning the Noir error, in addition to '/beta', then later in the
day '/beta' was returning the Noir error page but '/' was returning a
Tomcat error page. What changed this?

At this point, I'm thinking it might be something with the context
path setup, but need more information.

- Mark

zilti

unread,
Nov 5, 2011, 10:51:43 AM11/5/11
to clj-...@googlegroups.com
Hi,

1. I use a private tomcat hosting. Tomcat Version is Tomcat 6 with Sun Java 6, I guess the settings are pretty much default - I could access and change them, but since I don't know what I'd be doing there, I've not touched it. Never tried "real" Java Servlets, but I ran a Scala Scalatra page on there which worked fine (same routing mechanism as Sinatra, Noir).

2. No.

3. Someone in #scala recommended me to add a middleware which changes the context type to text/html instead of the default (application/octet-stream I guess)

4. I removed the root Noir. It seemed that this somehow changed the appearance of the /beta noir page?

Mark Rathwell

unread,
Nov 5, 2011, 1:19:42 PM11/5/11
to clj-...@googlegroups.com
Can you add these two defpages to your app (if they don't exist) then
check your app again on Tomcat:

(defpage "/" []
"Hello World 1")

(defpage "/beta" []
"Hello World 2")

I'm assuming you are expecting http://lyrion.ch/beta to return "Hello
World 1" here, but it will return "Hello World 2". If this is the
case, see the thread below:

http://groups.google.com/group/clj-noir/browse_thread/thread/733de25ae7d3dc5e/3591f05ac4c2685a?show_docid=3591f05ac4c2685a

Chris Granger

unread,
Nov 5, 2011, 1:28:36 PM11/5/11
to clj-...@googlegroups.com
How are you including your pages? A war is a much more complicated environment than a jar, and as such requires you to load your view manually.


Cheers,
Chris.
Message has been deleted

Mark Rathwell

unread,
Dec 24, 2011, 10:43:20 AM12/24/11
to clj-...@googlegroups.com
Have you tried the previous suggestions (manually requiring your
views)? Also, is there a reason you need to add [ring "1.0.1"] to
your dependencies? That will likely cause problems unless you are
using the 1.3 branch of noir.

If these don't correct the problems, if you are able to push your
project to github, I can take a look at it.

- Mark

On Sat, Dec 24, 2011 at 8:15 AM, zilti <dzil...@gmail.com> wrote:
> Has there a solution been found for the problem since the last answer? Sorry
> for digging up this thread, but I didn't have time for working with noir for
> quite some time and now still have that problem. The whole thing does not
> even work locally anymore when adding the [ring "1.0.1"] dependency to the
> project.clj.

zilti

unread,
Dec 28, 2011, 6:32:23 AM12/28/11
to clj-...@googlegroups.com
I just restarted a blank project to find out how to get it to work with Tomcat. What I have now is basically this: https://gist.github.com/1527607
(Project was created with lein-noir 1.2.1).
The point is it still doesn't work... What do I exactly have to do? The links posted in this thread weren't of any help, and, to be honest, I appreciate your help, but I'm not really in the mood of playing around another whole day without finding a solution. It can't be that difficult, right?

Chris Granger

unread,
Dec 28, 2011, 10:46:53 AM12/28/11
to clj-...@googlegroups.com
I think there might be some miscommunication here. As I mentioned, since wars setup the classpath differently and include files in a different way, you cannot use

(server/load-views "src/lyrionch/views/")

That will not work and will result in you seeing a 404 if you're using 1.2.2, or a 500 if you're using 1.2.1. To fix this, you simply need to include the views explicitly in your ns decl:

(ns lyrionch.server
(:require [noir.server :as server]
[lyrionch.views.welcome]
[lyrionch.views.whatever-other-views-I-have))

;;(server/load-views "src/lyrionch/views/")
(def handler (server/gen-handler {:mode :dev
:ns 'lyrionch}))

Cheers,
Chris.

Benoit Picaud

unread,
Dec 30, 2011, 3:23:47 AM12/30/11
to clj-...@googlegroups.com

Hi Chris, all,

I'm following this thread with a lot of interest since I'm quite stuck at the exact same place. 

Here is my project.clj
(defproject testsite "0.1.0-SNAPSHOT"
            :description "Test application for noir"
            :dependencies [[org.clojure/clojure "1.3.0"]
                           [noir "1.2.2-SNAPSHOT"]] ;; to ease war creation
            :dev-dependencies [[lein-ring "0.5.2"]]
            :ring {:handler testsite.server/handler
                   :url-pattern "/testsite/*"}
            :main testsite.server)

This is what I have in my server.clj:

(ns testsite.server
  (:require [noir.server :as server]
            [testsite.views.common]
            [testsite.views.welcome]))

; (server/load-views "src/testsite/views/")

(defn -main [& m]
  (let [mode (keyword (or (first m) :dev))
        port (Integer. (get (System/getenv) "PORT" "8080"))]
    (server/start port {:mode mode
                        :ns 'testsite})))

(def handler (server/gen-handler {:mode :dev
                                  :ns 'testsite}))


And I've the strange feeling that I can't follow more strictly your instructions and I'm sure I'll fell terribly wrong in a few moments.

This is how I create my war: 
rm -f testsite.war ; lein ring war testsite.war && scp testsite.war server:

On the server the war is deployed on /var/lib/tomcat6/webapps (debian stable). 
I've tried to deploy the war through the manager as well with no more luck.

When I connect to server:8080/testsite/ I've the following error:
HTTP Status 404 - /testsite/
type Status report
message /testsite/
description The requested resource (/testsite/) is not available.
Apache Tomcat/6.0.28

The permissions of the /testsite dir loo right (tomcat6).

I suspected the :url-pattern thing [1] so I removed the :url-pattern from the project.clj
rebuilt the war and deployed in under ROOT/

I've a different error message now: 
HTTP Status 404 - Servlet testsite.server/handler servlet is not available
type Status report
message Servlet testsite.server/handler servlet is not available
description The requested resource (Servlet testsite.server/handler
servlet is not available) is not available.

The reason why I'm confused is that of course the testsite app is working fine in my REPL (Emacs/swank with clojure-swank-in). 

Any help or clue would be much appreciated! 

Thank you all for the pleasure of working with this environment and have a great season holidays. 

  -- Ben


 [1] despite the fact that url-pattern seemed to work: here is the resulting web.xml
$ cat testsite/WEB-INF/web.xml 
<web-app><servlet><servlet-name>testsite.server/handler servlet</servlet-name><servlet-class>testsite.servlet</servlet-class></servlet><servlet-mapping><servlet-name>testsite.server/handler servlet</servlet-name><url-pattern>/testsite/*</url-pattern></servlet-mapping></web-app>

Benoit Picaud

unread,
Dec 30, 2011, 3:32:14 AM12/30/11
to clj-...@googlegroups.com

I suspected the :url-pattern thing [1] so I removed the :url-pattern from the project.clj
rebuilt the war and deployed in under ROOT/


My bad on this particular section. 
Actually when I do :
- lein ring uberwar testsite.war
- without the :url-pattern in the project.clj
- and deploy it in the tomcat/webapps/ROOT directory

It's just working fine.
When I add it to the uberwar and deploy it under /testsite/ 
I still have the HTTP Status 404 - /testsite/

My actual question is in fact: how to make :url-pattern to work?

Many thanks! 

Ben
 

Chris Granger

unread,
Dec 30, 2011, 11:47:43 AM12/30/11
to clj-...@googlegroups.com
Did you try deploying it outside of root without the :url-pattern? I've never heard of that option and it seems to work for me without it. Though I admittedly know very little about tomcat.

Cheers,
Chris.

Mark Rathwell

unread,
Dec 30, 2011, 12:12:05 PM12/30/11
to clj-...@googlegroups.com
It's been a long time since I've done anything with context paths, but
I think url-pattern is relative to the current context path. So, if
your current context path is /testsite, then you would want
url-pattern to be /*, which is the default in lein-ring, so you don't
actually need to specify it.

Benoit Picaud

unread,
Dec 30, 2011, 12:18:37 PM12/30/11
to clj-...@googlegroups.com
On Fri, Dec 30, 2011 at 5:47 PM, Chris Granger <ibd...@gmail.com> wrote:
Did you try deploying it outside of root without the :url-pattern? I've never heard of that option and it seems to work for me without it. Though I admittedly know very little about tomcat.


Hi Chris! 

thanks for your email.

Yes, that the first thing I did before investigating the :url-pattern thing. 
Conditions: 
- project.clj does NOT refer to :url-pattern 
- war created with lein ring uberwar testsite.war
- as expected in the generated TOMCAT/webapps/testsite/WEB-INF/web.xml we find <url-pattern>/*</url-pattern>

Results:
Executive Summary: there's something wrong with paths and I suspect url-pattern. 

Longer explanation: 

the app looks OK! but just for a few milliseconds.  
The reason is '/' is configured to redirect to '/identity' if a parameter is missing in the session

Part of the source: 

(defpage "/" []
 (...)
   (if ;; something we expect is present
      (common/layout ;; render the page ; (...)
   (resp/redirect "/identity")))) ;; else branch

So when I connect to the app. '/ ' redirects to '/identity'

The URL http://server/ seems to work well since I got the following error message from Tomcat:
HTTP Status 404 - /identity

The fact that '/' redirects to '/identity' is a sign that the app is working fine.
The fact that '/identity' triggers 404 seems to indicate that this app is not sandboxed or contained into the TOMCAT/webapps/testsite/ directory. 


Kindest regards

Ben



 

Chris Granger

unread,
Dec 30, 2011, 12:29:25 PM12/30/11
to clj-...@googlegroups.com
Ah, when you start your server, you need to add the :base-url option 

(server/start 8080 {:base-url "/testsite"})

Cheers,
Chris.

Benoit Picaud

unread,
Dec 30, 2011, 3:26:08 PM12/30/11
to clj-...@googlegroups.com
On Fri, Dec 30, 2011 at 6:29 PM, Chris Granger <ibd...@gmail.com> wrote:
Ah, when you start your server, you need to add the :base-url option 

(server/start 8080 {:base-url "/testsite"})



Oh thanks Chris! I did not know this one. 
I'm afraid it didn't change the '/identity' 404 redirect. 

For the records here's my server.clj
(ns testsite.server
  (:require [noir.server :as server]
            [testsite.views.common]
            [testsite.views.welcome]))
; (server/load-views "src/testsite/views/") ;; this one is commented out
(defn -main [& m]
  (let [mode (keyword (or (first m) :dev))
        port (Integer. (get (System/getenv) "PORT" "8080"))]
    (server/start port {:mode mode
                        :base-url "/testsite" ;; as Chris suggested 
                        :ns 'testsite})))
(def handler (server/gen-handler {:mode :dev
                                  :ns 'testsite}))

my project.clj
(defproject testsite "0.1.0-SNAPSHOT"
            :description "Test application for noir"
            :dependencies [[org.clojure/clojure "1.3.0"]
                           [noir "1.2.2-SNAPSHOT"]]
            :dev-dependencies [[lein-ring "0.5.2"]]
            :ring {:handler testsite.server/handler}
;                   :url-pattern "/testsite/*"} ;; this one is commented out as well
            :main testsite.server)

and the lein command to create the war: 
lein ring uberwar testsite.war

I made sure to explicitly stop and start tomcat and close and start a new firefox to avoid any caching issue, and got the same old HTTP Status 404 - /identity from Tomcat. 

Quite puzzling. 

Ben


Mark Rathwell

unread,
Dec 30, 2011, 4:25:05 PM12/30/11
to clj-...@googlegroups.com
Move the :base-url option to your handler var, as shown below. -main,
in this case, is used to starte the dev server. handler is the ring
handler you have specified in project.clj that will be used by tomcat.

(defn -main [& m]
  (let [mode (keyword (or (first m) :dev))
        port (Integer. (get (System/getenv) "PORT" "8080"))]
    (server/start port {:mode mode

                        :ns 'testsite})))

(def handler (server/gen-handler
{:mode :dev

:base-url "/testsite"
                     :ns 'testsite}))

Benoit Picaud

unread,
Dec 31, 2011, 1:57:42 PM12/31/11
to clj-...@googlegroups.com


(def handler (server/gen-handler
                   {:mode :dev
                    :base-url "/testsite"


 Thank you Mark! 
:base-url configured in the handler is the solution to contain the app in a directory with Tomcat.

I've googled quite a bit on this one so Google, please, mentions to the world that the case is [RESOLVED]! 

Thank you all! 

  -- Ben


Reply all
Reply to author
Forward
0 new messages