Step 6 Adding Code |
Add the code to the created HelloiServer.java:
package com.supermap.sample; import com.supermap.services.components.spi.ogc.WMS; import com.supermap.services.components.spi.ogc.WMSCapabilities; import com.supermap.services.components.spi.ogc.WMSClient; public class HelloiServer {
// WMS URL
private static String strURL = "http://localhost:8090/iserver/services/map-china400/wms111/China";
// The user name of WMS
private static String userName = null;
// The password of WMS
private static String password = null;
// Initializes a new instance of WMSClient in terms of the WMS URL, user name and password
private WMS wmsClient = new WMSClient(strURL, userName, password);
// Get the WMS service name
public String getServiceName() {
WMSCapabilities wmsCapabilities = null;
String wmsVersion = "1.1.1";
try {
// Get WMS metadata information
wmsCapabilities = wmsClient.getCapabilities(wmsVersion);
} catch (Exception e) {
e.printStackTrace();
}
// Get the WMS service name
String serviceName = wmsCapabilities.serviceDescription.name;
return serviceName;
}
public static void main(String[] args) {
HelloiServer helloiServer = new HelloiServer();
// Output Hello SuperMap iServer
System.out.println("Hello SuperMap iServer!");
String serviceName = helloiServer.getServiceName();
// Output the WMS service name
System.out.println("The WMS Service name is: " + serviceName);
}
}
You can get a WMS service name published by localhost.