Publishing the domain service component as REST resources

Feedback


In the mechanism in which SuperMap iServer/iEdge publishes the domain component as the REST service, the methods in the domain component implementing class can be published as the REST resource.

For example, publishes the following component implementing as the REST resource:

package com.supermap.sample.DomainResource;

public class myComponent  {

        //Compares whether two strings are identical. Simple parameter type and returns the simple results.

        public boolean compareString(String str1, String str2) {

                boolean flag = true;

                if (str1 != null) {

                        if (!str1.equals(str2)) {

                                flag = false;

                        }

                } else if (str2 != null) {

                        flag = false;

                }

                return flag;

        }

}

Only needs to put the Jar package after compiling this class into the directory %SuperMap iServer_HOME%/webapps/iserver/WEB-INF/lib, and adds the configuration of this component in the file services.xml in the directory %SuperMap iServer_HOME%/webapps/iserver/WEB-INF/config, as follows:

<?xml version="1.0" encoding="UTF-8"?>

<server>

        ...

        <application>

                ...

                <components>

                        ...

                        <component name="myComponent"

                                class="com.supermap.sample.DomainResource.myComponent" providers="" interfaceNames="rest">

                        </component>

                </components>

        </application>

</server>

The root directory of the domain resource published as the REST service is: http://<iServer-root>/{domainComponentName}/rest. In this example usage, the root directory of the domain resource published as the REST service is:

http://localhost:8090/iserver/services/myComponent/rest

The resource structure is as follows:

An example usage URI of accessing the compareStringResult resource and getting the XML representation is:

http://localhost:8090/iserver/services/myComponent/rest/domainComponents/mycomponent/compareStringResult.xml?arg0="abc"&arg1="abc"

The response results are as follows:

  <?xml version="1.0" encoding="UTF-8" standalone="no" ?>

  <boolean>true</boolean>

In the domain component implementing class, all the public methods having return values will be published as resources. Different methods with different parameter types and numbers will be published as domain resources of different types (please see two domain resource types mentioned in the ResourceType enumeration in the JavaDoc document, that is, DomainArithmeticResource and DomainArithResultResource). The details are as follows.

First, we define the methods in the domain component as the simple method and the complex method:

Also, we define the domain resources as simple domain resources and complex domain resources. SuperMap iServer publishes simple method in the domain component as simple domain resource, and publishes complex method as complex domain resource:

The following table lists the corresponding relations between the public method and the resource name after automatically publishing the method as the REST resource in a class:

Public method Description Resource
void output(String s) The methods without return values. None.
String getParam() The get method, used to get parameters. param
boolean isParamNull() The get method, used to determine whether it is null. paramNull
boolean isParamNull(String s) The general simple method (see the description of the method type). isParamNullResult
String Param() The simple method whose parameters are null, used to get the param parameter. ParamResult
Point getCenter(Point, Point) The complex method, because the parameter type is the complex type (see the description of the method type). getCenterResults
boolean compareString(String, String) The simple method (see the description of the method type).。 compareStringResult
boolean isStrContainedInArray(String, String[]) The complex method, because the parameter type is the complex type (see the description of the method type). isStrContainedInArrayResults

Note that when publishing the public method in the domain component as the REST resource and accessing the resource by the HTTP method, the passed parameters should use arg0, arg1, arg2 ... in turn as the parameter field names, according to the order of parameters in the original method, and the parameters are passed by means of key-value pair in the URI.

For more details of the domain spatial service extension, please see Domain Service Extensions.