public abstract class ServiceUsingHandler extends Object implements Handler
Subclasses must implement exactly one method named "handle"
that accepts a Context
as the first parameter,
and at least one other parameter of any type.
Each parameter after the first Context
parameter is expected to be a contextual object.
It's value will be the result of calling Registry.get(Class)
with the parameter type.
The following two handlers are functionally equivalent:
import ratpack.handling.*; import ratpack.file.FileSystemBinding; public class VerboseHandler implements Handler { public void handle(Context context) { FileSystemBinding fileSystemBinding = context.get(FileSystemBinding.class); context.render(fileSystemBinding.getFile().toString()); } } public class SuccinctHandler extends ServiceUsingHandler { public void handle(Context context, FileSystemBinding fileSystemBinding) { context.render(fileSystemBinding.getFile().toString()); } }
If the parameters cannot be satisfied, a NotInRegistryException
will be thrown.
If there is no suitable handle(Context, ...)
method, a ServiceUsingHandler.NoSuitableHandleMethodException
will be thrown at construction time.
Modifier and Type | Class and Description |
---|---|
static class |
ServiceUsingHandler.NoSuitableHandleMethodException
Exception thrown if the subclass doesn't provide a valid handle method.
|
Modifier | Constructor and Description |
---|---|
protected |
ServiceUsingHandler()
Constructor.
|
protected ServiceUsingHandler() throws ServiceUsingHandler.NoSuitableHandleMethodException
ServiceUsingHandler.NoSuitableHandleMethodException
- if this class doesn't provide a suitable handle method.