pedestal / pedestal

The Pedestal Server-side Libraries
http://pedestal.io/
2.69k stars 296 forks source link

war-example will not run #529

Open bherrmann7 opened 7 years ago

bherrmann7 commented 7 years ago

Description

war-example doesnt seem to deploy on Tomcat

Expected Behavior

Browser should display "Hello World!"

Actual Behavior

Type Exception Report

Message Failed to load namespace 'war-example.server'

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

javax.servlet.ServletException: Failed to load namespace 'war-example.server'
io.pedestal.servlet.ClojureVarServlet.getVar(ClojureVarServlet.java:111)
io.pedestal.servlet.ClojureVarServlet.init(ClojureVarServlet.java:67)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)

Steps to reproduce

Environment

Operating System (including version).

$ cat /etc/issue
OSX 10.13.4

Your current Leiningen version (lein --version)

Leiningen 2.7.1 on Java 1.8.0_131 Java HotSpot(TM) 64-Bit Server VM

Pedestal version

github master

Detailed Steps

$ git clone https://github.com/pedestal/pedestal
$ cd pedestal/samples/war-example
$ lein pedestal uberwar
$ wget http://supergsego.com/apache/tomcat/tomcat-9/v9.0.7/bin/apache-tomcat-9.0.7.tar.gz
$ tar xvfz apache-tomcat-9.0.7.tar.gz
$ cp target/war-example-0.5.1-standalone.war apache-tomcat-9.0.7/webapps/we.war
$ ./apache-tomcat-9.0.7/bin/startup.sh
$  open  http://localhost:8080/we
mtnygard commented 7 years ago

Did you I comment the "war changes" in server.clj as instructed in the reader?

mtnygard commented 7 years ago

I meant "uncomment." Trying to respond via a mobile.

bherrmann7 commented 7 years ago

The war-example, aka pedestal/samples/war-example, already has those uncommented.

ohpauleez commented 7 years ago

I'll take a look at this on Monday. Thanks Bob!

bherrmann7 commented 6 years ago

verified on osx today, still broken

bherrmann7 commented 6 years ago

For giggles I updated all references of "0.5.1" in the project.clj to "0.5.3" - but this was in vain. At first the error message's rootCause referenced Jetty. So I uncommented,

      ;;  :java-agents [[org.mortbay.jetty.alpn/jetty-alpn-agent "2.0.3"]]

from the profile.clj

and now I'm back again with...

    Root Cause

java.lang.IllegalStateException: Attempting to call unbound fn: #'war-example.server/servlet-init
    clojure.lang.Var$Unbound.throwArity(Var.java:43)
    clojure.lang.AFn.invoke(AFn.java:36)
    clojure.lang.Var.invoke(Var.java:383)
    io.pedestal.servlet.ClojureVarServlet.init(ClojureVarServlet.java:75)
    javax.servlet.GenericServlet.init(GenericServlet.java:158)
        ...

A quick look in the war file did not turn up anything odd. Specifically,

$  unzip -v target/war-example-0.5.3-standalone.war |grep '.clj$'
    1837  Defl:N      754  59% 04-15-2018 11:18 73814d4f  WEB-INF/classes/war_example/server.clj
    2764  Defl:N     1012  63% 04-15-2018 11:18 7912ec1e  WEB-INF/classes/war_example/service.clj
polvoblanco commented 6 years ago

I'm having the same issue with a new pedestal-service leiningen project. I have followed all the instructions in the Deploying a WAR File guide. The only change I made to the code other than what was in those instructions was to change the service http/type from jetty to tomcat.

After uploading the war file to an AWS Elastic Beanstalk Tomcat platform, when I first visit the site I get the error:

