C# Class OpenSim.ApplicationPlugins.Rest.Inventory.RestHandler

Inheritance: RestPlugin, IRestHandler, IHttpAgentHandler
Show file Open project: openmetaversefoundation/fortis-opensim

Public Methods

Method Description
AddPathHandler ( RestMethodHandler mh, string path, RestMethodAllocator ra ) : void

A method handler and a request allocator are stored using the designated path as a key. If an entry already exists, it is replaced by the new one.

AddStreamHandler ( string httpMethod, string path, RestMethod method ) : void

Add a stream handler for the designated HTTP method and path prefix. If the handler is not enabled, the request is ignored. If the path does not start with the REST prefix, it is added. If method-qualified path has not already been registered, the method is added to the active handler table.

Close ( ) : void

In the interests of efficiency, and because we cannot determine whether or not this instance will actually be harvested, we clobber the only anchoring reference to the working state for this plug-in. What the call to close does is irrelevant to this class beyond knowing that it can nullify the reference when it returns. To make sure everything is copacetic we make sure the primary interface is disabled by deleting the handler from the HTTP server tables.

Handle ( OpenSim.Framework.Servers.HttpServer.OSHttpRequest request, OpenSim.Framework.Servers.HttpServer.OSHttpResponse response ) : bool

This is called by the HTTP server once the handler has indicated that it is able to handle the request. Preconditions: [1] request != null and is a valid request object [2] response != null and is a valid response object Behavior is undefined if preconditions are not satisfied.

Initialise ( OpenSimBase openSim ) : void

This method is called by OpenSimMain immediately after loading the plugin and after basic server setup, but before running any server commands.

Note that entries MUST be added to the active configuration files before the plugin can be enabled.

Match ( OpenSim.Framework.Servers.HttpServer.OSHttpRequest request, OpenSim.Framework.Servers.HttpServer.OSHttpResponse response ) : bool

This method is called by the HTTP server to match an incoming request. It scans all of the strings registered by the underlying handlers and looks for the best match. It returns true if a match is found. The matching process could be made arbitrarily complex. Note: The match is case-insensitive.

Private Methods

Method Description
FindPathHandler ( OpenSim.Framework.Servers.HttpServer.OSHttpRequest request, OpenSim.Framework.Servers.HttpServer.OSHttpResponse response ) : bool

Given the supplied request/response, if the handler is enabled, the inbound information is used to match an entry in the active path handler tables, using the method-qualified path information. If a match is found, then the handler is invoked. The result is the boolean result of the handler, or false if no handler was located. The boolean indicates whether or not the request has been handled, not whether or not the request was successful - that information is in the response. Note: The selection process is case-insensitive

FindStreamHandler ( OpenSim.Framework.Servers.HttpServer.OSHttpRequest request, OpenSim.Framework.Servers.HttpServer.OSHttpResponse response ) : bool

If there is a stream handler registered that can handle the request, then fine. If the request is not matched, do nothing. Note: The selection is case-insensitive

LoadHandlers ( ) : void

This routine loads all of the handlers discovered during instance initialization. A table of all loaded and successfully constructed handlers is built, and this table is then used by the constructor to initialize each of the handlers in turn. NOTE: The loading process does not automatically imply that the handler has registered any kind of an interface, that may be (optionally) done by the handler either during construction, or during initialization. I was not able to make this code work within a constructor so it is isolated within this method.

RestHandler ( ) : System

This static initializer scans the ASSEMBLY for classes that export the IRest interface and builds a list of them. These are later activated by the handler. To add a new handler it is only necessary to create a new services class that implements the IRest interface, and recompile the handler. This gives all of the build-time flexibility of a modular approach while not introducing yet-another module loader. Note that multiple assembles can still be built, each with its own set of handlers. Examples of services classes are RestInventoryServices and RestSkeleton.

Method Details

AddPathHandler() public method

A method handler and a request allocator are stored using the designated path as a key. If an entry already exists, it is replaced by the new one.
public AddPathHandler ( RestMethodHandler mh, string path, RestMethodAllocator ra ) : void
mh RestMethodHandler
path string
ra RestMethodAllocator
return void

AddStreamHandler() public method

Add a stream handler for the designated HTTP method and path prefix. If the handler is not enabled, the request is ignored. If the path does not start with the REST prefix, it is added. If method-qualified path has not already been registered, the method is added to the active handler table.
public AddStreamHandler ( string httpMethod, string path, RestMethod method ) : void
httpMethod string
path string
method RestMethod
return void

Close() public method

In the interests of efficiency, and because we cannot determine whether or not this instance will actually be harvested, we clobber the only anchoring reference to the working state for this plug-in. What the call to close does is irrelevant to this class beyond knowing that it can nullify the reference when it returns. To make sure everything is copacetic we make sure the primary interface is disabled by deleting the handler from the HTTP server tables.
public Close ( ) : void
return void

Handle() public method

This is called by the HTTP server once the handler has indicated that it is able to handle the request. Preconditions: [1] request != null and is a valid request object [2] response != null and is a valid response object Behavior is undefined if preconditions are not satisfied.
public Handle ( OpenSim.Framework.Servers.HttpServer.OSHttpRequest request, OpenSim.Framework.Servers.HttpServer.OSHttpResponse response ) : bool
request OpenSim.Framework.Servers.HttpServer.OSHttpRequest
response OpenSim.Framework.Servers.HttpServer.OSHttpResponse
return bool

Initialise() public method

This method is called by OpenSimMain immediately after loading the plugin and after basic server setup, but before running any server commands.
Note that entries MUST be added to the active configuration files before the plugin can be enabled.
public Initialise ( OpenSimBase openSim ) : void
openSim OpenSimBase
return void

Match() public method

This method is called by the HTTP server to match an incoming request. It scans all of the strings registered by the underlying handlers and looks for the best match. It returns true if a match is found. The matching process could be made arbitrarily complex. Note: The match is case-insensitive.
public Match ( OpenSim.Framework.Servers.HttpServer.OSHttpRequest request, OpenSim.Framework.Servers.HttpServer.OSHttpResponse response ) : bool
request OpenSim.Framework.Servers.HttpServer.OSHttpRequest
response OpenSim.Framework.Servers.HttpServer.OSHttpResponse
return bool