English

How To: Create an ArcIMS service dynamically using the Java Connector

Summary

This article describes the necessary steps required to create an ArcIMS service using the Java Connector. The code described below does not require Map Configuration file to create the service. The map configuration information is provided in String format instead.

Procedure

  1. Set user-name, password and ConnectionType as TCP_ADMIN to the ConnectionProxy object.

    Code:
    cp.setHost("IMSHost");
    cp.setPort(5300);
    cp.setConnectionType(cp.TCP_ADMIN);
    cp.setUsername("admin");
    cp.setPassword("admin");


    Note:
    IMSHost and port are hostname and port number respectively for ArcIMS Application Server. The user-name and password are same as those for ArcIMS Administrator.

  2. Get the VirtualServerCollection and obtain the Image Server from the collection.

    Code:

    VirtualServerCollection vsCollection = VirtualServerCollection.getVirtualServers(cp);
    VirtualServer v = null;
    boolean imageServerAvailable=false;
    for(int i=0;i<vsCollection.size();i++) {
    v = vsCollection.getVirtualServer(i);
    if (v.getName().equals("ImageServer1")){
    imageServerAvailable = true;
    break;
    }
    }

  3. If ImageServer is available publicly, create a new Service object and set its properties as shown in the example code below.

    Code:

    if (imageServerAvailable){
    Service service = new Service();
    service.setName("mapServiceName");
    service.setOutputCleanup(20);
    service.setOutputDir("C:/ArcIMS/output");
    service.setOutputURL("http://webserver/output");
    service.setPixelCount(1048576);
    service.setImageType(Service.IMAGE_JPG);
    service.setVirtualServer(v.getName(),v.getType(),v.getVersion());

  4. Store the map configuration information in a String object.

    Code:

    StringBuffer sb = new StringBuffer();
    sb.append("<MAP> <PROPERTIES>");
    sb.append("<ENVIRONMENT>");
    sb.append("<LOCALE country=\"US\" language=\"en\" variant=\"\" />");
    sb.append("<UIFONT color=\"0,0,0\" name=\"dialog\" size=\"12\" style=\"regular\" />");
    sb.append("<SCREEN dpi=\"96\" />");
    sb.append("</ENVIRONMENT>");
    sb.append("<ENVELOPE minx=\"-178.2\" miny=\"18.9\" ");
    sb.append("maxx=\"-66.9\" maxy=\"71.4\" name=\"Initial_Extent\" />");
    sb.append("<MAPUNITS units=\"decimal_degrees\" /></PROPERTIES>");
    sb.append("<WORKSPACES>");
    sb.append("<SHAPEWORKSPACE name=\"shp_ws-0\" directory=\"C:\\ESRI\\ESRIDATA\\USA\" />");
    sb.append("</WORKSPACES>");
    sb.append("<LAYER type=\"featureclass\" name=\"states\" visible=\"true\" id=\"1\">");
    sb.append("<DATASET name=\"states\" type=\"polygon\" workspace=\"shp_ws-0\" />");
    sb.append("<SIMPLERENDERER>");
    sb.append("<SIMPLEPOLYGONSYMBOL boundarytransparency=\"1.0\" filltransparency=\"1.0\" ");
    sb.append("fillcolor=\"27,27,227\" boundarycaptype=\"round\" />");
    sb.append("</SIMPLERENDERER></LAYER>");
    sb.append("</MAP>");

    String configInfo = sb.toString();

  5. Set the ConfigContents to the Service.

    Code:

    service.setConfigFile("");
    service.setConfigContents(configInfo);

  6. Add and start the service.

    Code:

    service.addService(cp);
    service.startService(cp);
    }