Package org.restlet.service
Class TunnelService
java.lang.Object
org.restlet.service.Service
org.restlet.service.TunnelService
Application service tunneling request method or client preferences. The
tunneling can use query parameters, file-like extensions, and specific
headers. This is particularly useful for browser-based applications that
can't fully control the HTTP requests sent.
Here is the list of the default parameter names supported:
The client preferences can also be updated according to the user agent properties (its name, version, operating system, or other) available via the
The list of new media type preferences is loaded from a property file called "accept.properties" located in the classpath in the subdirectory "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.
The "acceptOld" property allows checking the value of the current "Accept" header. If it equals to the value of the "acceptOld" property or if the "acceptOld" property is empty, then the preferences will be updated. This can be useful for AJAX clients that look like their browser (same agentName, agentVersion, etc.) but can provide their own "Accept" header.
Here is the list of the default parameter names supported:
| Property | Default name | Value type | Description |
|---|---|---|---|
| methodParameter | method | See values in Method |
For POST requests, let you specify the actual method to use (DELETE, PUT, MOVE, etc.). For GET requests, let you specify OPTIONS as the actual method to use. |
| characterSetParameter | charset | Use extension names defined in MetadataService or the full
character set name |
For GET requests, replaces the accepted character set by the given value. |
| encodingParameter | encoding | Use extension names defined in MetadataService or the full
encoding name |
For GET requests, replaces the accepted encoding by the given value. |
| languageParameter | language | Use extension names defined in MetadataService or the full
language name |
For GET requests, replaces the accepted language by the given value. |
| mediaTypeParameter | media | Use extension names defined in MetadataService or the full media
type name |
For GET requests, replaces the accepted media type set by the given value. |
| methodHeader | X-HTTP-Method-Override | Name of non-standard header. It is a good practice to prefix it with "X-". | For POST requests, let you specify the actual method to use (DELETE, PUT, MOVE, etc.). |
The client preferences can also be updated according to the user agent properties (its name, version, operating system, or other) available via the
ClientInfo.getAgentAttributes() method. Check the
isUserAgentTunnel() method.The list of new media type preferences is loaded from a property file called "accept.properties" located in the classpath in the subdirectory "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.5Each declared property is a condition that must be filled to update the client preferences. For example, "agentName: firefox" expresses the fact this block concerns only "firefox" clients.
The "acceptOld" property allows checking the value of the current "Accept" header. If it equals to the value of the "acceptOld" property or if the "acceptOld" property is empty, then the preferences will be updated. This can be useful for AJAX clients that look like their browser (same agentName, agentVersion, etc.) but can provide their own "Accept" header.
- Author:
- Jerome Louvel
-
Constructor Summary
ConstructorsConstructorDescriptionTunnelService(boolean methodTunnel, boolean preferencesTunnel) Constructor that enables the query tunnel and disables the extensions and user agent tunnels.TunnelService(boolean enabled, boolean methodTunnel, boolean preferencesTunnel) Constructor that enables the query tunnel and disables the extensions and user agent tunnels.TunnelService(boolean enabled, boolean methodTunnel, boolean preferencesTunnel, boolean queryTunnel, boolean extensionsTunnel) Constructor that disables the user agent tunnel.TunnelService(boolean enabled, boolean methodTunnel, boolean preferencesTunnel, boolean queryTunnel, boolean extensionsTunnel, boolean userAgentTunnel) Constructor that enables the header tunneling.TunnelService(boolean enabled, boolean methodTunnel, boolean preferencesTunnel, boolean queryTunnel, boolean extensionsTunnel, boolean userAgentTunnel, boolean headersTunnel) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanallowClient(ClientInfo client) Indicates if the request from a given client can be tunneled.createInboundFilter(Context context) Create the filter that should be invoked for incoming calls.Returns the character set parameter name.Returns the name of the parameter containing the accepted encoding.Returns the name of the parameter containing the accepted language.Returns the name of the parameter containing the accepted media type.Returns the name of the header containing the method name.Returns the method parameter name.booleanIndicates if the client preferences can be tunneled via the extensions.booleanIndicates if the method can be tunneled via the header.booleanIndicates if the method name can be tunneled.booleanIndicates if the client preferences can be tunneled via the query parameters or via file extensions.booleanIndicates if the method and client preferences can be tunneled via query parameters or file extensions.booleanIndicates if the client preferences can be tunneled according to the user agent.voidsetCharacterSetParameter(String parameterName) Sets the character set parameter name.voidsetEncodingParameter(String parameterName) Sets the name of the parameter containing the accepted encoding.voidsetExtensionsTunnel(boolean extensionTunnel) Indicates if the client preferences can be tunneled via the extensions.voidsetHeadersTunnel(boolean headersTunnel) Indicates if the method can be tunneled via the header.voidsetLanguageParameter(String parameterName) Sets the name of the parameter containing the accepted language.voidsetMediaTypeParameter(String parameterName) Sets the name of the parameter containing the accepted media type.voidsetMethodHeader(String methodHeader) Sets the name of the header containing the method name.voidsetMethodParameter(String parameterName) Sets the method parameter name.voidsetMethodTunnel(boolean methodTunnel) Indicates if the method name can be tunneled.voidsetPreferencesTunnel(boolean preferencesTunnel) Indicates if the client preferences can be tunneled via the query parameters.voidsetQueryTunnel(boolean queryTunnel) Indicates if the method and client preferences can be tunneled via query parameters.voidsetUserAgentTunnel(boolean userAgentTunnel) Indicates if the client preferences can be tunneled according to the user agent.Methods inherited from class org.restlet.service.Service
createOutboundFilter, getContext, isEnabled, isStarted, isStopped, setContext, setEnabled, start, stop
-
Constructor Details
-
TunnelService
public TunnelService(boolean methodTunnel, boolean preferencesTunnel) Constructor that enables the query tunnel and disables the extensions and user agent tunnels.- Parameters:
methodTunnel- Indicates if the method name can be tunneled.preferencesTunnel- Indicates if the client preferences can be tunneled by query parameters or file-like extensions or user agent string.
-
TunnelService
public TunnelService(boolean enabled, boolean methodTunnel, boolean preferencesTunnel) Constructor that enables the query tunnel and disables the extensions and user agent tunnels.- Parameters:
enabled- True if the service has been enabled.methodTunnel- Indicates if the method name can be tunneled.preferencesTunnel- Indicates if the client preferences can be tunneled by query parameters or file-like extensions or user agent string.
-
TunnelService
public TunnelService(boolean enabled, boolean methodTunnel, boolean preferencesTunnel, boolean queryTunnel, boolean extensionsTunnel) Constructor that disables the user agent tunnel.- Parameters:
enabled- True if the service has been enabled.methodTunnel- Indicates if the method can be tunneled using a query parameter.preferencesTunnel- Indicates if the client preferences can be tunneled using query parameters or file-like extensions or user agent string.queryTunnel- Indicates if tunneling can use query parameters.extensionsTunnel- Indicates if tunneling can use file-like extensions.
-
TunnelService
public TunnelService(boolean enabled, boolean methodTunnel, boolean preferencesTunnel, boolean queryTunnel, boolean extensionsTunnel, boolean userAgentTunnel) Constructor that enables the header tunneling.- Parameters:
enabled- True if the service has been enabled.methodTunnel- Indicates if the method can be tunneled using a query parameter.preferencesTunnel- Indicates if the client preferences can be tunneled using query parameters or file-like extensions or user agent string.queryTunnel- Indicates if tunneling can use query parameters.extensionsTunnel- Indicates if tunneling can use file-like extensions.userAgentTunnel- Indicates if tunneling can use user agent string.
-
TunnelService
public TunnelService(boolean enabled, boolean methodTunnel, boolean preferencesTunnel, boolean queryTunnel, boolean extensionsTunnel, boolean userAgentTunnel, boolean headersTunnel) Constructor.- Parameters:
enabled- True if the service has been enabled.methodTunnel- Indicates if the method can be tunneled using a query parameter.preferencesTunnel- Indicates if the client preferences can be tunneled using query parameters or file-like extensions or user agent string.queryTunnel- Indicates if tunneling can use query parameters.extensionsTunnel- Indicates if tunneling can use file-like extensions.userAgentTunnel- Indicates if tunneling can use user agent string.headersTunnel- Indicates if method can be tunneled via a specific header.
-
-
Method Details
-
allowClient
Indicates if the request from a given client can be tunneled. The default implementation always returns true. This could be customized to restrict the usage of the tunnel service.- Parameters:
client- The client to test.- Returns:
- True if the request from a given client can be tunneled.
-
createInboundFilter
Description copied from class:ServiceCreate the filter that should be invoked for incoming calls.- Overrides:
createInboundFilterin classService- Parameters:
context- The current context.- Returns:
- The new filter or null.
-
getCharacterSetParameter
Returns the character set parameter name.- Returns:
- The character set parameter name.
-
getEncodingParameter
Returns the name of the parameter containing the accepted encoding.- Returns:
- The name of the parameter containing the accepted encoding.
-
getLanguageParameter
Returns the name of the parameter containing the accepted language.- Returns:
- The name of the parameter containing the accepted language.
-
getMediaTypeParameter
Returns the name of the parameter containing the accepted media type.- Returns:
- The name of the parameter containing the accepted media type.
-
getMethodHeader
Returns the name of the header containing the method name.- Returns:
- the name of the header containing the method name.
-
getMethodParameter
Returns the method parameter name.- Returns:
- The method parameter name.
-
isExtensionsTunnel
public boolean isExtensionsTunnel()Indicates if the client preferences can be tunneled via the extensions. Returns false by default.- Returns:
- True if the client preferences can be tunneled via the extensions
- See Also:
-
isHeadersTunnel
public boolean isHeadersTunnel()Indicates if the method can be tunneled via the header. Returns true by default.- Returns:
- True if the method can be tunneled via the header.
-
isMethodTunnel
public boolean isMethodTunnel()Indicates if the method name can be tunneled. Returns true by default.- Returns:
- True if the method name can be tunneled.
-
isPreferencesTunnel
public boolean isPreferencesTunnel()Indicates if the client preferences can be tunneled via the query parameters or via file extensions. Returns true by default.- Returns:
- True if the client preferences can be tunneled.
-
isQueryTunnel
public boolean isQueryTunnel()Indicates if the method and client preferences can be tunneled via query parameters or file extensions. Returns true by default.- Returns:
- True if the method and client preferences can be tunneled.
-
isUserAgentTunnel
public boolean isUserAgentTunnel()Indicates if the client preferences can be tunneled according to the user agent. Returns false by default.- Returns:
- True if the client preferences can be tunneled according to the user agent.
-
setCharacterSetParameter
Sets the character set parameter name.- Parameters:
parameterName- The character set parameter name.
-
setEncodingParameter
Sets the name of the parameter containing the accepted encoding.- Parameters:
parameterName- The name of the parameter containing the accepted encoding.
-
setExtensionsTunnel
public void setExtensionsTunnel(boolean extensionTunnel) Indicates if the client preferences can be tunneled via the extensions.- Parameters:
extensionTunnel- True if the client preferences can be tunneled via the extensions.- See Also:
-
setHeadersTunnel
public void setHeadersTunnel(boolean headersTunnel) Indicates if the method can be tunneled via the header.- Parameters:
headersTunnel- True if the method can be tunneled via the header.
-
setLanguageParameter
Sets the name of the parameter containing the accepted language.- Parameters:
parameterName- The name of the parameter containing the accepted language.
-
setMediaTypeParameter
Sets the name of the parameter containing the accepted media type.- Parameters:
parameterName- The name of the parameter containing the accepted media type.
-
setMethodHeader
Sets the name of the header containing the method name.- Parameters:
methodHeader- The name of the header containing the method name.
-
setMethodParameter
Sets the method parameter name.- Parameters:
parameterName- The method parameter name.
-
setMethodTunnel
public void setMethodTunnel(boolean methodTunnel) Indicates if the method name can be tunneled.- Parameters:
methodTunnel- True if the method name can be tunneled.
-
setPreferencesTunnel
public void setPreferencesTunnel(boolean preferencesTunnel) Indicates if the client preferences can be tunneled via the query parameters.- Parameters:
preferencesTunnel- True if the client preferences can be tunneled via the query parameters.
-
setQueryTunnel
public void setQueryTunnel(boolean queryTunnel) Indicates if the method and client preferences can be tunneled via query parameters.- Parameters:
queryTunnel- True if the method and client preferences can be tunneled via query parameters.
-
setUserAgentTunnel
public void setUserAgentTunnel(boolean userAgentTunnel) Indicates if the client preferences can be tunneled according to the user agent.- Parameters:
userAgentTunnel- True if the client preferences can be tunneled according to the user agent.
-