WorldWind Java 版学习:10、服务器响应

一、服务器处理请求过程
1、服务器启动时,会先读一系列配置文件,然后启动 SocketListener 进行监听
ApplicationServerLauncher.main(String[]) line: 59
ApplicationServer.loadApplications(File) line: 130
ApplicationServer.parseWebAppConfigFile(File) line: 231
ApplicationServer.register(ServerApplication) line: 320
SocketListener.listen(int, String) line: 181
SocketListener.<init>(int, String) line: 57

2、当得到请求时,转由 ApplicationServer 调度,然后创建并执行一个 ClientSocketTask
SocketListener.run() line: 195
ApplicationServer.dispatch(Socket) line: 388
ApplicationServer$ClientSocketTask.<init>(Socket) line: 432

3、请求最终交给新建的一个 ServerWorkerThread 线程
ApplicationServer$ClientSocketTask.run() line: 464
ApplicationPool.execute(Socket, ServerApplication) line: 48
ServerWorkerThread.<init>(Socket, ServerApplication) line: 32

4、调用 WMSServerApplication 的 doGet 方法响应请求
ServerWorkerThread.run() line: 131
WMSServerApplication(BasicServerApplication).service(Socket) line: 143
WMSServerApplication(BasicHttpServerApplication).doService(Socket) line: 62
WMSServerApplication.doGet(HTTPRequest, HTTPResponse) line: 172

5、在 doGet 中,首先根据请求类型由 WMSRequestFactory 创建请求 WMSRequest 对象,如果是空请求,会将请求重定向然后跳转到配置的 web.xml 文件中配置的 RedirectTo 页面(<property name="gov.nasa.worldwind.avkey.Server.RedirectTo" value="http://localhost:8000/wms?REQUEST=GetCapabilities"/>),在创建请求对象时,会获取服务名,如果没有得到会显示警告(严重: Malformed request )
WMSServerApplication.doGet(HTTPRequest, HTTPResponse) line: 173
WMSRequestFactory.create(HTTPRequest) line: 58

6、得到相应的请求对象后,调用请求对象的 service 方法进行响应,然后是一些收尾工作,以 GetCapabilities 请求为例,实际调用的是 WMSGetCapabilitiesRequest 的 getCapabilitiesString 方法返回了字符串
WMSServerApplication.doGet(HTTPRequest, HTTPResponse) line: 174
WMSGetCapabilitiesRequest.service(HTTPRequest, HTTPResponse) line: 92

二、地图服务的处理过程
1、程序启动过程中会读取地图服务的配置,需要在 wms.config.xml 文件中进行 mapsource 相关的配置,还会读取 GDAL 的路径,需要在 web.xml 文件中配置
ApplicationServerLauncher.main(String[]) line: 59
ApplicationServer.loadApplications(File) line: 130
ApplicationServer.parseWebAppConfigFile(File) line: 229
WMSServerApplication(BasicServerApplication).start() line: 154
WMSServerApplication.doStart() line: 83
WMSServerApplication.readConfigurationFile() line: 342
Configuration.<init>(InputStream) line: 130
Configuration.readMapSources(XPath, Document) line: 327

2、在 WorldWind 中获取地图影像的请求一般为:http://ip_address/wms?service=WMS&request=GetMap&version=1.3&srs=EPSG:4326&layers=bmng200405&styles=&transparent=TRUE&format=image/dds&width=512&height=512&bbox=left,bottom,right,top,在 create 方法中会读取响应参数,然后调用 Sector 的 fromDegrees 方法构造影像的范围,并计算跨度
WMSServerApplication.doGet(HTTPRequest, HTTPResponse) line: 173
WMSRequestFactory.create(HTTPRequest) line: 27
WMSGetMapRequest.<init>(HTTPRequest) line: 92
WMSGetMapRequest.parseBoundingBox(String, String, String[]) line: 210
Sector.fromDegrees(double, double, double, double) line: 57
Sector.<init>(Angle, Angle, Angle, Angle) line: 481

3、在 service 方法调用 buildBufferedImage 方法生成影像,中间调用了 pigeonHoleLon 和 pigeonHoleLat 得到经纬度对应的行列号,最终采用命令行方式调用 GDAL 的相关命令完成影像数据获取
WMSServerApplication.doGet(HTTPRequest, HTTPResponse) line: 174
WMSGetMapRequest.service(HTTPRequest, HTTPResponse) line: 457
BlueMarbleNG500MGenerator$BMNGServiceInstance.serviceRequest(IMapRequest) line: 140
BlueMarbleNG500MGenerator$BMNGServiceInstance.buildBufferedImage(IMapRequest) line: 200
BlueMarbleNG500MGenerator$BMNGServiceInstance.getImageFromSource(String, Sector, int, int) line: 257
GDALUtils.translate(String, String[], File, File) line: 477
GDALUtils.exec_gdal(String, List<String>) line: 233

4、获得影像数据后,根据请求影像的格式,再经过了一系列的处理,最后生成影像数据流发送回来
WMSServerApplication.doGet(HTTPRequest, HTTPResponse) line: 174
WMSGetMapRequest.service(HTTPRequest, HTTPResponse) line: 478
BufferedImageFormatter(ImageFormatter).getStreamFromMimeType(String, Properties) line: 130
BufferedImageFormatter(ImageFormatter).asDDS(Properties) line: 34
BufferedImageFormatter(ImageFormatter).intermediateToDDS(BufferedImage, Properties) line: 64

posted on 2012-11-13 16:51  redfler  阅读(433)  评论(0编辑  收藏  举报

导航