mirror of
https://github.com/yanlongqi/jhinno-openapi-java-sdk.git
synced 2026-03-22 06:15:10 +08:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import com.jhinno.sdk.openapi.client.JHApiHttpClient;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -48,15 +48,12 @@ public class JHApiExecutionManage {
|
||||
* 初始化默认的执行器
|
||||
*/
|
||||
private void initApiExecution() {
|
||||
API_CLIENT_MAP.put(JHAppApiExecution.class, new JHAppApiExecution());
|
||||
API_CLIENT_MAP.put(JHDataApiExecution.class, new JHDataApiExecution());
|
||||
API_CLIENT_MAP.put(JHFileApiExecution.class, new JHFileApiExecution());
|
||||
API_CLIENT_MAP.put(JHJobApiExecution.class, new JHJobApiExecution());
|
||||
API_CLIENT_MAP.put(JHDepartmentApiExecution.class, new JHDepartmentApiExecution());
|
||||
API_CLIENT_MAP.put(JHUserApiExecution.class, new JHUserApiExecution());
|
||||
API_CLIENT_MAP.forEach((key, value) -> {
|
||||
value.init(EXECUTION);
|
||||
});
|
||||
registerApiExecution(new JHAppApiExecution());
|
||||
registerApiExecution(new JHDataApiExecution());
|
||||
registerApiExecution(new JHFileApiExecution());
|
||||
registerApiExecution(new JHJobApiExecution());
|
||||
registerApiExecution(new JHDepartmentApiExecution());
|
||||
registerApiExecution(new JHUserApiExecution());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,7 +70,7 @@ public class JHApiExecutionManage {
|
||||
*
|
||||
* @param execution 自定义的执行器实例
|
||||
*/
|
||||
public void registerApiExecution(JHApiExecution execution) {
|
||||
public void registerApiExecution(JHApiExecutionAbstract execution) {
|
||||
execution.init(EXECUTION);
|
||||
API_CLIENT_MAP.put(execution.getClass(), execution);
|
||||
}
|
||||
@@ -85,7 +82,7 @@ public class JHApiExecutionManage {
|
||||
* @param clazz 执行器的类
|
||||
* @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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package com.jhinno.sdk.openapi.api.app;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.jhinno.sdk.openapi.ArgsException;
|
||||
import com.jhinno.sdk.openapi.CommonConstant;
|
||||
import com.jhinno.sdk.openapi.ServiceException;
|
||||
import com.jhinno.sdk.openapi.api.JHRequestExecution;
|
||||
import com.jhinno.sdk.openapi.*;
|
||||
import com.jhinno.sdk.openapi.api.ResponseResult;
|
||||
import com.jhinno.sdk.openapi.client.JHApiClient;
|
||||
import com.jhinno.sdk.openapi.utils.CollectionUtil;
|
||||
@@ -21,7 +18,8 @@ import java.util.Map;
|
||||
* @author yanlongqi
|
||||
* @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>
|
||||
* 以下是使用的伪代码:
|
||||
*
|
||||
* <pre>{@code
|
||||
* <pre class="code">
|
||||
* // 使用a标签实例代码
|
||||
* var a = document.createElement("a");
|
||||
* a.href = "{@link AppStartedInfo#getJhappUrl()}";
|
||||
* a.click();
|
||||
* }</pre>
|
||||
* </pre>
|
||||
*
|
||||
* <pre>{@code
|
||||
* <pre class="code">
|
||||
* // 使用iframe标签实例代码
|
||||
* var iframe = document.createElement("iframe");
|
||||
* iframe.style.display = "none";
|
||||
* iframe.src = "{@link AppStartedInfo#getJhappUrl()}";
|
||||
* }</pre>
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* 注意:如果使用JHAppClient启动应用的,并且没有做浏览器端和服务器没有做时间同步,
|
||||
@@ -62,9 +60,9 @@ public class JHAppApiExecution extends JHRequestExecution {
|
||||
*
|
||||
* <h4>通过浏览器启动</h4>
|
||||
*
|
||||
* <pre>{@code
|
||||
* <pre class="code">
|
||||
* window.open("{@link AppStartedInfo#getWebSessionUrl()}}")
|
||||
* }</pre>
|
||||
* </pre>
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param appId 应用拆
|
||||
@@ -73,7 +71,7 @@ public class JHAppApiExecution extends JHRequestExecution {
|
||||
*/
|
||||
public AppStartedInfo desktopStart(String username, String appId, AppStartRequest appStartRequest) {
|
||||
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>>>() {
|
||||
});
|
||||
if (CollectionUtil.isEmpty(data)) {
|
||||
@@ -86,7 +84,7 @@ public class JHAppApiExecution extends JHRequestExecution {
|
||||
|
||||
public String getWebSessionUrl(String username, String 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)) {
|
||||
return null;
|
||||
@@ -116,7 +114,7 @@ public class JHAppApiExecution extends JHRequestExecution {
|
||||
* @return 会话列表
|
||||
*/
|
||||
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>>>() {
|
||||
});
|
||||
}
|
||||
@@ -142,7 +140,7 @@ public class JHAppApiExecution extends JHRequestExecution {
|
||||
params.put("sessionName", sessionName);
|
||||
}
|
||||
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));
|
||||
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);
|
||||
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),
|
||||
params);
|
||||
this.post(path, username);
|
||||
execution.post(path, username);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,7 +236,7 @@ public class JHAppApiExecution extends JHRequestExecution {
|
||||
throw new ArgsException("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);
|
||||
params.put("interact", interact);
|
||||
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为必填字段");
|
||||
}
|
||||
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>>>() {
|
||||
});
|
||||
if (CollectionUtil.isEmpty(list)) {
|
||||
@@ -304,7 +302,7 @@ public class JHAppApiExecution extends JHRequestExecution {
|
||||
throw new ArgsException("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);
|
||||
params.put("sessionIds", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, sessionIds));
|
||||
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为必填字段");
|
||||
}
|
||||
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);
|
||||
params.put("sessionIds", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, sessionIds));
|
||||
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 应用列表
|
||||
*/
|
||||
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>>>() {
|
||||
});
|
||||
}
|
||||
@@ -383,7 +381,7 @@ public class JHAppApiExecution extends JHRequestExecution {
|
||||
throw new ArgsException("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>>>>() {
|
||||
});
|
||||
if (CollectionUtil.isEmpty(apps)) {
|
||||
@@ -416,7 +414,7 @@ public class JHAppApiExecution extends JHRequestExecution {
|
||||
params.put("suffixes", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, suffixes));
|
||||
}
|
||||
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));
|
||||
}
|
||||
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>>>() {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package com.jhinno.sdk.openapi.api.data;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.jhinno.sdk.openapi.ArgsException;
|
||||
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.*;
|
||||
import com.jhinno.sdk.openapi.api.ResponseResult;
|
||||
import com.jhinno.sdk.openapi.client.JHApiClient;
|
||||
import com.jhinno.sdk.openapi.utils.CollectionUtil;
|
||||
@@ -24,13 +20,7 @@ import java.util.Map;
|
||||
* @date 2024/2/4 17:09
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
public class JHDataApiExecution implements JHApiExecution {
|
||||
|
||||
private JHRequestExecution execution;
|
||||
|
||||
public void init(JHRequestExecution execution) {
|
||||
this.execution = execution;
|
||||
}
|
||||
public class JHDataApiExecution extends JHApiExecutionAbstract {
|
||||
|
||||
/**
|
||||
* 根据用户scope查询数据目录列表
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package com.jhinno.sdk.openapi.api.file;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.jhinno.sdk.openapi.ArgsException;
|
||||
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.*;
|
||||
import com.jhinno.sdk.openapi.api.ResponseResult;
|
||||
import com.jhinno.sdk.openapi.client.JHApiClient;
|
||||
import com.jhinno.sdk.openapi.utils.CollectionUtil;
|
||||
@@ -28,13 +24,7 @@ import java.util.Map;
|
||||
* @date 2024/2/4 18:58
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
public class JHFileApiExecution implements JHApiExecution {
|
||||
|
||||
private JHRequestExecution execution;
|
||||
|
||||
public void init(JHRequestExecution execution) {
|
||||
this.execution = execution;
|
||||
}
|
||||
public class JHFileApiExecution extends JHApiExecutionAbstract {
|
||||
|
||||
/**
|
||||
* 重命名文件
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
package com.jhinno.sdk.openapi.api.job;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.jhinno.sdk.openapi.ArgsException;
|
||||
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.*;
|
||||
import com.jhinno.sdk.openapi.api.ResponseResult;
|
||||
import com.jhinno.sdk.openapi.api.file.FileInfo;
|
||||
import com.jhinno.sdk.openapi.client.JHApiClient;
|
||||
@@ -23,13 +19,7 @@ import java.util.Map;
|
||||
* @date 2024/2/5 18:44
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
public class JHJobApiExecution implements JHApiExecution {
|
||||
|
||||
private JHRequestExecution execution;
|
||||
|
||||
public void init(JHRequestExecution execution) {
|
||||
this.execution = execution;
|
||||
}
|
||||
public class JHJobApiExecution extends JHApiExecutionAbstract {
|
||||
|
||||
/**
|
||||
* 提交作业
|
||||
@@ -91,7 +81,7 @@ public class JHJobApiExecution implements JHApiExecution {
|
||||
* @see JobStatusEnum
|
||||
*/
|
||||
public PageJobInfo getJobPage(String username, Integer page, Integer pageSize, String name, JobStatusEnum status,
|
||||
Map<String, Object> condition) {
|
||||
Map<String, Object> condition) {
|
||||
Map<String, Object> params = new HashMap<>(5);
|
||||
if (page != null) {
|
||||
params.put("page", page);
|
||||
@@ -129,7 +119,7 @@ public class JHJobApiExecution implements JHApiExecution {
|
||||
* @see JobStatusEnum
|
||||
*/
|
||||
public PageJobInfo getJobPage(String username, Integer page, Integer pageSize, String name, String status,
|
||||
Map<String, Object> condition) {
|
||||
Map<String, Object> condition) {
|
||||
return getJobPage(username, page, pageSize, name, JobStatusEnum.getJobStatus(status), condition);
|
||||
}
|
||||
|
||||
@@ -138,7 +128,7 @@ public class JHJobApiExecution implements JHApiExecution {
|
||||
* <p>
|
||||
* 注:name、status、condition均为删选条件,condition为 高级筛选
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param page 页码(非必填,默认:1)
|
||||
* @param pageSize 每页大小(非必填,默认:20)
|
||||
@@ -149,7 +139,7 @@ public class JHJobApiExecution implements JHApiExecution {
|
||||
* @see JobStatusEnum
|
||||
*/
|
||||
public PageJobInfo getHistoryJobs(String username, Integer page, Integer pageSize, String name,
|
||||
JobStatusEnum status, Map<String, Object> condition) {
|
||||
JobStatusEnum status, Map<String, Object> condition) {
|
||||
|
||||
Map<String, Object> params = new HashMap<>(5);
|
||||
if (page != null) {
|
||||
@@ -178,7 +168,7 @@ public class JHJobApiExecution implements JHApiExecution {
|
||||
* <p>
|
||||
* 注:name、status、condition均为删选条件,condition为 高级筛选
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param page 页码(非必填,默认:1)
|
||||
* @param pageSize 每页大小(非必填,默认:20)
|
||||
@@ -189,7 +179,7 @@ public class JHJobApiExecution implements JHApiExecution {
|
||||
* @see JobStatusEnum
|
||||
*/
|
||||
public PageJobInfo getHistoryJobs(String username, Integer page, Integer pageSize, String name, String status,
|
||||
Map<String, Object> condition) {
|
||||
Map<String, Object> condition) {
|
||||
return getHistoryJobs(username, page, pageSize, name, JobStatusEnum.getJobStatus(status), condition);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@ package com.jhinno.sdk.openapi.api.organization;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.jhinno.sdk.openapi.ArgsException;
|
||||
import com.jhinno.sdk.openapi.JHApiExecution;
|
||||
import com.jhinno.sdk.openapi.api.JHRequestExecution;
|
||||
import com.jhinno.sdk.openapi.JHApiExecutionAbstract;
|
||||
import com.jhinno.sdk.openapi.api.ResponseResult;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -20,13 +19,7 @@ import java.util.Map;
|
||||
* @date 2024/2/6 17:37
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
public class JHDepartmentApiExecution implements JHApiExecution {
|
||||
|
||||
private JHRequestExecution execution;
|
||||
|
||||
public void init(JHRequestExecution execution) {
|
||||
this.execution = execution;
|
||||
}
|
||||
public class JHDepartmentApiExecution extends JHApiExecutionAbstract {
|
||||
|
||||
/**
|
||||
* 查询用户列表
|
||||
|
||||
@@ -2,8 +2,7 @@ package com.jhinno.sdk.openapi.api.organization;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.jhinno.sdk.openapi.ArgsException;
|
||||
import com.jhinno.sdk.openapi.JHApiExecution;
|
||||
import com.jhinno.sdk.openapi.api.JHRequestExecution;
|
||||
import com.jhinno.sdk.openapi.JHApiExecutionAbstract;
|
||||
import com.jhinno.sdk.openapi.api.PageResult;
|
||||
import com.jhinno.sdk.openapi.api.ResponseResult;
|
||||
import com.jhinno.sdk.openapi.client.JHApiClient;
|
||||
@@ -22,13 +21,7 @@ import java.util.Map;
|
||||
* @date 2024/2/6 17:37
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
public class JHUserApiExecution implements JHApiExecution {
|
||||
|
||||
private JHRequestExecution execution;
|
||||
|
||||
public void init(JHRequestExecution execution) {
|
||||
this.execution = execution;
|
||||
}
|
||||
public class JHUserApiExecution extends JHApiExecutionAbstract {
|
||||
|
||||
/**
|
||||
* 分页查询用户列表
|
||||
@@ -96,7 +89,7 @@ public class JHUserApiExecution implements JHApiExecution {
|
||||
* @param type 类型,(非必填,取值见{@link UpdateUserPasswordType})
|
||||
*/
|
||||
public void updateUserPassword(String username, String updatePasswordUsername, String oldPassword, String password,
|
||||
String type) {
|
||||
String type) {
|
||||
if (StringUtils.isBlank(updatePasswordUsername)) {
|
||||
throw new ArgsException("updatePasswordUsername不能为空");
|
||||
}
|
||||
@@ -121,7 +114,7 @@ public class JHUserApiExecution implements JHApiExecution {
|
||||
* @param password 新密码
|
||||
*/
|
||||
public void updateUserPassword(String username, String updatePasswordUsername, String oldPassword,
|
||||
String password) {
|
||||
String password) {
|
||||
updateUserPassword(username, updatePasswordUsername, oldPassword, password, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.ParseException;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@@ -63,62 +64,57 @@ public class JHApiHttpClientImpl implements JHApiHttpClient {
|
||||
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客户端实例
|
||||
*
|
||||
* @return 返回一个可关闭的HTTP客户端示例
|
||||
*/
|
||||
public void createHttpClients() {
|
||||
public void createHttpClients(Integer maxTotal, Integer maxPerRoute) {
|
||||
SSLContextBuilder builder = new SSLContextBuilder();
|
||||
try {
|
||||
builder.loadTrustMaterial(null, (x509Certificates, s) -> true);
|
||||
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);
|
||||
cm.setMaxTotal(maxTotal);
|
||||
cm.setDefaultMaxPerRoute(maxPerRoute);
|
||||
if (Objects.nonNull(maxTotal)) {
|
||||
cm.setMaxTotal(maxTotal);
|
||||
}
|
||||
if (Objects.nonNull(maxPerRoute)) {
|
||||
cm.setDefaultMaxPerRoute(maxPerRoute);
|
||||
}
|
||||
closeableHttpClient = HttpClients.custom().setSSLSocketFactory(sslref).setConnectionManager(cm).setConnectionManagerShared(true).build();
|
||||
} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
|
||||
throw new ClientException(e.getMessage(), ClientErrorCode.SSL_EXCEPTION, e);
|
||||
}
|
||||
}
|
||||
|
||||
public void createHttpClients() {
|
||||
createHttpClients(null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化客户端
|
||||
*/
|
||||
public void init() {
|
||||
this.requestConfig = RequestConfig.custom()
|
||||
.setSocketTimeout(socketTimeout)
|
||||
.setConnectTimeout(connectTimeout)
|
||||
.setConnectionRequestTimeout(connectRequestTimeout)
|
||||
.build();
|
||||
public void init(Integer socketTimeout, Integer connectTimeout, Integer connectRequestTimeout) {
|
||||
RequestConfig.Builder custom = RequestConfig.custom();
|
||||
if (Objects.nonNull(socketTimeout)) {
|
||||
custom.setSocketTimeout(socketTimeout);
|
||||
}
|
||||
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();
|
||||
} catch (ParseException e) {
|
||||
throw new ClientException("时间格式获取失败,失败原因:" + e.getMessage(), e);
|
||||
}finally {
|
||||
} finally {
|
||||
httpGet.releaseConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class AppApiTest {
|
||||
public void testStartApp() {
|
||||
AppStartRequest appStartRequest = new AppStartRequest();
|
||||
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("JhAppURL:" + appStartedInfo.getJhappUrl());
|
||||
System.out.println("WebURL:" + appStartedInfo.getWebSessionUrl());
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.jhinno.sdk.openapi.example.api.extend;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.jhinno.sdk.openapi.JHApiExecution;
|
||||
import com.jhinno.sdk.openapi.api.JHRequestExecution;
|
||||
import com.jhinno.sdk.openapi.JHApiExecutionAbstract;
|
||||
import com.jhinno.sdk.openapi.api.ResponseResult;
|
||||
import com.jhinno.sdk.openapi.client.JHApiClient;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -12,44 +11,22 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@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 void init(JHRequestExecution execution) {
|
||||
this.execution = execution;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除作业
|
||||
*
|
||||
* @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 应用ID,如:common_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 getFileEnvPath(String username, FileEnvType env, FileSystemType type) {
|
||||
Map<String, Object> params = new HashMap<>(1);
|
||||
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>>() {
|
||||
});
|
||||
}
|
||||
|
||||
public FilePath getFileHomeEnvPath(String username, FileSystemType type) {
|
||||
return getFileEnvPath(username, FileEnvType.HOME_ENV, type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,13 +23,8 @@ public class JHOpenapiClientAutoConfigure {
|
||||
public JHApiClient jhApiClient(JHOpenapiProperties properties) {
|
||||
JHApiClient jhApiClient = new JHApiClient(properties.getServerUrl());
|
||||
JHApiHttpClientImpl jhApiHttpClient = new JHApiHttpClientImpl();
|
||||
jhApiHttpClient.setMaxPerRoute(properties.getMaxPerRout());
|
||||
jhApiHttpClient.setSocketTimeout(properties.getSocketTimeout());
|
||||
jhApiHttpClient.setMaxTotal(properties.getMaxTotal());
|
||||
jhApiHttpClient.setConnectTimeout(properties.getConnectTimeout());
|
||||
jhApiHttpClient.setConnectRequestTimeout(properties.getConnectRequestTimeout());
|
||||
jhApiHttpClient.init();
|
||||
jhApiHttpClient.createHttpClients();
|
||||
jhApiHttpClient.init(properties.getSocketTimeout(), properties.getConnectTimeout(), properties.getConnectRequestTimeout());
|
||||
jhApiHttpClient.createHttpClients(properties.getMaxTotal(), properties.getMaxPerRout());
|
||||
jhApiClient.setApiHttpClient(jhApiHttpClient);
|
||||
return jhApiClient;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* @author yanlongqi
|
||||
* @date 2024/6/4 16:03
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = CommonConstants.CONFIG_PREFIX)
|
||||
@@ -20,31 +19,31 @@ public class JHOpenapiProperties {
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user