本文整理汇总了Java中org.apache.catalina.connector.Connector.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java Connector.setAttribute方法的具体用法?Java Connector.setAttribute怎么用?Java Connector.setAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.catalina.connector.Connector
的用法示例。
在下文中一共展示了Connector.setAttribute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setConnector
import org.apache.catalina.connector.Connector; //导入方法依赖的package包/类
private void setConnector(Connector connector)
{
if( maxThreads != -2 )
{
connector.setAttribute("maxThreads", maxThreads);
}
connector.setURIEncoding("UTF-8");
connector.setUseBodyEncodingForURI(true);
tomcat.getService().addConnector(connector);
tomcat.setConnector(connector);
}
示例2: testCustomSslImplementation
import org.apache.catalina.connector.Connector; //导入方法依赖的package包/类
@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);
}
示例3: makeConnector
import org.apache.catalina.connector.Connector; //导入方法依赖的package包/类
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;
}
示例4: start
import org.apache.catalina.connector.Connector; //导入方法依赖的package包/类
/**
* Starts the Tomcat server.
*/
public void start() {
try {
System.out.println("(EmbeddedTomcat) Creating the embedded Tomcat servlet container");
System.out.println("(EmbeddedTomcat) Catalina home: " + tomcatHome);
System.setProperty("catalina.home", tomcatHome);
System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true");
// Create an embedded server
System.out.println("(EmbeddedTomcat) Creating a new instance of EmbeddedTomcat");
embedded = new Tomcat();
embedded.enableNaming();
// Assemble and install a default HTTP connector
int httpConnectorPort = 8080;
// We must load the engine properties first
EnginePropertiesManager.loadProperties();
String convertigoServer = com.twinsoft.convertigo.engine.EnginePropertiesManager.getProperty(
com.twinsoft.convertigo.engine.EnginePropertiesManager.PropertyName.APPLICATION_SERVER_CONVERTIGO_URL);
System.out.println("(EmbeddedTomcat) Convertigo server property: " + convertigoServer);
int i = convertigoServer.indexOf(':', 6);
if (i != -1) {
int j = convertigoServer.indexOf("/convertigo");
httpConnectorPort = Integer.parseInt(convertigoServer.substring(i+1, j));
}
embedded.setPort(httpPort = httpConnectorPort);
int httpsConnectorPort = httpConnectorPort + 1;
System.out.println("(EmbeddedTomcat) Installing the embedded HTTPS connector listening on port " + httpsConnectorPort);
Connector connector = new Connector();
connector.setPort(httpsConnectorPort);
connector.setSecure(true);
connector.setScheme("https");
connector.setAttribute("keystorePass", "password");
connector.setAttribute("keystoreFile", tomcatHome + "/conf/.keystore");
connector.setAttribute("clientAuth", false);
connector.setAttribute("sslProtocol", "TLS");
connector.setAttribute("SSLEnabled", true);
embedded.getService().addConnector(connector);
Context context = embedded.addWebapp("", tomcatHome + "webapps/ROOT");
context.setParentClassLoader(this.getClass().getClassLoader());
context = embedded.addWebapp("/convertigo", com.twinsoft.convertigo.engine.Engine.WEBAPP_PATH);
context.setParentClassLoader(this.getClass().getClassLoader());
File configFile = new File(com.twinsoft.convertigo.engine.Engine.USER_WORKSPACE_PATH + "/studio/context.xml");
if (configFile.exists()) {
System.out.println("(EmbeddedTomcat) Set convertigo webapp config file to " + configFile.getAbsolutePath());
context.setConfigFile(configFile.toURI().toURL());
}
// Start the embedded server
System.out.println("(EmbeddedTomcat) Starting the server");
embedded.start();
System.out.println("(EmbeddedTomcat) Server successfully started!");
}
catch(Throwable e) {
String stackTrace = Log.getStackTrace(e);
System.out.println("(EmbeddedTomcat) Unexpected exception while launching Tomcat:\n" + stackTrace);
Engine.isStartFailed = true;
}
}
示例5: setUp
import org.apache.catalina.connector.Connector; //导入方法依赖的package包/类
@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"));
}