Extending Service Component

Feedback


Below demonstrates the implementation of the component layer:

@Component(providerTypes={MapProvider.class},optional=false, type = "PushpinMap")
public class PushpinComponent implements ComponentContextAware{
        ...
}

@Component annotates the meta information of the service component, with type indicating the type the service component, providerTypes indicating the service providers associated with the service component, and nameMapping indicating an implementation class of the NameMapping class, which is used to provide service interface information when clustering and is required when clustering is employed (SuperMap iServer supports for clustering extended services, please refer to Building DSS Cluster).

Service Component context

Extension example

Service Component context

In the implementation class of the service interface, ComponentContextAware can be used to get the service component context, through which the configuration information of the of the service providers and service components is provided.

Note: To improve the flexibility and make the structure of the domain service clearer, it is suggested that the business logic should not be placed on the business component layer. It is suggested that the business logic should be placed on the service provider layer, with the business capabilities implemented through the service providers by the service components.

Getting service component configuration

The configuration information of the service components is in iserver-services.xml (please refer to iServer configuration file for more details). Below is the configuration for a service component:

<component class="com.supermap.sample.SampleComponent" interfacenames="rest" name="samplecomponent" providers="ugcMapProvider-China400">
        <config class="com.supermap.sample.SampleComponentConfig">
                <param1>default</param1>
                ...
        </config>
</component>

SampleComponentConfig is the configuration class for SampleComponent, with param1 corresponding to the property of the SampleComponentConfig class. "rest" is the name of the interface to publish the Web service, "ugcMapProvider-China400" is the service provider used by the service component (Please refer to Service configuration file Structure.

In the implementation class of the service component, ComponentContextAware can be used to get the service component context, through which the configuration information of the service component can be got. The code is as follows:

@Component(providerTypes={MapProvider.class},optional=false, type = "SampleType")
public class SampleComponent implements ComponentContextAware{
        ...
        public void setComponentContext(ComponentContext context) {
                SampleComponentConfig config=context.getConfig(SampleComponentConfig.class);
                ...
        }
}

The SampleComponentConfig  object corresponds to the <config class="com.supermap.sample.SampleComponentConfig"/> configuration item.

Getting service components

In SuperMap iServer, the service component can get service providers, therefore getting the corresponding GIS capabilities. The code is as follows:

@Component(providerTypes={MapProvider.class},optional=false, type = "SampleType")
public class SampleComponent implements ComponentContextAware{
        ...
        public void setComponentContext(ComponentContext context) {
                List<MapProvider> mapproviders=context.getProviders(MapProvider.class);
                ...
        }
}

Extension example

By extending and adding new service components, exsisting service providers can be resued to implement richer capabilities.

In this example, a new service component PushpinComponent is implemented using the MapProvider to provide the labeling capability on the map.

Below is the implementation code of PushpinComponent:

PushpinComponent.java

public String GetImage(double pushpinX,double pushpinY) returns the URI of a map image. The position of (pushpinX,pushpinY) on the map is labeled with a red flag.

Note: The URI of the image contains the server IP and port number. In this example, the IP and port need to be processed in the service component. Here we replace the IP and port with localhost and 8090, as shown below:

                imageURI=imageURI.replace("{ip}", "localhost");
                imageURI=imageURI.replace("{port}", "8090");

Below is the implementation of the configuration class for the service component:

PushpinCofig.java

Place the Jar package after compiling in Java_HOME%\webapps\iserver\WEB-INF\lib.

As an example, PushpinComponent uses "China" in the China.smwu workspace for output, with ugcProvider-China400 being the service provider. The configuration in iserver-services.xml is as follows:

<component class="com.supermap.sample.component.PushpinComponent" interfaceNames="rest" name="map-pushpin" providers="ugcMapProvider-China400">
        <config class="com.supermap.sample.component.PushpinCofig">
                <mapName>China</mapName>
        </config>
</component>

interfaceNames="rest" indicates that the service component will be published as REST service. SuperMap iServer can publish any service component as REST service through the Restlet mechanism (refer to Publishing Domain Service Component as REST Service).

In the http://localhost:8090/iserver/services/map-pushpin/rest/domainComponents/PushpinComponent page, we can see resource list mapped by the PushpinComponent method. Click the GetImageResult resource and type in html format parameters, such as 13000000.0,4800000.0, to get xml format representation, or access the URI below:

http://localhost:8090/iserver/services/map-pushpin/rest/domainComponents/PushpinComponent/GetImageResult.xml?arg0=13000000&arg1=4800000

The response representation in XML format is as follows:

<string>
http://localhost:8090//iserver/output/temp/China_1f4xfa/30236220/10x7/4129x3129_89252943.png?_t=1540880753569
</string>

We can get the map access URI, by accessing which the following map image will be got: