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?referrer={fi}" would redirect to the relative
URI, inserting the referrer URI as a query parameter.Template
,
User
Guide - URI rewriting and redirectionModifier and Type | Field and Description |
---|---|
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.
|
static int |
MODE_CLIENT_PERMANENT
In this mode, the client is permanently redirected to the URI generated
from the target URI pattern.
|
static int |
MODE_CLIENT_SEE_OTHER
In this mode, the client is simply redirected to the URI generated from
the target URI pattern.
|
static int |
MODE_CLIENT_TEMPORARY
In this mode, the client is temporarily redirected to the URI generated
from the target URI pattern.
|
static int |
MODE_DISPATCHER
Deprecated.
Use the
MODE_SERVER_OUTBOUND instead. |
static int |
MODE_SERVER_INBOUND
In this mode, the call is sent to the context's server dispatcher.
|
static int |
MODE_SERVER_OUTBOUND
In this mode, the call is sent to the application's outboundRoot or if
null to the context's client dispatcher.
|
protected java.lang.String |
targetTemplate
The target URI pattern.
|
Constructor and Description |
---|
Redirector(Context context,
java.lang.String targetTemplate)
Constructor for the client dispatcher mode.
|
Redirector(Context context,
java.lang.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.
|
java.lang.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.
|
protected void |
outboundServerRedirect(Reference targetRef,
Request request,
Response response)
Redirects a given call to a target reference.
|
protected void |
redirectDispatcher(Reference targetRef,
Request request,
Response response)
Deprecated.
Use
outboundServerRedirect(Reference, Request, Response)
instead. |
protected Representation |
rewrite(Representation initialEntity)
Optionally rewrites the response entity returned in the
MODE_SERVER_INBOUND and MODE_SERVER_OUTBOUND modes. |
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 |
setMode(int mode)
Sets the redirection mode.
|
void |
setTargetTemplate(java.lang.String targetTemplate)
Sets the target URI pattern.
|
finalize, getApplication, getAuthor, getContext, getDescription, getLogger, getName, getOwner, isStarted, isStopped, setAuthor, setContext, setDescription, setName, setOwner, start, stop
public static final int MODE_CLIENT_PERMANENT
public static final int MODE_CLIENT_FOUND
public static final int MODE_CLIENT_SEE_OTHER
public static final int MODE_CLIENT_TEMPORARY
@Deprecated public static final int MODE_DISPATCHER
MODE_SERVER_OUTBOUND
instead.public static final int MODE_SERVER_OUTBOUND
Redirector
as acting as a transparent server-side proxy Restlet.Component
and to declare them in the list of required connectors on the
Application.getConnectorService()
property.public static final int MODE_SERVER_INBOUND
Component
and to declare them in the list of required connectors on the
Application.getConnectorService()
property.protected volatile java.lang.String targetTemplate
protected volatile int mode
public Redirector(Context context, java.lang.String targetTemplate)
context
- The context.targetTemplate
- The template to build the target URI.Template
public Redirector(Context context, java.lang.String targetPattern, int mode)
context
- The context.targetPattern
- The pattern to build the target URI (using StringTemplate
syntax and the CallModel for variables).mode
- The redirection mode.public int getMode()
protected Reference getTargetRef(Request request, Response response)
request
- The request to handle.response
- The response to update.public java.lang.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.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.@Deprecated protected void redirectDispatcher(Reference targetRef, Request request, Response response)
outboundServerRedirect(Reference, Request, Response)
instead.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 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 setMode(int mode)
mode
- The redirection mode.public void setTargetTemplate(java.lang.String targetTemplate)
targetTemplate
- The target URI pattern.Copyright © 2005-2012. All Rights Reserved.