Top Description Inners Fields Constructors Methods
org.apache.coyote.ajp

public Class AjpProcessor

extends AbstractProcessor
Class Inheritance
Imports
java.io.ByteArrayInputStream, .EOFException, .IOException, .InterruptedIOException, java.net.InetAddress, java.nio.ByteBuffer, java.security.NoSuchProviderException, java.security.cert.CertificateException, .CertificateFactory, .X509Certificate, java.util.ArrayList, .Collections, .HashMap, .HashSet, .List, .Map, .Set, java.util.regex.Pattern, jakarta.servlet.ServletConnection, jakarta.servlet.http.HttpServletResponse, org.apache.coyote.AbstractProcessor, .ActionCode, .Adapter, .ContinueResponseTiming, .ErrorState, .InputBuffer, .OutputBuffer, .RequestInfo, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.util.ExceptionUtils, org.apache.tomcat.util.buf.ByteChunk, .MessageBytes, org.apache.tomcat.util.http.MimeHeaders, org.apache.tomcat.util.net.AbstractEndpoint.Handler.SocketState, .ApplicationBufferHandler, .SSLSupport, .SocketWrapperBase, org.apache.tomcat.util.res.StringManager

AJP Processor implementation.

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
AjpProcessor.SocketInputBuffer

This class is an input buffer which will read its data from an input stream.

protected class
AjpProcessor.SocketOutputBuffer

This class is an output buffer which will write data to an output stream.

Field Summary

Modifier and TypeField and Description
private final MessageBytes
bodyBytes

Body message.

private final AjpMessage
bodyMessage

Body message.

private long
bytesWritten

Bytes written to client for the current request.

private final MessageBytes
certificates

Byte chunk for certs.

private boolean
empty

Request body empty flag.

private static final byte[]
private static final byte[]
endMessageArray

End message array.

private boolean
endOfStream

End of stream flag.

private boolean
first

First read.

private static final byte[]
flushMessageArray

Flush message array.

private final byte[]
getBodyMessageArray

GetBody message array.

private static final Set<String>
private static final Map<String, String>
private static final Log
private final int
outputMaxChunkSize

AJP packet size.

private static final byte[]
pongMessageArray

Pong message array.

private final AbstractAjpProtocol<?>
private boolean
replay

Replay read.

private final AjpMessage
requestHeaderMessage

Header message.

private boolean
responseFinished

Finished response.

private final AjpMessage
responseMessage

Message used for response composition.

private int
responseMsgPos

Location of next write of the response message (used with non-blocking writes when the message may not be written in a single write).

private static final StringManager
sm

Hides org.apache.coyote.AbstractProcessor.sm.

The string manager for this package.
private boolean
swallowResponse

Should any response body be swallowed and not sent to the client.

private final MessageBytes
tmpMB

Temp message bytes used for processing.

private boolean
waitingForBodyMessage

Indicates that a 'get body chunk' message has been sent but the body chunk has not yet been received.

Inherited from org.apache.coyote.AbstractProcessor:
adapterasyncStateMachinerequestresponsesocketWrappersslSupportuserDataHelper

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected final void
ack(ContinueResponseTiming continueResponseTiming)

Implements abstract org.apache.coyote.AbstractProcessor.ack.

protected final int
available(boolean doRead)

Implements abstract org.apache.coyote.AbstractProcessor.available.

protected final void
protected AbstractEndpoint.Handler.SocketState
dispatchEndRequest()

Implements abstract org.apache.coyote.AbstractProcessor.dispatchEndRequest.

Perform any necessary clean-up processing if the dispatch resulted in the completion of processing for the current request.

protected void
dispatchNonBlockingRead()

Overrides org.apache.coyote.AbstractProcessor.dispatchNonBlockingRead.

Perform any necessary processing for a non-blocking read before dispatching to the adapter.

protected final void
finishResponse()

Implements abstract org.apache.coyote.AbstractProcessor.finishResponse.

Finish AJP response.

protected final void
flush()

Implements abstract org.apache.coyote.AbstractProcessor.flush.

Callback to write data from the buffer.

protected boolean
flushBufferedWrite()

Implements abstract org.apache.coyote.AbstractProcessor.flushBufferedWrite.

Flush any pending writes.

protected Log
protected final boolean
getPopulateRequestAttributesFromSocket()

Overrides org.apache.coyote.AbstractProcessor.getPopulateRequestAttributesFromSocket.

Processors that populate request attributes directly (e.g. AJP) should over-ride this method and return false.

protected ServletConnection
getServletConnection()

Implements abstract org.apache.coyote.AbstractProcessor.getServletConnection.

