or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

authentication.mdcatalina-core.mdconnectors.mdembedded-tomcat.mdindex.mdlogging.mdservlet-api.mdsession-management.mdutilities.mdvalves.mdweb-resources.md

connectors.mddocs/

0

# HTTP and Protocol Connectors

1

2

Coyote connector architecture provides protocol handlers for HTTP/1.1, HTTP/2, and AJP protocols. Connectors manage network I/O, thread pools, connection limits, and protocol-specific processing to efficiently handle incoming requests and generate responses.

3

4

## Capabilities

5

6

### Connector Class

7

8

Main connector implementation managing protocol handlers and network configuration.

9

10

```java { .api }

11

public class Connector extends LifecycleMBeanBase {

12

// Constructors

13

public Connector();

14

public Connector(String protocol);

15

public Connector(ProtocolHandler protocolHandler);

16

17

// Protocol configuration

18

public String getProtocol();

19

public String getProtocolHandlerClassName();

20

public ProtocolHandler getProtocolHandler();

21

22

// Network configuration

23

public int getPort();

24

public void setPort(int port);

25

public int getPortOffset();

26

public void setPortOffset(int portOffset);

27

public int getPortWithOffset();

28

public int getLocalPort();

29

30

// Scheme and security

31

public String getScheme();

32

public void setScheme(String scheme);

33

public boolean getSecure();

34

public void setSecure(boolean secure);

35

36

// Async timeout configuration

37

public long getAsyncTimeout();

38

public void setAsyncTimeout(long asyncTimeout);

39

40

// Request configuration

41

public int getMaxPostSize();

42

public void setMaxPostSize(int maxPostSize);

43

public int getMaxSavePostSize();

44

public void setMaxSavePostSize(int maxSavePostSize);

45

public int getMaxParameterCount();

46

public void setMaxParameterCount(int maxParameterCount);

47

public int getMaxCookieCount();

48

public void setMaxCookieCount(int maxCookieCount);

49

public String getParseBodyMethods();

50

public void setParseBodyMethods(String methods);

51

52

// Encoding

53

public String getURIEncoding();

54

public void setURIEncoding(String URIEncoding);

55

public Charset getURICharset();

56

public boolean getUseBodyEncodingForURI();

57

public void setUseBodyEncodingForURI(boolean useBodyEncodingForURI);

58

public String getEncodedSolidusHandling();

59

public void setEncodedSolidusHandling(String encodedSolidusHandling);

60

public String getEncodedReverseSolidusHandling();

61

public void setEncodedReverseSolidusHandling(String encodedReverseSolidusHandling);

62

63

// Proxy configuration

64

public String getProxyName();

65

public void setProxyName(String proxyName);

66

public int getProxyPort();

67

public void setProxyPort(int proxyPort);

68

69

// Redirect configuration

70

public int getRedirectPort();

71

public void setRedirectPort(int redirectPort);

72

public int getRedirectPortWithOffset();

73

74

// Service reference

75

public Service getService();

76

public void setService(Service service);

77

78

// Request/Response creation

79

public Request createRequest();

80

public Response createResponse();

81

82

// Protocol handler properties (delegated via reflection)

83

public boolean setProperty(String name, String value);

84

public Object getProperty(String name);

85

86

// Utility configuration

87

public boolean getAllowBackslash();

88

public void setAllowBackslash(boolean allowBackslash);

89

public boolean getAllowTrace();

90

public void setAllowTrace(boolean allowTrace);

91

public boolean getEnableLookups();

92

public void setEnableLookups(boolean enableLookups);

93

public boolean getDiscardFacades();

94

public void setDiscardFacades(boolean discardFacades);

95

public boolean getEnforceEncodingInGetWriter();

96

public void setEnforceEncodingInGetWriter(boolean enforceEncodingInGetWriter);

97

public boolean getXpoweredBy();

98

public void setXpoweredBy(boolean xpoweredBy);

99

public boolean getUseIPVHosts();

100

public void setUseIPVHosts(boolean useIPVHosts);

101

public boolean getRejectSuspiciousURIs();

102

public void setRejectSuspiciousURIs(boolean rejectSuspiciousURIs);

103

104

// SSL configuration

105

public void addSslHostConfig(SSLHostConfig sslHostConfig);

106

public SSLHostConfig[] findSslHostConfigs();

107

108

// Protocol upgrades

109

public void addUpgradeProtocol(UpgradeProtocol upgradeProtocol);

110

public UpgradeProtocol[] findUpgradeProtocols();

111

112

// Executor

113

public String getExecutorName();

114

public void setExecutorName(String executorName);

115

116

// Lifecycle methods

117

public void init() throws LifecycleException;

118

public void start() throws LifecycleException;

119

public void stop() throws LifecycleException;

120

public void destroy() throws LifecycleException;

121

public void pause();

122

public void resume();

123

public LifecycleState getState();

124

public String getStateName();

125

126

// Management

127

public String getDomain();

128

public ObjectName getObjectName();

129

130

// Lifecycle listeners

131

public void addLifecycleListener(LifecycleListener listener);

132

public void removeLifecycleListener(LifecycleListener listener);

133

public LifecycleListener[] findLifecycleListeners();

134

}

135

```

136

137

### Protocol Handler Properties

138

139

The `Connector` class delegates many configuration properties to its underlying `ProtocolHandler` using the `setProperty(String name, String value)` method. Common properties include:

140

141

- **maxThreads**: Maximum number of request processing threads (default: 200)

142

- **minSpareThreads**: Minimum number of spare threads (default: 10)

