GeoServer学习手记(五):Servlet及HTTP派发过程之二

本文详细介绍了GeoServer中GET和POST请求的区别及其处理流程,包括如何通过HTTP请求获取地理特征数据,以及GeoServer内部如何解析这些请求并作出响应。

GeoServer学习手记(五):Servlet及HTTP派发过程之二

转载 粟卫民http://www.gisdev.cn/ http://blog.youkuaiyun.com/suen/ 日期:2009-10-29

接上篇《GeoServer学习手记(四):Servlet及HTTP派发过程之一》(http://blog.youkuaiyun.com/suen/archive/2009/11/02/4759332.aspx)。

Request
A request can be sent to Geoserver as a GET or a POST, both are handled similarly.

The getFeature process keeps the distinction between a GET and POST until it hits the FeatureRequest object: org.vfny.geoserver.wfs.requests.FeatureRequest. Once you hit FeatureRequest, the code isn't forked and the request works from one spot, execute(). Read on for more details.

GET and POST

Here is an example HTTP GET request

http://localhost:8080/geoserver/wfs?request=getfeature&service=wfs&version=1.0.0&typename=states&filter=

xmlns:ogc="http://ogc.org" xmlns:gml="http://www.opengis.net/gml">
the_geom
-73.99312376470733,40.76203427979042 -73.9239210030026,40.80129519821393
 Try itIf you have Geoserver set up locally on port 8080, you can enter the above URL and Geoserver will process it.   Try it with this link
Here is an example HTTP XML POST request
http://localhost:8080/geoserver/wfs
 
  outputFormat="GML2"
  xmlns:topp="http://www.openplans.org/topp"
  xmlns:wfs="http://www.opengis.net/wfs"
  xmlns:ogc="http://www.opengis.net/ogc"
  xmlns:gml="http://www.opengis.net/gml"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.opengis.net/wfs
                      http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd">
 
   
     
        the_geom
       
          
               -73.99312376470733,40.76203427979042 -73.9239210030026,40.80129519821393
          
       
     
  
 
Exploring the HTTP GET request URL
There are 6 parts to the URL:

The server address - _http://localhost:8080/geoserver/wfs_

 

The request type - request=getfeature

 

The service type - service=wfs

 

The version - version=1.0.0

 

The type name, also known as the data you are querying - typename=states

 

The filter used to select exactly what you want from the type

 

The server address points to where your Geoserver instance is running. In this example, on the local machine on port 8080.
The request type is the command that you are sending to the server. In this case the URL is asking "get me some features". There are other commands that can be sent:

GetFeature (the case we are analyzing)

 

Transaction

 

LockFeature

 

GetFeatureWithLock

 

GetFeatureInfo

 

GetCapabilities

 

Service type tells the server what service mode you want. Here we want WFS. Another possible service is WMS.
Version number of the WFS specification that is used (1.0.0).
The type name is the FeatureType that you are querying, also known as the data. In our example, a shapefile that contains US states.
The filter is a restriction on our query. It pretty much says "restrict my query to only features in this bounding box". There are many filters you can use, but we will not explore them in this tutorial. Here is the sleep inducing OGC Filter specification if you really want to learn more.
How Geoserver interperets the request
Here is the overview of the program flow, in a bit of an abstract view.
  
Entry Point
When the request comes in, the servlet container (ie. jetty or tomcat) will send the request to the WfsDispatcher. This is the entry point for Geoserver to process the results.
You can set up where this entry point is by changing your web.xml file. Located in %GEOSERVER_HOME%/server/geoserver/WEB-INF
Here is the part of the xml file that we want:
WfsDispatcher
    org.vfny.geoserver.wfs.servlets.WfsDispatcher
 
...
 
    WfsDispatcher
    /wfs/*
 
This says that any request to "wfs/*" will get routed to the org.vfny.geoserver.wfs.servlets.WfsDispatcher servlet. Since both our requests (GET and POST) are to "http://localhost:8080/geoserver/wfs", the servlet container (ie. jetty or tomcat) will send the request to the WfsDispatcher.
WFS Dispatcher
There are two main methods in WfsDispatcher.java (located in org.vfny.geoserver.wfs.servlets):
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
 
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
If you send an HTTP POST request, doPost gets called. If you send an HTTP GET request, doGet gets called. Get it?
POST

  Since one cannot read the POST portion of a HTTP request more than once, a copy of the request is written to disk. This is done in WfsDispatcher.doPost().
NOTE: This is somewhat inefficient, but we originally done this way because very large feature insert requests can be very large. Holding the request in memory would not be scalable. A better (and faster) solution would be to have a simple class that would either hold a small request in memory or, if the request is large, write it to disk.
DispatcherXMLReader will then use SAX to parse the XML. It looks at the first tag in the XML request (see DispatchHandler) and can determine the request type from that. In our case (see above), its "" so we know this is a Dispatcher.GET_FEATURE_REQUEST request.
GET

  This case is very easy - it just looks at the request url for the "request=GetFeature". You can see that in WfsDispatcher.doGet() and DispatcherKvpReader.
NOTE: "Kvp" means "Key-Value Pair". For the clause "request=GetFeature", the Key is "request" and the value is "GetFeature".
Whether it was an HTTP GET or POST, the WfsDispatcher will create an appropriate servelet. Remember the 6 different request types: GetFeature, Transaction, LockFeature, GetFeatureWithLock, GetFeatureInfo, GetCapabilities? For 'GetFeature' it will create a Feature servelet: org.vfny.geoserver.wfs.servlets.Feature

  

  The GET or POST request information is then passed to that servelet, along with a response object that the servelet will populate. The response will be described later in the response section.

 
 NoteYou might be wondering why a request goes through the (WFS) Dispatcher and then through a second (GetFeature) servlet.If you look at the web.xml (the file the servlet container uses for configuration), you'll see these lines:    GetFeature    org.vfny.geoserver.wfs.servlets.Feature         GetFeature    /wfs/GetFeature/*  This means you can actually send your GetFeature request directly to the GetFeature servlet instead indirectly through the WFS dispatcher. Most people (and software) find it easier to just send all your requests to one URL instead of each request to a specific servlet. Geoserver lets you do either.http://localhost:8080/geoserver/wfs/GetFeature

The diagram below shows where the distinction between GET and POST ends:
 

 

  Not every object or class in the above diagram recognizes the difference, web.xml for example, but it is more to show the life of the GET and POST distinction.
Feature Servelet
The next stage of the getFeature request creates a FeatureRequest object and populates it with the query information.
Depending on whether a GET or a POST was used, different parsers are selected.
  

  The two parsers are GetFeatureKvpReader, for HTTP GET, and GetFeatureXMLReader, for HTTP POST. These will then create the FeatureRequest object.
The FeatureRequest object will then head over to the feature type that was specified in the URL, in this example "states", and query the data.


 
 NoteThe feature request object does not actually get the features from the data store. It is important to note this. Performing a query actually gets you a FeatureReader object, and no real data. This is explained below in the Response section.

(未完待续)


本文来自优快云博客,转载请标明出处:http://blog.youkuaiyun.com/suen/archive/2009/11/02/4759398.aspx

(1)普通用户端(全平台) 音乐播放核心体验: 个性化首页:基于 “听歌历史 + 收藏偏好” 展示 “推荐歌单(每日 30 首)、新歌速递、相似曲风推荐”,支持按 “场景(通勤 / 学习 / 运动)” 切换推荐维度。 播放页功能:支持 “无损音质切换、倍速播放(0.5x-2.0x)、定时关闭、歌词逐句滚动”,提供 “沉浸式全屏模式”(隐藏冗余控件,突出歌词与专辑封面)。 多端同步:自动同步 “播放进度、收藏列表、歌单” 至所有登录设备(如手机暂停后,电脑端打开可继续播放)。 音乐发现与管理: 智能搜索:支持 “歌曲名 / 歌手 / 歌词片段” 搜索,提供 “模糊匹配(如输入‘晴天’联想‘周杰伦 - 晴天’)、热门搜索词推荐”,结果按 “热度 / 匹配度” 排序。 歌单管理:创建 “公开 / 私有 / 加密” 歌单,支持 “批量添加歌曲、拖拽排序、一键分享到社交平台”,系统自动生成 “歌单封面(基于歌曲风格配色)”。 音乐分类浏览:按 “曲风(流行 / 摇滚 / 古典)、语言(国语 / 英语 / 日语)、年代(80 后经典 / 2023 新歌)” 分层浏览,每个分类页展示 “TOP50 榜单”。 社交互动功能: 动态广场:查看 “关注的用户 / 音乐人发布的动态(如‘分享新歌感受’)、好友正在听的歌曲”,支持 “点赞 / 评论 / 转发”,可直接点击动态中的歌曲播放。 听歌排行:个人页展示 “本周听歌 TOP10、累计听歌时长”,平台定期生成 “全球 / 好友榜”(如 “好友中你本周听歌时长排名第 3”)。 音乐圈:加入 “特定曲风圈子(如‘古典音乐爱好者’)”,参与 “话题讨论(如‘你心中最经典的钢琴曲’)、线上歌单共创”。 (2)音乐人端(创作者中心) 作品管理: 音乐上传:支持 “无损音频(FLAC/WAV)+ 歌词文件(LRC)+ 专辑封面” 上传,填写 “歌曲信息
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值