Protocols must override this method and return an appropriate ServletConnection instance

private boolean
protected final boolean
protected final boolean
protected boolean
public void
pause()

Implements org.apache.coyote.Processor.pause.

Informs the processor that the underlying I/O layer has stopped accepting new connections.

protected void
populateHost()

Overrides org.apache.coyote.AbstractProcessor.populateHost.

Called when a host header is not present in the request (e.g. HTTP/1.0).

protected void
populatePort()

Overrides org.apache.coyote.AbstractProcessor.populatePort.

Called when a host header is not present or is empty in the request (e.g. HTTP/1.0).

protected final void
protected final void
populateSslRequestAttributes()

Overrides org.apache.coyote.AbstractProcessor.populateSslRequestAttributes.

Populate the TLS related request attributes from the SSLSupport instance associated with this processor.

private void
prepareRequest()

After reading the request headers, we have to setup the request filters.

protected final void
prepareResponse()

Implements abstract org.apache.coyote.AbstractProcessor.prepareResponse.

When committing the response, we have to validate the set of headers, as well as setup the response filters.

private boolean

Returns:

true if the requested number of bytes were read else false
read
(byte[]
Buffer to read data into
buf
,
int
Start position
pos
,
int
The minimum number of bytes to read
n
,
boolean
If there is no data available to read when this method is called, should this call block until data becomes available?
block
)

Read at least the specified amount of bytes, and place them in the input buffer.

private boolean

Returns:

true if the message has been read, false if no data was read
readMessage
(AjpMessage
The message to populate
message
,
boolean
If there is no data available to read when this method is called, should this call block until data becomes available?
block
)

Read an AJP message.

private boolean

Returns:

true if at least one body byte was read, otherwise false
receive
(boolean
If there is no data available to read when this method is called, should this call block until data becomes available?
block
)

Read an AJP body message.

public void
recycle()

Overrides org.apache.coyote.AbstractProcessor.recycle.

Implements org.apache.coyote.Processor.recycle.

Recycle the processor, ready for the next request which may be on the same connection or a different connection.

protected boolean

Returns:

true if there is more data, false if not.
refillReadBuffer
(boolean
true if this is blocking IO
block
)

Get more request body data from the web server and store it in the internal buffer.

protected final void
public AbstractEndpoint.Handler.SocketState
service(SocketWrapperBase<?>
The connection to process
socket
)

Implements abstract org.apache.coyote.AbstractProcessorLight.service.

Service a 'standard' HTTP request.

protected final void
protected final void
private void
Inherited from org.apache.coyote.AbstractProcessor:
actionasyncPostProcesscheckAsyncTimeoutGenerationdispatchdoHttpUpgradedoPushexecuteexecuteDispatchesgetAdaptergetAsyncTimeoutgetErrorStategetLeftoverInputgetProtocolRequestIdgetRequestgetSocketWrappergetUpgradeTokenisAsyncisPushSupportedisReadyForReadisTrailerFieldsSupportedisUpgradelogAccessparseHostprocessSocketEventsetAsyncTimeoutsetErrorStatesetSocketWrappersetSslSupportsslReHandShaketimeoutAsync

Field Detail

bodyBytesback to summary
private final MessageBytes bodyBytes

Body message.

bodyMessageback to summary
private final AjpMessage bodyMessage

Body message.

bytesWrittenback to summary
private long bytesWritten

Bytes written to client for the current request.

certificatesback to summary
private final MessageBytes certificates

Byte chunk for certs.

emptyback to summary
private boolean empty

Request body empty flag.

endAndCloseMessageArrayback to summary
private static final byte[] endAndCloseMessageArray
endMessageArrayback to summary
private static final byte[] endMessageArray

End message array.

endOfStreamback to summary
private boolean endOfStream

End of stream flag.

firstback to summary
private boolean first

First read.

flushMessageArrayback to summary
private static final byte[] flushMessageArray

Flush message array.

getBodyMessageArrayback to summary
private final byte[] getBodyMessageArray

GetBody message array. Not static like the other message arrays since the message varies with packetSize and that can vary per connector.

iisTlsAttributesback to summary
private static final Set<String> iisTlsAttributes
jakartaAttributeMappingback to summary
private static final Map<String, String> jakartaAttributeMapping
logback to summary
private static final Log log
outputMaxChunkSizeback to summary
private final int outputMaxChunkSize

AJP packet size.

pongMessageArrayback to summary
private static final byte[] pongMessageArray

Pong message array.

protocolback to summary
private final AbstractAjpProtocol<?> protocol
replayback to summary
private boolean replay

Replay read.

requestHeaderMessageback to summary
private final AjpMessage requestHeaderMessage

