org.restlet
Class Redirector

java.lang.Object
  extended by org.restlet.Uniform
      extended by org.restlet.Restlet
          extended by org.restlet.Redirector

public class Redirector
extends Restlet

Rewrites URIs then redirects the call or the client to a new destination.

Author:
Jerome Louvel (contact@noelios.com)
See Also:
Template, Tutorial: URI rewriting and redirection

Field Summary
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.
See org.restlet.data.Status.REDIRECTION_FOUND.
static int MODE_CLIENT_PERMANENT
          In this mode, the client is permanently redirected to the URI generated from the target URI pattern.
See org.restlet.data.Status.REDIRECTION_PERMANENT.
static int MODE_CLIENT_SEE_OTHER
          In this mode, the client is simply redirected to the URI generated from the target URI pattern.
See org.restlet.data.Status.REDIRECTION_SEE_OTHER.
static int MODE_CLIENT_TEMPORARY
          In this mode, the client is temporarily redirected to the URI generated from the target URI pattern.
See org.restlet.data.Status.REDIRECTION_TEMPORARY.
static int MODE_DISPATCHER
          In this mode, the call is sent to the context's dispatcher.
protected  String targetTemplate
          The target URI pattern.
 
Constructor Summary
Redirector(Context context, String targetTemplate)
          Constructor for the dispatcher mode.
Redirector(Context context, String targetPattern, int mode)
          Constructor.
 
Method Summary
protected  Reference getTargetRef(Request request, Response response)
          Returns the target reference to redirect to.
 void handle(Request request, Response response)
          Handles a call to a resource or a set of resources.
protected  void redirectDispatcher(Reference targetRef, Request request, Response response)
          Redirects a given call to a target reference.
protected  Representation rewrite(Representation initialEntity)
          Optionnaly rewrites the response entity returned in the MODE_CONNECTOR mode.
 
Methods inherited from class org.restlet.Restlet
getContext, getLogger, init, isStarted, isStopped, setContext, start, stop
 
Methods inherited from class org.restlet.Uniform
delete, delete, get, get, handle, head, head, options, options, post, post, put, put
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_CLIENT_PERMANENT

public static final int MODE_CLIENT_PERMANENT
In this mode, the client is permanently redirected to the URI generated from the target URI pattern.
See org.restlet.data.Status.REDIRECTION_PERMANENT.

See Also:
Constant Field Values

MODE_CLIENT_FOUND

public static final int MODE_CLIENT_FOUND
In this mode, the client is simply redirected to the URI generated from the target URI pattern.
See org.restlet.data.Status.REDIRECTION_FOUND.

See Also:
Constant Field Values

MODE_CLIENT_SEE_OTHER

public static final int MODE_CLIENT_SEE_OTHER
In this mode, the client is simply redirected to the URI generated from the target URI pattern.
See org.restlet.data.Status.REDIRECTION_SEE_OTHER.

See Also:
Constant Field Values

MODE_CLIENT_TEMPORARY

public static final int MODE_CLIENT_TEMPORARY
In this mode, the client is temporarily redirected to the URI generated from the target URI pattern.
See org.restlet.data.Status.REDIRECTION_TEMPORARY.

See Also:
Constant Field Values

MODE_DISPATCHER

public static final int MODE_DISPATCHER
In this mode, the call is sent to the context's dispatcher. 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.

Remember to add the required connectors to the parent Component and to declare them in the list of required connectors on the Application.connectorService property.

Note that in this mode, the headers of HTTP requests, stored in the request's attributes, are removed before dispatching. Also, when a HTTP response comes back the headers are also removed.

See Also:
Constant Field Values

targetTemplate

protected String targetTemplate
The target URI pattern.


mode

protected int mode
The redirection mode.

Constructor Detail

Redirector

public Redirector(Context context,
                  String targetTemplate)
Constructor for the dispatcher mode.

Parameters:
context - The context.
targetTemplate - The template to build the target URI.
See Also:
Template

Redirector

public Redirector(Context context,
                  String targetPattern,
                  int mode)
Constructor.

Parameters:
context - The context.
targetPattern - The pattern to build the target URI (using StringTemplate syntax and the CallModel for variables).
mode - The redirection mode.
Method Detail

handle

public void handle(Request request,
                   Response response)
Handles a call to a resource or a set of resources.

Overrides:
handle in class Restlet
Parameters:
request - The request to handle.
response - The response to update.

redirectDispatcher

protected void redirectDispatcher(Reference targetRef,
                                  Request request,
                                  Response response)
Redirects a given call to a target reference. In the default implementation, the request HTTP headers, stored in the request's attributes, are removed before dispatching. After dispatching, the response HTTP headers are also removed to prevent conflicts with the main call.

Parameters:
targetRef - The target reference with URI variables resolved.
request - The request to handle.
response - The response to update.

getTargetRef

protected Reference getTargetRef(Request request,
                                 Response response)
Returns the target reference to redirect to.

Parameters:
request - The request to handle.
response - The response to update.
Returns:
The target reference to redirect to.

rewrite

protected Representation rewrite(Representation initialEntity)
Optionnaly rewrites the response entity returned in the MODE_CONNECTOR mode. By default, it just returns the initial entity without any modification.

Parameters:
initialEntity - The initial entity returned.
Returns:
The rewritten entity.


Copyright © 2005-2007 Noelios Consulting.