refactor: 优化API执行器架构和HTTP客户端配置

引入JHApiExecutionAbstract抽象类统一管理API执行器,所有执行器从实现JHApiExecution接口改为继承该抽象类,简化代码结构并提高可扩展性。同时优化HTTP客户端配置的灵活性,支持按需配置超时和连接参数。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
yanlongqi
2025-11-22 11:59:18 +08:00
parent 69c4037b4b
commit 360e30c4ff
13 changed files with 127 additions and 195 deletions

View File

@@ -0,0 +1,14 @@
package com.jhinno.sdk.openapi;
import com.jhinno.sdk.openapi.api.JHRequestExecution;
public abstract class JHApiExecutionAbstract {
protected JHRequestExecution execution;
public void init(JHRequestExecution execution) {
this.execution = execution;
}
}

View File

@@ -15,7 +15,7 @@ import com.jhinno.sdk.openapi.client.JHApiHttpClient;
public class JHApiExecutionManage { public class JHApiExecutionManage {
public static final Map<Class<? extends JHApiExecution>, JHApiExecution> API_CLIENT_MAP = new HashMap<>(); public static final Map<Class<? extends JHApiExecutionAbstract>, JHApiExecutionAbstract> API_CLIENT_MAP = new HashMap<>();
public final JHRequestExecution EXECUTION; public final JHRequestExecution EXECUTION;
/** /**
@@ -48,15 +48,12 @@ public class JHApiExecutionManage {
* 初始化默认的执行器 * 初始化默认的执行器
*/ */
private void initApiExecution() { private void initApiExecution() {
API_CLIENT_MAP.put(JHAppApiExecution.class, new JHAppApiExecution()); registerApiExecution(new JHAppApiExecution());
API_CLIENT_MAP.put(JHDataApiExecution.class, new JHDataApiExecution()); registerApiExecution(new JHDataApiExecution());
API_CLIENT_MAP.put(JHFileApiExecution.class, new JHFileApiExecution()); registerApiExecution(new JHFileApiExecution());
API_CLIENT_MAP.put(JHJobApiExecution.class, new JHJobApiExecution()); registerApiExecution(new JHJobApiExecution());
API_CLIENT_MAP.put(JHDepartmentApiExecution.class, new JHDepartmentApiExecution()); registerApiExecution(new JHDepartmentApiExecution());
API_CLIENT_MAP.put(JHUserApiExecution.class, new JHUserApiExecution()); registerApiExecution(new JHUserApiExecution());
API_CLIENT_MAP.forEach((key, value) -> {
value.init(EXECUTION);
});
} }
/** /**
@@ -73,7 +70,7 @@ public class JHApiExecutionManage {
* *
* @param execution 自定义的执行器实例 * @param execution 自定义的执行器实例
*/ */
public void registerApiExecution(JHApiExecution execution) { public void registerApiExecution(JHApiExecutionAbstract execution) {
execution.init(EXECUTION); execution.init(EXECUTION);
API_CLIENT_MAP.put(execution.getClass(), execution); API_CLIENT_MAP.put(execution.getClass(), execution);
} }
@@ -85,7 +82,7 @@ public class JHApiExecutionManage {
* @param clazz 执行器的类 * @param clazz 执行器的类
* @return 执行器实例 * @return 执行器实例
*/ */
public <T extends JHApiExecution> T getApiExecution(Class<? extends T> clazz) { public <T extends JHApiExecutionAbstract> T getApiExecution(Class<? extends T> clazz) {
return (T) API_CLIENT_MAP.get(clazz); return (T) API_CLIENT_MAP.get(clazz);
} }

View File

@@ -1,10 +1,7 @@
package com.jhinno.sdk.openapi.api.app; package com.jhinno.sdk.openapi.api.app;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.jhinno.sdk.openapi.ArgsException; import com.jhinno.sdk.openapi.*;
import com.jhinno.sdk.openapi.CommonConstant;
import com.jhinno.sdk.openapi.ServiceException;
import com.jhinno.sdk.openapi.api.JHRequestExecution;
import com.jhinno.sdk.openapi.api.ResponseResult; import com.jhinno.sdk.openapi.api.ResponseResult;
import com.jhinno.sdk.openapi.client.JHApiClient; import com.jhinno.sdk.openapi.client.JHApiClient;
import com.jhinno.sdk.openapi.utils.CollectionUtil; import com.jhinno.sdk.openapi.utils.CollectionUtil;
@@ -21,7 +18,8 @@ import java.util.Map;
* @author yanlongqi * @author yanlongqi
* @date 2024/2/1 16:26 * @date 2024/2/1 16:26
*/ */
public class JHAppApiExecution extends JHRequestExecution { public class JHAppApiExecution extends JHApiExecutionAbstract {
/** /**
* 启动一个会话 * 启动一个会话
@@ -41,19 +39,19 @@ public class JHAppApiExecution extends JHRequestExecution {
* </ul> * </ul>
* 以下是使用的伪代码: * 以下是使用的伪代码:
* *
* <pre>{@code * <pre class="code">
* // 使用a标签实例代码 * // 使用a标签实例代码
* var a = document.createElement("a"); * var a = document.createElement("a");
* a.href = "{@link AppStartedInfo#getJhappUrl()}"; * a.href = "{@link AppStartedInfo#getJhappUrl()}";
* a.click(); * a.click();
* }</pre> * </pre>
* *
* <pre>{@code * <pre class="code">
* // 使用iframe标签实例代码 * // 使用iframe标签实例代码
* var iframe = document.createElement("iframe"); * var iframe = document.createElement("iframe");
* iframe.style.display = "none"; * iframe.style.display = "none";
* iframe.src = "{@link AppStartedInfo#getJhappUrl()}"; * iframe.src = "{@link AppStartedInfo#getJhappUrl()}";
* }</pre> * </pre>
* *
* <p> * <p>
* 注意如果使用JHAppClient启动应用的并且没有做浏览器端和服务器没有做时间同步 * 注意如果使用JHAppClient启动应用的并且没有做浏览器端和服务器没有做时间同步
@@ -62,9 +60,9 @@ public class JHAppApiExecution extends JHRequestExecution {
* *
* <h4>通过浏览器启动</h4> * <h4>通过浏览器启动</h4>
* *
* <pre>{@code * <pre class="code">
* window.open("{@link AppStartedInfo#getWebSessionUrl()}}") * window.open("{@link AppStartedInfo#getWebSessionUrl()}}")
* }</pre> * </pre>
* *
* @param username 用户名 * @param username 用户名
* @param appId 应用拆 * @param appId 应用拆
@@ -73,7 +71,7 @@ public class JHAppApiExecution extends JHRequestExecution {
*/ */
public AppStartedInfo desktopStart(String username, String appId, AppStartRequest appStartRequest) { public AppStartedInfo desktopStart(String username, String appId, AppStartRequest appStartRequest) {
String path = AppPathConstant.APPS_START_PATH.replace("{appId}", appId); String path = AppPathConstant.APPS_START_PATH.replace("{appId}", appId);
List<AppStartedInfo> data = this.post(path, username, appStartRequest, List<AppStartedInfo> data = execution.post(path, username, appStartRequest,
new TypeReference<ResponseResult<List<AppStartedInfo>>>() { new TypeReference<ResponseResult<List<AppStartedInfo>>>() {
}); });
if (CollectionUtil.isEmpty(data)) { if (CollectionUtil.isEmpty(data)) {
@@ -86,7 +84,7 @@ public class JHAppApiExecution extends JHRequestExecution {
public String getWebSessionUrl(String username, String sessionId) { public String getWebSessionUrl(String username, String sessionId) {
String webSessionUrlPath = AppPathConstant.WEB_SESSION_URL_PATH.replace("{sessionId}", sessionId); String webSessionUrlPath = AppPathConstant.WEB_SESSION_URL_PATH.replace("{sessionId}", sessionId);
Map<String, String> result = this.get(webSessionUrlPath, username, new TypeReference<ResponseResult<Map<String, String>>>() { Map<String, String> result = execution.get(webSessionUrlPath, username, new TypeReference<ResponseResult<Map<String, String>>>() {
}); });
if (CollectionUtil.isEmpty(result)) { if (CollectionUtil.isEmpty(result)) {
return null; return null;
@@ -116,7 +114,7 @@ public class JHAppApiExecution extends JHRequestExecution {
* @return 会话列表 * @return 会话列表
*/ */
public List<SessionInfo> getDesktopList(String username) { public List<SessionInfo> getDesktopList(String username) {
return this.get(AppPathConstant.APPS_SESSIONS_ALL_PATH, username, return execution.get(AppPathConstant.APPS_SESSIONS_ALL_PATH, username,
new TypeReference<ResponseResult<List<SessionInfo>>>() { new TypeReference<ResponseResult<List<SessionInfo>>>() {
}); });
} }
@@ -142,7 +140,7 @@ public class JHAppApiExecution extends JHRequestExecution {
params.put("sessionName", sessionName); params.put("sessionName", sessionName);
} }
String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_PATH, params); String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_PATH, params);
return this.get(path, username, new TypeReference<ResponseResult<List<SessionInfo>>>() { return execution.get(path, username, new TypeReference<ResponseResult<List<SessionInfo>>>() {
}); });
} }
@@ -163,7 +161,7 @@ public class JHAppApiExecution extends JHRequestExecution {
} }
params.put("sessionIds", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, ids)); params.put("sessionIds", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, ids));
String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_IDS_PATH, params); String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_IDS_PATH, params);
return this.get(path, username, new TypeReference<ResponseResult<List<SessionInfo>>>() { return execution.get(path, username, new TypeReference<ResponseResult<List<SessionInfo>>>() {
}); });
} }
@@ -185,7 +183,7 @@ public class JHAppApiExecution extends JHRequestExecution {
} }
params.put("sessionName", sessionName); params.put("sessionName", sessionName);
String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_NAME_PATH, params); String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_NAME_PATH, params);
return this.get(path, username, new TypeReference<ResponseResult<List<SessionInfo>>>() { return execution.get(path, username, new TypeReference<ResponseResult<List<SessionInfo>>>() {
}); });
} }
@@ -220,7 +218,7 @@ public class JHAppApiExecution extends JHRequestExecution {
} }
String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_SHARE_PATH.replace("{sessionId}", sessionId), String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_SHARE_PATH.replace("{sessionId}", sessionId),
params); params);
this.post(path, username); execution.post(path, username);
} }
/** /**
@@ -238,7 +236,7 @@ public class JHAppApiExecution extends JHRequestExecution {
throw new ArgsException("sessionId为必填字段"); throw new ArgsException("sessionId为必填字段");
} }
String path = AppPathConstant.APPS_SESSIONS_CANCEL_SHARE_PATH.replace("{sessionId}", sessionId); String path = AppPathConstant.APPS_SESSIONS_CANCEL_SHARE_PATH.replace("{sessionId}", sessionId);
this.put(path, username); execution.put(path, username);
} }
/** /**
@@ -263,7 +261,7 @@ public class JHAppApiExecution extends JHRequestExecution {
Map<String, Object> params = new HashMap<>(1); Map<String, Object> params = new HashMap<>(1);
params.put("interact", interact); params.put("interact", interact);
path = JHApiClient.getUrl(path, params); path = JHApiClient.getUrl(path, params);
this.put(path, username); execution.put(path, username);
} }
/** /**
@@ -278,7 +276,7 @@ public class JHAppApiExecution extends JHRequestExecution {
throw new ArgsException("sessionId为必填字段"); throw new ArgsException("sessionId为必填字段");
} }
String path = AppPathConstant.APPS_SESSIONS_CONNECT_JHAPP_PATH.replace("{sessionId}", sessionId); String path = AppPathConstant.APPS_SESSIONS_CONNECT_JHAPP_PATH.replace("{sessionId}", sessionId);
List<AppStartedInfo> list = this.get(path, username, List<AppStartedInfo> list = execution.get(path, username,
new TypeReference<ResponseResult<List<AppStartedInfo>>>() { new TypeReference<ResponseResult<List<AppStartedInfo>>>() {
}); });
if (CollectionUtil.isEmpty(list)) { if (CollectionUtil.isEmpty(list)) {
@@ -304,7 +302,7 @@ public class JHAppApiExecution extends JHRequestExecution {
throw new ArgsException("sessionId为必填字段"); throw new ArgsException("sessionId为必填字段");
} }
String path = AppPathConstant.APPS_SESSIONS_DISCONNECT_PATH.replace("{sessionId}", sessionId); String path = AppPathConstant.APPS_SESSIONS_DISCONNECT_PATH.replace("{sessionId}", sessionId);
this.put(path, username); execution.put(path, username);
} }
/** /**
@@ -323,7 +321,7 @@ public class JHAppApiExecution extends JHRequestExecution {
Map<String, Object> params = new HashMap<>(1); Map<String, Object> params = new HashMap<>(1);
params.put("sessionIds", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, sessionIds)); params.put("sessionIds", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, sessionIds));
String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_DISCONNECT_IDS_PATH, params); String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_DISCONNECT_IDS_PATH, params);
this.put(path, username); execution.put(path, username);
} }
/** /**
@@ -340,7 +338,7 @@ public class JHAppApiExecution extends JHRequestExecution {
throw new ArgsException("sessionId为必填字段"); throw new ArgsException("sessionId为必填字段");
} }
String path = AppPathConstant.APPS_SESSIONS_DESTROY_PATH.replace("{sessionId}", sessionId); String path = AppPathConstant.APPS_SESSIONS_DESTROY_PATH.replace("{sessionId}", sessionId);
this.put(path, username); execution.put(path, username);
} }
/** /**
@@ -356,7 +354,7 @@ public class JHAppApiExecution extends JHRequestExecution {
Map<String, Object> params = new HashMap<>(1); Map<String, Object> params = new HashMap<>(1);
params.put("sessionIds", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, sessionIds)); params.put("sessionIds", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, sessionIds));
String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_DESTROY_IDS_PATH, params); String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_DESTROY_IDS_PATH, params);
this.put(path, username); execution.put(path, username);
} }
/** /**
@@ -366,7 +364,7 @@ public class JHAppApiExecution extends JHRequestExecution {
* @return 应用列表 * @return 应用列表
*/ */
public List<AppInfo> getAppList(String username) { public List<AppInfo> getAppList(String username) {
return this.get(AppPathConstant.APPS_LIST_PATH, username, return execution.get(AppPathConstant.APPS_LIST_PATH, username,
new TypeReference<ResponseResult<List<AppInfo>>>() { new TypeReference<ResponseResult<List<AppInfo>>>() {
}); });
} }
@@ -383,7 +381,7 @@ public class JHAppApiExecution extends JHRequestExecution {
throw new ArgsException("appName为必填字段"); throw new ArgsException("appName为必填字段");
} }
String path = AppPathConstant.APPS_GET_URL_PATH.replace("{appName}", appName); String path = AppPathConstant.APPS_GET_URL_PATH.replace("{appName}", appName);
List<Map<String, String>> apps = this.get(path, username, List<Map<String, String>> apps = execution.get(path, username,
new TypeReference<ResponseResult<List<Map<String, String>>>>() { new TypeReference<ResponseResult<List<Map<String, String>>>>() {
}); });
if (CollectionUtil.isEmpty(apps)) { if (CollectionUtil.isEmpty(apps)) {
@@ -416,7 +414,7 @@ public class JHAppApiExecution extends JHRequestExecution {
params.put("suffixes", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, suffixes)); params.put("suffixes", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, suffixes));
} }
String path = JHApiClient.getUrl(AppPathConstant.APPS_SUFFIXES_PATH, params); String path = JHApiClient.getUrl(AppPathConstant.APPS_SUFFIXES_PATH, params);
return this.get(path, username, new TypeReference<ResponseResult<List<AppstoreAppInfo>>>() { return execution.get(path, username, new TypeReference<ResponseResult<List<AppstoreAppInfo>>>() {
}); });
} }
@@ -444,7 +442,7 @@ public class JHAppApiExecution extends JHRequestExecution {
params.put("use_labels", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, labels)); params.put("use_labels", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, labels));
} }
String path = JHApiClient.getUrl(AppPathConstant.APP_USE_LABEL_PATH, params); String path = JHApiClient.getUrl(AppPathConstant.APP_USE_LABEL_PATH, params);
return this.get(path, username, new TypeReference<ResponseResult<List<UseLabelInfo>>>() { return execution.get(path, username, new TypeReference<ResponseResult<List<UseLabelInfo>>>() {
}); });
} }
} }