Header message. Note that this header is merely the one used during the processing of the first message of a "request", so it might not be a request header. It will stay unchanged during the processing of the whole request.

responseFinishedback to summary
private boolean responseFinished

Finished response.

responseMessageback to summary
private final AjpMessage responseMessage

Message used for response composition.

responseMsgPosback to summary
private int responseMsgPos

Location of next write of the response message (used with non-blocking writes when the message may not be written in a single write). A value of -1 indicates that no message has been written to the buffer.

smback to summary
private static final StringManager sm

Hides org.apache.coyote.AbstractProcessor.sm.

The string manager for this package.

swallowResponseback to summary
private boolean swallowResponse

Should any response body be swallowed and not sent to the client.

tmpMBback to summary
private final MessageBytes tmpMB

Temp message bytes used for processing.

waitingForBodyMessageback to summary
private boolean waitingForBodyMessage

Indicates that a 'get body chunk' message has been sent but the body chunk has not yet been received.

Constructor Detail

AjpProcessorback to summary
public AjpProcessor(AbstractAjpProtocol<?> protocol, Adapter adapter)

Method Detail

ackback to summary
protected final void ack(ContinueResponseTiming continueResponseTiming)

Implements abstract org.apache.coyote.AbstractProcessor.ack.

Annotations
@Override
availableback to summary
protected final int available(boolean doRead)

Implements abstract org.apache.coyote.AbstractProcessor.available.

Annotations
@Override
disableSwallowRequestback to summary
protected final void disableSwallowRequest()

Implements abstract org.apache.coyote.AbstractProcessor.disableSwallowRequest.

Annotations
@Override
dispatchEndRequestback to summary
protected AbstractEndpoint.Handler.SocketState dispatchEndRequest()

Implements abstract org.apache.coyote.AbstractProcessor.dispatchEndRequest.

Doc from org.apache.coyote.AbstractProcessor.dispatchEndRequest.

Perform any necessary clean-up processing if the dispatch resulted in the completion of processing for the current request.

Returns:AbstractEndpoint.Handler.SocketState

The state to return for the socket once the clean-up for the current request has completed

Annotations
@Override
dispatchNonBlockingReadback to summary
protected void dispatchNonBlockingRead()

Overrides org.apache.coyote.AbstractProcessor.dispatchNonBlockingRead.

Doc from org.apache.coyote.AbstractProcessor.dispatchNonBlockingRead.

Perform any necessary processing for a non-blocking read before dispatching to the adapter.

Annotations
@Override
finishResponseback to summary
protected final void finishResponse() throws IOException

Implements abstract org.apache.coyote.AbstractProcessor.finishResponse.

Finish AJP response.

Annotations
@Override
flushback to summary
protected final void flush() throws IOException

Implements abstract org.apache.coyote.AbstractProcessor.flush.

Callback to write data from the buffer.

Annotations
@Override
flushBufferedWriteback to summary
protected boolean flushBufferedWrite() throws IOException

Implements abstract org.apache.coyote.AbstractProcessor.flushBufferedWrite.

Doc from org.apache.coyote.AbstractProcessor.flushBufferedWrite.

Flush any pending writes. Used during non-blocking writes to flush any remaining data from a previous incomplete write.

Returns:boolean

true if data remains to be flushed at the end of method

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs while attempting to flush the data
getLogback to summary
protected Log getLog()

Implements abstract org.apache.coyote.AbstractProcessorLight.getLog.

Annotations
@Override
getPopulateRequestAttributesFromSocketback to summary
protected final boolean getPopulateRequestAttributesFromSocket()

Overrides org.apache.coyote.AbstractProcessor.getPopulateRequestAttributesFromSocket.

Doc from org.apache.coyote.AbstractProcessor.getPopulateRequestAttributesFromSocket.

Processors that populate request attributes directly (e.g. AJP) should over-ride this method and return false.

Returns:boolean

true if the SocketWrapper should be used to populate the request attributes, otherwise false.

Annotations
@Override
getServletConnectionback to summary
protected ServletConnection getServletConnection()

Implements abstract org.apache.coyote.AbstractProcessor.getServletConnection.

Doc from org.apache.coyote.AbstractProcessor.getServletConnection.

Protocols must override this method and return an appropriate ServletConnection instance

Returns:ServletConnection

the ServletConnection instance associated with the current request.

Annotations
@Override
hasDataToWriteback to summary
private boolean hasDataToWrite()
isReadyForWriteback to summary
protected final boolean isReadyForWrite()

Implements abstract org.apache.coyote.AbstractProcessor.isReadyForWrite.

