GeoServer learning note (5): Part 2 of Servlet and HTTP dispatching process

Source: Internet
Author: User

 

Geoserver learning note (5): Part 2 of Servlet and HTTP dispatching process

Su Weimin http://www.gisdev.cn/http://blog.csdn.net/suen/ Date:

All copyrights reserved. If you need to reprint the information, contact the author and indicate the source in a conspicuous position.

 

Next, I wrote geoserver learning notes (4): Servlet and HTTP dispatching process (http://blog.csdn.net/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 it

If 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
           
        
      
   
  

Processing the http get request URL

There are 6 parts to the URL:

  1. The server address-_ http: // localhost: 8080/geoserver/WFS _

  2. The request type-request = getfeature
  3. The service type-service = WFS
  4. The version-version = 1.0.0
  5. The type name, also known as the data you are querying-typename = states
  6. The filter used to select exactly what you want from the type

TheServer addressPoints to where your Geoserver instance is running. In this example, on the local machine on port 8080.

TheRequest typeIs 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 typeTells the server what service mode you want. Here we want WFS. Another possible service is WMS.

Version numberOf the WFS specification that is used (1.0.0 ).

TheType nameIs the FeatureType that you are querying, also known as the data. In our example, a shapefile that contains US states.

TheFilterIs a restriction on our query. it pretty much says "restrict my query to only features in this bounding box ". there are invalid filters you can use, but we will not have e 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 isEntry pointFor Geoserver to process the results.

You can set up where this entry point is by changing yourWeb. xmlFile. 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 wocould not be scalable. A better (and faster) solution wocould be to have a simple class that wocould 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, temperature, getfeatureinfo, getcapabilities? For 'getfeature 'it will createFeatureServelet: 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.

Note

You 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 dimo-below shows where the distinction between get and post ends:

Not every object or class in the above dimo-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.

Note

The feature request object does not actually get the features from the data store. it is important to note this. when Ming a query actually gets you a featurereader object, and no real data. this is explained below inResponseSection.

(To be continued)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.