當前位置: 首頁>>代碼示例>>Java>>正文


Java Tomcat.setPort方法代碼示例

本文整理匯總了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;
}
 
開發者ID:hantsy,項目名稱:spring-reactive-sample,代碼行數:17,代碼來源:Application.java

示例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 + "/");
}
 
開發者ID:opentracing-contrib,項目名稱:java-agent,代碼行數:21,代碼來源:TomcatServletITest.java

示例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();
    }
}
 
開發者ID:micrometer-metrics,項目名稱:micrometer,代碼行數:27,代碼來源:TomcatMetricsTest.java

示例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();
    }
}
 
開發者ID:micrometer-metrics,項目名稱:micrometer,代碼行數:18,代碼來源:TomcatMetricsTest.java

示例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();
}
 
開發者ID:DescartesResearch,項目名稱:Pet-Supply-Store,代碼行數:20,代碼來源:HeartbeatTest.java

示例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();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:AuthenticatorTestCase.java

示例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);
        }
    }
 
開發者ID:zhuxiaolei,項目名稱:dubbo2,代碼行數:35,代碼來源:TomcatHttpServer.java

示例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();
}
 
開發者ID:DescartesResearch,項目名稱:Pet-Supply-Store,代碼行數:19,代碼來源:RegistryTest.java

示例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();
}
 
開發者ID:DescartesResearch,項目名稱:Pet-Supply-Store,代碼行數:18,代碼來源:CRUDClientServerTest.java

示例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();
}
 
開發者ID:xbynet,項目名稱:crawler,代碼行數:12,代碼來源:Main.java

示例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();
	}
}
 
開發者ID:DescartesResearch,項目名稱:Pet-Supply-Store,代碼行數:28,代碼來源:LoadBalancerTest.java

示例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]");

}
 
開發者ID:ApptuitAI,項目名稱:JInsight,代碼行數:28,代碼來源:TomcatFilterInstrumentationTest.java

示例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();
}
 
開發者ID:auth0-blog,項目名稱:embedded-spring-5,代碼行數:11,代碼來源:Main.java

示例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();
}
 
開發者ID:dunwu,項目名稱:java-stack,代碼行數:13,代碼來源:SimpleTomcatServer.java

示例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();
}
 
開發者ID:nlighten,項目名稱:tomcat_exporter,代碼行數:41,代碼來源:AbstractTomcatMetricsTest.java


注:本文中的org.apache.catalina.startup.Tomcat.setPort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。