(1) java connector主要是利用ims自封装的一些java类(ConnectionProxy,Map)来实现,通过api方法进行调用,
举例如下:
ConnectionProxy mapCon=new ConnectionProxy();
if(connectiontype.equalsIgnoreCase("http"))
{
mapCon.setConnectionType(ConnectionProxy.HTTP);
URL url = new URL(host);
mapCon.setUrl(url);
}
else if (connectiontype.equalsIgnoreCase("tcp"))
{
mapCon.setConnectionType(ConnectionProxy.TCP);
mapCon.setHost(host);
}
mapCon.setPort(port);
mapCon.setService(datasource);
mapCon.setDisplayMessages(true);
map=new Map();
map.initMap(mapCon,750,false,false,false,false);
map.setHeight(option.getHeight());
map.setWidth(option.getWidth());
.................
map.refresh();
String mapurl=map.getMapOutput().getURL();
String legendurl=map.getLegend().getLegendOutput().getURL();
在此过程中,Map对象的方法主要工作为构造arcxml request,并解析arcxml response
优点:基于api接口实现起来方便易用
缺点:解析map对象,影响速度。且调用map.refresh()方法,默认为做两次arcims request. 第一次为遍历axl的request,第二次为实际的request.
举例如下:
ConnectionProxy mapCon=new ConnectionProxy();
if(connectiontype.equalsIgnoreCase("http"))
{
mapCon.setConnectionType(ConnectionProxy.HTTP);
URL url = new URL(host);
mapCon.setUrl(url);
}
else if (connectiontype.equalsIgnoreCase("tcp"))
{
mapCon.setConnectionType(ConnectionProxy.TCP);
mapCon.setHost(host);
}
mapCon.setPort(port);
mapCon.setService(datasource);
mapCon.setDisplayMessages(true);
map=new Map();
map.initMap(mapCon,750,false,false,false,false);
map.setHeight(option.getHeight());
map.setWidth(option.getWidth());
.................
map.refresh();
String mapurl=map.getMapOutput().getURL();
String legendurl=map.getLegend().getLegendOutput().getURL();
在此过程中,Map对象的方法主要工作为构造arcxml request,并解析arcxml response
优点:基于api接口实现起来方便易用
缺点:解析map对象,影响速度。且调用map.refresh()方法,默认为做两次arcims request. 第一次为遍历axl的request,第二次为实际的request.
(2)servlet connector主要通过向servlet地址发送请求,然后获得返回的url流,得到响应
举例如下:
String serverUrl=" http://localhost:8888/servlet/com.esri.esrimap.Esrimap?ServiceName=SantaClara";
URL imsURL =new URL(serverUrl);
URLConnection connection=imsURL.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
BufferedOutputStream bos = new BufferedOutputStream(connection.getOutputStream());
OutputStreamWriter out = new OutputStreamWriter(bos, "UTF8");
out.write(arcimsRequest, 0, arcimsRequest.length());
out.flush();
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF8"));
String ln;
String tempString=null;
while ((ln = in.readLine()) != null)
{
if (tempString == null)
{
tempString = ln;
}
else
{
tempString = tempString + ln;
}
}
arcxmlReponseStr = tempString.trim();
out.close();
in.close();
举例如下:
String serverUrl=" http://localhost:8888/servlet/com.esri.esrimap.Esrimap?ServiceName=SantaClara";
URL imsURL =new URL(serverUrl);
URLConnection connection=imsURL.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
BufferedOutputStream bos = new BufferedOutputStream(connection.getOutputStream());
OutputStreamWriter out = new OutputStreamWriter(bos, "UTF8");
out.write(arcimsRequest, 0, arcimsRequest.length());
out.flush();
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF8"));
String ln;
String tempString=null;
while ((ln = in.readLine()) != null)
{
if (tempString == null)
{
tempString = ln;
}
else
{
tempString = tempString + ln;
}
}
arcxmlReponseStr = tempString.trim();
out.close();
in.close();
其中arcimsRequest格式如下:
Arcxml request:
<?xml version="1.0" encoding="UTF-8"?>
<ARCXML version="1.1">
<REQUEST>
<GET_IMAGE autoresize="false">
<ENVIRONMENT>
<SEPARATORS cs=" " ts=";"/>
</ENVIRONMENT>
//scalebar is set
<LAYER id="8" name="LayerName" type="acetate" visible="true">
<OBJECT units="pixel">
<SCALEBAR antialiasing="true" barcolor="255,255,255" bartransparency="1.0" barwidth="12" coords="100.0 3.0" distance="0.0" font="Arial" fontcolor="0,0,0" fontsize="10" fontstyle="regular" mapunits="degrees" mode="cartesian" outline="255,255,255" overlap="true" precision="2" round="0.0" scaleunits="meters" screenlength="40" texttransparency="1.0"/>
</OBJECT>
</LAYER>
<PROPERTIES>
<ENVELOPE maxx="-121.87677055355464" maxy="37.33222499720282" minx="-121.90701583922555" miny="37.316082232930746"/>
<IMAGESIZE dpi="750" height="350" scalesymbols="false" width="500"/>
<BACKGROUND color="215,215,215"/>
<OUTPUT type="jpg"/>
<LEGEND antialiasing="false" autoextend="true" cansplit="false" cellspacing="2" columns="1" display="true" font="宋体" height="300" layerfontsize="12" reverseorder="false" splittext="(cont)" swatchheight="14" swatchwidth="18" title="图例" titlefontsize="15" valuefontsize="10" width="125"/>
<LAYERLIST dynamicfirst="false" nodefault="false" order="true">
<LAYERDEF id="0" name="boundary" visible="true"/>
<LAYERDEF id="1" name="tract" visible="true"/>
<LAYERDEF id="2" name="sc_streets" visible="true"/>
<LAYERDEF id="3" name="rivers" visible="false"/>
<LAYERDEF id="4" name="hospital" visible="true"/>
<LAYERDEF id="5" name="cities" visible="true"/>
<LAYERDEF id="6" name="topoq24" visible="false"/>
// scalebar is set
<LAYERDEF id="8" name="LayerName" visible="true"/>
</LAYERLIST>
</PROPERTIES>
</GET_IMAGE>
</REQUEST>
</ARCXML>
<?xml version="1.0" encoding="UTF-8"?>
<ARCXML version="1.1">
<REQUEST>
<GET_IMAGE autoresize="false">
<ENVIRONMENT>
<SEPARATORS cs=" " ts=";"/>
</ENVIRONMENT>
//scalebar is set
<LAYER id="8" name="LayerName" type="acetate" visible="true">
<OBJECT units="pixel">
<SCALEBAR antialiasing="true" barcolor="255,255,255" bartransparency="1.0" barwidth="12" coords="100.0 3.0" distance="0.0" font="Arial" fontcolor="0,0,0" fontsize="10" fontstyle="regular" mapunits="degrees" mode="cartesian" outline="255,255,255" overlap="true" precision="2" round="0.0" scaleunits="meters" screenlength="40" texttransparency="1.0"/>
</OBJECT>
</LAYER>
<PROPERTIES>
<ENVELOPE maxx="-121.87677055355464" maxy="37.33222499720282" minx="-121.90701583922555" miny="37.316082232930746"/>
<IMAGESIZE dpi="750" height="350" scalesymbols="false" width="500"/>
<BACKGROUND color="215,215,215"/>
<OUTPUT type="jpg"/>
<LEGEND antialiasing="false" autoextend="true" cansplit="false" cellspacing="2" columns="1" display="true" font="宋体" height="300" layerfontsize="12" reverseorder="false" splittext="(cont)" swatchheight="14" swatchwidth="18" title="图例" titlefontsize="15" valuefontsize="10" width="125"/>
<LAYERLIST dynamicfirst="false" nodefault="false" order="true">
<LAYERDEF id="0" name="boundary" visible="true"/>
<LAYERDEF id="1" name="tract" visible="true"/>
<LAYERDEF id="2" name="sc_streets" visible="true"/>
<LAYERDEF id="3" name="rivers" visible="false"/>
<LAYERDEF id="4" name="hospital" visible="true"/>
<LAYERDEF id="5" name="cities" visible="true"/>
<LAYERDEF id="6" name="topoq24" visible="false"/>
// scalebar is set
<LAYERDEF id="8" name="LayerName" visible="true"/>
</LAYERLIST>
</PROPERTIES>
</GET_IMAGE>
</REQUEST>
</ARCXML>
返回的arcxmlReponseStr ,格式如下:
<?xml version="1.0" encoding="UTF-8"?>
<ARCXML version="1.1">
<RESPONSE>
<IMAGE>
<ENVELOPE minx="-121.907015839225" miny="37.3135677650819" maxx="-121.876770553554" maxy="37.3347394650516" />
<OUTPUT file="C:/oc4j/j2ee/home/default-web-app/output/SantaClara_CHXW24002560270.jpg" url=" http://chxw:8888/output/SantaClara_CHXW24002560270.jpg" />
<LEGEND file="C:/oc4j/j2ee/home/default-web-app/output/SantaClara_CHXW24002568263.jpg" url=" http://chxw:8888/output/SantaClara_CHXW24002568263.jpg" />
</IMAGE>
</RESPONSE>
</ARCXML>
通过xml parse解析即可得到输出url.
优点:向arcims应用服务器,只需请求arcxml request一次,只需调用自己的建构的arcimsrequest对象,此类对象为开源,可实现自优化
缺点:需要自己定义arcims request 对象,没有java connector简洁明了。
优化:可直接进行socket通信,通过tcp协议实现。
<?xml version="1.0" encoding="UTF-8"?>
<ARCXML version="1.1">
<RESPONSE>
<IMAGE>
<ENVELOPE minx="-121.907015839225" miny="37.3135677650819" maxx="-121.876770553554" maxy="37.3347394650516" />
<OUTPUT file="C:/oc4j/j2ee/home/default-web-app/output/SantaClara_CHXW24002560270.jpg" url=" http://chxw:8888/output/SantaClara_CHXW24002560270.jpg" />
<LEGEND file="C:/oc4j/j2ee/home/default-web-app/output/SantaClara_CHXW24002568263.jpg" url=" http://chxw:8888/output/SantaClara_CHXW24002568263.jpg" />
</IMAGE>
</RESPONSE>
</ARCXML>
通过xml parse解析即可得到输出url.
优点:向arcims应用服务器,只需请求arcxml request一次,只需调用自己的建构的arcimsrequest对象,此类对象为开源,可实现自优化
缺点:需要自己定义arcims request 对象,没有java connector简洁明了。
优化:可直接进行socket通信,通过tcp协议实现。