play
Class GlobalSettings

java.lang.Object
  extended by play.GlobalSettings

public class GlobalSettings
extends java.lang.Object

GlobalSettings is instantiated by the framework when an application starts, to let you perform specific tasks at start-up or shut-down.

How to use it: create a Global.java class in your Java application and override the methods you want.


Constructor Summary
GlobalSettings()
           
 
Method Summary
 void beforeStart(Application app)
          Executed before any plugin - you can set-up your database schema here, for instance.
<T extends play.api.mvc.EssentialFilter>
java.lang.Class<T>[]
filters()
          Get the filters that should be used to handle each request.
<A> A
getControllerInstance(java.lang.Class<A> controllerClass)
          Manages controllers instantiation.
 F.Promise<SimpleResult> onBadRequest(Http.RequestHeader request, java.lang.String error)
          Called when an action has been found, but the request parsing has failed.
 F.Promise<SimpleResult> onError(Http.RequestHeader request, java.lang.Throwable t)
          Called when an exception occurred.
 F.Promise<SimpleResult> onHandlerNotFound(Http.RequestHeader request)
          Called when no action was found to serve a request.
 Configuration onLoadConfig(Configuration config, java.io.File path, java.lang.ClassLoader classloader)
          Called just after configuration has been loaded, to give the application an opportunity to modify it.
 Action onRequest(Http.Request request, java.lang.reflect.Method actionMethod)
          Call to create the root Action of a request for a Java application.
 play.api.mvc.Handler onRouteRequest(Http.RequestHeader request)
          Called when an HTTP request has been received.
 void onStart(Application app)
          Executed after all plugins, including the database set-up with Evolutions and the EBean wrapper.
 void onStop(Application app)
          Executed when the application stops.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GlobalSettings

public GlobalSettings()
Method Detail

beforeStart

public void beforeStart(Application app)
Executed before any plugin - you can set-up your database schema here, for instance.


onStart

public void onStart(Application app)
Executed after all plugins, including the database set-up with Evolutions and the EBean wrapper. This is a good place to execute some of your application code to create entries, for instance.


onStop

public void onStop(Application app)
Executed when the application stops.


onError

public F.Promise<SimpleResult> onError(Http.RequestHeader request,
                                       java.lang.Throwable t)
Called when an exception occurred. The default is to send the framework's default error page. This is achieved by returning null, so that the Scala engine handles the excepetion and shows an error page. By overriding this method one can provide an alternative error page.

Parameters:
t - is any throwable
Returns:
null as the default implementation

onRequest

public Action onRequest(Http.Request request,
                        java.lang.reflect.Method actionMethod)
Call to create the root Action of a request for a Java application. The request and actionMethod values are passed for information.

Parameters:
request - The HTTP Request
actionMethod - The action method containing the user code for this Action.
Returns:
The default implementation returns a raw Action calling the method.

onRouteRequest

public play.api.mvc.Handler onRouteRequest(Http.RequestHeader request)
Called when an HTTP request has been received. The default implementation (return null) means to use the application router to find the appropriate action By overriding this method one can provide an alternative routing mechanism. Please note, though, this API is very low level, useful for plugin/module authors only.

Parameters:
request - the HTTP request header as seen by the core framework (the body has not been parsed yet)
Returns:
an action to handle this request - if no action is returned, a 404 not found result will be sent to client

onHandlerNotFound

public F.Promise<SimpleResult> onHandlerNotFound(Http.RequestHeader request)
Called when no action was found to serve a request. The default behavior is to render the framework's default 404 page. This is achieved by returning null, so that the Scala engine handles onHandlerNotFound. By overriding this method one can provide an alternative 404 page.

Parameters:
request - the HTTP request
Returns:
null in the default implementation, you can return your own custom Result in your Global class.

onBadRequest

public F.Promise<SimpleResult> onBadRequest(Http.RequestHeader request,
                                            java.lang.String error)
Called when an action has been found, but the request parsing has failed. The default behavior is to render the framework's default 400 page. This is achieved by returning null, so that the Scala engine handles onBadRequest. By overriding this method one can provide an alternative 400 page.

Parameters:
request - the HTTP request
Returns:
null in the default implementation, you can return your own custom Result in your Global class.

getControllerInstance

public <A> A getControllerInstance(java.lang.Class<A> controllerClass)
                        throws java.lang.Exception
Manages controllers instantiation.

Parameters:
controllerClass - the controller class to instantiate.
Returns:
the appropriate instance for the given controller class.
Throws:
java.lang.Exception

onLoadConfig

public Configuration onLoadConfig(Configuration config,
                                  java.io.File path,
                                  java.lang.ClassLoader classloader)
Called just after configuration has been loaded, to give the application an opportunity to modify it.

Parameters:
config - the loaded configuration
path - the application path
classloader - The applications classloader
Returns:
The configuration that the application should use

filters

public <T extends play.api.mvc.EssentialFilter> java.lang.Class<T>[] filters()
Get the filters that should be used to handle each request.