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

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

粟卫民http://www.gisdev.cn/ http://blog.csdn.net/suen/ 日期:2009-10-29

保留所有版权。如需转载,请联系作者,并在醒目位置注明出处

1.6版之后的HTTP派发过程

接上篇《GeoServer学习手记(七):Servlet及HTTP派发过程之四》(http://blog.csdn.net/suen/archive/2009/11/11/4799572.aspx)。再转载一篇官方说明OWS的技术文档。(转载自:http://geoserver.org/display/GEOSDOC/0+Http

The GeoServer http / servlet module contains utilities and infrastructure used to implement services bound to the http protocol.

OWS Dispatching

The org.geoserver.ows.http package provides an ows dispatching framework for http. The term dispatching refers to mapping an incoming request to an operation. For example mapping the request http://geo.openplans.org/geoserver/wfs?request=GetCapabilities to the GetCapabilities operation of the WFS service.

The ows http dispatching framework builds off of the ows model provided by the [platform] module. In the GeoServer ows model services and operations are implemented as plain old java objects. Services are just java beans. The contain data which can be used by operations of the service.

Operations are also plain old java objects, which follow a few conventions:

· The name of the operation maps directly to a method name

· Paramters of the operation exist as a settable properties

As an example consider a service called TalkerService, which contains a single operation names SaySomething. First the service:

class TalkerService {
 
}

Nothing special here. The more interesting part is the operation:

class SaySomethingOperation {
 
    String message;
 
    void setMessage( String message ) {
        this.message = message;
    }
 
    void saySomething() {
        System.out.println( message );
    }
}

Two things to note about the operation:

1. The name of the operation "saySomething", maps to the saySomething method

2. The name of the property "message", maps to the setMessage method

With the above service and operation, the end goal is to be able to dispatch an http request and execute the operation. In other words execute the operation with the following url:

http://...?service=talker&request=saySomething&message=Hello World

In order for this to happen, the service and operation must first be described to the dispather. In GeoServer this is done in a spring context using a Service descriptor, and an Operation descriptor.

applicationContext.xml

 
 
 
  
  
  
  
 
  
  
  
  
            
  
  
       
  
  
  
 
  
  
  
  
 
  
  
  
  
                 
  
  
       
  
  
                  
  
  
  
 
 
 

At this point, the dispatcher has enough information to map the above url to the operation. A step by step guide which goes into more depth about how exactly to implement and deploy a simple service in this manner can be found [here].

Using the OWS Dispatcher

The OWS dispatcher can be used inside of any web application using the following steps:

1. Spring Dispatcher Servlet Declaration

First the spring dispatcher servlet must be declared in the web application descriptor, web.xml file.

web.xml

 
 
    dispatcher
    org.springframework.web.servlet.DispatcherServlet
 
 

2. Spring Dispatcher Mapping

Next a particular set of urls must be mapped to the dispatcher. The following example will map all requests to the dispatcher.

web.xml

 
 
    dispatcher
    /*
 
 

Alternativley, you could perform the mapping under a paritcular path such as:

web.xml

 
 
    dispatcher
    /ows/*
 
 

3. OWS Dispatcher Declaration

The next step is to set up the ows dispatcher. This is done in a special spring application context called dispatcher-servlet.xml which must be located in the WEB-INF folder of your application.

dispatcher-servlet.xml

 
 

4. OWS Dispatcher Mapping

Finally a particular set of urls must be mapped to the ows dispatcher:

dispatcher-servlet.xml

 
 
 
    
      
        dispatcher
        dispatcher
        dispatcher
      
    
 
 
 

猜你喜欢

转载自blog.csdn.net/suen/article/details/4799587
今日推荐