Annotations
@Override
isRequestBodyFullyReadback to summary
protected final boolean isRequestBodyFullyRead()

Implements abstract org.apache.coyote.AbstractProcessor.isRequestBodyFullyRead.

Annotations
@Override
isTrailerFieldsReadyback to summary
protected boolean isTrailerFieldsReady()

Implements abstract org.apache.coyote.AbstractProcessor.isTrailerFieldsReady.

Annotations
@Override
pauseback to summary
public void pause()

Implements org.apache.coyote.Processor.pause.

Doc from org.apache.coyote.Processor.pause.

Informs the processor that the underlying I/O layer has stopped accepting new connections. This is primarily intended to enable processors that use multiplexed connections to prevent further 'streams' being added to an existing multiplexed connection.

Annotations
@Override
populateHostback to summary
protected void populateHost()

Overrides org.apache.coyote.AbstractProcessor.populateHost.

Doc from org.apache.coyote.AbstractProcessor.populateHost.

Called when a host header is not present in the request (e.g. HTTP/1.0). It populates the server name with appropriate information. The source is expected to vary by protocol.

The default implementation is a NO-OP.

This implementation populates the server name from the local name provided by the AJP message.

Annotations
@Override
populatePortback to summary
protected void populatePort()

Overrides org.apache.coyote.AbstractProcessor.populatePort.

Doc from org.apache.coyote.AbstractProcessor.populatePort.

Called when a host header is not present or is empty in the request (e.g. HTTP/1.0). It populates the server port with appropriate information. The source is expected to vary by protocol.

The default implementation is a NO-OP.

This implementation populates the server port from the local port provided by the AJP message.

Annotations
@Override
populateRequestAttributeRemoteHostback to summary
protected final void populateRequestAttributeRemoteHost()

Overrides org.apache.coyote.AbstractProcessor.populateRequestAttributeRemoteHost.

Doc from org.apache.coyote.AbstractProcessor.populateRequestAttributeRemoteHost.

Populate the remote host request attribute. Processors (e.g. AJP) that populate this from an alternative source should override this method.

Annotations
@Override
populateSslRequestAttributesback to summary
protected final void populateSslRequestAttributes()

Overrides org.apache.coyote.AbstractProcessor.populateSslRequestAttributes.

Doc from org.apache.coyote.AbstractProcessor.populateSslRequestAttributes.

Populate the TLS related request attributes from the SSLSupport instance associated with this processor. Protocols that populate TLS attributes from a different source (e.g. AJP) should override this method.

Annotations
@Override
prepareRequestback to summary
private void prepareRequest()

After reading the request headers, we have to setup the request filters.

prepareResponseback to summary
protected final void prepareResponse() throws IOException

Implements abstract org.apache.coyote.AbstractProcessor.prepareResponse.

When committing the response, we have to validate the set of headers, as well as setup the response filters.

Annotations
@Override
readback to summary
private boolean read(byte[] buf, int pos, int n, boolean block) throws IOException

Read at least the specified amount of bytes, and place them in the input buffer. Note that if any data is available to read then this method will always block until at least the specified number of bytes have been read.

Parameters
buf:byte[]

Buffer to read data into

pos:int

Start position

n:int

The minimum number of bytes to read

block:boolean

If there is no data available to read when this method is called, should this call block until data becomes available?

Returns:boolean

true if the requested number of bytes were read else false

Exceptions
IOException:
If an I/O error occurs during the read
readMessageback to summary
private boolean readMessage(AjpMessage message, boolean block) throws IOException

Read an AJP message.

Parameters
message:AjpMessage

The message to populate

block:boolean

If there is no data available to read when this method is called, should this call block until data becomes available?

Returns:boolean

true if the message has been read, false if no data was read

Exceptions
IOException:
any other failure, including incomplete reads
receiveback to summary
private boolean receive(boolean block) throws IOException

Read an AJP body message. Used to read both the 'special' packet in ajp13 and to receive the data after we send a GET_BODY packet.

Parameters
block:boolean

If there is no data available to read when this method is called, should this call block until data becomes available?

Returns:boolean

true if at least one body byte was read, otherwise false

recycleback to summary
public void recycle()

Overrides org.apache.coyote.AbstractProcessor.recycle.

Implements org.apache.coyote.Processor.recycle.

Doc from org.apache.coyote.Processor.recycle.

Recycle the processor, ready for the next request which may be on the same connection or a different connection.

Annotations
@Override
refillReadBufferback to summary
protected boolean refillReadBuffer(boolean block) throws IOException

Get more request body data from the web server and store it in the internal buffer.

Parameters
block:boolean

true if this is blocking IO

