@Override public int getPort() { Connector connector = this.tomcat.getConnector(); if (connector != null) { return connector.getLocalPort(); } return 0; }
tomcat.setBaseDir(baseDir); tomcat.setPort(url.getPort()); tomcat.getConnector().setProperty( "maxThreads", 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");
tomcat.setBaseDir(baseDir); tomcat.setPort(url.getPort()); tomcat.getConnector().setProperty( "maxThreads", 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");
public static void main(String[] args) throws Exception { String webappsPath = args[0]; int port = Integer.parseInt( args[1] ); File dataDir = Files.createTempDir(); dataDir.deleteOnExit(); Tomcat tomcat = new Tomcat(); tomcat.setBaseDir(dataDir.getAbsolutePath()); tomcat.setPort(port); tomcat.getConnector().setAttribute("maxThreads", "1000"); tomcat.addWebapp("/", new File(webappsPath).getAbsolutePath()); logger.info("-----------------------------------------------------------------"); logger.info("Starting Tomcat port {} dir {}", port, webappsPath); logger.info("-----------------------------------------------------------------"); tomcat.start(); while ( true ) { Thread.sleep(1000); } }
@Override public void start() throws Exception { this.tomcatServer.start(); this.port = this.tomcatServer.getConnector().getLocalPort(); this.context.addLifecycleListener(event -> { if (logger.isDebugEnabled()) { logger.debug("Event: " + event.getType()); } }); }
@Override protected void startInternal() throws LifecycleException { this.tomcatServer.start(); setPort(this.tomcatServer.getConnector().getLocalPort()); }
private void checkThatConnectorsHaveStarted() { checkConnectorHasStarted(this.tomcat.getConnector()); for (Connector connector : this.tomcat.getService().findConnectors()) { checkConnectorHasStarted(connector); } }
Connector connector = this.tomcat.getConnector(); if (connector != null && this.autoStart) { performDeferredLoadOnStartup();
ctx.addServletMappingDecoded("/*", "webdav"); tomcat.start(); port1 = tomcat.getConnector().getLocalPort();
ctx.addServletMappingDecoded("/*", "webdav"); tomcat.start(); port1 = tomcat.getConnector().getLocalPort();
@Override protected void configure(ServerBuilder sb) throws Exception { // Prepare Tomcat instances. tomcatWithWebApp = new Tomcat(); tomcatWithWebApp.setPort(0); tomcatWithWebApp.setBaseDir("build" + File.separatorChar + "tomcat-" + UnmanagedTomcatServiceTest.class.getSimpleName() + "-1"); tomcatWithWebApp.addWebapp("", WebAppContainerTest.webAppRoot().getAbsolutePath()); TomcatUtil.engine(tomcatWithWebApp.getService(), "foo").setName("tomcatWithWebApp"); tomcatWithoutWebApp = new Tomcat(); tomcatWithoutWebApp.setPort(0); tomcatWithoutWebApp.setBaseDir("build" + File.separatorChar + "tomcat-" + UnmanagedTomcatServiceTest.class.getSimpleName() + "-2"); assertThat(TomcatUtil.engine(tomcatWithoutWebApp.getService(), "bar")).isNotNull(); // Start the Tomcats. tomcatWithWebApp.start(); tomcatWithoutWebApp.start(); // Bind them to the Server. sb.serviceUnder("/empty/", TomcatService.forConnector("someHost", new Connector())) .serviceUnder("/some-webapp-nohostname/", TomcatService.forConnector(tomcatWithWebApp.getConnector())) .serviceUnder("/no-webapp/", TomcatService.forTomcat(tomcatWithoutWebApp)) .serviceUnder("/some-webapp/", TomcatService.forTomcat(tomcatWithWebApp)); } };
public String getWsBaseUrl() { return "ws://localhost:" + this.tomcatServer.getConnector().getLocalPort(); }
@Override protected void before() throws LifecycleException { this.tomcat = new Tomcat(); this.tomcat.getConnector().setPort(0); Context context = this.tomcat.addContext("/", null); this.tomcat.addServlet("/", "test", new TestServlet()); context.addServletMappingDecoded("/", "test"); this.tomcat.addServlet("/", "set-cookie", new CookiesServlet()); context.addServletMappingDecoded("/set-cookie", "set-cookie"); this.tomcat.start(); this.port = this.tomcat.getConnector().getLocalPort(); }
private void configureDefaultConnector(int port, int securePort) { System.out.println("Creating default connector on port " + port); tomcat.setPort(port); if (securePort > 0) { tomcat.getConnector().setRedirectPort(securePort); } }
/** * Initialise the server. * * @throws LifecycleException */ public void init() throws LifecycleException { getServer(); getConnector(); server.init(); }
/** * Initialise the server. * * @throws LifecycleException */ public void init() throws LifecycleException { getServer(); getConnector(); server.init(); }
/** * Initialise the server. * * @throws LifecycleException */ public void init() throws LifecycleException { getServer(); getConnector(); server.init(); }
/** * Start the server. * * @throws LifecycleException */ public void start() throws LifecycleException { getServer(); getConnector(); server.start(); }
/** * Initialise the server. * * @throws LifecycleException */ public void init() throws LifecycleException { getServer(); getConnector(); server.init(); }
private void enableSSLConnector(Tomcat tomcat) { log.info("Using https protocol"); Connector connector = tomcat.getConnector(); connector.setPort(getSettings().getPort()); connector.setSecure(true); connector.setScheme("https"); connector.setAttribute("keyAlias", getSettings().getKeyAlias()); connector.setAttribute("keystorePass", getSettings().getKeystorePassword()); connector.setAttribute("keystoreType", getSettings().getKeyType()); connector.setAttribute("keystoreFile", getSettings().getKeystoreFile()); connector.setAttribute("clientAuth", getSettings().getClientAuth()); if (getSettings().getClientAuth()) { connector.setAttribute("truststoreFile", getSettings().getTruststoreFile()); connector.setAttribute("truststorePass", getSettings().getTruststorePassword()); } connector.setAttribute("protocol", "HTTP/1.1"); connector.setAttribute("sslProtocol", "TLS"); connector.setAttribute("maxThreads", getSettings().getMaxConnections()); connector.setAttribute("protocol", "org.apache.coyote.http11.Http11AprProtocol"); connector.setAttribute("SSLEnabled", true); }