public class Redirector extends Restlet
MODE_CLIENT_FOUND, MODE_CLIENT_PERMANENT,
MODE_CLIENT_SEE_OTHER, MODE_CLIENT_TEMPORARY) or
server-side redirections, similar to a reverse proxy (
MODE_SERVER_OUTBOUND and MODE_SERVER_INBOUND).Resolver
class. For example "/target?referer={fi}" would redirect to the relative URI,
inserting the referrer URI as a query parameter.MODE_SERVER_OUTBOUND constant and a target URI like
"http://targetHost/targetRootPath/{rr}" to ensure that all child URIs are
properly redirected as well, "rr" appending the remaining part of the current
request URI that hasn't been routed yet.Template| Modifier and Type | Field and Description |
|---|---|
protected boolean |
headersCleaning
Indicates if all headers of HTTP requests stored in the request's attributes,
must be removed before the redirection.
|
protected int |
mode
The redirection mode.
|
static int |
MODE_CLIENT_FOUND
In this mode, the client is simply redirected to the URI generated from the
target URI pattern using the
Status.REDIRECTION_FOUND status. |
static int |
MODE_CLIENT_PERMANENT
In this mode, the client is permanently redirected to the URI generated from
the target URI pattern, using the
Status.REDIRECTION_PERMANENT
status. |
static int |
MODE_CLIENT_SEE_OTHER
In this mode, the client is simply redirected to the URI generated from the
target URI pattern using the
Status.REDIRECTION_SEE_OTHER status. |
static int |
MODE_CLIENT_TEMPORARY
In this mode, the client is temporarily redirected to the URI generated from
the target URI pattern using the
Status.REDIRECTION_TEMPORARY status. |
static int |
MODE_SERVER_INBOUND
In this mode, the call is sent to
Context.getServerDispatcher(). |
static int |
MODE_SERVER_OUTBOUND
In this mode, the call is sent to
Application.getOutboundRoot() or if
null to Context.getClientDispatcher(). |
protected String |
targetTemplate
The target URI pattern.
|
| Constructor and Description |
|---|
Redirector(Context context,
String targetTemplate)
Constructor for the client dispatcher mode.
|
Redirector(Context context,
String targetPattern,
int mode)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getMode()
Returns the redirection mode.
|
protected Reference |
getTargetRef(Request request,
Response response)
Returns the target reference to redirect to by automatically resolving URI
template variables found using the
Template class using the request
and response as data models. |
String |
getTargetTemplate()
Returns the target URI pattern.
|
void |
handle(Request request,
Response response)
Handles a call by redirecting using the selected redirection mode.
|
protected void |
inboundServerRedirect(Reference targetRef,
Request request,
Response response)
Redirects a given call to a target reference.
|
boolean |
isHeadersCleaning()
Indicates if the headers must be cleaned.
|
protected void |
outboundServerRedirect(Reference targetRef,
Request request,
Response response)
Redirects a given call to a target reference.
|
protected Representation |
rewrite(Representation initialEntity)
Optionally rewrites the response entity returned in the
MODE_SERVER_INBOUND and MODE_SERVER_OUTBOUND modes. |
protected void |
rewrite(Request initialRequest)
Optionally updates the request sent in the
MODE_SERVER_INBOUND and
MODE_SERVER_OUTBOUND modes. |
protected void |
rewrite(Response initialResponse)
Optionally updates the response sent in the
MODE_SERVER_INBOUND and
MODE_SERVER_OUTBOUND modes. |
void |
rewriteLocation(Request request,
Response response)
Rewrite the location of the response, and the Location of the entity, if any.
|
protected void |
serverRedirect(Restlet next,
Reference targetRef,
Request request,
Response response)
Redirects a given call on the server-side to a next Restlet with a given
target reference.
|
void |
setHeadersCleaning(boolean headersCleaning)
Indicates if the headers must be cleaned.
|
void |
setMode(int mode)
Sets the redirection mode.
|
void |
setTargetTemplate(String targetTemplate)
Sets the target URI pattern.
|
createFinder, finalize, getApplication, getAuthor, getContext, getDescription, getFinderClass, getLogger, getName, getOwner, handle, handle, handle, isStarted, isStopped, setAuthor, setContext, setDescription, setFinderClass, setName, setOwner, start, stoppublic static final int MODE_CLIENT_FOUND
Status.REDIRECTION_FOUND status. Note:
this is a client-side redirection.Status.REDIRECTION_FOUND,
Constant Field Valuespublic static final int MODE_CLIENT_PERMANENT
Status.REDIRECTION_PERMANENT
status. Note: this is a client-side redirection.public static final int MODE_CLIENT_SEE_OTHER
Status.REDIRECTION_SEE_OTHER status.
Note: this is a client-side redirection.public static final int MODE_CLIENT_TEMPORARY
Status.REDIRECTION_TEMPORARY status.
Note: this is a client-side redirection.public static final int MODE_SERVER_INBOUND
Context.getServerDispatcher(). Once
the selected client connector has completed the request handling, the
response is normally returned to the client. In this case, you can view the
Redirector as acting as a transparent proxy Restlet. Note: this is a
server-side redirection.Component and to declare them in the list of required connectors on
the Application.getConnectorService() property.headersCleaning attribute or by overriding the
rewrite(Request) or rewrite(Response).public static final int MODE_SERVER_OUTBOUND
Application.getOutboundRoot() or if
null to Context.getClientDispatcher(). Once the selected client
connector has completed the request handling, the response is normally
returned to the client. In this case, you can view the Redirector as
acting as a transparent server-side proxy. Note: this is a server-side
redirection.Component and to declare them in the list of required connectors on
the Application.getConnectorService() property.headersCleaning attribute or by overriding the
rewrite(Request) or rewrite(Response).protected volatile boolean headersCleaning
protected volatile int mode
protected volatile String targetTemplate
public Redirector(Context context, String targetTemplate)
context - The context.targetTemplate - The template to build the target URI.Templatepublic int getMode()
protected Reference getTargetRef(Request request, Response response)
Template class using the request
and response as data models.request - The request to handle.response - The response to update.public String getTargetTemplate()
public void handle(Request request, Response response)
protected void inboundServerRedirect(Reference targetRef, Request request, Response response)
targetRef - The target reference with URI variables resolved.request - The request to handle.response - The response to update.public boolean isHeadersCleaning()
protected void outboundServerRedirect(Reference targetRef, Request request, Response response)
targetRef - The target reference with URI variables resolved.request - The request to handle.response - The response to update.protected Representation rewrite(Representation initialEntity)
MODE_SERVER_INBOUND and MODE_SERVER_OUTBOUND modes. By
default, it just returns the initial entity without any modification.initialEntity - The initial entity returned.protected void rewrite(Request initialRequest)
MODE_SERVER_INBOUND and
MODE_SERVER_OUTBOUND modes. By default, it leverages the
headersCleaning attribute in order to clean the headers: if set to
true, it removes all headers, otherwise it keeps only the extension (or non
HTTP standard) headersinitialRequest - The initial request returned.protected void rewrite(Response initialResponse)
MODE_SERVER_INBOUND and
MODE_SERVER_OUTBOUND modes. By default, it leverages the
headersCleaning attribute in order to clean the headers: if set to
true, it removes all headers, otherwise it keeps only the extension (or non
HTTP standard) headersinitialResponse - The initial response returned.public void rewriteLocation(Request request, Response response)
request - The request to handle.response - The response to update.protected void serverRedirect(Restlet next, Reference targetRef, Request request, Response response)
next - The next Restlet to forward the call to.targetRef - The target reference with URI variables resolved.request - The request to handle.response - The response to update.public void setHeadersCleaning(boolean headersCleaning)
headersCleaning - True if the headers must be cleaned.public void setMode(int mode)
mode - The redirection mode.public void setTargetTemplate(String targetTemplate)
targetTemplate - The target URI pattern.Copyright © 2005–2025. All rights reserved.