Java Code Examples for org.apache.catalina.connector.Connector#setProperty()
The following examples show how to use
org.apache.catalina.connector.Connector#setProperty() .
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: TestSwallowAbortedUploads.java From Tomcat8-Source-Read with MIT License | 6 votes |
private synchronized void init(int status, boolean swallow) throws Exception { Tomcat tomcat = getTomcatInstance(); context = tomcat.addContext("", TEMP_DIR); AbortedPOSTServlet servlet = new AbortedPOSTServlet(status); Tomcat.addServlet(context, servletName, servlet); context.addServletMappingDecoded(URI, servletName); context.setSwallowAbortedUploads(swallow); tomcat.start(); Connector c = tomcat.getConnector(); c.setMaxPostSize(2 * hugeSize); c.setProperty("maxSwallowSize", Integer.toString(hugeSize)); setPort(c.getLocalPort()); }
Example 3
Source File: MBeanFactory.java From tomcatsrc 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 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: AbstractWebServiceTest.java From openmeetings with Apache License 2.0 | 6 votes |
@BeforeAll public static void initialize() throws Exception { AbstractSpringTest.init(); tomcat = new Tomcat(); Connector connector = new Connector("HTTP/1.1"); connector.setProperty("address", InetAddress.getByName(HOST).getHostAddress()); connector.setPort(0); tomcat.getService().addConnector(connector); tomcat.setConnector(connector); File wd = Files.createTempDirectory("om" + randomUUID().toString()).toFile(); tomcat.setBaseDir(wd.getCanonicalPath()); tomcat.getHost().setAppBase(wd.getCanonicalPath()); tomcat.getHost().setAutoDeploy(false); tomcat.getHost().setDeployOnStartup(false); tomcat.addWebapp(CONTEXT, getOmHome().getAbsolutePath()); tomcat.getConnector(); // to init the connector tomcat.start(); port = tomcat.getConnector().getLocalPort(); }
Example 6
Source File: TestCustomSsl.java From tomcatsrc with Apache License 2.0 | 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"); connector.setProperty(TesterBug50640SslImpl.PROPERTY_NAME, TesterBug50640SslImpl.PROPERTY_VALUE); connector.setProperty("sslProtocol", "tls"); File keystoreFile = new File("test/org/apache/tomcat/util/net/localhost.jks"); connector.setAttribute( "keystoreFile", keystoreFile.getAbsolutePath()); connector.setSecure(true); connector.setProperty("SSLEnabled", "true"); File appDir = new File(getBuildDirectory(), "webapps/examples"); tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath()); tomcat.start(); ByteChunk res = getUrl("https://localhost:" + getPort() + "/examples/servlets/servlet/HelloWorldExample"); assertTrue(res.toString().indexOf("<a href=\"../helloworld.html\">") > 0); }
Example 7
Source File: ServiceMBean.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Add a new Connector to the set of defined Connectors, and associate it * with this Service's Container. * * @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 * * @throws MBeanException error creating the connector */ public void addConnector(String address, int port, boolean isAjp, boolean isSSL) throws MBeanException { Service service = doGetManagedResource(); String protocol = isAjp ? "AJP/1.3" : "HTTP/1.1"; Connector connector = new Connector(protocol); if ((address!=null) && (address.length()>0)) { connector.setProperty("address", address); } connector.setPort(port); connector.setSecure(isSSL); connector.setScheme(isSSL ? "https" : "http"); service.addConnector(connector); }
Example 8
Source File: TestCustomSsl.java From Tomcat7.0.67 with Apache License 2.0 | 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"); connector.setProperty(TesterBug50640SslImpl.PROPERTY_NAME, TesterBug50640SslImpl.PROPERTY_VALUE); connector.setProperty("sslProtocol", "tls"); File keystoreFile = new File("test/org/apache/tomcat/util/net/localhost.jks"); connector.setAttribute( "keystoreFile", keystoreFile.getAbsolutePath()); connector.setSecure(true); connector.setProperty("SSLEnabled", "true"); File appDir = new File(getBuildDirectory(), "webapps/examples"); tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath()); tomcat.start(); ByteChunk res = getUrl("https://localhost:" + getPort() + "/examples/servlets/servlet/HelloWorldExample"); assertTrue(res.toString().indexOf("<h1>Hello World!</h1>") > 0); }
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: 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 12
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 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: 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 15
Source File: TestSSLHostConfigCompat.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public void setUp() throws Exception { super.setUp(); AprLifecycleListener listener = new AprLifecycleListener(); Assume.assumeTrue(AprLifecycleListener.isAprAvailable()); Assume.assumeTrue(JreCompat.isJre8Available()); Tomcat tomcat = getTomcatInstance(); Connector connector = tomcat.getConnector(); connector.setPort(0); connector.setScheme("https"); connector.setSecure(true); connector.setProperty("SSLEnabled", "true"); connector.setProperty("sslImplementationName", sslImplementationName); sslHostConfig.setProtocols("TLSv1.2"); connector.addSslHostConfig(sslHostConfig); StandardServer server = (StandardServer) tomcat.getServer(); server.addLifecycleListener(listener); // Simple webapp Context ctxt = tomcat.addContext("", null); Tomcat.addServlet(ctxt, "TesterServlet", new TesterServlet()); ctxt.addServletMappingDecoded("/*", "TesterServlet"); }
Example 16
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 17
Source File: TestHttp11InputBuffer.java From Tomcat8-Source-Read with MIT License | 5 votes |
private Exception doRequest() { // Ensure body is read correctly setUseContentLength(true); Tomcat tomcat = getTomcatInstance(); Context root = tomcat.addContext("", TEMP_DIR); Tomcat.addServlet(root, "Bug59089", new TesterServlet()); root.addServletMappingDecoded("/test", "Bug59089"); try { Connector connector = tomcat.getConnector(); connector.setProperty("rejectIllegalHeaderName", "false"); tomcat.start(); setPort(connector.getLocalPort()); // Open connection connect(); String[] request = new String[1]; request[0] = "GET http://localhost:8080/test HTTP/1.1" + CRLF + "Host: localhost:8080" + CRLF + "X-Header: Ignore" + CRLF + "X-Header" + (char) 130 + ": Broken" + CRLF + CRLF; setRequest(request); processRequest(); // blocks until response has been read // Close the connection disconnect(); } catch (Exception e) { return e; } return null; }
Example 18
Source File: TestHttp11InputBuffer.java From Tomcat8-Source-Read with MIT License | 5 votes |
private Exception doRequest() { Tomcat tomcat = getTomcatInstance(); Context root = tomcat.addContext("", TEMP_DIR); Tomcat.addServlet(root, "Bug51557", new Bug51557Servlet(headerName)); root.addServletMappingDecoded("/test", "Bug51557"); try { Connector connector = tomcat.getConnector(); connector.setProperty("rejectIllegalHeaderName", Boolean.toString(rejectIllegalHeaderName)); tomcat.start(); setPort(connector.getLocalPort()); // Open connection connect(); String[] request = new String[1]; request[0] = "GET http://localhost:8080/test HTTP/1.1" + CRLF + "Host: localhost:8080" + CRLF + headerLine + CRLF + "X-Bug51557: abcd" + CRLF + "Connection: close" + CRLF + CRLF; setRequest(request); processRequest(); // blocks until response has been read // Close the connection disconnect(); } catch (Exception e) { return e; } return null; }
Example 19
Source File: TestSwallowAbortedUploads.java From Tomcat8-Source-Read with MIT License | 5 votes |
private synchronized void init(boolean limited, boolean swallow) throws Exception { Tomcat tomcat = getTomcatInstance(); context = tomcat.addContext("", TEMP_DIR); Wrapper w; w = Tomcat.addServlet(context, servletName, new AbortedUploadServlet()); // Tomcat.addServlet does not respect annotations, so we have // to set our own MultipartConfigElement. // Choose upload file size limit. if (limited) { w.setMultipartConfigElement(new MultipartConfigElement("", limitSize, -1, -1)); } else { w.setMultipartConfigElement(new MultipartConfigElement("")); } context.addServletMappingDecoded(URI, servletName); context.setSwallowAbortedUploads(swallow); Connector c = tomcat.getConnector(); c.setMaxPostSize(2 * hugeSize); c.setProperty("maxSwallowSize", Integer.toString(hugeSize)); tomcat.start(); setPort(c.getLocalPort()); }
Example 20
Source File: TomcatConnectorsUpdater.java From aceql-http with GNU Lesser General Public License v2.1 | 4 votes |
/** * If there are some SSL Connector properties, set them on Tomcat instance * default Connector */ public void setDefaultConnectorSslValues() throws DatabaseConfigurationException, ConnectException { String sslConnectorSSLEnabled = properties .getProperty("sslConnector.SSLEnabled"); if (sslConnectorSSLEnabled != null) { sslConnectorSSLEnabled = sslConnectorSSLEnabled.trim(); } // Do we have to add an SSL Connector? if (sslConnectorSSLEnabled == null || !sslConnectorSSLEnabled.trim().equals("true")) { return; } // Scheme is mandatory String scheme = getMandatoryPropertyValue("sslConnector.scheme"); if (!scheme.equals("https")) { throw new DatabaseConfigurationException( "The property sslConnector.https value must be \"https\" in properties file. " + SqlTag.PLEASE_CORRECT); } // Testing the keystore file String keyStoreFileStr = getMandatoryPropertyValue( "sslConnector.keystoreFile"); File keystoreFile = new File(keyStoreFileStr); if (!keystoreFile.exists()) { throw new DatabaseConfigurationException( "The file specified by sslConnector.keystoreFile property does not exists: " + keystoreFile + ". " + SqlTag.PLEASE_CORRECT); } // Testing that keystore & keyPass password are set @SuppressWarnings("unused") String keystorePass = getMandatoryPropertyValue( "sslConnector.keystorePass"); @SuppressWarnings("unused") String keyPass = getMandatoryPropertyValue("sslConnector.keyPass"); // Testing that key alias is set @SuppressWarnings("unused") String keyAlias = getMandatoryPropertyValue("sslConnector.keyAlias"); Connector defaultConnector = tomcat.getConnector(); defaultConnector.setScheme(scheme); defaultConnector.setSecure(true); // Set the SSL connector Enumeration<?> enumeration = properties.propertyNames(); if (enumeration.hasMoreElements()) { System.out.println(SqlTag.SQL_PRODUCT_START + " Setting Default Connector SSL attributes:"); } while (enumeration.hasMoreElements()) { String property = (String) enumeration.nextElement(); if (property.startsWith("sslConnector.") && !property.equals("sslConnector.scheme")) { String theValue = properties.getProperty(property); String tomcatProperty = StringUtils.substringAfter(property, "sslConnector."); if (theValue != null && !theValue.isEmpty()) { theValue = theValue.trim(); defaultConnector.setProperty(tomcatProperty, theValue); if (property.equals("sslConnector.keyPass") || property.equals("sslConnector.keystorePass")) { theValue = TomcatStarter.MASKED_PASSWORD; } System.out.println(SqlTag.SQL_PRODUCT_START + " -> " + tomcatProperty + " = " + theValue); } } } // Service service = tomcat.getService(); // service.addConnector(sslConnector); // Add the connector }