本文整理匯總了Java中org.apache.catalina.startup.Tomcat.setBaseDir方法的典型用法代碼示例。如果您正苦於以下問題:Java Tomcat.setBaseDir方法的具體用法?Java Tomcat.setBaseDir怎麽用?Java Tomcat.setBaseDir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.catalina.startup.Tomcat
的用法示例。
在下文中一共展示了Tomcat.setBaseDir方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: beforeTest
import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
@Before
public void beforeTest() throws Exception {
tomcatServer = new Tomcat();
tomcatServer.setPort(serverPort);
File baseDir = new File("tomcat");
tomcatServer.setBaseDir(baseDir.getAbsolutePath());
File applicationDir = new File(baseDir + "/webapps", "/ROOT");
if (!applicationDir.exists()) {
applicationDir.mkdirs();
}
Context appContext = tomcatServer.addWebapp("", applicationDir.getAbsolutePath());
Tomcat.addServlet(appContext, "helloWorldServlet", new TestServlet());
appContext.addServletMappingDecoded("/hello", "helloWorldServlet");
tomcatServer.start();
System.out.println("Tomcat server: http://" + tomcatServer.getHost().getName() + ":" + serverPort + "/");
}
示例2: setup
import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
/**
* Setup the test by deploying an embedded tomcat and adding the rest endpoints.
* @throws Throwable Throws uncaught throwables for test to fail.
*/
@Before
public void setup() throws Throwable {
registryTomcat = new Tomcat();
registryTomcat.setPort(3000);
registryTomcat.setBaseDir(testWorkingDir);
Context context = registryTomcat.addWebapp(CONTEXT, testWorkingDir);
context.addApplicationListener(RegistryStartup.class.getName());
ResourceConfig restServletConfig = new ResourceConfig();
restServletConfig.register(RegistryREST.class);
restServletConfig.register(Registry.class);
ServletContainer restServlet = new ServletContainer(restServletConfig);
registryTomcat.addServlet(CONTEXT, "restServlet", restServlet);
context.addServletMappingDecoded("/rest/*", "restServlet");
registryTomcat.start();
}
示例3: TomcatHttpServer
import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
public TomcatHttpServer(URL url, final HttpHandler handler) {
super(url, handler);
this.url = url;
DispatcherServlet.addHttpHandler(url.getPort(), handler);
String baseDir = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath();
tomcat = new Tomcat();
tomcat.setBaseDir(baseDir);
tomcat.setPort(url.getPort());
tomcat.getConnector().setProperty(
"maxThreads", String.valueOf(url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS)));
// tomcat.getConnector().setProperty(
// "minSpareThreads", String.valueOf(url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS)));
tomcat.getConnector().setProperty(
"maxConnections", String.valueOf(url.getParameter(Constants.ACCEPTS_KEY, -1)));
tomcat.getConnector().setProperty("URIEncoding", "UTF-8");
tomcat.getConnector().setProperty("connectionTimeout", "60000");
tomcat.getConnector().setProperty("maxKeepAliveRequests", "-1");
tomcat.getConnector().setProtocol("org.apache.coyote.http11.Http11NioProtocol");
Context context = tomcat.addContext("/", baseDir);
Tomcat.addServlet(context, "dispatcher", new DispatcherServlet());
context.addServletMapping("/*", "dispatcher");
ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext());
try {
tomcat.start();
} catch (LifecycleException e) {
throw new IllegalStateException("Failed to start tomcat server at " + url.getAddress(), e);
}
}
示例4: setup
import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
/**
* Setup the test by deploying an embedded tomcat and adding the rest endpoints.
* @throws Throwable Throws uncaught throwables for test to fail.
*/
@Before
public void setup() throws Throwable {
testTomcat = new Tomcat();
testTomcat.setPort(0);
testTomcat.setBaseDir(testWorkingDir);
Context context = testTomcat.addWebapp(CONTEXT, testWorkingDir);
ResourceConfig restServletConfig = new ResourceConfig();
restServletConfig.register(RegistryREST.class);
restServletConfig.register(Registry.class);
ServletContainer restServlet = new ServletContainer(restServletConfig);
testTomcat.addServlet(CONTEXT, "restServlet", restServlet);
context.addServletMappingDecoded("/rest/*", "restServlet");
testTomcat.start();
}
示例5: setup
import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
/**
* Setup the test by deploying an embedded tomcat and adding the rest endpoints.
* @throws Throwable Throws uncaught throwables for test to fail.
*/
@Before
public void setup() throws Throwable {
testTomcat = new Tomcat();
testTomcat.setPort(0);
testTomcat.setBaseDir(testWorkingDir);
Context context = testTomcat.addWebapp(CONTEXT, testWorkingDir);
ResourceConfig restServletConfig = new ResourceConfig();
restServletConfig.register(TestEntityEndpoint.class);
ServletContainer restServlet = new ServletContainer(restServletConfig);
testTomcat.addServlet(CONTEXT, "restServlet", restServlet);
context.addServletMappingDecoded("/rest/*", "restServlet");
testTomcat.start();
}
示例6: createClientTomcat
import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
private Tomcat createClientTomcat(Service service, Tomcat tomcat) throws ServletException, LifecycleException {
int clientPort = getNextClientPort();
tomcat.getEngine().setName("Catalina" + clientPort);
tomcat.setPort(clientPort);
tomcat.setBaseDir(testWorkingDir);
tomcat.enableNaming();
Context context = tomcat.addWebapp("/" + service.getServiceName(), testWorkingDir);
ContextEnvironment registryURL = new ContextEnvironment();
registryURL.setDescription("");
registryURL.setOverride(false);
registryURL.setType("java.lang.String");
registryURL.setName("registryURL");
registryURL.setValue("http://localhost:" + getRegistryPort() + "/test/rest/services/");
context.getNamingResources().addEnvironment(registryURL);
ContextEnvironment servicePort = new ContextEnvironment();
servicePort.setDescription("");
servicePort.setOverride(false);
servicePort.setType("java.lang.String");
servicePort.setName("servicePort");
servicePort.setValue("" + clientPort);
context.getNamingResources().addEnvironment(servicePort);
context.addApplicationListener(TestRegistryClientStartup.class.getName());
// HeartbeatServlet heartbeatServlet = new HeartbeatServlet();
// tomcat.addServlet("/" + service.getServiceName(), "heartbeatServlet", heartbeatServlet);
// context.addServletMappingDecoded("/heartbeat", "heartbeatServlet");
tomcat.start();
return tomcat;
}
示例7: setupAndAddTestTomcat
import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
private void setupAndAddTestTomcat(int i) {
Tomcat testTomcat = new Tomcat();
testTomcat.setPort(0);
testTomcat.setBaseDir(testWorkingDir);
Context context;
try {
context = testTomcat.addWebapp(CONTEXT, testWorkingDir);
testTomcat.getEngine().setName("Catalina" + i);
TestServlet testServlet = new TestServlet();
testServlet.setId(i);
testTomcat.addServlet(CONTEXT, "notFoundServlet", new NotFoundServlet());
testTomcat.addServlet(CONTEXT, "timeoutStatusServlet", new TimeoutStatusServlet());
testTomcat.addServlet(CONTEXT, "timeoutingServlet", new SlowTimeoutingServlet());
testTomcat.addServlet(CONTEXT, "restServlet", testServlet);
context.addServletMappingDecoded("/rest/" + ENDPOINT, "restServlet");
context.addServletMappingDecoded("/rest/" + ENDPOINT + "/*", "restServlet");
context.addServletMappingDecoded("/rest/" + NOT_FOUND_ENDPOINT, "notFoundServlet");
context.addServletMappingDecoded("/rest/" + NOT_FOUND_ENDPOINT + "/*", "notFoundServlet");
context.addServletMappingDecoded("/rest/" + TIMEOUT_STATUS_ENDPOINT, "timeoutStatusServlet");
context.addServletMappingDecoded("/rest/" + TIMEOUT_STATUS_ENDPOINT + "/*", "timeoutStatusServlet");
context.addServletMappingDecoded("/rest/" + TIMEOUTING_ENDPOINT, "timeoutStatusServlet");
context.addServletMappingDecoded("/rest/" + TIMEOUTING_ENDPOINT + "/*", "timeoutStatusServlet");
testTomcats.add(testTomcat);
} catch (ServletException e) {
e.printStackTrace();
}
}
示例8: setUp
import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
@BeforeClass
public static void setUp() throws Exception {
System.out.println("Tomcat [Configuring]");
tomcatServer = new Tomcat();
tomcatServer.setPort(SERVER_PORT);
Path tempDirectory = Files
.createTempDirectory(TomcatFilterInstrumentationTest.class.getSimpleName());
File baseDir = new File(tempDirectory.toFile(), "tomcat");
tomcatServer.setBaseDir(baseDir.getAbsolutePath());
File applicationDir = new File(baseDir + "/webapps", "/ROOT");
if (!applicationDir.exists()) {
applicationDir.mkdirs();
}
Context appContext = tomcatServer.addWebapp("", applicationDir.getAbsolutePath());
registerServlet(appContext, new PingPongServlet());
registerServlet(appContext, new ExceptionServlet());
registerServlet(appContext, new AsyncServlet());
System.out.println("Tomcat [Starting]");
tomcatServer.start();
System.out.println("Tomcat [Started]");
}
示例9: main
import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
String appBase = ".";
Tomcat tomcat = new Tomcat();
tomcat.setBaseDir(createTempDir());
tomcat.setPort(PORT);
tomcat.getHost().setAppBase(appBase);
tomcat.addWebapp("", ".");
tomcat.start();
tomcat.getServer().await();
}
示例10: setUpTomcat
import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
public static void setUpTomcat(String dataSourceFactory) throws LifecycleException, ServletException {
// create a tomcat instance
tomcat = new Tomcat();
tomcat.setBaseDir(".");
tomcat.setPort(0);
tomcat.enableNaming();
// create a context with our test servlet
Context ctx = tomcat.addContext(CONTEXT_PATH, new File(".").getAbsolutePath());
Tomcat.addServlet(ctx, SERVLET_NAME, new TestServlet());
ctx.addServletMappingDecoded("/*", SERVLET_NAME);
// add our metrics filter
FilterDef def = new FilterDef();
def.setFilterClass(TomcatServletMetricsFilter.class.getName());
def.setFilterName("metricsFilter");
def.addInitParameter("buckets",".01, .05, .1, .25, .5, 1, 2.5, 5, 10, 30");
ctx.addFilterDef(def);
FilterMap map = new FilterMap();
map.setFilterName("metricsFilter");
map.addURLPattern("/*");
ctx.addFilterMap(map);
// create a datasource
ContextResource resource = new ContextResource();
resource.setName("jdbc/db");
resource.setAuth("Container");
resource.setType("javax.sql.DataSource");
resource.setScope("Sharable");
resource.setProperty("name", "foo");
resource.setProperty("factory", dataSourceFactory);
resource.setProperty("driverClassName", "org.h2.Driver");
resource.setProperty("url", "jdbc:h2:mem:dummy");
resource.setProperty("jdbcInterceptors", "nl.nlighten.prometheus.tomcat.TomcatJdbcInterceptor(logFailed=true,logSlow=true,threshold=0,buckets=.01|.05|.1|1|10,slowQueryBuckets=1|10|30)");
ctx.getNamingResources().addResource(resource);
// start instance
tomcat.init();
tomcat.start();
}
示例11: setup
import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
@Before
public void setup() throws ServletException, LifecycleException, InterruptedException, JsonProcessingException {
webUITomcat = new Tomcat();
webUITomcat.setPort(3000);
webUITomcat.setBaseDir(testWorkingDir);
webUITomcat.enableNaming();
Context context = webUITomcat.addWebapp(CONTEXT, System.getProperty("user.dir") + File.separator + "src"
+ File.separator + "main" + File.separator + "webapp");
ContextEnvironment registryURL = new ContextEnvironment();
registryURL.setDescription("");
registryURL.setOverride(false);
registryURL.setType("java.lang.String");
registryURL.setName("registryURL");
registryURL.setValue("http://localhost:9001/tools.descartes.petsupplystore.registry/rest/services/");
context.getNamingResources().addEnvironment(registryURL);
webUITomcat.addServlet(CONTEXT, "servlet", getServlet());
webUITomcat.addServlet(CONTEXT, "index", new IndexServlet());
webUITomcat.addServlet(CONTEXT, "login", new LoginServlet());
webUITomcat.addServlet(CONTEXT, "order", new OrderServlet());
context.addServletMappingDecoded("/test", "servlet");
context.addServletMappingDecoded("/index", "index");
context.addServletMappingDecoded("/login", "login");
context.addServletMappingDecoded("/order", "order");
context.addWelcomeFile("/index");
webUITomcat.start();
// Mock registry
List<String> strings = new LinkedList<String>();
strings.add("localhost:9001");
String json = new ObjectMapper().writeValueAsString(strings);
wireMockRule.stubFor(get(urlEqualTo(
"/tools.descartes.petsupplystore.registry/rest/services/" + Service.IMAGE.getServiceName() + "/"))
.willReturn(okJson(json)));
wireMockRule.stubFor(get(urlEqualTo(
"/tools.descartes.petsupplystore.registry/rest/services/" + Service.STORE.getServiceName() + "/"))
.willReturn(okJson(json)));
wireMockRule.stubFor(get(urlEqualTo(
"/tools.descartes.petsupplystore.registry/rest/services/" + Service.PERSISTENCE.getServiceName() + "/"))
.willReturn(okJson(json)));
wireMockRule.stubFor(get(urlEqualTo(
"/tools.descartes.petsupplystore.registry/rest/services/" + Service.RECOMMENDER.getServiceName() + "/"))
.willReturn(okJson(json)));
// Mock images
HashMap<String, String> img = new HashMap<>();
img.put("andreBauer", "andreBauer");
img.put("johannesGrohmann", "johannesGrohmann");
img.put("joakimKistowski", "joakimKistowski");
img.put("simonEismann", "simonEismann");
img.put("norbertSchmitt", "norbertSchmitt");
img.put("descartesLogo", "descartesLogo");
img.put("icon", "icon");
mockValidPostRestCall(img, "/tools.descartes.petsupplystore.image/rest/image/getWebImages");
}
示例12: setup
import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
/**
* Sets up a store.
* @throws Throwable Throws uncaught throwables for test to fail.
*/
@Before
public void setup() throws Throwable {
storeTomcat = new Tomcat();
storeTomcat.setPort(3000);
storeTomcat.setBaseDir(testWorkingDir);
storeTomcat.enableNaming();
Context context3 = storeTomcat.addWebapp("/tools.descartes.petsupplystore.store", testWorkingDir);
ContextEnvironment registryURL3 = new ContextEnvironment();
registryURL3.setDescription("");
registryURL3.setOverride(false);
registryURL3.setType("java.lang.String");
registryURL3.setName("registryURL");
registryURL3.setValue("http://localhost:18080/tools.descartes.petsupplystore.registry/rest/services/");
context3.getNamingResources().addEnvironment(registryURL3);
ContextEnvironment servicePort3 = new ContextEnvironment();
servicePort3.setDescription("");
servicePort3.setOverride(false);
servicePort3.setType("java.lang.String");
servicePort3.setName("servicePort");
servicePort3.setValue("3000");
context3.getNamingResources().addEnvironment(servicePort3);
ResourceConfig restServletConfig3 = new ResourceConfig();
restServletConfig3.register(StoreCartREST.class);
restServletConfig3.register(StoreCategoriesREST.class);
restServletConfig3.register(StoreProductREST.class);
restServletConfig3.register(StoreUserActionsREST.class);
restServletConfig3.register(StoreUserREST.class);
ServletContainer restServlet3 = new ServletContainer(restServletConfig3);
storeTomcat.addServlet("/tools.descartes.petsupplystore.store", "restServlet", restServlet3);
context3.addServletMappingDecoded("/rest/*", "restServlet");
context3.addApplicationListener(EmptyStoreStartup.class.getName());
// Mock registry
List<String> strings = new LinkedList<String>();
strings.add("localhost:18080");
String json = new ObjectMapper().writeValueAsString(strings);
List<String> strings2 = new LinkedList<String>();
strings2.add("localhost:3000");
String json2 = new ObjectMapper().writeValueAsString(strings2);
wireMockRule.stubFor(get(urlEqualTo(
"/tools.descartes.petsupplystore.registry/rest/services/" + Service.IMAGE.getServiceName() + "/"))
.willReturn(okJson(json)));
wireMockRule.stubFor(get(urlEqualTo(
"/tools.descartes.petsupplystore.registry/rest/services/" + Service.STORE.getServiceName() + "/"))
.willReturn(okJson(json2)));
wireMockRule.stubFor(WireMock.put(WireMock.urlMatching(
"/tools.descartes.petsupplystore.registry/rest/services/" + Service.STORE.getServiceName() + "/.*"))
.willReturn(okJson(json2)));
wireMockRule.stubFor(WireMock.delete(WireMock.urlMatching(
"/tools.descartes.petsupplystore.registry/rest/services/" + Service.STORE.getServiceName() + "/.*"))
.willReturn(okJson(json2)));
wireMockRule.stubFor(get(urlEqualTo(
"/tools.descartes.petsupplystore.registry/rest/services/" + Service.PERSISTENCE.getServiceName() + "/"))
.willReturn(okJson(json)));
wireMockRule.stubFor(get(urlEqualTo(
"/tools.descartes.petsupplystore.registry/rest/services/" + Service.RECOMMENDER.getServiceName() + "/"))
.willReturn(okJson(json)));
// Mock images
HashMap<String, String> img = new HashMap<>();
img.put("andreBauer", "andreBauer");
img.put("johannesGrohmann", "johannesGrohmann");
img.put("joakimKistowski", "joakimKistowski");
img.put("simonEismann", "simonEismann");
img.put("norbertSchmitt", "norbertSchmitt");
img.put("descartesLogo", "descartesLogo");
img.put("icon", "icon");
mockValidPostRestCall(img, "/tools.descartes.petsupplystore.image/rest/image/getWebImages");
storeTomcat.start();
}
示例13: configureTomcat
import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
private void configureTomcat(Tomcat tomcat, Connector connector) {
tomcat.setBaseDir(noSuchBaseDir.toAbsolutePath().toString());
tomcat.setConnector(connector);
}