Java Code Examples for org.apache.catalina.connector.Connector#setAttribute()
The following examples show how to use
org.apache.catalina.connector.Connector#setAttribute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AjpConfiguration.java From osiam with MIT License | 5 votes |
@Override public void customize(ConfigurableEmbeddedServletContainer container) { if (container instanceof TomcatEmbeddedServletContainerFactory) { TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container; Connector ajpConnector = new Connector("AJP/1.3"); ajpConnector.setAttribute("address", bindAddress); ajpConnector.setPort(port); ajpConnector.setSecure(false); ajpConnector.setAllowTrace(false); ajpConnector.setScheme("http"); tomcat.addAdditionalTomcatConnectors(ajpConnector); } }
Example 2
Source File: IdpTest.java From cxf-fediz with Apache License 2.0 | 5 votes |
private static Tomcat startServer(boolean idp, String port) throws ServletException, LifecycleException, IOException { Tomcat server = new Tomcat(); server.setPort(0); String currentDir = new File(".").getCanonicalPath(); String baseDir = currentDir + File.separator + "target"; server.setBaseDir(baseDir); server.getHost().setAppBase("tomcat/idp/webapps"); server.getHost().setAutoDeploy(true); server.getHost().setDeployOnStartup(true); Connector httpsConnector = new Connector(); httpsConnector.setPort(Integer.parseInt(port)); httpsConnector.setSecure(true); httpsConnector.setScheme("https"); httpsConnector.setAttribute("keyAlias", "mytomidpkey"); httpsConnector.setAttribute("keystorePass", "tompass"); httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("truststorePass", "tompass"); httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("clientAuth", "want"); // httpsConnector.setAttribute("clientAuth", "false"); httpsConnector.setAttribute("sslProtocol", "TLS"); httpsConnector.setAttribute("SSLEnabled", true); server.getService().addConnector(httpsConnector); File stsWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-idp-sts"); server.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath()); File idpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-idp"); server.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath()); server.start(); return server; }
Example 3
Source File: FederationTest.java From cxf-fediz with Apache License 2.0 | 5 votes |
private static void initRp() { try { rpServer = new Tomcat(); rpServer.setPort(0); String currentDir = new File(".").getCanonicalPath(); rpServer.setBaseDir(currentDir + File.separator + "target"); rpServer.getHost().setAppBase("tomcat/rp/webapps"); rpServer.getHost().setAutoDeploy(true); rpServer.getHost().setDeployOnStartup(true); Connector httpsConnector = new Connector(); httpsConnector.setPort(Integer.parseInt(rpHttpsPort)); httpsConnector.setSecure(true); httpsConnector.setScheme("https"); httpsConnector.setAttribute("keyAlias", "mytomidpkey"); httpsConnector.setAttribute("keystorePass", "tompass"); httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("truststorePass", "tompass"); httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks"); // httpsConnector.setAttribute("clientAuth", "false"); httpsConnector.setAttribute("clientAuth", "want"); httpsConnector.setAttribute("sslProtocol", "TLS"); httpsConnector.setAttribute("SSLEnabled", true); rpServer.getService().addConnector(httpsConnector); rpServer.addWebapp("/fedizhelloworld", "cxfWebapp"); rpServer.addWebapp("/fedizhelloworldnoreqvalidation", "cxfWebapp"); rpServer.start(); } catch (Exception e) { e.printStackTrace(); } }
Example 4
Source File: FederationTest.java From cxf-fediz with Apache License 2.0 | 5 votes |
private static void initIdp() { try { idpServer = new Tomcat(); idpServer.setPort(0); String currentDir = new File(".").getCanonicalPath(); idpServer.setBaseDir(currentDir + File.separator + "target"); idpServer.getHost().setAppBase("tomcat/idp/webapps"); idpServer.getHost().setAutoDeploy(true); idpServer.getHost().setDeployOnStartup(true); Connector httpsConnector = new Connector(); httpsConnector.setPort(Integer.parseInt(idpHttpsPort)); httpsConnector.setSecure(true); httpsConnector.setScheme("https"); httpsConnector.setAttribute("keyAlias", "mytomidpkey"); httpsConnector.setAttribute("keystorePass", "tompass"); httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("truststorePass", "tompass"); httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("clientAuth", "want"); // httpsConnector.setAttribute("clientAuth", "false"); httpsConnector.setAttribute("sslProtocol", "TLS"); httpsConnector.setAttribute("SSLEnabled", true); idpServer.getService().addConnector(httpsConnector); idpServer.addWebapp("/fediz-idp-sts", "fediz-idp-sts"); idpServer.addWebapp("/fediz-idp", "fediz-idp"); idpServer.start(); } catch (Exception e) { e.printStackTrace(); } }
Example 5
Source File: IdpTest.java From cxf-fediz with Apache License 2.0 | 5 votes |
private static Tomcat startServer(String port) throws ServletException, LifecycleException, IOException { Tomcat server = new Tomcat(); server.setPort(0); String currentDir = new File(".").getCanonicalPath(); String baseDir = currentDir + File.separator + "target"; server.setBaseDir(baseDir); server.getHost().setAppBase("tomcat/idp/webapps"); server.getHost().setAutoDeploy(true); server.getHost().setDeployOnStartup(true); Connector httpsConnector = new Connector(); httpsConnector.setPort(Integer.parseInt(port)); httpsConnector.setSecure(true); httpsConnector.setScheme("https"); httpsConnector.setAttribute("keyAlias", "mytomidpkey"); httpsConnector.setAttribute("keystorePass", "tompass"); httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("truststorePass", "tompass"); httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("clientAuth", "want"); // httpsConnector.setAttribute("clientAuth", "false"); httpsConnector.setAttribute("sslProtocol", "TLS"); httpsConnector.setAttribute("SSLEnabled", true); server.getService().addConnector(httpsConnector); File stsWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-idp-sts"); server.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath()); File idpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-idp"); server.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath()); server.start(); return server; }
Example 6
Source File: TokenExpiryTest.java From cxf-fediz with Apache License 2.0 | 5 votes |
private static void initIdp() { try { idpServer = new Tomcat(); idpServer.setPort(0); String currentDir = new File(".").getCanonicalPath(); idpServer.setBaseDir(currentDir + File.separator + "target"); idpServer.getHost().setAppBase("tomcat/idp/webapps"); idpServer.getHost().setAutoDeploy(true); idpServer.getHost().setDeployOnStartup(true); Connector httpsConnector = new Connector(); httpsConnector.setPort(Integer.parseInt(idpHttpsPort)); httpsConnector.setSecure(true); httpsConnector.setScheme("https"); httpsConnector.setAttribute("keyAlias", "mytomidpkey"); httpsConnector.setAttribute("keystorePass", "tompass"); httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("truststorePass", "tompass"); httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("clientAuth", "want"); // httpsConnector.setAttribute("clientAuth", "false"); httpsConnector.setAttribute("sslProtocol", "TLS"); httpsConnector.setAttribute("SSLEnabled", true); idpServer.getService().addConnector(httpsConnector); idpServer.addWebapp("/fediz-idp-sts", "fediz-idp-sts"); idpServer.addWebapp("/fediz-idp", "fediz-idp"); idpServer.start(); } catch (Exception e) { e.printStackTrace(); } }
Example 7
Source File: WebsphereTest.java From cxf-fediz with Apache License 2.0 | 5 votes |
private static void initIdp() { try { idpServer = new Tomcat(); idpServer.setPort(0); String currentDir = new File(".").getCanonicalPath(); idpServer.setBaseDir(currentDir + File.separator + "target"); idpServer.getHost().setAppBase("tomcat/idp/webapps"); idpServer.getHost().setAutoDeploy(true); idpServer.getHost().setDeployOnStartup(true); Connector httpsConnector = new Connector(); httpsConnector.setPort(Integer.parseInt(idpHttpsPort)); httpsConnector.setSecure(true); httpsConnector.setScheme("https"); // httpsConnector.setAttribute("keyAlias", keyAlias); httpsConnector.setAttribute("keystorePass", "tompass"); httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("truststorePass", "tompass"); httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("clientAuth", "want"); // httpsConnector.setAttribute("clientAuth", "false"); httpsConnector.setAttribute("sslProtocol", "TLS"); httpsConnector.setAttribute("SSLEnabled", true); idpServer.getService().addConnector(httpsConnector); idpServer.addWebapp("/fediz-idp-sts", "fediz-idp-sts"); idpServer.addWebapp("/fediz-idp", "fediz-idp"); idpServer.start(); } catch (Exception e) { e.printStackTrace(); } }
Example 8
Source File: WebAnno.java From webanno with Apache License 2.0 | 5 votes |
@Bean public TomcatServletWebServerFactory servletContainer() { TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); if (ajpPort > 0) { Connector ajpConnector = new Connector(PROTOCOL); ajpConnector.setPort(ajpPort); ajpConnector.setAttribute("secretRequired", ajpSecretRequired); ajpConnector.setAttribute("secret", ajpSecret); ajpConnector.setAttribute("address", ajpAddress); factory.addAdditionalTomcatConnectors(ajpConnector); } return factory; }
Example 9
Source File: TokenExpiryTest.java From cxf-fediz with Apache License 2.0 | 5 votes |
private static void initRp() { try { rpServer = new Tomcat(); rpServer.setPort(0); String currentDir = new File(".").getCanonicalPath(); rpServer.setBaseDir(currentDir + File.separator + "target"); rpServer.getHost().setAppBase("tomcat/rp/webapps"); rpServer.getHost().setAutoDeploy(true); rpServer.getHost().setDeployOnStartup(true); Connector httpsConnector = new Connector(); httpsConnector.setPort(Integer.parseInt(rpHttpsPort)); httpsConnector.setSecure(true); httpsConnector.setScheme("https"); httpsConnector.setAttribute("keyAlias", "mytomidpkey"); httpsConnector.setAttribute("keystorePass", "tompass"); httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("truststorePass", "tompass"); httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks"); // httpsConnector.setAttribute("clientAuth", "false"); httpsConnector.setAttribute("clientAuth", "want"); httpsConnector.setAttribute("sslProtocol", "TLS"); httpsConnector.setAttribute("SSLEnabled", true); rpServer.getService().addConnector(httpsConnector); rpServer.addWebapp("/fedizhelloworld", "cxfWebappExpiry"); rpServer.start(); } catch (Exception e) { e.printStackTrace(); } }
Example 10
Source File: TestCustomSsl.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testCustomSslImplementation() throws Exception { TesterSupport.configureClientSsl(); Tomcat tomcat = getTomcatInstance(); Connector connector = tomcat.getConnector(); Assume.assumeFalse("This test is only for JSSE based SSL connectors", connector.getProtocolHandlerClassName().contains("Apr")); connector.setProperty("sslImplementationName", "org.apache.tomcat.util.net.jsse.TesterBug50640SslImpl"); // This setting will break ssl configuration unless the custom // implementation is used. connector.setProperty(TesterBug50640SslImpl.PROPERTY_NAME, TesterBug50640SslImpl.PROPERTY_VALUE); connector.setProperty("sslProtocol", "tls"); File keystoreFile = new File(TesterSupport.LOCALHOST_RSA_JKS); connector.setAttribute( "keystoreFile", keystoreFile.getAbsolutePath()); connector.setSecure(true); connector.setProperty("SSLEnabled", "true"); File appDir = new File(getBuildDirectory(), "webapps/examples"); Context ctxt = tomcat.addWebapp( null, "/examples", appDir.getAbsolutePath()); ctxt.addApplicationListener(WsContextListener.class.getName()); tomcat.start(); ByteChunk res = getUrl("https://localhost:" + getPort() + "/examples/servlets/servlet/HelloWorldExample"); Assert.assertTrue(res.toString().indexOf("<a href=\"../helloworld.html\">") > 0); }
Example 11
Source File: TomcatConfig.java From find with MIT License | 4 votes |
private Connector createAjpConnector() { final Connector connector = new Connector("AJP/1.3"); connector.setPort(ajpPort); connector.setAttribute("tomcatAuthentication", false); return connector; }
Example 12
Source File: TomcatLauncher.java From cxf-fediz with Apache License 2.0 | 4 votes |
private static Tomcat startServer(String port, String servletContextName) throws ServletException, LifecycleException, IOException { Tomcat server = new Tomcat(); server.setPort(0); Path targetDir = Paths.get("target").toAbsolutePath(); server.setBaseDir(targetDir.toString()); server.getHost().setAutoDeploy(true); server.getHost().setDeployOnStartup(true); Connector httpsConnector = new Connector(); httpsConnector.setPort(Integer.parseInt(port)); httpsConnector.setSecure(true); httpsConnector.setScheme("https"); httpsConnector.setAttribute("sslProtocol", "TLS"); httpsConnector.setAttribute("SSLEnabled", true); httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("keystorePass", "tompass"); httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("truststorePass", "tompass"); httpsConnector.setAttribute("clientAuth", "want"); server.getService().addConnector(httpsConnector); if (null == servletContextName) { // IDP server.getHost().setAppBase("tomcat/idp/webapps"); Path stsWebapp = targetDir.resolve(server.getHost().getAppBase()).resolve("fediz-idp-sts"); server.addWebapp("/fediz-idp-sts", stsWebapp.toString()); Path idpWebapp = targetDir.resolve(server.getHost().getAppBase()).resolve("fediz-idp"); server.addWebapp("/fediz-idp", idpWebapp.toString()); } else { // RP server.getHost().setAppBase("tomcat/rp/webapps"); Path rpWebapp = targetDir.resolve(server.getHost().getAppBase()).resolve("simpleWebapp"); Context cxt = server.addWebapp(servletContextName, rpWebapp.toString()); // Substitute the IDP port. Necessary if running the test in eclipse where port filtering doesn't seem // to work Path fedizConfig = targetDir.resolve("tomcat").resolve("fediz_config.xml"); try (InputStream is = TomcatLauncher.class.getResourceAsStream("/fediz_config.xml")) { byte[] content = new byte[is.available()]; is.read(content); Files.write(fedizConfig, new String(content).replace("${idp.https.port}", IDP_HTTPS_PORT).getBytes()); } FederationAuthenticator fa = new FederationAuthenticator(); fa.setConfigFile(fedizConfig.toString()); cxt.getPipeline().addValve(fa); } server.start(); return server; }
Example 13
Source File: CustomParametersTest.java From cxf-fediz with Apache License 2.0 | 4 votes |
private static Tomcat startServer(boolean idp, String port) throws ServletException, LifecycleException, IOException { Tomcat server = new Tomcat(); server.setPort(0); Path targetDir = Paths.get("target").toAbsolutePath(); server.setBaseDir(targetDir.toString()); server.getHost().setAutoDeploy(true); server.getHost().setDeployOnStartup(true); Connector httpsConnector = new Connector(); httpsConnector.setPort(Integer.parseInt(port)); httpsConnector.setSecure(true); httpsConnector.setScheme("https"); httpsConnector.setAttribute("sslProtocol", "TLS"); httpsConnector.setAttribute("SSLEnabled", true); // httpsConnector.setAttribute("keyAlias", "mytomidpkey"); httpsConnector.setAttribute("keystorePass", "tompass"); httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks"); server.getService().addConnector(httpsConnector); if (idp) { server.getHost().setAppBase("tomcat/idp/webapps"); httpsConnector.setAttribute("truststorePass", "tompass"); httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("clientAuth", "want"); Path stsWebapp = targetDir.resolve(server.getHost().getAppBase()).resolve("fediz-idp-sts"); server.addWebapp("/fediz-idp-sts", stsWebapp.toString()); Path idpWebapp = targetDir.resolve(server.getHost().getAppBase()).resolve("fediz-idp"); server.addWebapp("/fediz-idp", idpWebapp.toString()); } else { server.getHost().setAppBase("tomcat/rp/webapps"); httpsConnector.setAttribute("clientAuth", "false"); Path rpWebapp = targetDir.resolve(server.getHost().getAppBase()).resolve("simpleWebapp"); Context cxt = server.addWebapp("/fedizhelloworld", rpWebapp.toString()); // Substitute the IDP port. Necessary if running the test in eclipse where port filtering doesn't seem // to work Path fedizConfig = targetDir.resolve("tomcat").resolve("fediz_config.xml"); try (InputStream is = CustomParametersTest.class.getResourceAsStream("/fediz_config.xml")) { byte[] content = new byte[is.available()]; is.read(content); Files.write(fedizConfig, new String(content).replace("${idp.https.port}", IDP_HTTPS_PORT).getBytes()); } FederationAuthenticator fa = new FederationAuthenticator(); fa.setConfigFile(fedizConfig.toString()); cxt.getPipeline().addValve(fa); } server.start(); return server; }
Example 14
Source File: TomcatServer.java From athena-rest with Apache License 2.0 | 4 votes |
private void initTomcat() { serverStatus = ServerStatus.STARTING; tomcat = new Tomcat(); tomcat.setPort(port); // Changed it to use NIO due to poor performance in burdon test Connector connector = new Connector(Utils.getStringProperty(properties, "web.connectorProtocol")); connector.setURIEncoding("UTF-8"); connector.setPort(port); connector.setUseBodyEncodingForURI(true); connector.setAsyncTimeout(Utils.getIntegerValue(properties, WEB_ASYNC_TIMEOUT, DEFAULT_ASYNC_TIMEOUT)); connector.setAttribute("minProcessors", Utils.getIntegerValue( properties, WEB_MIN_PROCESSORS, DEFAULT_MIN_PROCESSORS)); connector.setAttribute("maxProcessors", Utils.getIntegerValue( properties, WEB_MAX_PROCESSORS, DEFAULT_MAX_PROCESSORS)); connector.setAttribute("acceptCount", Utils.getIntegerValue(properties, WEB_ACCEPT_COUNT, DEFAULT_ACCEPT_COUNT)); connector.setAttribute("minSpareThreads", Utils.getIntegerValue( properties, WEB_MIN_SPARE_THREADS, DEFAULT_MIN_SPARE_THREADS)); connector.setAttribute("maxThreads", Utils.getIntegerValue(properties, WEB_MAX_THREADS, DEFAULT_MAX_THREADS)); connector.setRedirectPort(Utils.getIntegerValue(properties, WEB_REDIRECT_PORT, DEFAULT_WEB_REDIRECT_PORT)); if (this.minThreads != -1 && this.maxThreads != -1) { connector.setAttribute("minThreads", minThreads); connector.setAttribute("maxThreads", maxThreads); } Service tomcatService = tomcat.getService(); tomcatService.addConnector(connector); tomcat.setConnector(connector); Context context = null; try { context = tomcat.addWebapp(contextPath, new File(webappPath).getAbsolutePath()); } catch (ServletException e) { log.error("Failed to add webapp + " + webappPath, e); exit(); } context.setLoader(new WebappLoader(Thread.currentThread() .getContextClassLoader())); String extraResourcePaths = properties .getProperty(WEB_EXTRA_RESOURCE_PATHS); if (!StringUtils.isBlank(extraResourcePaths)) { VirtualDirContext virtualDirContext = new VirtualDirContext(); virtualDirContext.setExtraResourcePaths(extraResourcePaths); context.setResources(virtualDirContext); } StandardServer server = (StandardServer) tomcat.getServer(); AprLifecycleListener listener = new AprLifecycleListener(); server.addLifecycleListener(listener); }
Example 15
Source File: TomcatPluginTest.java From cxf-fediz with Apache License 2.0 | 4 votes |
private static Tomcat startServer(boolean idp, String port) throws ServletException, LifecycleException, IOException { Tomcat server = new Tomcat(); server.setPort(0); String currentDir = new File(".").getCanonicalPath(); String baseDir = currentDir + File.separator + "target"; server.setBaseDir(baseDir); if (idp) { server.getHost().setAppBase("tomcat/idp/webapps"); } else { server.getHost().setAppBase("tomcat/rp/webapps"); } server.getHost().setAutoDeploy(true); server.getHost().setDeployOnStartup(true); Connector httpsConnector = new Connector(); httpsConnector.setPort(Integer.parseInt(port)); httpsConnector.setSecure(true); httpsConnector.setScheme("https"); httpsConnector.setAttribute("keyAlias", "mytomidpkey"); httpsConnector.setAttribute("keystorePass", "tompass"); httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("truststorePass", "tompass"); httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("clientAuth", "want"); // httpsConnector.setAttribute("clientAuth", "false"); httpsConnector.setAttribute("sslProtocol", "TLS"); httpsConnector.setAttribute("SSLEnabled", true); server.getService().addConnector(httpsConnector); if (idp) { File stsWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-idp-sts"); server.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath()); File idpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-idp"); server.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath()); } else { File rpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "simpleWebapp"); Context cxt = server.addWebapp("/fedizhelloworld", rpWebapp.getAbsolutePath()); // Substitute the IDP port. Necessary if running the test in eclipse where port filtering doesn't seem // to work File f = new File(currentDir + "/src/test/resources/fediz_config.xml"); String content = new String(Files.readAllBytes(f.toPath()), "UTF-8"); if (content.contains("idp.https.port")) { content = content.replaceAll("\\$\\{idp.https.port\\}", IDP_HTTPS_PORT); File f2 = new File(baseDir + "/test-classes/fediz_config.xml"); Files.write(f2.toPath(), content.getBytes()); } FederationAuthenticator fa = new FederationAuthenticator(); fa.setConfigFile(currentDir + File.separator + "target" + File.separator + "test-classes" + File.separator + "fediz_config.xml"); cxt.getPipeline().addValve(fa); } server.start(); return server; }
Example 16
Source File: ServingLayer.java From oryx with Apache License 2.0 | 4 votes |
private Connector makeConnector() { Connector connector = new Connector(Http11Nio2Protocol.class.getName()); if (keystoreFile == null) { // HTTP connector connector.setPort(port); connector.setSecure(false); connector.setScheme("http"); } else { // HTTPS connector connector.setPort(securePort); connector.setSecure(true); connector.setScheme("https"); connector.setAttribute("SSLEnabled", "true"); SSLHostConfig sslHostConfig = new SSLHostConfig(); SSLHostConfigCertificate cert = new SSLHostConfigCertificate(sslHostConfig, SSLHostConfigCertificate.Type.RSA); cert.setCertificateKeystoreFile(keystoreFile.toAbsolutePath().toString()); cert.setCertificateKeystorePassword(keystorePassword); cert.setCertificateKeyAlias(keyAlias); sslHostConfig.addCertificate(cert); connector.addSslHostConfig(sslHostConfig); } connector.addUpgradeProtocol(new Http2Protocol()); // Keep quiet about the server type connector.setXpoweredBy(false); // Basic tuning params: connector.setAttribute("maxThreads", 400); connector.setAttribute("acceptCount", 50); //connector.setAttribute("connectionTimeout", 2000); connector.setAttribute("maxKeepAliveRequests", 100); // Avoid running out of ephemeral ports under heavy load? connector.setAttribute("socket.soReuseAddress", true); connector.setMaxPostSize(0); connector.setAttribute("disableUploadTimeout", false); // Allow long URLs connector.setAttribute("maxHttpHeaderSize", 65536); // Enable response compression connector.setAttribute("compression", "on"); // Defaults are text/html,text/xml,text/plain,text/css connector.setAttribute("compressableMimeType", "text/html,text/xml,text/plain,text/css,text/csv,application/json"); return connector; }
Example 17
Source File: TomcatBaseTest.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Before @Override public void setUp() throws Exception { super.setUp(); // Trigger loading of catalina.properties CatalinaProperties.getProperty("foo"); File appBase = new File(getTemporaryDirectory(), "webapps"); if (!appBase.exists() && !appBase.mkdir()) { fail("Unable to create appBase for test"); } tomcat = new TomcatWithFastSessionIDs(); String protocol = getProtocol(); Connector connector = new Connector(protocol); // Listen only on localhost connector.setAttribute("address", InetAddress.getByName("localhost").getHostAddress()); // Use random free port connector.setPort(0); // Mainly set to reduce timeouts during async tests connector.setAttribute("connectionTimeout", "3000"); tomcat.getService().addConnector(connector); tomcat.setConnector(connector); // Add AprLifecycleListener if we are using the Apr connector if (protocol.contains("Apr")) { StandardServer server = (StandardServer) tomcat.getServer(); AprLifecycleListener listener = new AprLifecycleListener(); listener.setSSLRandomSeed("/dev/urandom"); server.addLifecycleListener(listener); connector.setAttribute("pollerThreadCount", Integer.valueOf(1)); } File catalinaBase = getTemporaryDirectory(); tomcat.setBaseDir(catalinaBase.getAbsolutePath()); tomcat.getHost().setAppBase(appBase.getAbsolutePath()); accessLogEnabled = Boolean.parseBoolean( System.getProperty("tomcat.test.accesslog", "false")); if (accessLogEnabled) { String accessLogDirectory = System .getProperty("tomcat.test.reports"); if (accessLogDirectory == null) { accessLogDirectory = new File(getBuildDirectory(), "logs") .toString(); } AccessLogValve alv = new AccessLogValve(); alv.setDirectory(accessLogDirectory); alv.setPattern("%h %l %u %t \"%r\" %s %b %I %D"); tomcat.getHost().getPipeline().addValve(alv); } // Cannot delete the whole tempDir, because logs are there, // but delete known subdirectories of it. addDeleteOnTearDown(new File(catalinaBase, "webapps")); addDeleteOnTearDown(new File(catalinaBase, "work")); }
Example 18
Source File: Runner.java From myrrix-recommender with Apache License 2.0 | 4 votes |
private Connector makeConnector() throws IOException { Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); File keystoreFile = config.getKeystoreFile(); String keystorePassword = config.getKeystorePassword(); if (keystoreFile == null && keystorePassword == null) { // HTTP connector connector.setPort(config.getPort()); connector.setSecure(false); connector.setScheme("http"); } else { if (keystoreFile == null || !keystoreFile.exists()) { log.info("Keystore file not found; trying to load remote keystore file if applicable"); ResourceRetriever resourceRetriever = ClassUtils.loadInstanceOf("net.myrrix.online.io.DelegateResourceRetriever", ResourceRetriever.class); resourceRetriever.init(config.getBucket()); keystoreFile = resourceRetriever.getKeystoreFile(config.getInstanceID()); if (keystoreFile == null) { throw new FileNotFoundException(); } } // HTTPS connector connector.setPort(config.getSecurePort()); connector.setSecure(true); connector.setScheme("https"); connector.setAttribute("SSLEnabled", "true"); String protocol = chooseSSLProtocol("TLSv1.1", "TLSv1"); if (protocol != null) { connector.setAttribute("sslProtocol", protocol); } if (keystoreFile != null) { connector.setAttribute("keystoreFile", keystoreFile.getAbsoluteFile()); } connector.setAttribute("keystorePass", keystorePassword); } // Keep quiet about the server type connector.setXpoweredBy(false); connector.setAttribute("server", "Myrrix"); // Basic tuning params: connector.setAttribute("maxThreads", 400); connector.setAttribute("acceptCount", 50); //connector.setAttribute("connectionTimeout", 2000); connector.setAttribute("maxKeepAliveRequests", 100); // Avoid running out of ephemeral ports under heavy load? connector.setAttribute("socket.soReuseAddress", true); connector.setMaxPostSize(0); connector.setAttribute("disableUploadTimeout", false); return connector; }
Example 19
Source File: SpringTest.java From cxf-fediz with Apache License 2.0 | 4 votes |
private static Tomcat startServer(boolean idp, String port) throws ServletException, LifecycleException, IOException { Tomcat server = new Tomcat(); server.setPort(0); String currentDir = new File(".").getCanonicalPath(); String baseDir = currentDir + File.separator + "target"; server.setBaseDir(baseDir); if (idp) { server.getHost().setAppBase("tomcat/idp/webapps"); } else { server.getHost().setAppBase("tomcat/rp/webapps"); } server.getHost().setAutoDeploy(true); server.getHost().setDeployOnStartup(true); Connector httpsConnector = new Connector(); httpsConnector.setPort(Integer.parseInt(port)); httpsConnector.setSecure(true); httpsConnector.setScheme("https"); httpsConnector.setAttribute("keyAlias", "mytomidpkey"); httpsConnector.setAttribute("keystorePass", "tompass"); httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("truststorePass", "tompass"); httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("clientAuth", "want"); // httpsConnector.setAttribute("clientAuth", "false"); httpsConnector.setAttribute("sslProtocol", "TLS"); httpsConnector.setAttribute("SSLEnabled", true); server.getService().addConnector(httpsConnector); if (idp) { File stsWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-idp-sts"); server.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath()); File idpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-idp"); server.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath()); } else { File rpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-systests-webapps-spring"); server.addWebapp("/fedizhelloworld", rpWebapp.getAbsolutePath()); server.addWebapp("/fedizhelloworldspringnoreqvalidation", rpWebapp.getAbsolutePath()); } server.start(); return server; }
Example 20
Source File: TokenExpiryTest.java From cxf-fediz with Apache License 2.0 | 4 votes |
private static Tomcat startServer(boolean idp, String port) throws ServletException, LifecycleException, IOException { Tomcat server = new Tomcat(); server.setPort(0); String currentDir = new File(".").getCanonicalPath(); String baseDir = currentDir + File.separator + "target"; server.setBaseDir(baseDir); if (idp) { server.getHost().setAppBase("tomcat/idp/webapps"); } else { server.getHost().setAppBase("tomcat/rp/webapps"); } server.getHost().setAutoDeploy(true); server.getHost().setDeployOnStartup(true); Connector httpsConnector = new Connector(); httpsConnector.setPort(Integer.parseInt(port)); httpsConnector.setSecure(true); httpsConnector.setScheme("https"); httpsConnector.setAttribute("keyAlias", "mytomidpkey"); httpsConnector.setAttribute("keystorePass", "tompass"); httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("truststorePass", "tompass"); httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks"); httpsConnector.setAttribute("clientAuth", "want"); // httpsConnector.setAttribute("clientAuth", "false"); httpsConnector.setAttribute("sslProtocol", "TLS"); httpsConnector.setAttribute("SSLEnabled", true); server.getService().addConnector(httpsConnector); if (idp) { File stsWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-idp-sts"); server.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath()); File idpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-idp"); server.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath()); } else { File rpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-systests-webapps-spring"); server.addWebapp("/fedizhelloworld_wfresh", rpWebapp.getAbsolutePath()); } server.start(); return server; }