Class TunnelFilter

  • All Implemented Interfaces:
    Uniform

    public class TunnelFilter
    extends Filter
    Filter tunneling browser calls into full REST calls. The request method can be changed (via POST requests only) as well as the accepted media types, languages, encodings and character sets. Concurrency note: instances of this class or its subclasses can be invoked by several threads at the same time and therefore must be thread-safe. You should be especially careful when storing state in member variables.
    • Field Detail

      • acceptEncodingReplacers

        private final java.util.List<TunnelFilter.HeaderReplacer> acceptEncodingReplacers
        Used to replace accept-encoding header values.
    • Constructor Detail

      • TunnelFilter

        public TunnelFilter​(Context context)
        Constructor.
        Parameters:
        context - The parent context.
    • Method Detail

      • getAcceptEncodingReplacers

        private java.util.List<TunnelFilter.HeaderReplacer> getAcceptEncodingReplacers()
        Returns the list of new accept-encoding header values. Each of them describe also a set of conditions required to set the new value. This method is used only to initialize the headerReplacers field.
        Returns:
        The list of new accept-encoding header values.
      • getAcceptReplacers

        private java.util.List<TunnelFilter.HeaderReplacer> getAcceptReplacers()
        Returns the list of new accept header values. Each of them describe also a set of conditions required to set the new value. This method is used only to initialize the headerReplacers field.
        Returns:
        The list of new accept header values.
      • getheaderReplacers

        private java.util.List<TunnelFilter.HeaderReplacer> getheaderReplacers​(java.net.URL userAgentPropertiesUrl,
                                                                               java.lang.String oldHeaderName,
                                                                               java.lang.String newHeaderName)
        Returns the list of new header values. Each of them describe also a set of conditions required to set the new value. This method is used only to initialize the headerReplacers field.
        Parameters:
        userAgentPropertiesUrl - The URL of the properties file that describe replacement values based on the user agent string.
        oldHeaderName - The name of the property that gives the value of the header to be replaced (could be null - in that case, the new value is unconditionnaly set.
        newHeaderName - The name of the property that gives the replacement value.
        Returns:
        The list of new header values.
      • getMetadata

        private Metadata getMetadata​(java.lang.String extension)
        Returns the metadata associated to the given extension using the MetadataService.
        Parameters:
        extension - The extension to lookup.
        Returns:
        The matched metadata.
      • getMetadataService

        public MetadataService getMetadataService()
        Returns the metadata service of the parent application.
        Returns:
        The metadata service of the parent application.
      • getTunnelService

        public TunnelService getTunnelService()
        Returns the tunnel service of the parent application.
        Returns:
        The tunnel service of the parent application.
      • processExtensions

        private boolean processExtensions​(Request request)
        Updates the client preferences based on file-like extensions. The matched extensions are removed from the last segment. See also section 3.6.1 of JAX-RS specification (https://jsr311.dev.java.net)
        Parameters:
        request - The request to update.
        Returns:
        True if the query has been updated, false otherwise.
      • processHeaders

        private void processHeaders​(Request request)
        Updates the request method based on specific header.
        Parameters:
        request - The request to update.
      • processQuery

        private boolean processQuery​(Request request)
        Updates the request method and client preferences based on query parameters. The matched parameters are removed from the query.
        Parameters:
        request - The request to update.
        Returns:
        True if the query has been updated, false otherwise.
      • processUserAgent

        private void processUserAgent​(Request request)
        Updates the client preferences according to the user agent properties (name, version, etc.) taken from the "agent.properties" file located in the classpath. See ClientInfo.getAgentAttributes() for more details.
        The list of new media type preferences is loaded from a property file called "accept.properties" located in the classpath in the sub directory "org/restlet/service". This property file is composed of blocks of properties. One "block" of properties starts either with the beginning of the properties file or with the end of the previous block. One block ends with the "acceptNew" property which contains the value of the new accept header. Here is a sample block.
         agentName: firefox
         acceptOld: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,\*\/\*;q=0.5
         acceptNew: application/xhtml+xml,text/html,text/xml;q=0.9,application/xml;q=0.9,text/plain;q=0.8,image/png,\*\/\*;q=0.5
         
        Each declared property is a condition that must be filled in order to update the client preferences. For example "agentName: firefox" expresses the fact this block concerns only "firefox" clients. The "acceptOld" property allows to check the value of the current "Accept" header. If the latest equals to the value of the "acceptOld" property then the preferences will be updated. This is useful for Ajax clients which looks like their browser (same agentName, agentVersion, etc.) but can provide their own "Accept" header.
        Parameters:
        request - the request to update.
      • updateMetadata

        private void updateMetadata​(ClientInfo clientInfo,
                                    Metadata metadata)
        Updates the client info with the given metadata. It clears existing preferences for the same type of metadata if necessary.
        Parameters:
        clientInfo - The client info to update.
        metadata - The metadata to use.