REST service publishing mechanism

Feedback


SuperMap iServer publishes REST services through Restlet. Firstly, construct a REST application, and then deploy the application object in an HTTP environment, such as Servlet container, OSGI core, Spring, Guice Ioc container, independent JVMS, Groovy, Scala, JAIN/SLEE, etc. Currently, the application object is deployed in the Servlet container. After that, SuperMap iServer can publish REST services through the REST application object, as illustrated below.

As shown above, an HTTP request firstly arrives at the HTTP environment, then the HTTP environment passes the request to the REST application object, the corresponding class of which inherits from Application in Restlet. The HTTP request will be handled according to the context and the response will be sent back to the client through the HTTP environment.

When an HTTP request arrives at the REST application object, the application object will search the resource configuration information in the REST application context and compare the URI for the HTTP request with those templates. The best matched resource will be found and the implementation of the resource is expected to handle the HTTP request. The procedure is as follows:

The REST application context contains the information about the resource configuration, REST application configuration, core component configuration, etc. needed by the REST application. The REST application context is obtained from the configuration file when starting the server.

The resource configuration information includes the resource ID, resource type, URI template, implementation class, etc. Resources are implemented through the REST application object and are published in the form of the corresponding URI templates.

The implementation class of a resource is used to handle all operations on the resource. Each implementation class has an HTTP MethodHandler, which aims at managing the HTTP request handling. The HTTP request handling has the following steps:

  1. Extract parameters from the HTTP request (it is possible that there are no parameters in the HTTP request);

  2. Get the correct Decoder according to the HTTP request header, parsing the parameters in the HTTP request into Java objects;

  3. Handle the business logic according to the parameters (there can be no parameters) and return the result;

  4. Obtain the correct Encoder according to URI, encode the result and write the result into the HTTP response object.

In short, when an HTTP request arrives at the REST application object, a proper resource will be found to handle the request. After that the result will be returned to the client through the HTTP environment as an HTTP response.