官方文档:REST配置API引用 — GeoServer 2.24.x User Manual
本系列文章的准备工作,前置。
我使用 hutool 工具包,主要使用其http包,我进行简单封装。
<!-- 添加 hutool 依赖 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.18</version>
</dependency>
我创建自己的http类,对hutool工具进行包装,方便自己调用。
创建 IcehengHttp
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
public class IcehengHttp {
public static final int CODE_200 = 200; //(成功) - 服务器成功返回网页。
public static final int CODE_201 = 201; //(已创建) - 请求成功并且服务器创建了新的资源。
public static final int CODE_400 = 400; //(错误请求)- 服务器不理解请求的语法。
public static final int CODE_404 = 404; //(未找到)- 服务器找不到请求的网页。
public static HttpResponse get(String url, String user, String password){
return HttpRequest
.get(url)
.basicAuth(user, password)
.execute();
}
public static HttpResponse postXML(String url, String user, String password, String body){
return HttpRequest
.post(url)
.body(body)
.header("Content-Type", "application/xml")
.basicAuth(user, password)
.execute();
}
public static HttpResponse putXML(String url, String user, String password, String body){
return HttpRequest
.put(url)
.body(body)
.header("Content-Type", "application/xml")
.basicAuth(user, password)
.execute();
}
public static HttpResponse delete(String url, String user, String password){
return HttpRequest
.delete(url)
.basicAuth(user, password)
.execute();
}
}
创建 GeoserverRest ,准备好geoserver相关配置
public class GeoserverRest {
private final String restUrl; //geoserver服务地址
private final String restUser; //geoserver 账户名
private final String restPassword; //geoserver 登陆密码
/**
* 构造函数
* 初始化服务器地址、用户名、登陆密码
*/
public GeoserverRest(String url, String user, String password){
restUrl = url;
restUser = user;
restPassword = password;
//TODO:测试连接
}
}
5944

被折叠的 条评论
为什么被折叠?



