org.restlet.engine.application

## Class StatusFilter

- java.lang.Object
- - org.restlet.Restlet
  - - org.restlet.routing.Filter
    - - org.restlet.engine.application.StatusFilter

All Implemented Interfaces:
  Uniform

    public class StatusFilter
    extends Filter

Filter associating a response entity based on the status. In order to customize the default representation, just subclass this class and override the "getRepresentation" method.
If any exception occurs during the call handling, a "server internal error" status is automatically associated to the call. Of course, you can personalize the representation of this error. Also, if no status is set (null), then the "success OK" status is assumed. 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.

Author:
  Jerome Louvel

### Field Summary

### Fields inherited from class org.restlet.routing.Filter

`CONTINUE, SKIP, STOP`

### Constructor Summary

Constructors
Constructor and Description
`StatusFilter(Context context, boolean overwriting, java.lang.String email, Reference homeRef)` Constructor.
`StatusFilter(Context context, StatusService statusService)` Constructor from a status service.

### Method Summary

Methods
`void` `afterHandle(Request request, Response response)` Allows filtering after its handling by the target Restlet.
`protected int` `doHandle(Request request, Response response)` Handles the call by distributing it to the next Restlet.
`java.lang.String` `getContactEmail()` Returns the email address of the administrator to contact in case of error.
`protected Representation` `getDefaultRepresentation(Status status, Request request, Response response)` Returns a representation for the given status. In order to customize the default representation, this method can be overridden.
`Reference` `getHomeRef()` Returns the home URI to propose in case of error.
`protected Representation` `getRepresentation(Status status, Request request, Response response)` Returns a representation for the given status. In order to customize the default representation, this method can be overridden.
`protected Status` `getStatus(java.lang.Throwable throwable, Request request, Response response)` Returns a status for a given exception or error.
`protected java.lang.String` `getStatusInfo(Status status)` Returns the status information to display in the default representation.
`StatusService` `getStatusService()` Returns the helped status service.
`boolean` `isOverwrite()` Deprecated. Use `isOverwriting()` instead.
`boolean` `isOverwriting()` Indicates if existing representations should be overwritten.
`void` `setContactEmail(java.lang.String email)` Sets the email address of the administrator to contact in case of error.
`void` `setHomeRef(Reference homeRef)` Sets the home URI to propose in case of error.
`void` `setOverwrite(boolean overwriting)` Deprecated. Use `setOverwriting(boolean)` instead.
`void` `setOverwriting(boolean overwriting)` Indicates if existing representations should be overwritten.
`void` `setStatusService(StatusService statusService)` Sets the helped status service.

### Methods inherited from class org.restlet.routing.Filter

`beforeHandle, getNext, handle, hasNext, setNext, setNext, start, stop`

### Methods inherited from class org.restlet.Restlet

`finalize, getApplication, getAuthor, getContext, getDescription, getLogger, getName, getOwner, isStarted, isStopped, setAuthor, setContext, setDescription, setName, setOwner`

### Methods inherited from class java.lang.Object

`clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### StatusFilter

    public StatusFilter(Context context,
                boolean overwriting,
                java.lang.String email,
                Reference homeRef)

Constructor.

Parameters:
  `context` - The context.
  `overwriting` - Indicates whether an existing representation should be overwritten.
  `email` - Email address of the administrator to contact in case of error.
  `homeRef` - The home URI to propose in case of error.

#### StatusFilter

    public StatusFilter(Context context,
                StatusService statusService)

Constructor from a status service.

Parameters:
  `context` - The context.
  `statusService` - The helped status service.

### Method Detail

#### afterHandle

    public void afterHandle(Request request,
                   Response response)

Allows filtering after its handling by the target Restlet. Does nothing by default.

Overrides:
  `afterHandle` in class `Filter`
Parameters:
  `request` - The request to handle.
  `response` - The response to update.

#### doHandle

    protected int doHandle(Request request,
               Response response)

Handles the call by distributing it to the next Restlet. If a throwable is caught, the `getStatus(Throwable, Request, Response)` method is invoked.

Overrides:
  `doHandle` in class `Filter`
Parameters:
  `request` - The request to handle.
  `response` - The response to update.
Returns:
  The continuation status.

#### getContactEmail

    public java.lang.String getContactEmail()

Returns the email address of the administrator to contact in case of error.

Returns:
  The email address.

#### getDefaultRepresentation

    protected Representation getDefaultRepresentation(Status status,
                                          Request request,
                                          Response response)

Returns a representation for the given status.
In order to customize the default representation, this method can be overridden.

Parameters:
  `status` - The status to represent.
  `request` - The request handled.
  `response` - The response updated.
Returns:
  The representation of the given status.

#### getHomeRef

    public Reference getHomeRef()

Returns the home URI to propose in case of error.

Returns:
  The home URI.

#### getRepresentation

    protected Representation getRepresentation(Status status,
                                   Request request,
                                   Response response)

Returns a representation for the given status.
In order to customize the default representation, this method can be overridden.

Parameters:
  `status` - The status to represent.
  `request` - The request handled.
  `response` - The response updated.
Returns:
  The representation of the given status.

#### getStatus

    protected Status getStatus(java.lang.Throwable throwable,
                   Request request,
                   Response response)

Returns a status for a given exception or error. By default it returns an `Status.SERVER_ERROR_INTERNAL` status including the related error or exception and logs a severe message.
In order to customize the default behavior, this method can be overriden.

Parameters:
  `throwable` - The exception or error caught.
  `request` - The request handled.
  `response` - The response updated.
Returns:
  The representation of the given status.

#### getStatusInfo

    protected java.lang.String getStatusInfo(Status status)

Returns the status information to display in the default representation. By default it returns the status's name.

Parameters:
  `status` - The status.
Returns:
  The status information.
See Also:
  `getDefaultRepresentation(Status, Request, Response)`

#### getStatusService

    public StatusService getStatusService()

Returns the helped status service.

Returns:
  The helped status service.

#### isOverwrite

    @Deprecated
    public boolean isOverwrite()

Deprecated. Use `isOverwriting()` instead.
Indicates if existing representations should be overwritten.

Returns:
  True if existing representations should be overwritten.

#### isOverwriting

    public boolean isOverwriting()

Indicates if existing representations should be overwritten.

Returns:
  True if existing representations should be overwritten.

#### setContactEmail

    public void setContactEmail(java.lang.String email)

Sets the email address of the administrator to contact in case of error.

Parameters:
  `email` - The email address.

#### setHomeRef

    public void setHomeRef(Reference homeRef)

Sets the home URI to propose in case of error.

Parameters:
  `homeRef` - The home URI.

#### setOverwrite

    @Deprecated
    public void setOverwrite(boolean overwriting)

Deprecated. Use `setOverwriting(boolean)` instead.
Indicates if existing representations should be overwritten.

Parameters:
  `overwriting` - True if existing representations should be overwritten.

#### setOverwriting

    public void setOverwriting(boolean overwriting)

Indicates if existing representations should be overwritten.

Parameters:
  `overwriting` - True if existing representations should be overwritten.

#### setStatusService

    public void setStatusService(StatusService statusService)

Sets the helped status service.

Parameters:
  `statusService` - The helped status service.