mirror of
https://gitee.com/egzosn/pay-java-parent.git
synced 2026-05-31 12:59:35 +08:00
补全注释
This commit is contained in:
@@ -26,8 +26,10 @@ import static com.egzosn.pay.common.http.UriVariables.getMapToParameters;
|
||||
/**
|
||||
* 一个HTTP请求的客户端
|
||||
* @author: egan
|
||||
* @email egzosn@gmail.com
|
||||
* @date 2017/3/4 17:56
|
||||
* <pre>
|
||||
* email egzosn@gmail.com
|
||||
* date 2017/3/4 17:56
|
||||
* </pre>
|
||||
*/
|
||||
public class ClientHttpRequest<T> extends HttpEntityEnclosingRequestBase implements org.apache.http.client.ResponseHandler<T>{
|
||||
//http请求
|
||||
@@ -83,7 +85,7 @@ public class ClientHttpRequest<T> extends HttpEntityEnclosingRequestBase impleme
|
||||
/**
|
||||
* 设置代理
|
||||
* @param httpProxy http代理配置信息
|
||||
* @return
|
||||
* @return 当前HTTP请求的客户端
|
||||
*/
|
||||
public ClientHttpRequest setProxy(HttpHost httpProxy){
|
||||
if (httpProxy != null) {
|
||||
@@ -98,7 +100,7 @@ public class ClientHttpRequest<T> extends HttpEntityEnclosingRequestBase impleme
|
||||
* 设置请求参数
|
||||
*
|
||||
* @param request 请求参数
|
||||
* @return
|
||||
* @return 当前HTTP请求的客户端
|
||||
*/
|
||||
public ClientHttpRequest setParameters(Object request) {
|
||||
if (null == request){
|
||||
|
||||
@@ -4,8 +4,10 @@ package com.egzosn.pay.common.http;
|
||||
/**
|
||||
* HTTP 配置
|
||||
* @author: egan
|
||||
* @email egzosn@gmail.com
|
||||
* @date 2017/3/3 20:48
|
||||
* <pre>
|
||||
* email egzosn@gmail.com
|
||||
* date 2017/3/3 20:48
|
||||
* </pre>
|
||||
*/
|
||||
public class HttpConfigStorage {
|
||||
//http代理地址
|
||||
@@ -20,7 +22,7 @@ public class HttpConfigStorage {
|
||||
|
||||
/**
|
||||
* http代理地址
|
||||
* @return
|
||||
* @return http代理地址
|
||||
*/
|
||||
public String getHttpProxyHost() {
|
||||
return httpProxyHost;
|
||||
@@ -33,7 +35,7 @@ public class HttpConfigStorage {
|
||||
|
||||
/**
|
||||
* 代理端口
|
||||
* @return
|
||||
* @return 代理端口
|
||||
*/
|
||||
public int getHttpProxyPort() {
|
||||
return httpProxyPort;
|
||||
@@ -44,7 +46,7 @@ public class HttpConfigStorage {
|
||||
}
|
||||
/**
|
||||
* 代理用户名
|
||||
* @return
|
||||
* @return 代理用户名
|
||||
*/
|
||||
public String getHttpProxyUsername() {
|
||||
return httpProxyUsername;
|
||||
@@ -56,7 +58,7 @@ public class HttpConfigStorage {
|
||||
|
||||
/**
|
||||
* 代理密码
|
||||
* @return
|
||||
* @return 代理密码
|
||||
*/
|
||||
public String getHttpProxyPassword() {
|
||||
return httpProxyPassword;
|
||||
|
||||
@@ -18,8 +18,10 @@ import java.util.Map;
|
||||
/**
|
||||
* http请求工具
|
||||
* @author: egan
|
||||
* @email egzosn@gmail.com
|
||||
* @date 2017/3/3 21:33
|
||||
* <pre>
|
||||
* email egzosn@gmail.com
|
||||
* date 2017/3/3 21:33
|
||||
* </pre>
|
||||
*/
|
||||
public class HttpRequestTemplate {
|
||||
|
||||
@@ -43,6 +45,11 @@ public class HttpRequestTemplate {
|
||||
setHttpConfigStorage(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置HTTP请求的配置
|
||||
* @param configStorage 请求配置
|
||||
* @return 当前HTTP请求的客户端模板
|
||||
*/
|
||||
public HttpRequestTemplate setHttpConfigStorage(HttpConfigStorage configStorage){
|
||||
|
||||
if (null == configStorage){
|
||||
@@ -79,11 +86,11 @@ public class HttpRequestTemplate {
|
||||
*
|
||||
* post
|
||||
* @param uri 请求地址
|
||||
* @param request
|
||||
* @param request 请求参数
|
||||
* @param responseType 为响应类(需要自己依据响应格式来确定)
|
||||
* @param <T>
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @param uriVariables 地址通配符对应的值
|
||||
* @param <T> 响应类型
|
||||
* @return 类型对象
|
||||
*/
|
||||
public <T> T postForObject(String uri, Object request, Class<T> responseType, Object... uriVariables){
|
||||
return doExecute(URI.create(UriVariables.getUri(uri, uriVariables)), request, responseType, MethodType.POST);
|
||||
@@ -105,10 +112,10 @@ public class HttpRequestTemplate {
|
||||
* @param responseType 响应类型
|
||||
* @param uriVariables 用于匹配表达式
|
||||
* @param <T> 响应类型
|
||||
* @return
|
||||
* @return 类型对象
|
||||
*
|
||||
* <code>
|
||||
* getForObject("http://egan.in/pay/{id}/f/{type}", String.class, "1", "APP")
|
||||
* getForObject("http://egan.in/pay/{id}/f/{type}", String.class, "1", "APP")
|
||||
* </code>
|
||||
*/
|
||||
public <T> T getForObject(String uri, Class<T> responseType, Object... uriVariables){
|
||||
@@ -123,12 +130,12 @@ public class HttpRequestTemplate {
|
||||
* @param responseType 响应类型
|
||||
* @param uriVariables 用于匹配表达式
|
||||
* @param <T> 响应类型
|
||||
* @return
|
||||
* @return 类型对象
|
||||
* <code>
|
||||
* Map<String, String> uriVariables = new HashMap<String, String>();
|
||||
* uriVariables.put("id", "1");
|
||||
* uriVariables.put("type", "APP");
|
||||
* getForObject("http://egan.in/pay/{id}/f/{type}", String.class, uriVariables)
|
||||
* Map<String, String> uriVariables = new HashMap<String, String>();
|
||||
* uriVariables.put("id", "1");
|
||||
* uriVariables.put("type", "APP");
|
||||
* getForObject("http://egan.in/pay/{id}/f/{type}", String.class, uriVariables)
|
||||
* </code>
|
||||
*/
|
||||
public <T> T getForObject(String uri, Class<T> responseType, Map<String, ?> uriVariables){
|
||||
@@ -142,9 +149,8 @@ public class HttpRequestTemplate {
|
||||
* @param request 请求数据
|
||||
* @param responseType 响应类型
|
||||
* @param method 请求方法
|
||||
* @param <T>
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @param <T> 响应类型
|
||||
* @return 类型对象
|
||||
*/
|
||||
public <T>T doExecute(URI uri, Object request, Class<T> responseType, MethodType method){
|
||||
ClientHttpRequest<T> httpRequest = new ClientHttpRequest(uri ,method, request);
|
||||
@@ -165,9 +171,8 @@ public class HttpRequestTemplate {
|
||||
* @param request 请求数据
|
||||
* @param responseType 响应类型
|
||||
* @param method 请求方法
|
||||
* @param <T>
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @param <T> 响应类型
|
||||
* @return 类型对象
|
||||
*/
|
||||
public <T>T doExecute(String uri, Object request, Class<T> responseType, MethodType method){
|
||||
return doExecute(URI.create(uri), request, responseType, method);
|
||||
|
||||
@@ -17,18 +17,20 @@ import java.util.regex.Pattern;
|
||||
* URL表达式处理器
|
||||
*
|
||||
* @author: egan
|
||||
* @email egzosn@gmail.com
|
||||
* @date 2017/3/5 10:07
|
||||
* <pre>
|
||||
* email egzosn@gmail.com
|
||||
* date 2017/3/5 10:07
|
||||
* </pre>
|
||||
*/
|
||||
public class UriVariables {
|
||||
|
||||
/**
|
||||
* 依次匹配
|
||||
* @param uri
|
||||
* @param uriVariables
|
||||
* @return
|
||||
* @param uri 匹配的uri,带代表式
|
||||
* @param uriVariables 匹配表达式的值
|
||||
* @return 匹配完的url
|
||||
* <code>
|
||||
* System.out.println(getUri("http://egan.in/{a}/ba/{a1}?{bb}={a1}", "no1", "no2", "no3", "no4"));
|
||||
* System.out.println(getUri("http://egan.in/{a}/ba/{a1}?{bb}={a1}", "no1", "no2", "no3", "no4"));
|
||||
* 结果 http://egan.in/no1/ba/no2?no3=no4
|
||||
* </code>
|
||||
*
|
||||
@@ -51,15 +53,15 @@ public class UriVariables {
|
||||
|
||||
/**
|
||||
* 匹配Map.key
|
||||
* @param uri
|
||||
* @param uriVariables
|
||||
* @return
|
||||
* @param uri 匹配的uri,带代表式
|
||||
* @param uriVariables 匹配表达式的值
|
||||
* @return 匹配完的url
|
||||
* <code>
|
||||
* Map<String, Object> uriVariable = new HashMap<>();
|
||||
* uriVariable.put("a", "no1");
|
||||
* uriVariable.put("a1", "no2");
|
||||
* uriVariable.put("bb", "no3");
|
||||
* System.out.println(getUri("http://egan.in/{a}/ba/{a1}?{bb}={a1}", uriVariable));
|
||||
* Map<String, Object> uriVariable = new HashMap<String, Object>();
|
||||
* uriVariable.put("a", "no1");
|
||||
* uriVariable.put("a1", "no2");
|
||||
* uriVariable.put("bb", "no3");
|
||||
* System.out.println(getUri("http://egan.in/{a}/ba/{a1}?{bb}={a1}", uriVariable));
|
||||
* 结果 http://egan.in/no1/ba/no2?no3=no2
|
||||
* </code>
|
||||
*/
|
||||
@@ -83,8 +85,8 @@ public class UriVariables {
|
||||
|
||||
/**
|
||||
* Map转化为对应得参数字符串
|
||||
* @param pe
|
||||
* @return
|
||||
* @param pe 参数
|
||||
* @return 参数字符串
|
||||
*/
|
||||
public static String getMapToParameters(Map pe){
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
Reference in New Issue
Block a user