2 Star 1 Fork 2

符节开源 / jap-http

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

jap-http

介绍

抽象 javax.servlet.http 包下的类,包括:request、response、cookie、session,用来适配第三方框架,比如:blade、jakarta等

为什么要开发这个东西?

在开发 jap 的时候,碰到一个问题:在 blade 框架中集成 jap 时,因为 blade 中是自实现的一套 web 组件,没有 HttpServletRequest 等相关接口,那么也就意味着在 blade 中,无法使用 jap。

这叔能忍,婶不能忍。jap 的设计理念中重要的一条就是:复杂的东西接口化,就类似 simple-http 的使用,开发者想使用何种工具/框架,我们不干预。

因此,对于 jakarta.servlet 依赖中的 javax.servlet.http 包下的内容,全部重构,提取出一套标准的接口,这样的话,就可以适配任何框架,nice~!

快速开始

  1. 引入依赖
<dependency>
    <groupId>com.fujieid.jap.http</groupId>
    <artifactId>jap-http</artifactId>
    <version>1.0.0</version>
</dependency>
  1. 引入需要适配的第三方框架,此处以 jakarta.servlet 为例
<dependency>
    <groupId>jakarta.servlet</groupId>
    <artifactId>jakarta.servlet-api</artifactId>
    <version>4.0.4</version>
</dependency>
  1. 实现 jap-http 的接口,以 request 为例
public class JakartaRequestAdapter implements JapHttpRequest {

    private final HttpServletRequest request;

    public JakartaRequestAdapter(HttpServletRequest request) {
        this.request = request;
    }

    @Override
    public String getParameter(String name) {
        return this.request.getParameter(name);
    }
    // ...
}
  1. 在需要适用 HttpServletRequest 的地方,替换为
new JakartaRequestAdapter(HttpServletRequest);

支持的所有适配接口/类

// 适配 Request
JapHttpRequest
// 适配 Cookie
JapHttpCookie
// 适配 Session
JapHttpSession
// 适配 Response
JapHttpResponse
MIT License Copyright (c) 2021 yadong.zhang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

抽象 javax.servlet.http 包下的类,包括:request、response、cookie、session,用来适配第三方框架,比如:blade、jakarta等 展开 收起
Java
MIT
取消

发行版 (1)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/fujieid/jap-http.git
git@gitee.com:fujieid/jap-http.git
fujieid
jap-http
jap-http
master

搜索帮助

14c37bed 8189591 565d56ea 8189591