MCPcopy Create free account
hub / github.com/apache/tomcat / Tomcat

Class Tomcat

java/org/apache/catalina/startup/Tomcat.java:135–1326  ·  view source on GitHub ↗

Minimal tomcat starter for embedding/unit tests. Tomcat supports multiple styles of configuration and startup - the most common and stable is server.xml-based, implemented in org.apache.catalina.startup.Bootstrap. This class is for use in apps that embed tomcat. Requirements: al

Source from the content-addressed store, hash-verified

133 * "https://gitbox.apache.org/repos/asf?p=tomcat.git;a=blob;f=test/org/apache/catalina/startup/TestTomcat.java">TestTomcat</a>
134 */
135public class Tomcat {
136
137 private static final StringManager sm = StringManager.getManager(Tomcat.class);
138
139 // Some logging implementations use weak references for loggers so there is
140 // the possibility that logging configuration could be lost if GC runs just
141 // after Loggers are configured but before they are used. The purpose of
142 // this Map is to retain strong references to explicitly configured loggers
143 // so that configuration is not lost.
144 private final Map<String,Logger> pinnedLoggers = new HashMap<>();
145
146 /**
147 * The embedded Server instance.
148 */
149 protected Server server;
150
151 /**
152 * The HTTP connector port.
153 */
154 protected int port = 8080;
155
156 /**
157 * The default hostname.
158 */
159 protected String hostname = "localhost";
160
161 /**
162 * The base directory for the embedded server.
163 */
164 protected String basedir;
165
166 private final Map<String,String> userPass = new HashMap<>();
167 private final Map<String,List<String>> userRoles = new HashMap<>();
168 private final Map<String,Principal> userPrincipals = new HashMap<>();
169
170 private boolean addDefaultWebXmlToWebapp = true;
171
172 /**
173 * Constructs a new embedded Tomcat instance with default settings.
174 */
175 public Tomcat() {
176 ExceptionUtils.preload();
177 }
178
179 /**
180 * Tomcat requires that the base directory is set because the defaults for a number of other locations, such as the
181 * work directory, are derived from the base directory. This should be the first method called.
182 * <p>
183 * If this method is not called then Tomcat will attempt to use these locations in the following order:
184 * <ol>
185 * <li>if set, the catalina.base system property</li>
186 * <li>if set, the catalina.home system property</li>
187 * <li>The user.dir system property (the directory where Java was run from) where a directory named tomcat.$PORT
188 * will be created. $PORT is the value configured via {@link #setPort(int)} which defaults to 8080 if not set</li>
189 * </ol>
190 * The user should ensure that the file permissions for the base directory are appropriate.
191 * <p>
192 * TODO: disable work dir if not needed ( no jsp, etc ).

Callers

nothing calls this directly

Calls 4

getManagerMethod · 0.95
isGraalAvailableMethod · 0.95
readConfigurationMethod · 0.80
getPropertyMethod · 0.65

Tested by

no test coverage detected