Java Code Examples for org.apache.catalina.connector.Connector#setScheme()
The following examples show how to use
org.apache.catalina.connector.Connector#setScheme() .
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: MBeanFactory.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Create a new Connector * * @param parent MBean Name of the associated parent component * @param address The IP address on which to bind * @param port TCP port number to listen on * @param isAjp Create a AJP/1.3 Connector * @param isSSL Create a secure Connector * * @exception Exception if an MBean cannot be created or registered */ private String createConnector(String parent, String address, int port, boolean isAjp, boolean isSSL) throws Exception { // Set the protocol String protocol = isAjp ? "AJP/1.3" : "HTTP/1.1"; Connector retobj = new Connector(protocol); if ((address!=null) && (address.length()>0)) { retobj.setProperty("address", address); } // Set port number retobj.setPort(port); // Set SSL retobj.setSecure(isSSL); retobj.setScheme(isSSL ? "https" : "http"); // Add the new instance to its parent component // FIX ME - addConnector will fail ObjectName pname = new ObjectName(parent); Service service = getService(pname); service.addConnector(retobj); // Return the corresponding MBean name ObjectName coname = retobj.getObjectName(); return coname.toString(); }
Example 2
Source File: TomcatConfiguration.java From odata with Apache License 2.0 | 6 votes |
private Connector createSslConnector() { Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler(); try { File keystore = new ClassPathResource(keystorePath).getFile(); connector.setScheme(HTTPS_SCHEME); connector.setSecure(true); connector.setPort(Integer.parseInt(httpsPort)); protocol.setSSLEnabled(true); protocol.setKeystoreFile(keystore.getAbsolutePath()); protocol.setKeystorePass(keystorePasswd); protocol.setTruststoreFile(keystore.getAbsolutePath()); protocol.setTruststorePass(truststorePasswd); protocol.setKeyAlias(keyAlias); return connector; } catch (IOException ex) { throw new IllegalStateException("cant access keystore: [" + "keystore" + "] or truststore: [" + "keystore" + "]", ex); } }
Example 3
Source File: TomcatConfig.java From singleton with Eclipse Public License 2.0 | 6 votes |
/** * create the https additional connection for tomcat */ private Connector initiateHttpsConnector(ServerProperties serverProperties) { Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); connector.setScheme(ConstantsTomcat.HTTPS); connector.setPort(serverProperties.getServerPort()); connector.setSecure(true); Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler(); protocol.setSSLEnabled(true); protocol.setKeystoreFile(serverProperties.getHttpsKeyStore()); protocol.setKeystorePass(serverProperties.getHttpsKeyStorePassword()); protocol.setKeystoreType(serverProperties.getHttpsKeyStoreType()); protocol.setKeyPass(serverProperties.getHttpsKeyPassword()); protocol.setKeyAlias(serverProperties.getHttpsKeyAlias()); protocol.setMaxHttpHeaderSize(serverProperties.getMaxHttpHeaderSize()); connector.setRedirectPort(ConstantsTomcat.REDIRECT_PORT); connector.setAllowTrace(serverProperties.isAllowTrace()); return connector; }
Example 4
Source File: MBeanFactory.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Create a new Connector * * @param parent MBean Name of the associated parent component * @param address The IP address on which to bind * @param port TCP port number to listen on * @param isAjp Create a AJP/1.3 Connector * @param isSSL Create a secure Connector * * @exception Exception if an MBean cannot be created or registered */ private String createConnector(String parent, String address, int port, boolean isAjp, boolean isSSL) throws Exception { Connector retobj = new Connector(); if ((address!=null) && (address.length()>0)) { retobj.setProperty("address", address); } // Set port number retobj.setPort(port); // Set the protocol retobj.setProtocol(isAjp ? "AJP/1.3" : "HTTP/1.1"); // Set SSL retobj.setSecure(isSSL); retobj.setScheme(isSSL ? "https" : "http"); // Add the new instance to its parent component // FIX ME - addConnector will fail ObjectName pname = new ObjectName(parent); Service service = getService(pname); service.addConnector(retobj); // Return the corresponding MBean name ObjectName coname = retobj.getObjectName(); return (coname.toString()); }
Example 5
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 6
Source File: App.java From danyuan-application with Apache License 2.0 | 5 votes |
private Connector createHTTPConnector() { Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); // 同时启用http(8080)、https(8443)两个端口 connector.setScheme("http"); connector.setSecure(false); connector.setPort(80); connector.setRedirectPort(8443); return connector; }
Example 7
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 8
Source File: WebConfiguration.java From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License | 5 votes |
public void configureConnector(Connector connector) { if (port != null) connector.setPort(port); if (secure != null) connector.setSecure(secure); if (scheme != null) connector.setScheme(scheme); if (ssl != null) connector.setProperty("SSLEnabled", ssl.toString()); if (keystore != null && keystore.exists()) { connector.setProperty("keystoreFile", keystore.getAbsolutePath()); connector.setProperty("keystorePassword", keystorePassword); } }
Example 9
Source File: WebConfiguration.java From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License | 5 votes |
public void configureConnector(Connector connector) { if (port != null) connector.setPort(port); if (secure != null) connector.setSecure(secure); if (scheme != null) connector.setScheme(scheme); if (ssl != null) connector.setProperty("SSLEnabled", ssl.toString()); if (keystore != null && keystore.exists()) { connector.setProperty("keystoreFile", keystore.getAbsolutePath()); connector.setProperty("keystorePassword", keystorePassword); } }
Example 10
Source File: WebConfiguration.java From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License | 5 votes |
public void configureConnector(Connector connector) { if (port != null) connector.setPort(port); if (secure != null) connector.setSecure(secure); if (scheme != null) connector.setScheme(scheme); if (ssl != null) connector.setProperty("SSLEnabled", ssl.toString()); if (keystore != null && keystore.exists()) { connector.setProperty("keystoreFile", keystore.getAbsolutePath()); connector.setProperty("keystorePassword", keystorePassword); } }
Example 11
Source File: JettyTest.java From cxf-fediz with Apache License 2.0 | 5 votes |
private static void initIdp() throws Exception { idpServer = new Tomcat(); idpServer.setPort(0); final Path targetDir = Paths.get("target").toAbsolutePath(); idpServer.setBaseDir(targetDir.toString()); idpServer.getHost().setAppBase("tomcat/idp/webapps"); idpServer.getHost().setAutoDeploy(true); idpServer.getHost().setDeployOnStartup(true); Connector httpsConnector = new Connector(); httpsConnector.setPort(Integer.parseInt(IDP_HTTPS_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); idpServer.getService().addConnector(httpsConnector); Path stsWebapp = targetDir.resolve(idpServer.getHost().getAppBase()).resolve("fediz-idp-sts"); idpServer.addWebapp("/fediz-idp-sts", stsWebapp.toString()); Path idpWebapp = targetDir.resolve(idpServer.getHost().getAppBase()).resolve("fediz-idp"); idpServer.addWebapp("/fediz-idp", idpWebapp.toString()); idpServer.start(); }
Example 12
Source File: SslConfig.java From spring-boot-cookbook with Apache License 2.0 | 5 votes |
@Bean public Connector httpConnector() { Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); connector.setScheme("http"); //Connector监听的http的端口号 connector.setPort(80); connector.setSecure(false); //监听到http的端口号后转向到的https的端口号 connector.setRedirectPort(8443); return connector; }
Example 13
Source File: WebConfiguration.java From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License | 5 votes |
public void configureConnector(Connector connector) { if (port != null) connector.setPort(port); if (secure != null) connector.setSecure(secure); if (scheme != null) connector.setScheme(scheme); if (ssl != null) connector.setProperty("SSLEnabled", ssl.toString()); if (keystore != null && keystore.exists()) { connector.setProperty("keystoreFile", keystore.getAbsolutePath()); connector.setProperty("keystorePassword", keystorePassword); } }
Example 14
Source File: WebServerService.java From kurento-java with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean public ServletWebServerFactory servletContainer() { TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory(); Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); connector.setScheme("http"); connector.setPort(getAppHttpPort()); tomcat.addAdditionalTomcatConnectors(connector); return tomcat; }
Example 15
Source File: SystemConfiguration.java From NFVO with Apache License 2.0 | 5 votes |
private Connector initiateHttpConnector() { Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); connector.setScheme("http"); connector.setPort(8080); if (https) { connector.setSecure(false); connector.setRedirectPort(8443); } return connector; }
Example 16
Source File: WebConfig.java From jcart with MIT License | 5 votes |
private Connector initiateHttpConnector() { Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); connector.setScheme("http"); connector.setPort(9090); connector.setSecure(false); connector.setRedirectPort(serverPort); return connector; }
Example 17
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 18
Source File: LDAPTest.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()); 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 19
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 20
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; }