Class AbstractAjpProtocol<S>

java.lang.Object
org.apache.coyote.AbstractProtocol<S>
org.apache.coyote.ajp.AbstractAjpProtocol<S>
Type Parameters:
S - The type of socket used by the implementation
All Implemented Interfaces:
MBeanRegistration, ProtocolHandler
Direct Known Subclasses:
AjpNio2Protocol, AjpNioProtocol

public abstract class AbstractAjpProtocol<S> extends AbstractProtocol<S>
This the base implementation for the AJP protocol handlers. Implementations typically extend this base class rather than implement ProtocolHandler. All of the implementations that ship with Tomcat are implemented this way.
  • Field Details

    • sm

      protected static final StringManager sm
      The string manager for this package.
  • Constructor Details

    • AbstractAjpProtocol

      public AbstractAjpProtocol(AbstractEndpoint<S,?> endpoint)
      Creates a new AJP protocol handler.
      Parameters:
      endpoint - The endpoint for low-level network I/O
  • Method Details

    • getProtocolName

      protected String getProtocolName()
      Gets the name of the protocol.
      Specified by:
      getProtocolName in class AbstractProtocol<S>
      Returns:
      the protocol name
    • getEndpoint

      protected AbstractEndpoint<S,?> getEndpoint()
      Gets the endpoint. Overridden to make getter accessible to other classes in this package.
      Overrides:
      getEndpoint in class AbstractProtocol<S>
      Returns:
      the endpoint
    • getNegotiatedProtocol

      protected UpgradeProtocol getNegotiatedProtocol(String name)
      Find a suitable handler for the protocol negotiated at the network layer. AJP does not support protocol negotiation so this always returns null.
      Specified by:
      getNegotiatedProtocol in class AbstractProtocol<S>
      Parameters:
      name - The name of the requested negotiated protocol.
      Returns:
      The instance where UpgradeProtocol.getAlpnName() matches the requested protocol
    • getUpgradeProtocol

      protected UpgradeProtocol getUpgradeProtocol(String name)
      Find a suitable handler for the protocol upgraded name specified. This is used for direct connection protocol selection. AJP does not support protocol upgrade so this always returns null.
      Specified by:
      getUpgradeProtocol in class AbstractProtocol<S>
      Parameters:
      name - The name of the requested negotiated protocol.
      Returns:
      The instance where UpgradeProtocol.getAlpnName() matches the requested protocol
    • getAjpFlush

      public boolean getAjpFlush()
      Gets whether AJP flush packets are used.
      Returns:
      true if flush packets are used
    • setAjpFlush

      public void setAjpFlush(boolean ajpFlush)
      Configure whether to aend an AJP flush packet when flushing. A flush packet is a zero byte AJP13 SEND_BODY_CHUNK packet. mod_jk and mod_proxy_ajp interpret this as a request to flush data to the client. AJP always does flush at the end of the response, so if it is not important, that the packets get streamed up to the client, do not use extra flush packets. For compatibility and to stay on the safe side, flush packets are enabled by default.
      Parameters:
      ajpFlush - The new flush setting
    • getTomcatAuthentication

      public boolean getTomcatAuthentication()
      Should authentication be done in the native web server layer, or in the Servlet container ?
      Returns:
      true if authentication should be performed by Tomcat, otherwise false
    • setTomcatAuthentication

      public void setTomcatAuthentication(boolean tomcatAuthentication)
      Sets whether authentication should be done in Tomcat.
      Parameters:
      tomcatAuthentication - true if authentication should be performed by Tomcat
    • getTomcatAuthorization

      public boolean getTomcatAuthorization()
      Should authentication be done in the native web server layer and authorization in the Servlet container?
      Returns:
      true if authorization should be performed by Tomcat, otherwise false
    • setTomcatAuthorization

      public void setTomcatAuthorization(boolean tomcatAuthorization)
      Sets whether authorization should be done by Tomcat.
      Parameters:
      tomcatAuthorization - true if authorization should be performed by Tomcat
    • setSecret

      public void setSecret(String secret)
      Set the secret that must be included with every request.
      Parameters:
      secret - The required secret
    • getSecret

      protected String getSecret()
      Gets the secret that must be included with every request.
      Returns:
      the secret
    • setSecretRequired

      public void setSecretRequired(boolean secretRequired)
      Sets whether a secret is required with every request.
      Parameters:
      secretRequired - true if a secret is required
    • getSecretRequired

      public boolean getSecretRequired()
      Gets whether a secret is required with every request.
      Returns:
      true if a secret is required
    • setAllowedRequestAttributesPattern

      public void setAllowedRequestAttributesPattern(String allowedRequestAttributesPattern)
      Sets the pattern for allowed request attributes.
      Parameters:
      allowedRequestAttributesPattern - The regex pattern
    • getAllowedRequestAttributesPattern

      public String getAllowedRequestAttributesPattern()
      Gets the pattern for allowed request attributes.
      Returns:
      the pattern string
    • getAllowedRequestAttributesPatternInternal

      protected Pattern getAllowedRequestAttributesPatternInternal()
      Gets the compiled pattern for allowed request attributes.
      Returns:
      the pattern
    • getPacketSize

      public int getPacketSize()
      Gets the AJP packet size.
      Returns:
      the packet size
    • setPacketSize

      public void setPacketSize(int packetSize)
      Sets the AJP packet size.
      Parameters:
      packetSize - The packet size (must be at least MAX_PACKET_SIZE)
    • getDesiredBufferSize

      public int getDesiredBufferSize()
      Gets the desired buffer size for AJP packets.
      Returns:
      the desired buffer size
    • addSslHostConfig

      public void addSslHostConfig(SSLHostConfig sslHostConfig)
      Adds an SSL host configuration. AJP does not support SSL so this logs a warning.
      Parameters:
      sslHostConfig - The SSL host configuration
    • addSslHostConfig

      public void addSslHostConfig(SSLHostConfig sslHostConfig, boolean replace)
      Adds an SSL host configuration. AJP does not support SSL so this logs a warning.
      Parameters:
      sslHostConfig - The SSL host configuration
      replace - Whether to replace existing configurations
    • findSslHostConfigs

      public SSLHostConfig[] findSslHostConfigs()
      Finds SSL host configurations. AJP does not support SSL so this always returns an empty array.
      Returns:
      an empty array
    • addUpgradeProtocol

      public void addUpgradeProtocol(UpgradeProtocol upgradeProtocol)
      Adds an upgrade protocol. AJP does not support upgrade so this logs a warning.
      Parameters:
      upgradeProtocol - The upgrade protocol
    • findUpgradeProtocols

      public UpgradeProtocol[] findUpgradeProtocols()
      Finds upgrade protocols. AJP does not support upgrade so this always returns an empty array.
      Returns:
      an empty array
    • createProcessor

      protected Processor createProcessor()
      Creates a new AJP processor.
      Specified by:
      createProcessor in class AbstractProtocol<S>
      Returns:
      the processor
    • createUpgradeProcessor

      protected Processor createUpgradeProcessor(SocketWrapperBase<?> socket, UpgradeToken upgradeToken)
      Creates an upgrade processor. AJP does not support upgrade so this always throws.
      Specified by:
      createUpgradeProcessor in class AbstractProtocol<S>
      Parameters:
      socket - The socket wrapper
      upgradeToken - The upgrade token
      Returns:
      never returns
      Throws:
      IllegalStateException - always
    • start

      public void start() throws Exception
      Starts the AJP protocol handler. Validates that a secret is configured if required.
      Specified by:
      start in interface ProtocolHandler
      Overrides:
      start in class AbstractProtocol<S>
      Throws:
      Exception - if start fails