Package org.restlet.engine.application
Class TunnelFilter
- java.lang.Object
-
- org.restlet.Restlet
-
- org.restlet.routing.Filter
-
- org.restlet.engine.application.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classTunnelFilter.HeaderReplacerUsed to describe the replacement value for an old client preference and for a a series of specific agent (i.e.
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<TunnelFilter.HeaderReplacer>acceptEncodingReplacersUsed to replace accept-encoding header values.private java.util.List<TunnelFilter.HeaderReplacer>acceptReplacersUsed to replace accept header values.
-
Constructor Summary
Constructors Constructor Description TunnelFilter(Context context)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intbeforeHandle(Request request, Response response)Allows filtering before processing by the next Restlet.private java.util.List<TunnelFilter.HeaderReplacer>getAcceptEncodingReplacers()Returns the list of new accept-encoding header values.private java.util.List<TunnelFilter.HeaderReplacer>getAcceptReplacers()Returns the list of new accept header values.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.private MetadatagetMetadata(java.lang.String extension)Returns the metadata associated to the given extension using theMetadataService.MetadataServicegetMetadataService()Returns the metadata service of the parent application.TunnelServicegetTunnelService()Returns the tunnel service of the parent application.private booleanprocessExtensions(Request request)Updates the client preferences based on file-like extensions.private voidprocessHeaders(Request request)Updates the request method based on specific header.private booleanprocessQuery(Request request)Updates the request method and client preferences based on query parameters.private voidprocessUserAgent(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.private voidupdateMetadata(ClientInfo clientInfo, Metadata metadata)Updates the client info with the given metadata.-
Methods inherited from class org.restlet.routing.Filter
afterHandle, doHandle, getNext, handle, hasNext, setNext, setNext, start, stop
-
Methods inherited from class org.restlet.Restlet
createFinder, finalize, getApplication, getAuthor, getContext, getDescription, getFinderClass, getLogger, getName, getOwner, handle, handle, handle, isStarted, isStopped, setAuthor, setContext, setDescription, setFinderClass, setName, setOwner
-
-
-
-
Field Detail
-
acceptEncodingReplacers
private final java.util.List<TunnelFilter.HeaderReplacer> acceptEncodingReplacers
Used to replace accept-encoding header values.
-
acceptReplacers
private final java.util.List<TunnelFilter.HeaderReplacer> acceptReplacers
Used to replace accept header values.
-
-
Constructor Detail
-
TunnelFilter
public TunnelFilter(Context context)
Constructor.- Parameters:
context- The parent context.
-
-
Method Detail
-
beforeHandle
public int beforeHandle(Request request, Response response)
Description copied from class:FilterAllows filtering before processing by the next Restlet. ReturnsFilter.CONTINUEby default.- Overrides:
beforeHandlein classFilter- Parameters:
request- The request to handle.response- The response to update.- Returns:
- The continuation status. Either
Filter.CONTINUEorFilter.SKIPorFilter.STOP.
-
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 theMetadataService.- 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. SeeClientInfo.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.
-
-