Je commence EMBEDDED Jetty avec ce code:Jetty signale de manière incorrecte enFonctionnement d'état() et isFailed()
Server server = new Server(8080);
MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
server.addBean(mbContainer);
WebAppContext webapp = new WebAppContext("/home/igor/projects/javalite/activeweb-simple/src/main/webapp/", "/");
server.setHandler(webapp);
server.start();
Thread.sleep(10000);
System.out.println("Failed: " + server.isFailed());
System.out.println("Running: " + server.isRunning());
System.out.println("Started: " + server.isStarted());
System.out.println("Stopped: " + server.isStopped());
server.join();
Le Webapp je déploiement lève une intentionnelleRuntimeException
pendant méthode ServletFilter.init()
.
Quand je démarre le serveur, je reçois la sortie suivante:
526 [main] WARN org.eclipse.jetty.webapp.WebAppContext - Failed startup of context o.e.j.w.WebAppContext{/,file:/home/igor/projects/javalite/activeweb-simple/src/main/webapp/},/home/igor/projects/javalite/activeweb-simple/src/main/webapp/
org.javalite.activeweb.InitException: Failed to create and init a new instance of class: app.config.AppBootstrap: class java.lang.RuntimeException:Fail!
at app.config.AppBootstrap.init(AppBootstrap.java:32)
at org.javalite.activeweb.RequestDispatcher.initAppConfig(RequestDispatcher.java:134)
at org.javalite.activeweb.RequestDispatcher.initApp(RequestDispatcher.java:70)
at org.javalite.activeweb.RequestDispatcher.init(RequestDispatcher.java:64)
at org.eclipse.jetty.servlet.FilterHolder.doStart(FilterHolder.java:118)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:770)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:265)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1242)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
at org.eclipse.jetty.server.Server.doStart(Server.java:282)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at app.controllers.SimpleTest.test(SimpleTest.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.RuntimeException: Fail!
... 42 more
543 [main] INFO org.eclipse.jetty.server.AbstractConnector - Started [email protected]:8080
Failed: false
Running: true
Started: true
Stopped: false
D'après ce que je peux voir, le server.start();
est syncronous, et mon application omet pendant cet appel.
Comme vous pouvez le voir, l'application ne démarre pas. Cependant, les valeurs d'état "failed", "running", "started" ne sont pas correctes!
Mon application n'est pas opérationnelle (intentionnellement) et le serveur a reçu une exception au démarrage, mais il signale que tous les bons.
Ce dont j'ai besoin est: démarrez le serveur et assurez-vous qu'il a correctement démarré la webapp avant d'aller plus loin.
Comment puis-je tester que le serveur a démarré et déployé avec succès mon application?
EDIT: dépendances pertinentes:
<dependency>
<groupId>org.eclipse.jetty.aggregate</groupId>
<artifactId>jetty-webapp</artifactId>
<version>8.1.20.v20160902</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jmx</artifactId>
<version>8.1.20.v20160902</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
cela a du sens. Malheureusement, après avoir changé pour: System.out.println ("Failed:" + webapp.isFailed()); System.out.println ("Exécution:" + webapp.isRunning()); System.out.println ("Started:" + webapp.isStarted()); System.out.println ("Arrêté:" + webapp.isStopped()); Je reçois encore cette sortie: Échec: false course: true Commencé vrai Stopped: false Désolé pour le formatage, SO! – ipolevoy
merci pour la mise à jour, cela fonctionne! Les docs de la jetée ne sont pas si bons. Les deux 'isAvailable()' et 'getUnavailableException()' font ce qui est requis. – ipolevoy
Vous pouvez également faire échouer la webapp avec 'webappcontext.setThrowUnavailableOnStartupException (true)' –