embed-apache-tomcat-core

Embed Apache Tomcat

License

License

Categories

Categories

Tomcat Container Application Servers
GroupId

GroupId

org.pidster
ArtifactId

ArtifactId

embed-apache-tomcat-core
Last Version

Last Version

0.2
Release Date

Release Date

Type

Type

jar
Description

Description

embed-apache-tomcat-core
Embed Apache Tomcat
Project URL

Project URL

http://pidster.org
Source Code Management

Source Code Management

https://github.com/pidster-dot-org/embed-apache-tomcat

Download embed-apache-tomcat-core

How to add to project

<!-- https://jarcasting.com/artifacts/org.pidster/embed-apache-tomcat-core/ -->
<dependency>
    <groupId>org.pidster</groupId>
    <artifactId>embed-apache-tomcat-core</artifactId>
    <version>0.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.pidster/embed-apache-tomcat-core/
implementation 'org.pidster:embed-apache-tomcat-core:0.2'
// https://jarcasting.com/artifacts/org.pidster/embed-apache-tomcat-core/
implementation ("org.pidster:embed-apache-tomcat-core:0.2")
'org.pidster:embed-apache-tomcat-core:jar:0.2'
<dependency org="org.pidster" name="embed-apache-tomcat-core" rev="0.2">
  <artifact name="embed-apache-tomcat-core" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.pidster', module='embed-apache-tomcat-core', version='0.2')
)
libraryDependencies += "org.pidster" % "embed-apache-tomcat-core" % "0.2"
[org.pidster/embed-apache-tomcat-core "0.2"]

Dependencies

compile (17)

Group / Artifact Type Version
org.apache.tomcat : tomcat-jasper jar 8.0.0-RC5
org.apache.tomcat : tomcat-servlet-api jar 8.0.0-RC5
org.apache.tomcat : tomcat-websocket jar 8.0.0-RC5
org.apache.tomcat : tomcat-jasper-el jar 8.0.0-RC5
org.apache.tomcat : tomcat jar 8.0.0-RC5
org.apache.tomcat : tomcat-jsp-api jar 8.0.0-RC5
org.apache.tomcat : tomcat-tribes jar 8.0.0-RC5
org.apache.tomcat : tomcat-spdy jar 8.0.0-RC5
org.apache.tomcat : tomcat-juli jar 8.0.0-RC5
org.apache.tomcat : tomcat-util jar 8.0.0-RC5
org.apache.tomcat : tomcat-catalina jar 8.0.0-RC5
org.apache.tomcat : tomcat-websocket-api jar 8.0.0-RC5
org.apache.tomcat : tomcat-api jar 8.0.0-RC5
org.apache.tomcat : tomcat-catalina-ha jar 8.0.0-RC5
org.apache.tomcat : tomcat-el-api jar 8.0.0-RC5
org.apache.tomcat : tomcat-coyote jar 8.0.0-RC5
org.apache.tomcat : tomcat-annotations-api jar 8.0.0-RC5

test (1)

Group / Artifact Type Version
junit : junit jar 4.11

Project Modules

There are no modules declared in this project.

Embed Apache Tomcat

Just like the name says, this project provides a fluent API for embedding Apache Tomcat.

Embed a Tomcat instance for testing using the following code, where MyContainerInitializer.class is a ServletContainerInitializer implementation used to programmatically bootstrap a Servlet 3.0 application.

Properties properties = new Properties();
properties.put("catalina.base", "build/resources/test");

Tomcat tomcat = new TomcatFactory(properties).create()
  .newMinimalServer(url.getPort())
      .createApplication("test-make-dirs")
      .makeDirs()
      .addServletContainerInitializer(MyContainerInitializer.class)
  .build();

Alternatively, add Servlet components individually:

Tomcat tomcat = new TomcatFactory(properties).create()
  .newMinimalServer(url.getPort())
      .createApplication("test")
      .addServletContextListener(DummyListener.class)
      .addServletFilter(DummyFilter.class, "/*")
      .addServlet(DummyServlet.class, "/dummy")
  .build();

These minimal Tomcat instances are examples of minimal configurations, but the container can be configured entirely programmatically, specifying Valves, Connectors, LifecycleListeners etc as required.

Testing usage

You can embed Tomcat in a unit test (e.g. JUnit) as follows:

public class SomeTest {

    private TomcatRuntime runtime;

    @Before
    public void setupTomcat() throws Exception {

        Tomcat tomcat = new TomcatFactory().create()
            .newMinimalServer(8082)
                .createApplication("test")
                .addServlet(DummyServlet.class, "/dummy")
            .build();

        this.runtime = tomcat.start(5000L);  // wait for start
    }

    @Test
    public void testServlet() throws Exception {
    	// do some HTTP tests
    }

    @After
    public void teardown() {
        runtime.stop(5000L); // wait for stop
    }
}

Build configuration

Using Gradle and the current snapshot, the dependency is:

repositories {
    mavenCentral()
}

dependencies {
	    compile "org.pidster:embed-apache-tomcat-core:0.2"
}
org.pidster

Pidster.org

Versions

Version
0.2
0.1-ALPHA