本文整理匯總了Java中org.apache.catalina.startup.Tomcat.setPort方法的典型用法代碼示例。如果您正苦於以下問題:Java Tomcat.setPort方法的具體用法?Java Tomcat.setPort怎麽用?Java Tomcat.setPort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.catalina.startup.Tomcat
的用法示例。
在下文中一共展示了Tomcat.setPort方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: embededTomcatServer
import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
@Bean
public Tomcat embededTomcatServer(ApplicationContext context) throws Exception {
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
// Tomcat and Jetty (also see notes below)
Servlet servlet = new TomcatHttpHandlerAdapter(handler);
Tomcat tomcatServer = new Tomcat();
tomcatServer.setHostname("localhost");
tomcatServer.setPort(this.port);
Context rootContext = tomcatServer.addContext("", System.getProperty("java.io.tmpdir"));
Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
rootContext.addServletMappingDecoded("/", "httpHandlerServlet");
return tomcatServer;
}
示例2: 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 + "/");
}
示例3: mbeansAvailableAfterBinder
import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
@Test
void mbeansAvailableAfterBinder() throws LifecycleException, InterruptedException {
TomcatMetrics.monitor(registry, null);
CountDownLatch latch = new CountDownLatch(1);
registry.config().onMeterAdded(m -> {
if(m.getId().getName().equals("tomcat.global.received"))
latch.countDown();
});
Tomcat server = new Tomcat();
try {
StandardHost host = new StandardHost();
host.setName("localhost");
server.setHost(host);
server.setPort(61000);
server.start();
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(registry.find("tomcat.global.received").functionCounter()).isNotNull();
} finally {
server.stop();
server.destroy();
}
}
示例4: mbeansAvailableBeforeBinder
import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
@Test
void mbeansAvailableBeforeBinder() throws LifecycleException {
Tomcat server = new Tomcat();
try {
StandardHost host = new StandardHost();
host.setName("localhost");
server.setHost(host);
server.setPort(61000);
server.start();
TomcatMetrics.monitor(registry, null);
assertThat(registry.find("tomcat.global.received").functionCounter()).isNotNull();
} finally {
server.stop();
server.destroy();
}
}
示例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 {
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();
}
示例6: startTomcat
import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
protected void startTomcat() throws Exception {
tomcat = new Tomcat();
File base = new File(System.getProperty("java.io.tmpdir"));
org.apache.catalina.Context ctx =
tomcat.addContext("/foo",base.getAbsolutePath());
FilterDef fd = new FilterDef();
fd.setFilterClass(TestFilter.class.getName());
fd.setFilterName("TestFilter");
FilterMap fm = new FilterMap();
fm.setFilterName("TestFilter");
fm.addURLPattern("/*");
fm.addServletName("/bar");
ctx.addFilterDef(fd);
ctx.addFilterMap(fm);
tomcat.addServlet(ctx, "/bar", TestServlet.class.getName());
ctx.addServletMapping("/bar", "/bar");
host = "localhost";
port = getLocalPort();
tomcat.setHostname(host);
tomcat.setPort(port);
tomcat.start();
}
示例7: 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);
}
}
示例8: 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();
}
示例9: 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();
}
示例10: main
import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
String contextPath = "/";
String appBase = ".";
Tomcat tomcat = new Tomcat();
tomcat.setPort(8666);
tomcat.getHost().setAppBase(appBase);
StandardContext ctx=(StandardContext)tomcat.addWebapp(contextPath, appBase);//Context ctx = tomcat.addContext("/", new File(".").getAbsolutePath());
tomcat.start();
tomcat.getServer().await();
}
示例11: 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();
}
}
示例12: 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]");
}
示例13: 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();
}
示例14: main
import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
// 設定 profile
Optional<String> profile = Optional.ofNullable(System.getProperty("spring.profiles.active"));
System.setProperty("spring.profiles.active", profile.orElse("develop"));
Tomcat tomcat = new Tomcat();
tomcat.setPort(PORT);
tomcat.getHost().setAppBase(".");
tomcat.addWebapp(CONTEXT_PATH, getAbsolutePath() + "src/main/webapp");
tomcat.start();
tomcat.getServer().await();
}
示例15: 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();
}