The AJP Connector
Table of Contents
Introduction
The AJP Connector element represents a
Connector component that communicates with a web
connector via the AJP
protocol. This is used for cases
where you wish to invisibly integrate Tomcat into an existing (or new)
Apache installation, and you want Apache to handle the static content
contained in the web application, and/or utilize Apache's SSL
processing.
Use of the AJP protocol requires additional security considerations because
it allows greater direct manipulation of Tomcat's internal data structures
than the HTTP connectors. Particular attention should be paid to the values
used for the address
, secret
,
secretRequired
and allowedRequestAttributesPattern
attributes.
This connector supports load balancing when used in conjunction with
the jvmRoute
attribute of the
Engine.
The native connectors supported with this Tomcat release are:
- JK 1.2.x with any of the supported servers. See the JK docs for details.
- mod_proxy on Apache httpd 2.x (included by default in Apache HTTP Server 2.2), with AJP enabled: see the httpd docs for details.
Other native connectors supporting AJP may work, but are no longer supported.
Attributes
Common Attributes
All implementations of Connector support the following attributes:
Attribute | Description |
---|---|
allowBackslash |
If this is If not specified, the default value of |
allowTrace |
A boolean value which can be used to enable or disable the TRACE
HTTP method. If not specified, this attribute is set to false. As per RFC
7231 section 4.3.8, cookie and authorization headers will be excluded from
the response to the TRACE request. If you wish to include these, you can
implement the |
asyncTimeout |
The default timeout for asynchronous requests in milliseconds. If not specified, this attribute is set to the Servlet specification default of 30000 (30 seconds). |
discardFacades |
A boolean value which can be used to enable or disable the recycling
of the facade objects that isolate the container internal request
processing objects. If set to |
enableLookups |
Set to |
encodedSolidusHandling |
When set to |
enforceEncodingInGetWriter |
If this is If not specified, the default specification compliant value of
|
maxCookieCount |
The maximum number of cookies that are permitted for a request. A value of less than zero means no limit. If not specified, a default value of 200 will be used. |
maxParameterCount |
The maximum total number of request parameters (including uploaded
files) obtained from the query string and, for POST requests, the request
body if the content type is
|
maxPostSize |
The maximum size in bytes of the POST which will be handled by the container FORM URL parameter parsing. The limit can be disabled by setting this attribute to a value less than zero. Requests that exceed this limit will be rejected. If not specified, this attribute is set to 2097152 (2 MiB). |
maxSavePostSize |
The maximum size in bytes of the POST which will be saved/buffered by the container during FORM or CLIENT-CERT authentication. For both types of authentication, the POST will be saved/buffered before the user is authenticated. For CLIENT-CERT authentication, the POST is buffered for the duration of the SSL handshake and the buffer emptied when the request is processed. For FORM authentication the POST is saved whilst the user is re-directed to the login form and is retained until the user successfully authenticates or the session associated with the authentication request expires. The limit can be disabled by setting this attribute to -1. Setting the attribute to zero will disable the saving of POST data during authentication. If not specified, this attribute is set to 4096 (4 KiB). |
parseBodyMethods |
A comma-separated list of HTTP methods for which request
bodies using |
port |
The TCP port number on which this Connector will create a server socket and await incoming connections. Your operating system will allow only one server application to listen to a particular port number on a particular IP address. If the special value of 0 (zero) is used, then Tomcat will select a free port at random to use for this connector. This is typically only useful in embedded and testing applications. |
protocol |
Sets the protocol to handle incoming traffic. To configure an AJP
connector this must be specified. If no value for protocol is provided,
an HTTP connector rather than an AJP connector
will be configured. |
proxyName |
If this Connector is being used in a proxy
configuration, configure this attribute to specify the server name
to be returned for calls to |
proxyPort |
If this Connector is being used in a proxy
configuration, configure this attribute to specify the server port
to be returned for calls to |
redirectPort |
If this Connector is supporting non-SSL
requests, and a request is received for which a matching
|
rejectSuspiciousURIs |
Should this Connector reject a requests if the URI
matches one of the suspicious URIs patterns identified by the Servlet 6.0
specification? The default value is |
scheme |
Set this attribute to the name of the protocol you wish to have
returned by calls to |
secure |
Set this attribute to |
URIEncoding |
This specifies the character encoding used to decode the URI bytes,
after %xx decoding the URL. The default value is |
useBodyEncodingForURI |
This specifies if the encoding specified in contentType should be used
for URI query parameters, instead of using the URIEncoding. This
setting is present for compatibility with Tomcat 4.1.x, where the
encoding specified in the contentType, or explicitly set using
Request.setCharacterEncoding method was also used for the parameters from
the URL. The default value is Notes: See notes on this attribute in HTTP Connector documentation. |
useIPVHosts |
Set this attribute to |
xpoweredBy |
Set this attribute to |
Standard Implementations
To use AJP, you must specify the protocol attribute (see above).
The standard AJP connectors (NIO and NIO2) both support the following attributes in addition to the common Connector attributes listed above.
Attribute | Description |
---|---|
acceptCount |
The maximum length of the operating system provided queue for incoming
connection requests when |
acceptorThreadCount |
The number of threads to be used to accept connections. Increase this
value on a multi CPU machine, although you would never really need more
than |
acceptorThreadPriority |
The priority of the acceptor threads. The threads used to accept
new connections. The default value is |
address |
For servers with more than one IP address, this attribute specifies
which address will be used for listening on the specified port. By
default, the connector will listen on the loopback address. Unless the JVM
is configured otherwise using system properties, the Java based connectors
(NIO, NIO2) will listen on both IPv4 and IPv6 addresses when configured
with either |
ajpFlush |
A boolean value which can be used to enable or disable sending
AJP flush messages to the fronting proxy whenever an explicit
flush happens. The default value is |
allowedRequestAttributesPattern |
The AJP protocol passes some information from the reverse proxy to the AJP connector using request attributes. These attributes are:
The AJP protocol supports the passing of arbitrary request attributes.
Requests containing arbitrary request attributes will be rejected with a
403 response unless the entire attribute name matches this regular
expression. If not specified, the default value is |
bindOnInit |
Controls when the socket used by the connector is bound. If set to
|
clientCertProvider |
When client certificate information is presented in a form other than
instances of |
connectionLinger |
The number of seconds during which the sockets used by this
Connector will linger when they are closed. The default
value is |
connectionTimeout |
The number of milliseconds this Connector will wait,
after accepting a connection, for the request URI line to be
presented. The default value for AJP protocol connectors
is |
executor |
A reference to the name in an Executor element. If this attribute is set, and the named executor exists, the connector will use the executor, and all the other thread attributes will be ignored. Note that if a shared executor is not specified for a connector then the connector will use a private, internal executor to provide the thread pool. |
executorTerminationTimeoutMillis |
The time that the private internal executor will wait for request
processing threads to terminate before continuing with the process of
stopping the connector. If not set, the default is |
keepAliveTimeout |
The number of milliseconds this Connector will wait for another AJP request before closing the connection. The default value is to use the value that has been set for the connectionTimeout attribute. |
maxConnections |
The maximum number of connections that the server will accept and
process at any given time. When this number has been reached, the server
will accept, but not process, one further connection. This additional
connection be blocked until the number of connections being processed
falls below maxConnections at which point the server will
start accepting and processing new connections again. Note that once the
limit has been reached, the operating system may still accept connections
based on the For NIO/NIO2 only, setting the value to -1, will disable the maxConnections feature and connections will not be counted. |
maxHeaderCount |
The maximum number of headers in a request that are allowed by the container. A request that contains more headers than the specified limit will be rejected. A value of less than 0 means no limit. If not specified, a default of 100 is used. |
maxThreads |
The maximum number of request processing threads to be created
by this Connector, which therefore determines the
maximum number of simultaneous requests that can be handled. If
not specified, this attribute is set to 200. If an executor is associated
with this connector, this attribute is ignored as the connector will
execute tasks using the executor rather than an internal thread pool. Note
that if an executor is configured any value set for this attribute will be
recorded correctly but it will be reported (e.g. via JMX) as
|
minSpareThreads |
The minimum number of threads always kept running. This includes both
active and idle threads. If not specified, the default of |
packetSize |
This attribute sets the maximum AJP packet size in Bytes. The maximum
value is 65536. It should be the same as the |
processorCache |
The protocol handler caches Processor objects to speed up performance.
This setting dictates how many of these objects get cached.
|
secret |
Only requests from workers with this secret keyword will be accepted.
The default value is |
secretRequired |
If this attribute is |
tcpNoDelay |
If set to |
threadPriority |
The priority of the request processing threads within the JVM.
The default value is |
throwOnFailure |
If the Connector experiences an Exception during a Lifecycle transition
should the Exception be rethrown or logged? If not specified, the default
of |
tomcatAuthentication |
If set to The web server must send the user principal (username) as a request
attribute named Note that this principal will have no roles associated with it. The default value is |
tomcatAuthorization |
If set to |
useVirtualThreads |
(bool) Use this attribute to enable or disable usage of virtual threads
with the internal executor. If an executor is associated with this
connector, this attribute is ignored. The default value is
|
Java TCP socket attributes
The NIO and NIO2 implementation support the following Java TCP socket attributes in addition to the common Connector and HTTP attributes listed above.
Attribute | Description |
---|---|
socket.rxBufSize |
(int)The socket receive buffer (SO_RCVBUF) size in bytes. JVM default used if not set. |
socket.txBufSize |
(int)The socket send buffer (SO_SNDBUF) size in bytes. JVM default used if not set. Care should be taken if explicitly setting this value. Very poor performance has been observed on some JVMs with values less than ~8k. |
socket.tcpNoDelay |
(bool)This is equivalent to standard attribute tcpNoDelay. |
socket.soKeepAlive |
(bool)Boolean value for the socket's keep alive setting (SO_KEEPALIVE). JVM default used if not set. |
socket.ooBInline |
(bool)Boolean value for the socket OOBINLINE setting. JVM default used if not set. |
socket.soReuseAddress |
(bool)Boolean value for the sockets reuse address option (SO_REUSEADDR). JVM default used if not set. |
socket.soLingerOn |
(bool)Boolean value for the sockets so linger option (SO_LINGER).
A value for the standard attribute connectionLinger
that is >=0 is equivalent to setting this to |
socket.soLingerTime |
(int)Value in seconds for the sockets so linger option (SO_LINGER).
This is equivalent to standard attribute
connectionLinger.
Both this attribute and |
socket.soTimeout |
This is equivalent to standard attribute connectionTimeout. |
socket.performanceConnectionTime |
(int)The first value for the performance settings. See Socket Performance Options All three performance attributes must be set else the JVM defaults will be used for all three. |
socket.performanceLatency |
(int)The second value for the performance settings. See Socket Performance Options All three performance attributes must be set else the JVM defaults will be used for all three. |
socket.performanceBandwidth |
(int)The third value for the performance settings. See Socket Performance Options All three performance attributes must be set else the JVM defaults will be used for all three. |
socket.unlockTimeout |
(int) The timeout for a socket unlock. When a connector is stopped, it will try to release the acceptor thread by opening a connector to itself.
The default value is |
NIO specific configuration
The following attributes are specific to the NIO connector.
Attribute | Description |
---|---|
socket.directBuffer |
(bool)Boolean value, whether to use direct ByteBuffers or java mapped
ByteBuffers. Default is |
socket.appReadBufSize |
(int)Each connection that is opened up in Tomcat get associated with
a read ByteBuffer. This attribute controls the size of this buffer. By
default this read buffer is sized at |
socket.appWriteBufSize |
(int)Each connection that is opened up in Tomcat get associated with
a write ByteBuffer. This attribute controls the size of this buffer. By
default this write buffer is sized at |
socket.bufferPool |
(int)The NIO connector uses a class called NioChannel that holds
elements linked to a socket. To reduce garbage collection, the NIO
connector caches these channel objects. This value specifies the size of
this cache. The default value is |
socket.bufferPoolSize |
(int)The NioChannel pool can also be size based, not used object
based. The size is calculated as follows: |
socket.processorCache |
(int)Tomcat will cache SocketProcessor objects to reduce garbage
collection. The integer value specifies how many objects to keep in the
cache at most. The default is |
socket.eventCache |
(int)Tomcat will cache PollerEvent objects to reduce garbage
collection. The integer value specifies how many objects to keep in the
cache at most. The default is |
NIO2 specific configuration
The following attributes are specific to the NIO2 connector.
Attribute | Description |
---|---|
useCaches |
(bool)Use this attribute to enable or disable object caching to
reduce the amount of GC objects produced.
The default value is |
socket.directBuffer |
(bool)Boolean value, whether to use direct ByteBuffers or java mapped
ByteBuffers. Default is |
socket.appReadBufSize |
(int)Each connection that is opened up in Tomcat get associated with
a read ByteBuffer. This attribute controls the size of this buffer. By
default this read buffer is sized at |
socket.appWriteBufSize |
(int)Each connection that is opened up in Tomcat get associated with
a write ByteBuffer. This attribute controls the size of this buffer. By
default this write buffer is sized at |
socket.bufferPoolSize |
(int)The NIO2 connector uses a class called Nio2Channel that holds
elements linked to a socket. To reduce garbage collection, the NIO
connector caches these channel objects. This value specifies the size of
this cache. The default value is |
socket.processorCache |
(int)Tomcat will cache SocketProcessor objects to reduce garbage
collection. The integer value specifies how many objects to keep in the
cache at most. The default is |
Nested Components
None at this time.
Special Features
Proxy Support
The proxyName
and proxyPort
attributes can
be used when Tomcat is run behind a proxy server. These attributes
modify the values returned to web applications that call the
request.getServerName()
and request.getServerPort()
methods, which are often used to construct absolute URLs for redirects.
Without configuring these attributes, the values returned would reflect
the server name and port on which the connection from the proxy server
was received, rather than the server name and port to whom the client
directed the original request.
For more information, see the Proxy Support How-To.
Connector Comparison
Below is a small chart that shows how the connectors differ.
Java Nio Connector NIO |
Java Nio2 Connector NIO2 |
|
---|---|---|
Classname | AjpNioProtocol |
AjpNio2Protocol |
Tomcat Version | 7.x onwards | 8.x onwards |
Support Polling | YES | YES |
Polling Size | maxConnections |
maxConnections |
Read Request Headers | Blocking | Blocking |
Read Request Body | Blocking | Blocking |
Write Response Headers and Body | Blocking | Blocking |
Wait for next Request | Non Blocking | Non Blocking |
Max Connections | maxConnections |
maxConnections |