Returns:boolean

true if there is more data, false if not.

Exceptions
IOException:
An IO error occurred
registerReadInterestback to summary
protected final void registerReadInterest()

Implements abstract org.apache.coyote.AbstractProcessor.registerReadInterest.

Annotations
@Override
serviceback to summary
public AbstractEndpoint.Handler.SocketState service(SocketWrapperBase<?> socket) throws IOException

Implements abstract org.apache.coyote.AbstractProcessorLight.service.

Doc from org.apache.coyote.AbstractProcessorLight.service.

Service a 'standard' HTTP request. This method is called for both new requests and for requests that have partially read the HTTP request line or HTTP headers. Once the headers have been fully read this method is not called again until there is a new HTTP request to process. Note that the request type may change during processing which may result in one or more calls to dispatch(SocketEvent). Requests may be pipe-lined.

Parameters
socket:SocketWrapperBase<?>

The connection to process

Returns:AbstractEndpoint.Handler.SocketState

The state the caller should put the socket in when this method returns

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs during the processing of the request
setRequestBodyback to summary
protected final void setRequestBody(ByteChunk body)

Implements abstract org.apache.coyote.AbstractProcessor.setRequestBody.

Annotations
@Override
setSwallowResponseback to summary
protected final void setSwallowResponse()

Implements abstract org.apache.coyote.AbstractProcessor.setSwallowResponse.

Annotations
@Override
writeDataback to summary
private void writeData(ByteBuffer chunk) throws IOException
org.apache.coyote.ajp back to summary

protected Class AjpProcessor.SocketInputBuffer

extends Object
implements InputBuffer
Class Inheritance
All Implemented Interfaces
org.apache.coyote.InputBuffer

This class is an input buffer which will read its data from an input stream.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public int
available()

Implements org.apache.coyote.InputBuffer.available.

Obtain an estimate of the number of bytes that can be read without blocking.

public int
doRead(ApplicationBufferHandler
ApplicationBufferHandler that provides the buffer to read data into.
handler
)

Implements org.apache.coyote.InputBuffer.doRead.

Read from the input stream into the ByteBuffer provided by the ApplicationBufferHandler.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SocketInputBufferback to summary
protected SocketInputBuffer()

Method Detail

availableback to summary
public int available()

Implements org.apache.coyote.InputBuffer.available.

Doc from org.apache.coyote.InputBuffer.available.

Obtain an estimate of the number of bytes that can be read without blocking. Typically, this will be the number of available bytes known to be buffered.

Returns:int

The number of bytes that can be read without blocking

Annotations
@Override
doReadback to summary
public int doRead(ApplicationBufferHandler handler) throws IOException

Implements org.apache.coyote.InputBuffer.doRead.

Doc from org.apache.coyote.InputBuffer.doRead.

Read from the input stream into the ByteBuffer provided by the ApplicationBufferHandler.

Important Note

the current model assumes that the protocol will 'own' the ByteBuffer and return a pointer to it.

Parameters
handler:ApplicationBufferHandler

ApplicationBufferHandler that provides the buffer to read data into.

Returns:int

The number of bytes that have been added to the buffer or -1 for end of stream

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs reading from the input stream
org.apache.coyote.ajp back to summary

protected Class AjpProcessor.SocketOutputBuffer

extends Object
implements OutputBuffer
Class Inheritance
All Implemented Interfaces
org.apache.coyote.OutputBuffer

This class is an output buffer which will write data to an output stream.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public int
doWrite(ByteBuffer
data to write
chunk
)

Implements org.apache.coyote.OutputBuffer.doWrite.

Write the given data to the response.

public long
getBytesWritten()

Implements org.apache.coyote.OutputBuffer.getBytesWritten.

Bytes written to the underlying socket.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SocketOutputBufferback to summary
protected SocketOutputBuffer()

Method Detail

doWriteback to summary
public int doWrite(ByteBuffer chunk) throws IOException

Implements org.apache.coyote.OutputBuffer.doWrite.

Doc from org.apache.coyote.OutputBuffer.doWrite.

Write the given data to the response. The caller owns the chunks.

Parameters
chunk:ByteBuffer

data to write

Returns:int

The number of bytes written which may be less than available in the input chunk

Annotations
@Override
Exceptions
IOException:
an underlying I/O error occurred
getBytesWrittenback to summary
public long getBytesWritten()

Implements org.apache.coyote.OutputBuffer.getBytesWritten.

Doc from org.apache.coyote.OutputBuffer.getBytesWritten.

Bytes written to the underlying socket. This includes the effects of chunking, compression, etc.

Returns:long

Bytes written for the current request

Annotations
@Override