geoserver的rest服务介绍,搭建java程序
来源:互联网 发布:网络教育的在职研究生 编辑:程序博客网 时间:2024/05/17 21:48
当新建一个项目的时候需要新建一个 pom.xml到meven项目中
<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.0 http://maven.apache.org/maven-v4_0_0.xsd "> <modelVersion>4.0.0</modelVersion> <groupId>org.geoserver</groupId> <artifactId>hello_rest</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>hello_rest</name> <dependencies> <dependency> <groupId>org.geoserver</groupId> <artifactId>gs-rest</artifactId> <version>2.8-SNAPSHOT</version> <!-- change this to the proper GeoServer version --> </dependency> <dependency> <groupId>org.geoserver</groupId> <artifactId>gs-main</artifactId> <version>2.8-SNAPSHOT</version> <!-- change this to the proper GeoServer version --> <classifier>tests</classifier> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>com.mockrunner</groupId> <artifactId>mockrunner</artifactId> <version>0.3.6</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build></project>
建立项目的时候需要继承一个类,以及实现其中的方法
The class org.geoserver.rest.AbstractResource is a convenient base class available when creating new resources. Create a new class called HelloResource in the package org.geoserver.hellorest, which extends from AbstractResource.
package org.geoserver.hellorest;import java.util.List;import org.geoserver.rest.AbstractResource;import org.geoserver.rest.format.DataFormat;import org.restlet.data.Request;import org.restlet.data.Response;public class HelloResource extends AbstractResource { @Override protected List<DataFormat> createSupportedFormats(Request request, Response response) { return null; }}
The first method to implement is createSupportedFormats(). The purpose of this method is to create mapping from an extension, to a particular format. For now the goal will be to return the text “Hello World” when a ”.txt” extension is requested by the client.
import java.util.ArrayList;import org.geoserver.rest.format.StringFormat;...@Overrideprotected List<DataFormat> createSupportedFormats(Request request, Response response) { List<DataFormat> formats = new ArrayList(); formats.add(new StringFormat( MediaType.TEXT_PLAIN )); return formats;}
The next step is to override the handleGet() method. This method is called when a GET request is made for the resource.
@Overridepublic void handleGet() { //get the appropriate format DataFormat format = getFormatGet(); //transform the string "Hello World" to the appropriate response getResponse().setEntity(format.toRepresentation("Hello World"));}
The above makes use of the getFormatGet() method, whose purpose is to determine the extension being requested by the client, and look up the appropriate format for it. In this case when the client requests the ”.txt” extension, the StringFormat setup in the previous step will be found.
创建一个application context
The next step is to create an application context that tells GeoServer about the resource created in the previous section. Create the directory src/main/resources under the root of the hello_rest module:
[hello_rest]% mkdir src/main/resources
Add the following applicationContext.xml file to the src/main/resources directory under the root of thehello_rest module.
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="hello" class="org.geoserver.hellorest.HelloResource"/> <bean id="helloMapping" class="org.geoserver.rest.RESTMapping"> <property name="routes"> <map> <entry> <key><value>/hello.{format}</value></key> <value>hello</value> </entry> </map> </property> </bean></beans>
There are two things to note above. The first is the hello bean which is an instance of the HelloResourceclass created in the previous section. The second is the helloMapping bean, which defines a template for the uri in which the resource will be accessed. The above mapping specifies that the resource will be located at /rest/hello.{format} where format is the representation being requested by the client. As implemented hello.txt is the only supported representation
- geoserver的rest服务介绍,搭建java程序
- java搭建rest服务
- myeclipse 搭建最简单的Rest 服务
- jersey搭建rest服务
- REST Web 服务介绍
- REST Web 服务介绍
- REST服务介绍
- REST服务介绍
- REST服务介绍
- REST服务介绍
- 使用jersey(2.5.1)搭建java REST服务
- Jersey搭建Rest web服务
- Jersey框架搭建Rest服务
- jersey 搭建rest风格服务
- 部署在wcf rest服务上的wcf rest服务调用页面程序
- Rest web服务详细介绍
- 用Spring MVC搭建REST风格的服务
- 服务类组件RSS、XML-RPC、REST的介绍
- geoserver笔记
- geoserver 开发1
- geoserver 开发2
- geoserver 源码介绍
- geoserver 文件系统
- geoserver的rest服务介绍,搭建java程序
- geoserver 问题解决
- geoserver 的缓存技术
- linux的命令操作
- restful发布服务
- Ambari 安装agent失败解决
- geoserver 通过代码实现发布地图服务
- mapping 映射
- 三维dem