tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maxim Solodovnik <solomax...@gmail.com>
Subject Re: Start embedded Tomcat 9.0.1 server from java code
Date Wed, 08 Nov 2017 13:50:26 GMT
Thanks a lot for the review Konstantin,
I have correct our tests :)

Will Also contact CXF project
This code was taken from their tests: [1] :))

[1]
https://github.com/apache/cxf/blob/master/systests/cdi/base/src/main/java/org/apache/cxf/systests/cdi/base/tomcat/AbstractTomcatServer.java#L45


On Wed, Nov 8, 2017 at 6:08 PM, Konstantin Kolinko <knst.kolinko@gmail.com>
wrote:

> I have several comments on
> [1] https://github.com/apache/openmeetings/blob/master/
> openmeetings-web/src/test/java/org/apache/openmeetings/webservice/
> AbstractWebServiceTest.java#L98
>
>
> 2017-11-07 20:07 GMT+03:00 Tobias Soloschenko
> <tobiassoloschenko@googlemail.com>:
> > Hi Maxim,
> >
> > same for me I just created a simple setup like this:
> >
> >         String baseDir =".";
> >         String webappDirLocation = "src/main/webapp/";
> >         String webxmlDirLocation = "src/main/webapp/WEB-INF/web.xml";
> >         Tomcat tomcat = new Tomcat();
> >         tomcat.setPort(8080);
>
> 1) Maybe you will want to update the test to use a random port number,
> so that several tests could be run in parallel.
>
> Use connector.setPort(0) to enable random port number feature (see
> TomcatBaseTest.setUp())
> followed by connector.getLocalPort(); after startup  (see
> TomcatBaseTest.getPort())
>
> http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/
> catalina/startup/TomcatBaseTest.java?revision=1812119&view=markup#l146
>
> An example of a simple test case and use of getPort():
> http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/
> catalina/startup/TestTomcat.java?revision=1769263&view=markup#l189
>
> 2) Tomcat tests use address="localhost" on connector.
> See TomcatBaseTest.setUp()
>
> Running with localhost avoids opening ports on a public interface.
>
> (When running on Windows its Firewall pops up a dialog and asks
> whether to allow network access for this software.
> Using localhost avoid this dialog.)
>
> >         tomcat.setBaseDir(baseDir);
> >         tomcat.getHost().setAppBase(baseDir);
> >         tomcat.getHost().setDeployOnStartup(true);
> >         tomcat.getHost().setAutoDeploy(true);
> >         tomcat.enableNaming();
> >         StandardContext ctx = (StandardContext)
> tomcat.addWebapp("/project", new File(webappDirLocation).
> getAbsolutePath());
> >         File additionWebInfClasses = new File("target/classes");
> >         WebResourceRoot resources = new StandardRoot(ctx);
> >         resources.addPreResources(new DirResourceSet(resources,
> "/WEB-INF/classes",
> >                 additionWebInfClasses.getAbsolutePath(), "/"));
> >         ctx.setResources(resources);
> >         ctx.setDefaultWebXml(new File(webxmlDirLocation).
> getAbsolutePath());
> >         tomcat.start();
> >         tomcat.getServer().await();
> >
>
> 3) In an automated test both "deployOnStartup" and "autoDeploy" flags
> should be set to "false".
>
> Do you want that any random files and directories created in a
> temporary directory (baseDir) to be auto-deployed
> and exposed as web applications in Tomcat?  I guess that you do not
> want that, so set those flags to false.
>
> Tomcat.addWebapp explicitly configures a web application.
> Auto-deployment is not needed.
>
> > I just placed in a Servlet into my classpath and applied the mapping in
> the web.xml - with the dependencies of tomcat-embed-core and
> tomcat-embed-jasper of version 9.0.1 it is not working and with 8.5.23 it
> does.
> >
> > Here is the log of both.
> > [...]
>
> Best regards,
> Konstantin Kolinko
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


-- 
WBR
Maxim aka solomax

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message