org.apache.catalina.core.StandardWrapperValve.invoke Allocate exception for servlet PedestalServlet
 java.io.FileNotFoundException: Could not locate io/pedestal/http/tomcat__init.class or io/pedestal/http/tomcat.clj on classpath.
    at clojure.lang.RT.load(RT.java:463)
    at clojure.lang.RT.load(RT.java:426)
    at clojure.core$load$fn__6548.invoke(core.clj:6046)
    at clojure.core$load.invokeStatic(core.clj:6045)
    at clojure.core$load.doInvoke(core.clj:6029)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core$load_one.invokeStatic(core.clj:5848)
    at clojure.core$load_one.invoke(core.clj:5843)
    at clojure.core$load_lib$fn__6493.invoke(core.clj:5888)
    at clojure.core$load_lib.invokeStatic(core.clj:5887)
    at clojure.core$load_lib.doInvoke(core.clj:5868)
    at clojure.lang.RestFn.applyTo(RestFn.java:142)
    at clojure.core$apply.invokeStatic(core.clj:659)
    at clojure.core$load_libs.invokeStatic(core.clj:5925)
    at clojure.core$load_libs.doInvoke(core.clj:5909)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.core$apply.invokeStatic(core.clj:659)
    at clojure.core$require.invokeStatic(core.clj:5947)
    at clojure.core$require.doInvoke(core.clj:5947)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at io.pedestal.http$server.invokeStatic(http.clj:337)
    at io.pedestal.http$server.invoke(http.clj:330)
    at io.pedestal.http$create_server.invokeStatic(http.clj:353)
    at io.pedestal.http$create_server.invoke(http.clj:348)
    at io.pedestal.http$create_server.invokeStatic(http.clj:350)
    at io.pedestal.http$create_server.invoke(http.clj:348)
    ...

After refreshing the page I then get the error:

org.apache.catalina.core.ApplicationContext.log StandardWrapper.Throwable
 java.lang.IllegalStateException: Attempting to call unbound fn: #'myapp.server/servlet-init
    at clojure.lang.Var$Unbound.throwArity(Var.java:45)
    at clojure.lang.AFn.invoke(AFn.java:36)
    at clojure.lang.Var.invoke(Var.java:385)
    at io.pedestal.servlet.ClojureVarServlet.init(ClojureVarServlet.java:75)
    at javax.servlet.GenericServlet.init(GenericServlet.java:158)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1188)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1132)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:811)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:676)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)
bherrmann7 commented 6 years ago

FYI: My project was just a small weekend project, so as a work around - I simply dropped back to using ring directly, https://github.com/weavejester/lein-ring

polvoblanco commented 6 years ago

Thanks, I'm only experimenting with Pedestal myself at the moment, we're looking to move a few functions from AWS Lambda to an always on micro-service as the start up time of Java and a Datomic connection is a major problem with Lambda. Pedestal may be overkill for what we need but I like the way it works. As AWS offers a ready to go Tomcat platform, I thought it was almost meant to be, but then I, like you, discovered there are some problems with Pedestals Tomcat implementation. If I do decide to go with Pedestal, which I am now forced to question seeing as this issue has gone unresolved for the best part of a year, there are of course other options to hosting it on AWS without Tomcat. Still, it would be nice if we could find a way to get this working.

ohpauleez commented 6 years ago

@polvoblanco Pedestal has a set of AWS Lambda tools that are incubating and will most likely be released in the next release. They're currently being used in production systems - perhaps that could help you.

I apologize that this issue has been unresolved for so long - I was unable to recreate it initially. It's not common to see WAR deployments of Pedestal services, so this got low priority. The thread here is reporting slightly different issues though, so it'll involve a bit of investigation.

polvoblanco commented 6 years ago

@ohpauleez Thanks for the reply, I was just a little concerned that the project was not getting updates - the Lambda tools sound very interesting. I don't mean to hijack this thread, but can I just ask what is the recommended approach to hosting Pedestal apps on AWS (Elastic Beanstalk / ECS)?

ohpauleez commented 6 years ago

@polvoblanco I think most people pick a deployment strategy that makes the most sense for their operations and system/service. It's most common to see people package everything up as an uberjar (complete with webserver) as the JVM artifact. Some use that as the deployment artifact and others repackage it into a something else (like a container). Deployment using this setup could be Beanstalk, ECS, EC2 using something like CodePipeline/CodeDeploy or Spinnaker. It's really only common to see WARs as artifacts in legacy systems.