View File

@@ -1,11 +1,7 @@
package com.jhinno.sdk.openapi.api.data; package com.jhinno.sdk.openapi.api.data;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.jhinno.sdk.openapi.ArgsException; import com.jhinno.sdk.openapi.*;
import com.jhinno.sdk.openapi.CommonConstant;
import com.jhinno.sdk.openapi.JHApiExecution;
import com.jhinno.sdk.openapi.ServiceException;
import com.jhinno.sdk.openapi.api.JHRequestExecution;
import com.jhinno.sdk.openapi.api.ResponseResult; import com.jhinno.sdk.openapi.api.ResponseResult;
import com.jhinno.sdk.openapi.client.JHApiClient; import com.jhinno.sdk.openapi.client.JHApiClient;
import com.jhinno.sdk.openapi.utils.CollectionUtil; import com.jhinno.sdk.openapi.utils.CollectionUtil;
@@ -24,13 +20,7 @@ import java.util.Map;
* @date 2024/2/4 17:09 * @date 2024/2/4 17:09
*/ */
@NoArgsConstructor @NoArgsConstructor
public class JHDataApiExecution implements JHApiExecution { public class JHDataApiExecution extends JHApiExecutionAbstract {
private JHRequestExecution execution;
public void init(JHRequestExecution execution) {
this.execution = execution;
}
/** /**
* 根据用户scope查询数据目录列表 * 根据用户scope查询数据目录列表

View File

@@ -1,11 +1,7 @@
package com.jhinno.sdk.openapi.api.file; package com.jhinno.sdk.openapi.api.file;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.jhinno.sdk.openapi.ArgsException; import com.jhinno.sdk.openapi.*;
import com.jhinno.sdk.openapi.CommonConstant;
import com.jhinno.sdk.openapi.JHApiExecution;
import com.jhinno.sdk.openapi.ServiceException;
import com.jhinno.sdk.openapi.api.JHRequestExecution;
import com.jhinno.sdk.openapi.api.ResponseResult; import com.jhinno.sdk.openapi.api.ResponseResult;
import com.jhinno.sdk.openapi.client.JHApiClient; import com.jhinno.sdk.openapi.client.JHApiClient;
import com.jhinno.sdk.openapi.utils.CollectionUtil; import com.jhinno.sdk.openapi.utils.CollectionUtil;
@@ -28,13 +24,7 @@ import java.util.Map;
* @date 2024/2/4 18:58 * @date 2024/2/4 18:58
*/ */
@NoArgsConstructor @NoArgsConstructor
public class JHFileApiExecution implements JHApiExecution { public class JHFileApiExecution extends JHApiExecutionAbstract {
private JHRequestExecution execution;
public void init(JHRequestExecution execution) {
this.execution = execution;
}
/** /**
* 重命名文件 * 重命名文件

View File

@@ -1,11 +1,7 @@
package com.jhinno.sdk.openapi.api.job; package com.jhinno.sdk.openapi.api.job;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.jhinno.sdk.openapi.ArgsException; import com.jhinno.sdk.openapi.*;
import com.jhinno.sdk.openapi.CommonConstant;
import com.jhinno.sdk.openapi.JHApiExecution;
import com.jhinno.sdk.openapi.ServiceException;
import com.jhinno.sdk.openapi.api.JHRequestExecution;
import com.jhinno.sdk.openapi.api.ResponseResult; import com.jhinno.sdk.openapi.api.ResponseResult;
import com.jhinno.sdk.openapi.api.file.FileInfo; import com.jhinno.sdk.openapi.api.file.FileInfo;
import com.jhinno.sdk.openapi.client.JHApiClient; import com.jhinno.sdk.openapi.client.JHApiClient;
@@ -23,13 +19,7 @@ import java.util.Map;
* @date 2024/2/5 18:44 * @date 2024/2/5 18:44
*/ */
@NoArgsConstructor @NoArgsConstructor
public class JHJobApiExecution implements JHApiExecution { public class JHJobApiExecution extends JHApiExecutionAbstract {
private JHRequestExecution execution;
public void init(JHRequestExecution execution) {
this.execution = execution;
}
/** /**
* 提交作业 * 提交作业

View File

@@ -2,8 +2,7 @@ package com.jhinno.sdk.openapi.api.organization;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.jhinno.sdk.openapi.ArgsException; import com.jhinno.sdk.openapi.ArgsException;
import com.jhinno.sdk.openapi.JHApiExecution; import com.jhinno.sdk.openapi.JHApiExecutionAbstract;
import com.jhinno.sdk.openapi.api.JHRequestExecution;
import com.jhinno.sdk.openapi.api.ResponseResult; import com.jhinno.sdk.openapi.api.ResponseResult;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -20,13 +19,7 @@ import java.util.Map;
* @date 2024/2/6 17:37 * @date 2024/2/6 17:37
*/ */
@NoArgsConstructor @NoArgsConstructor
public class JHDepartmentApiExecution implements JHApiExecution { public class JHDepartmentApiExecution extends JHApiExecutionAbstract {
private JHRequestExecution execution;
public void init(JHRequestExecution execution) {
this.execution = execution;
}
/** /**
* 查询用户列表 * 查询用户列表

View File

@@ -2,8 +2,7 @@ package com.jhinno.sdk.openapi.api.organization;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.jhinno.sdk.openapi.ArgsException; import com.jhinno.sdk.openapi.ArgsException;
import com.jhinno.sdk.openapi.JHApiExecution; import com.jhinno.sdk.openapi.JHApiExecutionAbstract;
import com.jhinno.sdk.openapi.api.JHRequestExecution;
import com.jhinno.sdk.openapi.api.PageResult; import com.jhinno.sdk.openapi.api.PageResult;
import com.jhinno.sdk.openapi.api.ResponseResult; import com.jhinno.sdk.openapi.api.ResponseResult;
import com.jhinno.sdk.openapi.client.JHApiClient; import com.jhinno.sdk.openapi.client.JHApiClient;
@@ -22,13 +21,7 @@ import java.util.Map;
* @date 2024/2/6 17:37 * @date 2024/2/6 17:37
*/ */
@NoArgsConstructor @NoArgsConstructor
public class JHUserApiExecution implements JHApiExecution { public class JHUserApiExecution extends JHApiExecutionAbstract {
private JHRequestExecution execution;
public void init(JHRequestExecution execution) {
this.execution = execution;
}
/** /**
* 分页查询用户列表 * 分页查询用户列表

View File

@@ -35,6 +35,7 @@ import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.text.ParseException; import java.text.ParseException;
import java.util.Map; import java.util.Map;
import java.util.Objects;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@@ -63,62 +64,57 @@ public class JHApiHttpClientImpl implements JHApiHttpClient {
private RequestConfig requestConfig; private RequestConfig requestConfig;
/**
* Socket连接超时的时间(单位:毫秒,默认:{@link DefaultHttpClientConfig#SOCKET_TIMEOUT})
*/
private int socketTimeout = DefaultHttpClientConfig.SOCKET_TIMEOUT;
/**
* 连接超时的时间(单位:毫秒,默认:{@link DefaultHttpClientConfig#CONNECT_TIMEOUT})
*/
private int connectTimeout = DefaultHttpClientConfig.CONNECT_TIMEOUT;
/**
* 默认请求超时的时间(单位:毫秒,默认:{@link DefaultHttpClientConfig#CONNECTION_REQUEST_TIMEOUT})
*/
private int connectRequestTimeout = DefaultHttpClientConfig.CONNECTION_REQUEST_TIMEOUT;
/**
* 设置最大连接数(默认:{@link DefaultHttpClientConfig#MAX_TOTAL})
*/
private int maxTotal = DefaultHttpClientConfig.MAX_TOTAL;
/**
* 服务每次能并行接收的请求数量(默认:{@link DefaultHttpClientConfig#MAX_PER_ROUTE})
*/
private int maxPerRoute = DefaultHttpClientConfig.MAX_PER_ROUTE;
/** /**
* 初始化一个HTTP客户端实例 * 初始化一个HTTP客户端实例
* *
* @return 返回一个可关闭的HTTP客户端示例 * @return 返回一个可关闭的HTTP客户端示例
*/ */
public void createHttpClients() { public void createHttpClients(Integer maxTotal, Integer maxPerRoute) {
SSLContextBuilder builder = new SSLContextBuilder(); SSLContextBuilder builder = new SSLContextBuilder();
try { try {
builder.loadTrustMaterial(null, (x509Certificates, s) -> true); builder.loadTrustMaterial(null, (x509Certificates, s) -> true);
SSLConnectionSocketFactory sslref = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE); SSLConnectionSocketFactory sslref = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("http", new PlainConnectionSocketFactory()).register("https", sslref).build(); Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", new PlainConnectionSocketFactory())
.register("https", sslref)
.build();
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry); PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry);
if (Objects.nonNull(maxTotal)) {
cm.setMaxTotal(maxTotal); cm.setMaxTotal(maxTotal);
}
if (Objects.nonNull(maxPerRoute)) {
cm.setDefaultMaxPerRoute(maxPerRoute); cm.setDefaultMaxPerRoute(maxPerRoute);
}
closeableHttpClient = HttpClients.custom().setSSLSocketFactory(sslref).setConnectionManager(cm).setConnectionManagerShared(true).build(); closeableHttpClient = HttpClients.custom().setSSLSocketFactory(sslref).setConnectionManager(cm).setConnectionManagerShared(true).build();
} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) { } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
throw new ClientException(e.getMessage(), ClientErrorCode.SSL_EXCEPTION, e); throw new ClientException(e.getMessage(), ClientErrorCode.SSL_EXCEPTION, e);
} }
} }
public void createHttpClients() {
createHttpClients(null, null);
}
/** /**
* 初始化客户端 * 初始化客户端
*/ */
public void init() { public void init(Integer socketTimeout, Integer connectTimeout, Integer connectRequestTimeout) {
this.requestConfig = RequestConfig.custom() RequestConfig.Builder custom = RequestConfig.custom();
.setSocketTimeout(socketTimeout) if (Objects.nonNull(socketTimeout)) {
.setConnectTimeout(connectTimeout) custom.setSocketTimeout(socketTimeout);
.setConnectionRequestTimeout(connectRequestTimeout) }
.build(); if (Objects.nonNull(connectTimeout)) {
custom.setConnectTimeout(connectTimeout);
}
if (Objects.nonNull(connectRequestTimeout)) {
custom.setConnectionRequestTimeout(connectRequestTimeout);
}
this.requestConfig = custom.build();
} }
public void init() {
init(null, null, null);
}
/** /**
* 原始发送请求 * 原始发送请求
@@ -226,7 +222,7 @@ public class JHApiHttpClientImpl implements JHApiHttpClient {
return CommonConstant.HTTP_DATETIME_FORMAT.parse(value).getTime(); return CommonConstant.HTTP_DATETIME_FORMAT.parse(value).getTime();
} catch (ParseException e) { } catch (ParseException e) {
throw new ClientException("时间格式获取失败,失败原因:" + e.getMessage(), e); throw new ClientException("时间格式获取失败,失败原因:" + e.getMessage(), e);
}finally { } finally {
httpGet.releaseConnection(); httpGet.releaseConnection();
} }
} }

View File

@@ -29,7 +29,7 @@ public class AppApiTest {
public void testStartApp() { public void testStartApp() {
AppStartRequest appStartRequest = new AppStartRequest(); AppStartRequest appStartRequest = new AppStartRequest();
appStartRequest.setStartNew(true); appStartRequest.setStartNew(true);
AppStartedInfo appStartedInfo = jhAppApiExecution.desktopStart("yanlongqi", "linux_desktop", appStartRequest); AppStartedInfo appStartedInfo = jhAppApiExecution.desktopStart("jhadmin", "linux_desktop", appStartRequest);
System.out.println("会话ID" + appStartedInfo.getDesktopId()); System.out.println("会话ID" + appStartedInfo.getDesktopId());
System.out.println("JhAppURL" + appStartedInfo.getJhappUrl()); System.out.println("JhAppURL" + appStartedInfo.getJhappUrl());
System.out.println("WebURL:" + appStartedInfo.getWebSessionUrl()); System.out.println("WebURL:" + appStartedInfo.getWebSessionUrl());

View File

@@ -1,8 +1,7 @@
package com.jhinno.sdk.openapi.example.api.extend; package com.jhinno.sdk.openapi.example.api.extend;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.jhinno.sdk.openapi.JHApiExecution; import com.jhinno.sdk.openapi.JHApiExecutionAbstract;
import com.jhinno.sdk.openapi.api.JHRequestExecution;
import com.jhinno.sdk.openapi.api.ResponseResult; import com.jhinno.sdk.openapi.api.ResponseResult;
import com.jhinno.sdk.openapi.client.JHApiClient; import com.jhinno.sdk.openapi.client.JHApiClient;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -12,44 +11,22 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
@Component @Component
public class JHFileApiExtendExecution implements JHApiExecution { public class JHFileApiExtendExecution extends JHApiExecutionAbstract {
private JHRequestExecution execution; public static String GET_FILE_ENV_PATH = "/appform/ws/api/files/path/{env}";
@Override public FilePath getFileEnvPath(String username, FileEnvType env, FileSystemType type) {
public void init(JHRequestExecution execution) { Map<String, Object> params = new HashMap<>(1);
this.execution = execution; if (StringUtils.isNotBlank(type.getType())) {
params.put("type", type.getType());
} }
String url = JHApiClient.getUrl(GET_FILE_ENV_PATH.replace("{env}", env.getEnv()), params);
return execution.get(url, username, new TypeReference<ResponseResult<FilePath>>() {
/**
* 删除作业
*
* @param username 用户名
* @param jobId 作业ID
*/
public void deleteJob(String username, String jobId) {
execution.delete("/appform/ws/api/jobs/" + jobId, username);
}
/**
* 获取集群的应用的CPU核数和排队作业数
*
* @param username 用户名
* @param jobQueue 队列没有要求就填写normal
* @param jobPlatform 作业查询条件type==LINUX64
* @param appName 应用IDcommon_sub
* @return
*/
public JobTooltipDTO getJobTooltipInfo(String username, String jobQueue, String jobPlatform, String appName) {
Map<String, Object> params = new HashMap<>();
params.put("jobQueue", jobQueue);
params.put("jobPlatform", jobPlatform);
params.put("isTestApp", false);
params.put("appName", appName);
String path = JHApiClient.getUrl("/appform/ws/api/jobs/tooltip", params);
return execution.get(path, username, new TypeReference<ResponseResult<JobTooltipDTO>>() {
}); });
} }
public FilePath getFileHomeEnvPath(String username, FileSystemType type) {
return getFileEnvPath(username, FileEnvType.HOME_ENV, type);
}
} }