143

- **maxConnections**: Maximum number of connections (default: 8192 for NIO)

144

- **acceptCount**: Maximum queue length for incoming connections (default: 100)

145

- **connectionTimeout**: Network connection timeout in milliseconds (default: 20000)

146

- **keepAliveTimeout**: Keep-alive timeout in milliseconds (default: connectionTimeout)

147

- **maxKeepAliveRequests**: Maximum keep-alive requests per connection (default: 100)

148

- **compression**: Enable compression ("on", "off", "force")

149

- **compressionMinSize**: Minimum response size to compress (default: 2048)

150

- **compressibleMimeType**: MIME types to compress (default: text/html,text/xml,text/plain,text/css,text/javascript,application/javascript)

151

- **address**: Network address to bind (default: all addresses)

152

153

These properties are accessed via reflection on the `ProtocolHandler` implementation.

154

155

### Protocol Handlers

156

157

Base interfaces for protocol implementations.

158

159

```java { .api }

160

public interface ProtocolHandler {

161

// Configuration

162

public void setAdapter(Adapter adapter);

163

public Adapter getAdapter();

164

165

// Executor

166

public Executor getExecutor();

167

168

// Lifecycle

169

public void init() throws Exception;

170

public void start() throws Exception;

171

public void pause() throws Exception;

172

public void resume() throws Exception;

173

public void stop() throws Exception;

174

public void destroy() throws Exception;

175

176

// Socket utilities

177

public boolean isSendfileSupported();

178

}

179

180

public interface Adapter {

181

public void service(org.apache.coyote.Request req, org.apache.coyote.Response res)

182

throws Exception;

183

public boolean prepare(org.apache.coyote.Request req, org.apache.coyote.Response res)

184

throws Exception;

185

public boolean asyncDispatch(org.apache.coyote.Request req, org.apache.coyote.Response res,

186

SocketEvent status) throws Exception;

187

public void log(org.apache.coyote.Request req, org.apache.coyote.Response res, long time);

188

public void checkRecycled(org.apache.coyote.Request req, org.apache.coyote.Response res);

189

public String getDomain();

190

}

191

```

192

193

### Coyote Request and Response

194

195

Low-level request/response objects used by protocol handlers.

196

197

```java { .api }

198

// Coyote Request

199

public final class Request {

200

// Request line

201

public MessageBytes method();

202

public MessageBytes requestURI();

203

public MessageBytes decodedURI();

204

public MessageBytes queryString();

205

public MessageBytes protocol();

206

207

// Headers

208

public MimeHeaders getMimeHeaders();

209

public int getServerPort();

210

public void setServerPort(int port);

211

public MessageBytes serverName();

212

213

// Request body

214

public InputBuffer getInputBuffer();

215

public void setInputBuffer(InputBuffer inputBuffer);

216

public int doRead(ApplicationBufferHandler handler) throws IOException;

217

public int getAvailable();

218

public boolean isFinished();

219

220

// Attributes

221

public void setAttribute(String name, Object o);

222

public Object getAttribute(String name);

223

224

// Content

225

public long getContentLengthLong();

226

public String getContentType();

227

228

// Connection

229

public MessageBytes remoteAddr();

230

public MessageBytes remoteHost();

231

public int getRemotePort();

232

public MessageBytes localAddr();

233

public int getLocalPort();

234

public MessageBytes localName();

235

236

// Lifecycle

237

public void recycle();

238

239

// Async

240

public boolean isAsync();

241

}

242

243

// Coyote Response

244

public final class Response {

245

// Status

246

public void setStatus(int status);

247

public int getStatus();

248

public String getMessage();

249

public void setMessage(String message);

250

251

// Headers

252

public MimeHeaders getMimeHeaders();

253

public void setContentLength(long length);

254

public long getContentLength();

255

public void setContentType(String type);

256

public String getContentType();

257

258

// Response body

259

public OutputBuffer getOutputBuffer();

260

public void setOutputBuffer(OutputBuffer outputBuffer);

261

public int doWrite(ByteBuffer chunk) throws IOException;

262

263

// State

264

public boolean isCommitted();

265

public void setCommitted(boolean committed);

266

public void action(ActionCode actionCode, Object param);

267

268

// Error

269

public void setErrorException(Exception ex);

270

public Exception getErrorException();

271

272

// Lifecycle

273

public void recycle();

274

275

// Async

276

public boolean isAsync();

277

}

278

```

279

280

## Usage Examples

281

282

### Custom Connector Configuration

283

284

```java

285

import org.apache.catalina.startup.Tomcat;

286

import org.apache.catalina.connector.Connector;

287

288

public class ConnectorConfigExample {

289

public static void main(String[] args) throws Exception {

290

Tomcat tomcat = new Tomcat();

291

292

// HTTP/1.1 NIO connector

293

Connector connector = new Connector("HTTP/1.1");

294

connector.setPort(8080);

295

connector.setScheme("http");

296

297

// Configure protocol handler properties via setProperty

298

connector.setProperty("maxThreads", "200");

299

connector.setProperty("minSpareThreads", "10");

300

connector.setProperty("maxConnections", "10000");

301

connector.setProperty("connectionTimeout", "20000");

302

connector.setProperty("compression", "on");

303

connector.setProperty("compressionMinSize", "2048");

304

connector.setProperty("compressibleMimeType",

305

"text/html,text/xml,text/plain,text/css,application/json");

306

307

tomcat.setConnector(connector);

308

tomcat.start();

309

tomcat.getServer().await();

310

}

311

}

312

```

313