geoserver-ows服务扩展

1.       开发环境以及工具

IDE:Eclipse或其他

JDK:1.6+

svn、maven3.1等

2.       资料准备

从geoserver官网下载源码,本次使用的version=2.5,以及geoserver发布版安装。

提取pom.xml文件(作为自定义项目的parent-pom),放在你自定义工程目录的上级目录中

3.       开始

a)在你的workspace中建立名为hello的项目。导入eclipse中,右键-maven选项-变成maven项目。Java-source目录:hello/src/main/java

目录结构:

Workspace/

  + pom.xmlparent-pom

+ hello/

     +pom.xml

     +src/

        +main/

          + java/

 

b)新建或修改pom.xml,你的pom配置应该如下:

 

<?xml
version=“1.0”encoding=“ISO-8859-1”?>

<project
xmlns=“http://maven.apache.org/POM/4.0.0”xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

    xsi:schemaLocation=“http://maven.apache.org/POM/4.0.0http://maven.apache.org/maven-v4_0_0.xsd”>

 

    <modelVersion>4.0.0</modelVersion>

 

    <!– set parent pom to community
pom–>

    <parent>

       <groupId>org.geoserver</groupId>

       <artifactId>community</artifactId>

       <version>2.5-SNAPSHOT</version>

    </parent>

 

    <groupId>org.geoserver</groupId>

    <artifactId>fileService</artifactId>

    <packaging>jar</packaging>

    <version>1.0.0</version>

    <name>Cnpc File Service Module</name>

 

    <!– declare depenency on
geoserver
main –>

    <dependencies>

       <dependency>

           <groupId>org.geoserver</groupId>

           <artifactId>main</artifactId>

           <version>2.5-SNAPSHOT</version>

       </dependency>

    </dependencies>

    <repositories>

       <repository>

           <id>opengeo</id>

           <name>opengeo</name>

           <url>http://repo.opengeo.org</url>

       </repository>

    </repositories>

</project>

 

C)新建类:HelloWorld

importjava.io.IOException;
importjavax.servlet.ServletException;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
 
publicclassHelloWorld{
 
  publicHelloWorld(){
    // Do nothing
  }
 
  publicvoidsayHello(HttpServletRequestrequest,HttpServletResponseresponse)
  throwsServletException,IOException{
    response.getOutputStream().write("Hello World".getBytes());
  }
}

D)创建spring配置文件applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
 
<beans>
    <!-- Spring will reference the instance of the HelloWorld class
           by the id name "helloService" -->
    <beanid="helloService"class="HelloWorld">
        </bean>
 
    <!-- This creates a Service descriptor, which allows the org.geoserver.ows.Dispatcher
           to locate it. -->
        <beanid="helloService-1.0.0"class="org.geoserver.platform.Service">
    <!-- used to reference the service in the URL -->
        <constructor-argindex="0"value="hello"/>
 
        <!-- our actual service POJO defined previously -->
        <constructor-argindex="1"ref="helloService"/>
 
        <!-- a version number for this service -->
        <constructor-argindex="2"value="1.0.0"/>
 
        <!-- a list of functions for this service -->
        <constructor-argindex="3">
            <list>
                <value>sayHello</value>
            </list>
        </constructor-arg>
 
        </bean>
</beans>

 

 

 

 

 

 

 

 

 

 

此时目录结构:

hello/
  + pom.xml
  + src/
    + main/
      + java/
        + HelloWorld.java
        + applicationContext.xml

 

e)打包:

在cmd窗口进入你的hello目录,运行maven命令

[hello]% mvn install

 

[hello]% mvn install
 
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building Hello World Service Module
[INFO]    task-segment: [install]
[INFO] ----------------------------------------------------------------------------
[INFO][resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO][compiler:compile]
[INFO] Compiling 1 source file to /home/ak/geoserver/community/hello/target/classes
[INFO][resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO][compiler:testCompile]
[INFO] No sources to compile
[INFO][surefire:test]
[INFO] No tests to run.
[INFO][jar:jar]
[INFO] Building jar: /home/ak/geoserver/community/hello/target/hello-1.0.jar
[INFO][jar:test-jar {execution: default}]
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: /home/ak/geoserver/community/hello/target/hello-1.0-tests.jar
[INFO][install:install]
[INFO] Installing /home/ak/geoserver/community/hello/target/hello-1.0.jar to /home/ak/.m2/repository/org/geoserver/hello/1.0/hello-1.0.jar
[INFO] Installing /home/ak/geoserver/community/hello/target/hello-1.0-tests.jar to /home/ak/.m2/repository/org/geoserver/hello/1.0/hello-1.0-tests.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6 seconds
[INFO] Finished at: Fri Sep 21 14:52:31 EDT 2007
[INFO] Final Memory: 27M/178M
[INFO] -----------------------------------------------------------------------

 

 f)发布

拷贝target/hello-1.0.jargeoserver安装目录:

如:D:\Program Files (x86)\GeoServer2.4.3\webapps\geoserver\WEB-INF\lib

重新启动geoserver即可。

g)访问

http://<host>/geoserver/ows?request=sayHello&service=hello&version=1.0.0

参数说明:

request:在HelloWorld中定义的方法

service:applicationContext.xml中定义的hello

hello:applicationContext.xml中定义的1.0.0

 

预览结果:

转载自:https://blog.csdn.net/sd_30_oldman/article/details/18555411

You may also like...