View File

@@ -23,13 +23,8 @@ public class JHOpenapiClientAutoConfigure {
public JHApiClient jhApiClient(JHOpenapiProperties properties) { public JHApiClient jhApiClient(JHOpenapiProperties properties) {
JHApiClient jhApiClient = new JHApiClient(properties.getServerUrl()); JHApiClient jhApiClient = new JHApiClient(properties.getServerUrl());
JHApiHttpClientImpl jhApiHttpClient = new JHApiHttpClientImpl(); JHApiHttpClientImpl jhApiHttpClient = new JHApiHttpClientImpl();
jhApiHttpClient.setMaxPerRoute(properties.getMaxPerRout()); jhApiHttpClient.init(properties.getSocketTimeout(), properties.getConnectTimeout(), properties.getConnectRequestTimeout());
jhApiHttpClient.setSocketTimeout(properties.getSocketTimeout()); jhApiHttpClient.createHttpClients(properties.getMaxTotal(), properties.getMaxPerRout());
jhApiHttpClient.setMaxTotal(properties.getMaxTotal());
jhApiHttpClient.setConnectTimeout(properties.getConnectTimeout());
jhApiHttpClient.setConnectRequestTimeout(properties.getConnectRequestTimeout());
jhApiHttpClient.init();
jhApiHttpClient.createHttpClients();
jhApiClient.setApiHttpClient(jhApiHttpClient); jhApiClient.setApiHttpClient(jhApiHttpClient);
return jhApiClient; return jhApiClient;
} }

View File

@@ -8,7 +8,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
/** /**
* @author yanlongqi * @author yanlongqi
* @date 2024/6/4 16:03
*/ */
@Data @Data
@ConfigurationProperties(prefix = CommonConstants.CONFIG_PREFIX) @ConfigurationProperties(prefix = CommonConstants.CONFIG_PREFIX)
@@ -20,31 +19,31 @@ public class JHOpenapiProperties {
private String serverUrl; private String serverUrl;
/** /**
* 设置连接池的最大连接数,默认{@link DefaultHttpClientConfig#MAX_TOTAL} * 设置连接池的最大连接数
*/ */
private int maxTotal = DefaultHttpClientConfig.MAX_TOTAL; private Integer maxTotal;
/** /**
* 设置服务每次能并行接收的请求数量,默认{@link DefaultHttpClientConfig#MAX_PER_ROUTE} * 设置服务每次能并行接收的请求数量
*/ */
private int maxPerRout = DefaultHttpClientConfig.MAX_PER_ROUTE; private Integer maxPerRout;
/** /**
* 设置服务socket连接超时的时间(单位:毫秒),默认{@link DefaultHttpClientConfig#SOCKET_TIMEOUT} * 设置服务socket连接超时的时间(单位:毫秒)
*/ */
private int socketTimeout = DefaultHttpClientConfig.SOCKET_TIMEOUT; private int socketTimeout;
/** /**
* 设置服务连接超时的时间(单位:毫秒),默认{@link DefaultHttpClientConfig#CONNECT_TIMEOUT} * 设置服务连接超时的时间(单位:毫秒)
*/ */
private int connectTimeout = DefaultHttpClientConfig.CONNECT_TIMEOUT; private int connectTimeout;
/** /**
* 设置服务请求超时的时间(单位:毫秒),默认{@link DefaultHttpClientConfig#CONNECTION_REQUEST_TIMEOUT} * 设置服务请求超时的时间(单位:毫秒)
*/ */
private int connectRequestTimeout = DefaultHttpClientConfig.CONNECTION_REQUEST_TIMEOUT; private int connectRequestTimeout;
/** /**