Handlers are pluggable components, that contain custom processing logic for handling resources. All handlers extend an abstract class named Handler
, which provides default implementations for resource handling methods as well as a few utilities useful for concrete handler implementations.
Handler
implementations can provide alternative behaviors for basic resource related operations, by overwriting one or more methods in the Handler
class. At this point, it is useful to look at the Handler
class listed below.
Note
Here some details are omitted for clarity.
Here is a description of how each of these methods works.
Method | Important parameters (To extract from Request Context) | Return value | Description |
---|---|---|---|
| requestContext.getResourcePath() // path, the resource is getting | Resource // the resource at the path | Retrieves a resource in a given path. |
| requestContext.getResourcePath() // path to put | - | Stores a resource in a given path. |
| requestContext.getResourcePath() // path to put | - | Imports a resource from a URL. |
| requestContext.getSourcePath() // source to move from | String // the new path | Moves a resource from one to another. |
| requestContext.getSourcePath() // source to copy from | String // the new path | Copies a resource from one to another. |
| requestContext.getSourcePath() // source of the resource | String // the new path | Changes a name of a resource. |
| requestContext.getResourcePath() // the path of the link is creating | - | Creates a sym-link or a remote link. |
| requestContext.getResourcePath() // the path of the link to remove | - | Removes a link. |
| requestContext.getResourcePath() // the path of the resource to remove | - | Deletes a resource. If this is a collection, all the children will also be removed. |
| requestContext.getResourcePath() // the path resource is putting | String // the path of the resource | Called when putting a resource to any path except root. |
| requestContext.getResourcePath() // the path resource is importing to | String // the path of the resource | Called when importing a resource to any path except root. |
| requestContext.getResource() // the resource to invoke the aspect | - | Triggered when invoking an aspect (Aspects are described in detail in following sections). |
| requestContext.getSourcePath() // left branch of the association | - | Triggered when adding an association. |
| requestContext.getSourcePath() // left branch of the association | - | Triggered when removing an association. |
| requestContext.getResourcePath() // the path of the resource | Association[] | Returns all the associations of a given resource. |
| requestContext.getResourcePath() // the path of the resource | Association[] | Returns associations of a give association type of a given resource. |
| requestContext.getResourcePath() // the path of the resource | - | Applies a tag to a particular path. |
| requestContext.getResourcePath() // the path of the resource | - | Removes a tag in a particular path. |
| requestContext.getResourcePath() // the path of the resource | - | Triggered when Rating a resource. |
| requestContext.getVersionPath() // the path + version of the resource | - | Triggered when restoring a version-ed resource. |
| requestContext.getResourcePath() // Create a version of a resource | - | Triggered when creating a resource. |
| requestContext.getCommentPath() // The path of the comment of a resource | - | Edits a comment in a given path. |
| requestContext.getResourcePath() // The path of the resource | String // the comment path | Adds a comment to the given path. |
| requestContext.getCommentPath() // The path of the comment of a resource | - | Removes a comment in a given path. |
| requestContext.getResourcePath() // The path of the resource | Comment[] | Gets all comments in a given path. |
| requestContext.getResourcePath() // The path of the resource | float | Gets the average rating of a resource. |
| requestContext.getResourcePath() // The path of the resource | int | Gets the rating given by a user to a given resource. |
| requestContext.getResourcePath() // The path of the resource | String[] | Returns version paths of a given resource. |
| requestContext.getResourcePath() // The path of the resource | Tag[] | Returns tags of a given resource. |
| requestContext.getResourcePath() // The path of the resource | TaggedResourcePath[] | Returns resource paths with a given tag. |
| requestContext.getResourcePath() // The path of the query | Collection | Returns collection (paths as the content) queried in the given query. |
| requestContext.getKeywords() // The search keywords | Collection | Returns collection (paths as the content) found as a result of search operation. |
| requestContext.getResourcePath() // The path of the resource | boolean | Returns whether the resource in the given path exists. |
| requestContext.getResourcePath() // The path of the resource | - | Dumps a particular path. |
| requestContext.getResourcePath() // The path of the resource | - | Restores a dump. |
Handlers can be engaged and configured using the registry configuration file (registry.xml
). Here is an example of using registry.xml
to declare a handler.
<handler class="org.wso2.carbon.registry.extensions.handlers.WSDLMediaTypeHandler"> <property name="schemaLocationConfiguration" type="xml"> <locationType>absolute</locationType> <location>/governance/schemas/</location> </property> <property name="wsdlLocationConfiguration" type="xml"> <locationType>absolute</locationType> <!-- absolute or relative --> <location>/governance/wsdls/</location> </property> <filter class="org.wso2.carbon.registry.core.jdbc.handlers.filters.MediaTypeMatcher"> <property name="mediaType">application/wsdl+xml</property> </filter> </handler>
Here are the important parameters you can provide in the handler configuration.
- Handler class - The class name of the handler. Provided in the
class
attribute in the Handler. For example:
<handler class="org.wso2.carbon.registry.extensions.handlers.WSDLMediaTypeHandler"> ... </handler>
- Handler properties - Custom properties that will be used in handler processing logic. For example:
<property name="wsdlLocationConfiguration" type="xml">
The attributes in the property
element:
- name - The name of the property. In order to store the property value, you should have an setter method in the particular handler class. The method name should be
set
+ property name with the first letter capitalized. The method name for the above property would be:
setWsdlLocationConfiguration
- type - The type of the property. Possible values are
xml
andnull
. If the type isxml,
the handler method should have an method argument of the typeorg.apache.axiom.om.OMElement
. If the type attribute is not given, the method argument will be of the typejava.lang.String
. So the method signature for the above example property is:
public void setWsdlLocationConfiguration(OMElement locationConfiguration) throws RegistryException { }
- Filter is associated with the handler. You can refer a filter inside a handler which would provide the filter functionality to that particular handler. The handler for a particular method is invoked only if the filter is returning true for the corresponding method. For more details about filters, see Configuring Filters .
Common steps in writing a handler.
1. Extend the Handler
class and overwrite necessary methods.
2. Implement whatever custom behaviors in overwritten methods. You may use information provided in the RequestContext
instance, in your custom implementation.
3. Once the custom behavior is completed, it is usually required to perform the actual requested operation (for example, add the resource in put(...)
method).
Tip
Use the Repository
instance provided in the RequestContext
to perform the actual operation. If it is required to version the resource in put operation, use VersionRepository
instance.
Note
It is not recommended to use the Registry
instance to perform resource related operations (get, put, import, delete) inside a handler as it may cause infinite loops as the Registry tries to invoke all handlers again.
See also Handlers.