[GeoServer] Java 调用 REST API(0)准备工作

官方文档: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:测试连接
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值