arcims 兩種連接方式(java connector,servlet connector)的一些比較- -
(1) java connector主要是利用ims自封裝的一些java類(lèi)(ConnectionProxy,Map)來(lái)實(shí)現,通過(guò)api方法進(jìn)行調用,
舉例如下:
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();
在此過(guò)程中,Map對象的方法主要工作為構造arcxml request,并解析arcxml response
優(yōu)點(diǎn):基于api接口實(shí)現起來(lái)方便易用
缺點(diǎn):解析map對象,影響速度。且調用map.refresh()方法,默認為做兩次arcims request. 第一次為遍歷axl的request,第二次為實(shí)際的request.
(2)servlet connector主要通過(guò)向servlet地址發(fā)送請求,然后獲得返回的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();
其中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>
返回的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>
通過(guò)xml parse解析即可得到輸出url.
優(yōu)點(diǎn):向arcims應用服務(wù)器,只需請求arcxml request一次,只需調用自己的建構的arcimsrequest對象,此類(lèi)對象為開(kāi)源,可實(shí)現自?xún)?yōu)化
缺點(diǎn):需要自己定義arcims request 對象,沒(méi)有java connector簡(jiǎn)潔明了。
優(yōu)化:可直接進(jìn)行socket通信,通過(guò)tcp協(xié)議實(shí)現。