polvoblanco commented 6 years ago

@ohpauleez Ahh, fair enough, my introduction to the whole Java ecosystem was with Clojure. That's great, many thanks.

bherrmann7 commented 6 years ago

"It's really only common to see WARs as artifacts in legacy systems." Yikes! Now I feel like a legacy system!

falberto commented 2 years ago

any news on this? Im facing the same issue with war-example

11/04/22 13:00:09.660 [APP/13-0] SYS   ###88F3DAF6FAAE4EBD93E2981C250E65BD##poc-pedestal#org.apache.juli.logging.DirectJDKLog########http-nio-127.0.0.1-50138-exec-3#PLAIN##
11/04/22 13:00:09.660 [APP/13-0] SYS   Allocate exception for servlet [PedestalWarExample]
11/04/22 13:00:09.660 [APP/13-0] SYS   java.lang.ClassNotFoundException: io.pedestal.servlet.ClojureVarServlet
11/04/22 13:00:09.660 [APP/13-0] SYS    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1358)
11/04/22 13:00:09.660 [APP/13-0] SYS    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1180)
11/04/22 13:00:09.660 [APP/13-0] SYS    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:545)
11/04/22 13:00:09.660 [APP/13-0] SYS    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:526)
11/04/22 13:00:09.660 [APP/13-0] SYS    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:150)
11/04/22 13:00:09.660 [APP/13-0] SYS    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1044)
11/04/22 13:00:09.660 [APP/13-0] SYS    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:763)
11/04/22 13:00:09.660 [APP/13-0] SYS    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:134)
11/04/22 13:00:09.660 [APP/13-0] SYS    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
11/04/22 13:00:09.660 [APP/13-0] SYS    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:544)
11/04/22 13:00:09.660 [APP/13-0] SYS    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
11/04/22 13:00:09.660 [APP/13-0] SYS    at com.sap.xs.java.valves.ErrorReportValve.invoke(ErrorReportValve.java:66)
11/04/22 13:00:09.660 [APP/13-0] SYS    at ch.qos.logback.access.tomcat.LogbackValve.invoke(LogbackValve.java:256)
11/04/22 13:00:09.660 [APP/13-0] SYS    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
11/04/22 13:00:09.660 [APP/13-0] SYS    at com.sap.xs.security.TenantIdValve.invoke(TenantIdValve.java:34)
11/04/22 13:00:09.660 [APP/13-0] SYS    at com.sap.xs.security.UserInfoValve.invoke(UserInfoValve.java:18)
11/04/22 13:00:09.660 [APP/13-0] SYS    at com.sap.xs.statistics.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:43)
11/04/22 13:00:09.660 [APP/13-0] SYS    at com.sap.xs.logging.catalina.RuntimeInfoValve.invoke(RuntimeInfoValve.java:42)
11/04/22 13:00:09.660 [APP/13-0] SYS    at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:764)
11/04/22 13:00:09.660 [APP/13-0] SYS    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
11/04/22 13:00:09.660 [APP/13-0] SYS    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:616)
11/04/22 13:00:09.660 [APP/13-0] SYS    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
11/04/22 13:00:09.660 [APP/13-0] SYS    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:831)
11/04/22 13:00:09.660 [APP/13-0] SYS    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1634)
11/04/22 13:00:09.660 [APP/13-0] SYS    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
11/04/22 13:00:09.660 [APP/13-0] SYS    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
11/04/22 13:00:09.660 [APP/13-0] SYS    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
11/04/22 13:00:09.660 [APP/13-0] SYS    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
11/04/22 13:00:09.660 [APP/13-0] SYS    at java.lang.Thread.run(Thread.java:836)
11/04/22 13:00:09.660 [APP/13-0] SYS
ddeaguiar commented 2 years ago

@falberto no additional news on this. Fixing the war examples is on the todo list but we haven't gotten to it yet.