Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
符节科技
Jap
提交
196e5bc9
Jap
项目概览
符节科技
/
Jap
大约 1 年 前同步成功
通知
91
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Jap
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
196e5bc9
编写于
9月 19, 2021
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
📝
change: Delete useless files
上级
63831663
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
0 addition
and
1269 deletion
+0
-1269
jap-http-adapter/pom.xml
jap-http-adapter/pom.xml
+0
-28
jap-http-adapter/src/main/java/com/fujieid/jap/http/adapter/jakarta/JakartaCookieAdapter.java
...ujieid/jap/http/adapter/jakarta/JakartaCookieAdapter.java
+0
-41
jap-http-adapter/src/main/java/com/fujieid/jap/http/adapter/jakarta/JakartaRequestAdapter.java
...jieid/jap/http/adapter/jakarta/JakartaRequestAdapter.java
+0
-208
jap-http-adapter/src/main/java/com/fujieid/jap/http/adapter/jakarta/JakartaResponseAdapter.java
...ieid/jap/http/adapter/jakarta/JakartaResponseAdapter.java
+0
-163
jap-http-adapter/src/main/java/com/fujieid/jap/http/adapter/jakarta/JakartaSessionAdapter.java
...jieid/jap/http/adapter/jakarta/JakartaSessionAdapter.java
+0
-99
jap-http/pom.xml
jap-http/pom.xml
+0
-15
jap-http/src/main/java/com/fujieid/jap/http/JapHttpCookie.java
...ttp/src/main/java/com/fujieid/jap/http/JapHttpCookie.java
+0
-103
jap-http/src/main/java/com/fujieid/jap/http/JapHttpRequest.java
...tp/src/main/java/com/fujieid/jap/http/JapHttpRequest.java
+0
-148
jap-http/src/main/java/com/fujieid/jap/http/JapHttpResponse.java
...p/src/main/java/com/fujieid/jap/http/JapHttpResponse.java
+0
-146
jap-http/src/main/java/com/fujieid/jap/http/JapHttpSession.java
...tp/src/main/java/com/fujieid/jap/http/JapHttpSession.java
+0
-74
jap-http/src/main/java/com/fujieid/jap/http/RequestUtil.java
jap-http/src/main/java/com/fujieid/jap/http/RequestUtil.java
+0
-244
未找到文件。
jap-http-adapter/pom.xml
已删除
100644 → 0
浏览文件 @
63831663
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<groupId>
com.fujieid
</groupId>
<artifactId>
jap
</artifactId>
<version>
${revision}
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
jap-http-adapter
</artifactId>
<name>
jap-http-adapter
</name>
<description>
jap-http-adapter
</description>
<dependencies>
<dependency>
<groupId>
com.fujieid
</groupId>
<artifactId>
jap-http
</artifactId>
</dependency>
<!-- servlet -->
<dependency>
<groupId>
jakarta.servlet
</groupId>
<artifactId>
jakarta.servlet-api
</artifactId>
<scope>
provided
</scope>
</dependency>
</dependencies>
</project>
jap-http-adapter/src/main/java/com/fujieid/jap/http/adapter/jakarta/JakartaCookieAdapter.java
已删除
100644 → 0
浏览文件 @
63831663
/*
* Copyright (c) 2020-2040, 北京符节科技有限公司 (support@fujieid.com & https://www.fujieid.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.fujieid.jap.http.adapter.jakarta
;
import
com.fujieid.jap.http.JapHttpCookie
;
import
javax.servlet.http.Cookie
;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0.0
* @since 1.0.0
*/
public
class
JakartaCookieAdapter
extends
JapHttpCookie
{
public
JakartaCookieAdapter
(
Object
cookie
)
{
super
(
cookie
);
Cookie
jakartaCookie
=
(
Cookie
)
cookie
;
super
.
setDomain
(
jakartaCookie
.
getDomain
());
super
.
setPath
(
jakartaCookie
.
getDomain
());
super
.
setName
(
jakartaCookie
.
getDomain
());
super
.
setValue
(
jakartaCookie
.
getDomain
());
super
.
setMaxAge
(
jakartaCookie
.
getMaxAge
());
super
.
setSecure
(
jakartaCookie
.
getSecure
());
super
.
setHttpOnly
(
jakartaCookie
.
isHttpOnly
());
}
}
jap-http-adapter/src/main/java/com/fujieid/jap/http/adapter/jakarta/JakartaRequestAdapter.java
已删除
100644 → 0
浏览文件 @
63831663
/*
* Copyright (c) 2020-2040, 北京符节科技有限公司 (support@fujieid.com & https://www.fujieid.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.fujieid.jap.http.adapter.jakarta
;
import
com.fujieid.jap.http.JapHttpCookie
;
import
com.fujieid.jap.http.JapHttpRequest
;
import
com.fujieid.jap.http.JapHttpSession
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.util.Map
;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0.0
* @since 1.0.0
*/
public
class
JakartaRequestAdapter
implements
JapHttpRequest
{
private
final
HttpServletRequest
request
;
public
JakartaRequestAdapter
(
HttpServletRequest
request
)
{
this
.
request
=
request
;
}
/**
* Get the actual source object
*
* @return Object
*/
@Override
public
Object
getSource
()
{
return
request
;
}
/**
* Returns the value of a request parameter as a <code>String</code>, or <code>null</code> if the parameter does not
* exist.
*
* @param name a <code>String</code> specifying the name of the parameter
* @return a <code>String</code> representing the single value of the parameter
*/
@Override
public
String
getParameter
(
String
name
)
{
return
this
.
request
.
getParameter
(
name
);
}
/**
* Returns an array of <code>String</code> objects containing all of the values the given request parameter has, or
* <code>null</code> if the parameter does not exist.
*
* @param name a <code>String</code> containing the name of the parameter whose value is requested
* @return an array of <code>String</code> objects containing the parameter's values
*/
@Override
public
String
[]
getParameterValues
(
String
name
)
{
return
this
.
request
.
getParameterValues
(
name
);
}
/**
* an immutable java.util.Map containing parameter names as keys and parameter values as map values.
*
* @return Returns a java.util.Map of the parameters of this request.
*/
@Override
public
Map
<
String
,
String
[]>
getParameterMap
()
{
return
this
.
request
.
getParameterMap
();
}
/**
* Returns the value of the specified request header as a <code>String</code>. If the request did not include a
* header of the specified name, this method returns <code>null</code>.
*
* @param name a <code>String</code> specifying the header name
* @return a <code>String</code> containing the value of the requested header, or <code>null</code> if the request
* does not have a header of that name
*/
@Override
public
String
getHeader
(
String
name
)
{
return
this
.
request
.
getHeader
(
name
);
}
/**
* Returns the part of this request's URL from the protocol name up to the query string in the first line of the
* HTTP request.
*
* @return a <code>String</code> containing the part of the URL from the protocol name up to the query string
*/
@Override
public
String
getRequestUri
()
{
return
this
.
request
.
getRequestURI
();
}
/**
* Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port
* number, and server path, but it does not include query string parameters.
*
* @return a <code>StringBuffer</code> object containing the reconstructed URL
*/
@Override
public
StringBuffer
getRequestUrl
()
{
return
this
.
request
.
getRequestURL
();
}
/**
* Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.
*
* @return a <code>String</code> specifying the name of the method with which this request was made
*/
@Override
public
String
getMethod
()
{
return
this
.
request
.
getMethod
();
}
/**
* Returns the query string that is contained in the request URL after the path. This method returns
* <code>null</code> if the URL does not have a query string.
*
* @return a <code>String</code> containing the query string or <code>null</code> if the URL contains no query
* string.
*/
@Override
public
String
getQueryString
()
{
return
this
.
request
.
getQueryString
();
}
/**
* Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.
*
* @return a <code>String</code> containing the IP address of the client that sent the request
*/
@Override
public
String
getRemoteAddr
()
{
return
this
.
request
.
getRemoteAddr
();
}
/**
* Returns the part of this request's URL that calls the servlet. This path starts with a "/" character and includes
* either the servlet name or a path to the servlet, but does not include any extra path information or a query
* string.
*
* @return a <code>String</code> containing the name or path of the servlet being called, as specified in the
* request URL, decoded, or an empty string if the servlet used to process the request is matched using the
* "/*" pattern.
*/
@Override
public
String
getServletPath
()
{
return
this
.
request
.
getServletPath
();
}
/**
* Returns an array containing all of the <code>JapHttpCookie</code> objects the client sent with this request. This method
* returns <code>null</code> if no cookies were sent.
*
* @return an array of all the <code>JapHttpCookie</code> included with this request, or <code>null</code> if the request
* has no cookies
*/
@Override
public
JapHttpCookie
[]
getCookies
()
{
Cookie
[]
cookies
=
this
.
request
.
getCookies
();
if
(
null
==
cookies
||
cookies
.
length
==
0
)
{
return
null
;
}
int
cookieLen
=
cookies
.
length
;
JapHttpCookie
[]
japHttpCookies
=
new
JakartaCookieAdapter
[
cookieLen
];
for
(
int
i
=
0
;
i
<
cookieLen
;
i
++)
{
japHttpCookies
[
i
]
=
new
JakartaCookieAdapter
(
cookies
[
i
]);
}
return
japHttpCookies
;
}
/**
* Returns the current <code>HttpSession</code> associated with this request
*
* @return the <code>HttpSession</code> associated with this request
*/
@Override
public
JapHttpSession
getSession
()
{
return
new
JakartaSessionAdapter
(
this
.
request
.
getSession
());
}
/**
* Retrieves the body of the request as character data using a <code>BufferedReader</code>. The reader translates
* the character data according to the character encoding used on the body.
*
* @return a <code>BufferedReader</code> containing the body of the request
* @throws IOException if an input or output exception occurred
*/
@Override
public
BufferedReader
getReader
()
throws
IOException
{
return
this
.
request
.
getReader
();
}
}
jap-http-adapter/src/main/java/com/fujieid/jap/http/adapter/jakarta/JakartaResponseAdapter.java
已删除
100644 → 0
浏览文件 @
63831663
/*
* Copyright (c) 2020-2040, 北京符节科技有限公司 (support@fujieid.com & https://www.fujieid.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.fujieid.jap.http.adapter.jakarta
;
import
com.fujieid.jap.http.JapHttpResponse
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.io.PrintWriter
;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0.0
* @since 1.0.0
*/
public
class
JakartaResponseAdapter
implements
JapHttpResponse
{
private
final
HttpServletResponse
response
;
public
JakartaResponseAdapter
(
HttpServletResponse
response
)
{
this
.
response
=
response
;
}
/**
* Get the actual source object
*
* @return Object
*/
@Override
public
Object
getSource
()
{
return
this
.
response
;
}
/**
* Delete cookie
*
* @param name cookie name
* @return current response
*/
@Override
public
JapHttpResponse
delCookie
(
String
name
)
{
addCookie
(
null
);
return
this
;
}
/**
* Add cookie
*
* @param name name of the cookie.
* @param value value of this Cookie.
* @param path the path on the server to which the browser returns this cookie.
* @param domain domain name of this Cookie.
* @param expiry maximum age in seconds of this Cookie.
* @param secure send cookies only over a secure protocol, such as HTTPS or SSL.
* @param isHttpOnly http only.
* @return current response
*/
@Override
public
JapHttpResponse
addCookie
(
String
name
,
String
value
,
String
path
,
String
domain
,
int
expiry
,
boolean
secure
,
boolean
isHttpOnly
)
{
Cookie
cookie
=
new
Cookie
(
name
,
value
);
cookie
.
setPath
(
path
);
cookie
.
setDomain
(
domain
);
cookie
.
setMaxAge
(
expiry
);
cookie
.
setSecure
(
secure
);
cookie
.
setHttpOnly
(
isHttpOnly
);
this
.
response
.
addCookie
(
cookie
);
return
this
;
}
/**
* Set response status code
*
* @param status Response status code
* @return current response
*/
@Override
public
JapHttpResponse
setStatus
(
int
status
)
{
this
.
response
.
setStatus
(
status
);
return
this
;
}
/**
* Add response header
*
* @param name name of the response header
* @param value value of the response header
* @return current response
*/
@Override
public
JapHttpResponse
addHeader
(
String
name
,
String
value
)
{
this
.
response
.
addHeader
(
name
,
value
);
return
this
;
}
@Override
public
JapHttpResponse
setContentType
(
String
contentType
)
{
this
.
response
.
setContentType
(
contentType
);
return
this
;
}
@Override
public
JapHttpResponse
setContentLength
(
int
len
)
{
this
.
response
.
setContentLength
(
len
);
return
this
;
}
@Override
public
PrintWriter
getWriter
()
throws
IOException
{
return
this
.
response
.
getWriter
();
}
/**
* Returns the name of the character encoding (MIME charset) used for the body sent in this response
* <p>
* See RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt) for more information about character encoding and MIME.
*
* @return a <code>String</code> specifying the name of the character encoding, for example, <code>UTF-8</code>
*/
@Override
public
String
getCharacterEncoding
()
{
return
this
.
response
.
getCharacterEncoding
();
}
/**
* Returns a {@link OutputStream} suitable for writing binary data in the response.
*
* @return a {@link OutputStream} for writing binary data
* @throws IOException if an input or output exception occurred
*/
@Override
public
OutputStream
getOutputStream
()
throws
IOException
{
return
this
.
response
.
getOutputStream
();
}
/**
* Redirect to url
*
* @param url Redirect url
*/
@Override
public
void
redirect
(
String
url
)
{
try
{
this
.
response
.
sendRedirect
(
url
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
jap-http-adapter/src/main/java/com/fujieid/jap/http/adapter/jakarta/JakartaSessionAdapter.java
已删除
100644 → 0
浏览文件 @
63831663
/*
* Copyright (c) 2020-2040, 北京符节科技有限公司 (support@fujieid.com & https://www.fujieid.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.fujieid.jap.http.adapter.jakarta
;
import
com.fujieid.jap.http.JapHttpSession
;
import
javax.servlet.http.HttpSession
;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0.0
* @since 1.0.0
*/
public
class
JakartaSessionAdapter
implements
JapHttpSession
{
private
final
HttpSession
session
;
public
JakartaSessionAdapter
(
HttpSession
session
)
{
this
.
session
=
session
;
}
/**
* Returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.
*
* @return a <code>long</code> specifying when this session was created, expressed in milliseconds since 1/1/1970
* GMT
*/
@Override
public
long
getCreationTime
()
{
return
this
.
session
.
getCreationTime
();
}
/**
* Returns a string containing the unique identifier assigned to this session. The identifier is assigned by the
* servlet container and is implementation dependent.
*
* @return a string specifying the identifier assigned to this session
*/
@Override
public
String
getId
()
{
return
this
.
session
.
getId
();
}
/**
* Returns the object bound with the specified name in this session, or <code>null</code> if no object is bound
* under the name.
*
* @param name a string specifying the name of the object
* @return the object with the specified name
*/
@Override
public
Object
getAttribute
(
String
name
)
{
return
this
.
session
.
getAttribute
(
name
);
}
/**
* Binds an object to this session, using the name specified. If an object of the same name is already bound to the
* session, the object is replaced.
*
* @param name the name to which the object is bound; cannot be null
* @param value the object to be bound; cannot be null
*/
@Override
public
void
setAttribute
(
String
name
,
Object
value
)
{
this
.
session
.
setAttribute
(
name
,
value
);
}
/**
* Removes the object bound with the specified name from this session. If the session does not have an object bound
* with the specified name, this method does nothing.
*
* @param name the name of the object to remove from this session
*/
@Override
public
void
removeAttribute
(
String
name
)
{
this
.
session
.
removeAttribute
(
name
);
}
/**
* Invalidates this session then unbinds any objects bound to it.
*/
@Override
public
void
invalidate
()
{
this
.
session
.
invalidate
();
}
}
jap-http/pom.xml
已删除
100644 → 0
浏览文件 @
63831663
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<groupId>
com.fujieid
</groupId>
<artifactId>
jap
</artifactId>
<version>
${revision}
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
jap-http
</artifactId>
<name>
jap-http
</name>
<description>
jap-http
</description>
</project>
jap-http/src/main/java/com/fujieid/jap/http/JapHttpCookie.java
已删除
100644 → 0
浏览文件 @
63831663
/*
* Copyright (c) 2020-2040, 北京符节科技有限公司 (support@fujieid.com & https://www.fujieid.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.fujieid.jap.http
;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0.0
* @since 1.0.5
*/
public
class
JapHttpCookie
{
private
String
name
;
private
String
value
;
private
String
domain
;
private
String
path
=
"/"
;
private
int
maxAge
=
-
1
;
private
boolean
secure
;
private
boolean
httpOnly
;
public
JapHttpCookie
(
Object
cookie
)
{
}
public
JapHttpCookie
(
String
name
,
String
value
)
{
this
.
name
=
name
;
this
.
value
=
value
;
}
public
String
getName
()
{
return
name
;
}
public
JapHttpCookie
setName
(
String
name
)
{
this
.
name
=
name
;
return
this
;
}
public
String
getValue
()
{
return
value
;
}
public
JapHttpCookie
setValue
(
String
value
)
{
this
.
value
=
value
;
return
this
;
}
public
String
getDomain
()
{
return
domain
;
}
public
JapHttpCookie
setDomain
(
String
domain
)
{
this
.
domain
=
domain
;
return
this
;
}
public
String
getPath
()
{
return
path
;
}
public
JapHttpCookie
setPath
(
String
path
)
{
this
.
path
=
path
;
return
this
;
}
public
int
getMaxAge
()
{
return
maxAge
;
}
public
JapHttpCookie
setMaxAge
(
int
maxAge
)
{
this
.
maxAge
=
maxAge
;
return
this
;
}
public
boolean
isSecure
()
{
return
secure
;
}
public
JapHttpCookie
setSecure
(
boolean
secure
)
{
this
.
secure
=
secure
;
return
this
;
}
public
boolean
isHttpOnly
()
{
return
httpOnly
;
}
public
JapHttpCookie
setHttpOnly
(
boolean
httpOnly
)
{
this
.
httpOnly
=
httpOnly
;
return
this
;
}
}
jap-http/src/main/java/com/fujieid/jap/http/JapHttpRequest.java
已删除
100644 → 0
浏览文件 @
63831663
/*
* Copyright (c) 2020-2040, 北京符节科技有限公司 (support@fujieid.com & https://www.fujieid.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.fujieid.jap.http
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.util.Map
;
/**
* Define an interface to adapt to request objects of different frameworks,
* such as: <code>javax.servlet.http.HttpServletRequest</code> or <code>com.blade.mvc.http.HttpRequest</code>
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0.0
* @since 1.0.5
*/
public
interface
JapHttpRequest
{
/**
* Get the actual source object
*
* @return Object
*/
Object
getSource
();
/**
* Returns the value of a request parameter as a <code>String</code>, or <code>null</code> if the parameter does not
* exist.
*
* @param name a <code>String</code> specifying the name of the parameter
* @return a <code>String</code> representing the single value of the parameter
*/
String
getParameter
(
String
name
);
/**
* Returns an array of <code>String</code> objects containing all of the values the given request parameter has, or
* <code>null</code> if the parameter does not exist.
*
* @param name a <code>String</code> containing the name of the parameter whose value is requested
* @return an array of <code>String</code> objects containing the parameter's values
*/
String
[]
getParameterValues
(
String
name
);
/**
* an immutable java.util.Map containing parameter names as keys and parameter values as map values.
*
* @return Returns a java.util.Map of the parameters of this request.
*/
Map
<
String
,
String
[]>
getParameterMap
();
/**
* Returns the value of the specified request header as a <code>String</code>. If the request did not include a
* header of the specified name, this method returns <code>null</code>.
*
* @param name a <code>String</code> specifying the header name
* @return a <code>String</code> containing the value of the requested header, or <code>null</code> if the request
* does not have a header of that name
*/
String
getHeader
(
String
name
);
/**
* Returns the part of this request's URL from the protocol name up to the query string in the first line of the
* HTTP request.
*
* @return a <code>String</code> containing the part of the URL from the protocol name up to the query string
*/
String
getRequestUri
();
/**
* Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port
* number, and server path, but it does not include query string parameters.
*
* @return a <code>StringBuffer</code> object containing the reconstructed URL
*/
StringBuffer
getRequestUrl
();
/**
* Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.
*
* @return a <code>String</code> specifying the name of the method with which this request was made
*/
String
getMethod
();
/**
* Returns the query string that is contained in the request URL after the path. This method returns
* <code>null</code> if the URL does not have a query string.
*
* @return a <code>String</code> containing the query string or <code>null</code> if the URL contains no query
* string.
*/
String
getQueryString
();
/**
* Returns an array containing all of the <code>JapHttpCookie</code> objects the client sent with this request. This method
* returns <code>null</code> if no cookies were sent.
*
* @return an array of all the <code>JapHttpCookie</code> included with this request, or <code>null</code> if the request
* has no cookies
*/
JapHttpCookie
[]
getCookies
();
/**
* Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.
*
* @return a <code>String</code> containing the IP address of the client that sent the request
*/
String
getRemoteAddr
();
/**
* Returns the part of this request's URL that calls the servlet. This path starts with a "/" character and includes
* either the servlet name or a path to the servlet, but does not include any extra path information or a query
* string.
*
* @return a <code>String</code> containing the name or path of the servlet being called, as specified in the
* request URL, decoded, or an empty string if the servlet used to process the request is matched using the
* "/*" pattern.
*/
String
getServletPath
();
/**
* Returns the current <code>HttpSession</code> associated with this request
*
* @return the <code>HttpSession</code> associated with this request
*/
JapHttpSession
getSession
();
/**
* Retrieves the body of the request as character data using a <code>BufferedReader</code>. The reader translates
* the character data according to the character encoding used on the body.
*
* @return a <code>BufferedReader</code> containing the body of the request
* @throws IOException if an input or output exception occurred
*/
BufferedReader
getReader
()
throws
IOException
;
}
jap-http/src/main/java/com/fujieid/jap/http/JapHttpResponse.java
已删除
100644 → 0
浏览文件 @
63831663
/*
* Copyright (c) 2020-2040, 北京符节科技有限公司 (support@fujieid.com & https://www.fujieid.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.fujieid.jap.http
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.io.PrintWriter
;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0.0
* @since 1.0.5
*/
public
interface
JapHttpResponse
{
/**
* Get the actual source object
*
* @return Object
*/
Object
getSource
();
/**
* Delete cookie
*
* @param name cookie name
* @return current response
*/
JapHttpResponse
delCookie
(
String
name
);
/**
* Add cookie
*
* @param name name of the cookie.
* @param value value of this Cookie.
* @param path the path on the server to which the browser returns this cookie.
* @param domain domain name of this Cookie.
* @param expiry maximum age in seconds of this Cookie.
* @param secure send cookies only over a secure protocol, such as HTTPS or SSL.
* @param isHttpOnly http only.
* @return current response
*/
JapHttpResponse
addCookie
(
String
name
,
String
value
,
String
path
,
String
domain
,
int
expiry
,
boolean
secure
,
boolean
isHttpOnly
);
/**
* Add cookie
*
* @param cookie JapHttpCookie
* @return current response
*/
default
JapHttpResponse
addCookie
(
JapHttpCookie
cookie
)
{
if
(
null
==
cookie
)
{
return
this
.
addCookie
(
null
,
null
,
null
,
null
,
0
,
false
,
false
);
}
return
this
.
addCookie
(
cookie
.
getName
(),
cookie
.
getValue
(),
cookie
.
getPath
(),
cookie
.
getDomain
(),
cookie
.
getMaxAge
(),
cookie
.
isSecure
(),
cookie
.
isHttpOnly
()
);
}
/**
* Set response status code
*
* @param status Response status code
* @return current response
*/
JapHttpResponse
setStatus
(
int
status
);
/**
* Add response header
*
* @param name name of the response header
* @param value value of the response header
* @return current response
*/
JapHttpResponse
addHeader
(
String
name
,
String
value
);
/**
* Sets the content type of the response being sent to the client, if the response has not been committed yet. The
* given content type may include a character encoding specification, for example,
* <code>text/html;charset=UTF-8</code>. The response's character encoding is only set from the given content type
* if this method is called before <code>getWriter</code> is called.
*
* @param contentType a <code>String</code> specifying the MIME type of the content
* @return current response
*/
JapHttpResponse
setContentType
(
String
contentType
);
/**
* Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length
* header.
*
* @param len an integer specifying the length of the content being returned to the client; sets the Content-Length
* header
* @return current response
*/
JapHttpResponse
setContentLength
(
int
len
);
/**
* Returns a <code>PrintWriter</code> object that can send character text to the client. The
* <code>PrintWriter</code> uses the character encoding returned by {@link #getCharacterEncoding}. If the response's
* character encoding has not been specified as described in <code>getCharacterEncoding</code> (i.e., the method
* just returns the default value <code>ISO-8859-1</code>), <code>getWriter</code> updates it to
* <code>ISO-8859-1</code>.
*
* @return a <code>PrintWriter</code> object that can return character data to the client
* @throws IOException if an input or output exception occurred
*/
PrintWriter
getWriter
()
throws
IOException
;
/**
* Returns the name of the character encoding (MIME charset) used for the body sent in this response
* <p>
* See RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt) for more information about character encoding and MIME.
*
* @return a <code>String</code> specifying the name of the character encoding, for example, <code>UTF-8</code>
*/
String
getCharacterEncoding
();
/**
* Returns a {@link OutputStream} suitable for writing binary data in the response.
*
* @return a {@link OutputStream} for writing binary data
* @throws IOException if an input or output exception occurred
*/
OutputStream
getOutputStream
()
throws
IOException
;
/**
* Redirect to url
*
* @param url Redirect url
*/
void
redirect
(
String
url
);
}
jap-http/src/main/java/com/fujieid/jap/http/JapHttpSession.java
已删除
100644 → 0
浏览文件 @
63831663
/*
* Copyright (c) 2020-2040, 北京符节科技有限公司 (support@fujieid.com & https://www.fujieid.com).
* <p>
* Licensed under the GNU LESSER GENERAL LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.fujieid.jap.http
;
/**
* Define an interface to adapt to session objects of different frameworks,
* such as: <code>javax.servlet.http.HttpSession</code> or <code>com.blade.mvc.http.Session</code>
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0.0
* @since 1.0.5
*/
public
interface
JapHttpSession
{
/**
* Returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.
*
* @return a <code>long</code> specifying when this session was created, expressed in milliseconds since 1/1/1970
* GMT
*/
long
getCreationTime
();
/**
* Returns a string containing the unique identifier assigned to this session. The identifier is assigned by the
* servlet container and is implementation dependent.
*
* @return a string specifying the identifier assigned to this session
*/
String
getId
();
/**
* Returns the object bound with the specified name in this session, or <code>null</code> if no object is bound
* under the name.
*
* @param name a string specifying the name of the object
* @return the object with the specified name
*/
Object
getAttribute
(
String
name
);
/**
* Binds an object to this session, using the name specified. If an object of the same name is already bound to the
* session, the object is replaced.
*
* @param name the name to which the object is bound; cannot be null
* @param value the object to be bound; cannot be null
*/
void
setAttribute
(
String
name
,
Object
value
);
/**
* Removes the object bound with the specified name from this session. If the session does not have an object bound
* with the specified name, this method does nothing.
*
* @param name the name of the object to remove from this session
*/
void
removeAttribute
(
String
name
);
/**
* Invalidates this session then unbinds any objects bound to it.
*/
void
invalidate
();
}
jap-http/src/main/java/com/fujieid/jap/http/RequestUtil.java
已删除
100644 → 0
浏览文件 @
63831663
/*
* Copyright (c) 2020-2040, 北京符节科技有限公司 (support@fujieid.com & https://www.fujieid.com).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.fujieid.jap.http
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* http servlet request util
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0.0
* @since 1.0.1
*/
public
class
RequestUtil
{
/**
* Get the url parameter value of the request through {@code request.getParameter(paramName)}
*
* @param paramName parameter name
* @param request current HTTP request
* @return string
*/
public
static
String
getParam
(
String
paramName
,
JapHttpRequest
request
)
{
if
(
null
==
request
)
{
return
null
;
}
return
request
.
getParameter
(
paramName
);
}
/**
* Get request header
*
* @param headerName request header name
* @param request current HTTP request
* @return string
*/
public
static
String
getHeader
(
String
headerName
,
JapHttpRequest
request
)
{
if
(
null
==
request
)
{
return
""
;
}
return
request
.
getHeader
(
headerName
);
}
/**
* Get the referer of the current HTTP request
*
* @param request current HTTP request
* @return string
*/
public
static
String
getReferer
(
JapHttpRequest
request
)
{
return
getHeader
(
"Referer"
,
request
);
}
/**
* Get subdomain name
*
* @param request current HTTP request
* @return string
*/
public
static
String
getFullDomainName
(
JapHttpRequest
request
)
{
StringBuffer
url
=
request
.
getRequestUrl
();
return
url
.
delete
(
url
.
length
()
-
request
.
getRequestUri
().
length
(),
url
.
length
()).
toString
();
}
/**
* Get the User-Agent of the current HTTP request
*
* @param request current HTTP request
* @return string
*/
public
static
String
getUa
(
JapHttpRequest
request
)
{
return
getHeader
(
"User-Agent"
,
request
);
}
/**
* Get the IP of the current HTTP request
*
* @param request current HTTP request
* @return string
*/
public
static
String
getIp
(
JapHttpRequest
request
)
{
if
(
null
==
request
)
{
return
""
;
}
String
[]
headers
=
{
"X-Forwarded-For"
,
"X-Real-IP"
,
"Proxy-Client-IP"
,
"WL-Proxy-Client-IP"
,
"HTTP_CLIENT_IP"
,
"HTTP_X_FORWARDED_FOR"
};
String
ip
;
for
(
String
header
:
headers
)
{
ip
=
request
.
getHeader
(
header
);
if
(
isValidIp
(
ip
))
{
return
getMultistageReverseProxyIp
(
ip
);
}
}
ip
=
request
.
getRemoteAddr
();
return
getMultistageReverseProxyIp
(
ip
);
}
/**
* Obtain the first non-unknown ip address from the multi-level reverse proxy
*
* @param ip IP
* @return The first non-unknown ip address
*/
private
static
String
getMultistageReverseProxyIp
(
String
ip
)
{
if
(
ip
!=
null
&&
ip
.
indexOf
(
","
)
>
0
)
{
final
String
[]
ips
=
ip
.
trim
().
split
(
","
);
for
(
String
subIp
:
ips
)
{
if
(
isValidIp
(
subIp
))
{
ip
=
subIp
;
break
;
}
}
}
return
ip
;
}
/**
* Verify ip legitimacy
*
* @param ip ip
* @return boolean
*/
private
static
boolean
isValidIp
(
String
ip
)
{
return
isNotEmpty
(
ip
)
&&
!
"unknown"
.
equalsIgnoreCase
(
ip
);
}
/**
* Get the value of the cookie
*
* @param request current HTTP request
* @param name cookie name
* @return String
*/
public
static
String
getCookieVal
(
JapHttpRequest
request
,
String
name
)
{
JapHttpCookie
cookie
=
getCookie
(
request
,
name
);
return
cookie
!=
null
?
cookie
.
getValue
()
:
null
;
}
private
static
boolean
isNotEmpty
(
String
s
)
{
return
s
!=
null
&&
s
.
trim
().
length
()
!=
0
;
}
/**
* Get the request url
*
* @param encode Whether to encode url
* @param request current HTTP request
* @return string
*/
public
static
String
getRequestUrl
(
boolean
encode
,
JapHttpRequest
request
)
{
if
(
null
==
request
)
{
return
""
;
}
String
currentUrl
=
request
.
getRequestUrl
().
toString
();
String
queryString
=
request
.
getQueryString
();
if
(
isNotEmpty
(
queryString
))
{
currentUrl
=
currentUrl
+
"?"
+
queryString
;
}
if
(
encode
)
{
String
result
=
""
;
try
{
result
=
URLEncoder
.
encode
(
currentUrl
,
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
e
)
{
//ignore
}
return
result
;
}
return
currentUrl
;
}
/**
* Get cookie
*
* @param request current HTTP request
* @param name cookie name
* @return Cookie
*/
public
static
JapHttpCookie
getCookie
(
JapHttpRequest
request
,
String
name
)
{
JapHttpCookie
[]
cookies
=
request
.
getCookies
();
if
(
cookies
!=
null
)
{
for
(
JapHttpCookie
cookie
:
cookies
)
{
if
(
name
.
equals
(
cookie
.
getName
()))
{
return
cookie
;
}
}
}
return
null
;
}
/**
* Get all the cookies, and use the cookie name as the key to form a map
*
* @param request current HTTP request
* @return Map
*/
public
static
Map
<
String
,
JapHttpCookie
>
getCookieMap
(
JapHttpRequest
request
)
{
final
JapHttpCookie
[]
cookies
=
request
.
getCookies
();
if
(
null
==
cookies
||
cookies
.
length
==
0
)
{
return
new
HashMap
<>(
0
);
}
return
Arrays
.
stream
(
cookies
).
collect
(
Collectors
.
toMap
(
JapHttpCookie:
:
getName
,
v
->
v
,
(
k1
,
k2
)
->
k1
));
}
/**
* Set cookie
*
* @param response current HTTP response
* @param name cookie name
* @param value cookie value
* @param maxAge maxAge
* @param path path
* @param domain domain
*/
public
static
void
setCookie
(
JapHttpResponse
response
,
String
name
,
String
value
,
int
maxAge
,
String
path
,
String
domain
)
{
JapHttpCookie
cookie
=
new
JapHttpCookie
(
name
,
value
);
cookie
.
setPath
(
path
);
if
(
null
!=
domain
)
{
cookie
.
setDomain
(
domain
);
}
cookie
.
setMaxAge
(
maxAge
);
cookie
.
setHttpOnly
(
false
);
response
.
addCookie
(
cookie
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录