Class AbstractAjpProtocol<S>

  • Type Parameters:
    S - The type of socket used by the implementation
    All Implemented Interfaces:
    javax.management.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 Detail

      • sm

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

      • AbstractAjpProtocol

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

      • getProtocolName

        protected java.lang.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​(java.lang.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​(java.lang.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​(java.lang.String secret)
        Set the secret that must be included with every request.
        Parameters:
        secret - The required secret
      • getSecret

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

        @Deprecated
        public void setRequiredSecret​(java.lang.String requiredSecret)
        Deprecated.
        Replaced by setSecret(String). Will be removed in Tomcat 11 onwards
        Set the required secret that must be included with every request.
        Parameters:
        requiredSecret - The required secret
      • getRequiredSecret

        @Deprecated
        protected java.lang.String getRequiredSecret()
        Deprecated.
        Replaced by getSecret(). Will be removed in Tomcat 11 onwards
        Returns:
        The current 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​(java.lang.String allowedRequestAttributesPattern)
        Sets the pattern for allowed request attributes.
        Parameters:
        allowedRequestAttributesPattern - The regex pattern
      • getAllowedRequestAttributesPattern

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

        protected java.util.regex.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
      • 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:
        java.lang.IllegalStateException - always
      • start

        public void start()
                   throws java.lang.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:
        java.lang.Exception - if start fails