use of org.apache.coyote.ProtocolHandler in project tomcat by apache.
the class ConnectorStoreAppender method getPropertyKeys.
/**
* Get all properties from Connector and current ProtocolHandler.
*
* @param bean The connector
* @return List of Connector property names
* @throws IntrospectionException Error introspecting connector
*/
protected List<String> getPropertyKeys(Connector bean) throws IntrospectionException {
List<String> propertyKeys = new ArrayList<>();
// Acquire the list of properties for this bean
ProtocolHandler protocolHandler = bean.getProtocolHandler();
// Acquire the list of properties for this bean
PropertyDescriptor[] descriptors = Introspector.getBeanInfo(bean.getClass()).getPropertyDescriptors();
if (descriptors == null) {
descriptors = new PropertyDescriptor[0];
}
for (PropertyDescriptor descriptor : descriptors) {
if (descriptor instanceof IndexedPropertyDescriptor) {
// Indexed properties are not persisted
continue;
}
if (!isPersistable(descriptor.getPropertyType()) || (descriptor.getReadMethod() == null) || (descriptor.getWriteMethod() == null)) {
// Must be a read-write primitive or String
continue;
}
if ("protocol".equals(descriptor.getName()) || "protocolHandlerClassName".equals(descriptor.getName())) {
continue;
}
propertyKeys.add(descriptor.getName());
}
// Add the properties of the protocol handler
descriptors = Introspector.getBeanInfo(protocolHandler.getClass()).getPropertyDescriptors();
if (descriptors == null) {
descriptors = new PropertyDescriptor[0];
}
for (PropertyDescriptor descriptor : descriptors) {
if (descriptor instanceof IndexedPropertyDescriptor) {
// Indexed properties are not persisted
continue;
}
if (!isPersistable(descriptor.getPropertyType()) || (descriptor.getReadMethod() == null) || (descriptor.getWriteMethod() == null)) {
// Must be a read-write primitive or String
continue;
}
String key = descriptor.getName();
if (!Connector.INTERNAL_EXECUTOR_NAME.equals(bean.getExecutorName()) && internalExecutorAttributes.contains(key)) {
continue;
}
if (replacements.get(key) != null) {
key = replacements.get(key);
}
if (!propertyKeys.contains(key)) {
propertyKeys.add(key);
}
}
// Add the properties for the socket
final String socketName = "socket.";
descriptors = Introspector.getBeanInfo(SocketProperties.class).getPropertyDescriptors();
if (descriptors == null) {
descriptors = new PropertyDescriptor[0];
}
for (PropertyDescriptor descriptor : descriptors) {
if (descriptor instanceof IndexedPropertyDescriptor) {
// Indexed properties are not persisted
continue;
}
if (!isPersistable(descriptor.getPropertyType()) || (descriptor.getReadMethod() == null) || (descriptor.getWriteMethod() == null)) {
// Must be a read-write primitive or String
continue;
}
String key = descriptor.getName();
if (replacements.get(key) != null) {
key = replacements.get(key);
}
if (!propertyKeys.contains(key)) {
// Add socket.[original name] if this is not a property
// that could be set elsewhere
propertyKeys.add(socketName + descriptor.getName());
}
}
return propertyKeys;
}
use of org.apache.coyote.ProtocolHandler in project tomcat by apache.
the class ThreadLocalLeakPreventionListener method stopIdleThreads.
/**
* Updates each ThreadPoolExecutor with the current time, which is the time
* when a context is being stopped.
*
* @param context
* the context being stopped, used to discover all the Connectors
* of its parent Service.
*/
private void stopIdleThreads(Context context) {
if (serverStopping) {
return;
}
if (!(context instanceof StandardContext) || !((StandardContext) context).getRenewThreadsWhenStoppingContext()) {
log.debug("Not renewing threads when the context is stopping. " + "It is not configured to do it.");
return;
}
Engine engine = (Engine) context.getParent().getParent();
Service service = engine.getService();
Connector[] connectors = service.findConnectors();
if (connectors != null) {
for (Connector connector : connectors) {
ProtocolHandler handler = connector.getProtocolHandler();
Executor executor = null;
if (handler != null) {
executor = handler.getExecutor();
}
if (executor instanceof ThreadPoolExecutor) {
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executor;
threadPoolExecutor.contextStopping();
} else if (executor instanceof StandardThreadExecutor) {
StandardThreadExecutor stdThreadExecutor = (StandardThreadExecutor) executor;
stdThreadExecutor.contextStopping();
}
}
}
}
use of org.apache.coyote.ProtocolHandler in project tomcat by apache.
the class TestCustomSslTrustManager method doTestCustomTrustManager.
private void doTestCustomTrustManager(TrustType trustType) throws Exception {
Tomcat tomcat = getTomcatInstance();
TesterSupport.configureClientCertContext(tomcat);
Connector connector = tomcat.getConnector();
TesterSupport.configureSSLImplementation(tomcat, sslImplementationName);
if (needApr) {
AprLifecycleListener listener = new AprLifecycleListener();
Assume.assumeTrue(AprLifecycleListener.isAprAvailable());
StandardServer server = (StandardServer) tomcat.getServer();
server.addLifecycleListener(listener);
}
// Override the defaults
ProtocolHandler handler = connector.getProtocolHandler();
if (handler instanceof AbstractHttp11JsseProtocol) {
connector.findSslHostConfigs()[0].setTruststoreFile(null);
} else {
// Unexpected
Assert.fail("Unexpected handler type");
}
if (trustType.equals(TrustType.ALL)) {
connector.findSslHostConfigs()[0].setTrustManagerClassName("org.apache.tomcat.util.net.TesterSupport$TrustAllCerts");
} else if (trustType.equals(TrustType.CA)) {
connector.findSslHostConfigs()[0].setTrustManagerClassName("org.apache.tomcat.util.net.TesterSupport$SequentialTrustManager");
}
// Start Tomcat
tomcat.start();
TesterSupport.configureClientSsl();
// Unprotected resource
ByteChunk res = getUrl("https://localhost:" + getPort() + "/unprotected");
Assert.assertEquals("OK", res.toString());
// Protected resource
res.recycle();
int rc = -1;
try {
rc = getUrl("https://localhost:" + getPort() + "/protected", res, null, null);
} catch (SocketException | SSLException e) {
if (!trustType.equals(TrustType.NONE)) {
Assert.fail(e.getMessage());
e.printStackTrace();
}
}
if (trustType.equals(TrustType.CA)) {
if (log.isDebugEnabled()) {
int count = TesterSupport.getLastClientAuthRequestedIssuerCount();
log.debug("Last client KeyManager usage: " + TesterSupport.getLastClientAuthKeyManagerUsage() + ", " + count + " requested Issuers, first one: " + (count > 0 ? TesterSupport.getLastClientAuthRequestedIssuer(0).getName() : "NONE"));
log.debug("Expected requested Issuer: " + TesterSupport.getClientAuthExpectedIssuer());
}
Assert.assertTrue("Checking requested client issuer against " + TesterSupport.getClientAuthExpectedIssuer(), TesterSupport.checkLastClientAuthRequestedIssuers());
}
if (trustType.equals(TrustType.NONE)) {
Assert.assertTrue(rc != 200);
Assert.assertNull(res.toString());
} else {
Assert.assertEquals(200, rc);
Assert.assertEquals("OK-" + TesterSupport.ROLE, res.toString());
}
}
use of org.apache.coyote.ProtocolHandler in project spring-boot by spring-projects.
the class TomcatWebServerFactoryCustomizer method customizeMaxKeepAliveRequests.
private void customizeMaxKeepAliveRequests(ConfigurableTomcatWebServerFactory factory, int maxKeepAliveRequests) {
factory.addConnectorCustomizers((connector) -> {
ProtocolHandler handler = connector.getProtocolHandler();
if (handler instanceof AbstractHttp11Protocol) {
AbstractHttp11Protocol<?> protocol = (AbstractHttp11Protocol<?>) handler;
protocol.setMaxKeepAliveRequests(maxKeepAliveRequests);
}
});
}
use of org.apache.coyote.ProtocolHandler in project spring-boot by spring-projects.
the class TomcatWebServerFactoryCustomizer method customizeKeepAliveTimeout.
private void customizeKeepAliveTimeout(ConfigurableTomcatWebServerFactory factory, Duration keepAliveTimeout) {
factory.addConnectorCustomizers((connector) -> {
ProtocolHandler handler = connector.getProtocolHandler();
if (handler instanceof AbstractProtocol) {
AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;
protocol.setKeepAliveTimeout((int) keepAliveTimeout.toMillis());
}
});
}
Aggregations