mirror of
https://github.com/yanlongqi/jhinno-openapi-java-sdk.git
synced 2026-03-22 06:15:10 +08:00
Compare commits
14 Commits
fix-config
...
release-2.
| Author | SHA1 | Date | |
|---|---|---|---|
| 7096ec5175 | |||
|
|
4d70ec9bd6 | ||
|
|
0cdae4fba8 | ||
|
|
73691e1373 | ||
|
|
717792f057 | ||
|
|
70c9f2deaf | ||
|
|
db26e8fae6 | ||
|
|
5c5b9c198e | ||
|
|
bc36e3d0ac | ||
|
|
08a56f782a | ||
|
|
1c00f7eaee | ||
|
|
360e30c4ff | ||
|
|
69c4037b4b | ||
|
|
89a3783e69 |
158
README.md
158
README.md
@@ -17,7 +17,8 @@
|
||||
3. JH_Appform_6.1_Release
|
||||
4. JH_Appform_6.2_Release(使用: release-2.0.3)
|
||||
5. JH_Appform_6.3_Release(使用: release-2.0.4)
|
||||
5. JH_Appform_6.3_Release(使用: release-2.0.5)
|
||||
5. JH_Appform_6.4_Release(使用: release-2.0.5)
|
||||
6. JH_Appform_6.5_Release(使用: release-2.0.6)
|
||||
|
||||
# 2. 快速开始
|
||||
|
||||
@@ -64,13 +65,15 @@ mvn clean install
|
||||
<dependency>
|
||||
<groupId>com.jhinno</groupId>
|
||||
<artifactId>jhinno-openapi-sdk-spring-boot-starter</artifactId>
|
||||
<version>${最新的版本号}</version>
|
||||
<version>2.0.6</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
#### 方法三:直接使用 jar 包
|
||||
|
||||
如果开发环境没有网络,或者没有使用 maven 的构建工具,则可以使用 jar 包的方式导入。下载`dependency-jar.zip`和`jhinno-openapi-java-sdk-2.0.3-sources.jar`、`jhinno-openapi-java-sdk-2.0.3.jar`导入到你的 java 项目的 lib 里面。如果你的项目是 SpringBoot 项目,则还需要导入`jhinno-openapi-sdk-spring-boot-starter-2.0.3.jar`、`jhinno-openapi-sdk-spring-boot-starter-2.0.3-sources.jar
|
||||
如果开发环境没有网络,或者没有使用 maven 的构建工具,则可以使用 jar 包的方式导入。下载`dependency-jar.zip`和
|
||||
`jhinno-openapi-java-sdk-2.0.3-sources.jar`、`jhinno-openapi-java-sdk-2.0.3.jar`导入到你的 java 项目的 lib 里面。如果你的项目是
|
||||
SpringBoot 项目,则还需要导入`jhinno-openapi-sdk-spring-boot-starter-2.0.3.jar`、`jhinno-openapi-sdk-spring-boot-starter-2.0.3-sources.jar
|
||||
`这两个 jar 包。
|
||||
|
||||
### 2.1.3 配置
|
||||
@@ -101,14 +104,30 @@ jhinno.openapi.auth-type=access_secret_mode
|
||||
> 注:
|
||||
>
|
||||
> - 其中`jhinno.openapi.server-url`为景行接口服务的 BaseUrl;
|
||||
> - `auth-type` 认证类型,`token_mode`(Token 认证) 和 `access_secret_mode`(AccessKey 认证);Appform Release 6.2 `token_mode`
|
||||
> - `auth-type` 认证类型,`token_mode`(Token 认证) 和 `access_secret_mode`(AccessKey 认证);Appform Release 6.2
|
||||
`token_mode`
|
||||
|
||||
作为过渡,将会弃用;
|
||||
|
||||
> - `jhinno.openapi.used-server-time`是否获取服务器时间来请求 token,关闭可提高获取 token 的时间,但打开有可能因为服务器时间不准确而导致 token 获取失败的问题。
|
||||
> - `jhinno.openapi.used-server-time`是否获取服务器时间来请求 token,关闭可提高获取 token 的时间,但打开有可能因为服务器时间不准确而导致
|
||||
token 获取失败的问题(token模式配置)。
|
||||
> - `access-key` 和 `access-key-secret` 作为访问接口的凭证,需要提供集成商名称、系统名称、负责人姓名、负责电话电话信息申请。
|
||||
> - 更多配置见`com.jhinno.sdk.openapi.autoconfigure.JHOpenapiProperties`源码。
|
||||
|
||||
```java
|
||||
// 新增全局用户获取方式
|
||||
@Configuration
|
||||
public class ApiConfig implements JHApiRequestHandler {
|
||||
|
||||
@Override
|
||||
public String getCurrentUserName() {
|
||||
return "yanlongqi";
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
### 2.1.4 使用
|
||||
|
||||
在`com.jhinno.sdk.openapi.api`包下面对应`app`、`data`、`file`、`job`、`organization`这几个子包,分别代表景行`Appform`
|
||||
@@ -129,6 +148,10 @@ public class DemoUserSDK {
|
||||
// 调用执行其中想要调用的方法
|
||||
List<FileInfo> list = fileApiExecution.getFileList("jhadmin", "$HOME");
|
||||
System.out.println(list);
|
||||
|
||||
// 如果配置全局的 JHApiRequestHandler 方式获取用户名,可以不用传userName
|
||||
List<FileInfo> list1 = fileApiExecution.getFileList("$HOME");
|
||||
System.out.println(list1);
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -185,15 +208,17 @@ spring.xml 添加以下内容
|
||||
</bean>
|
||||
|
||||
<bean id="requestExecution" class="com.jhinno.sdk.openapi.api.JHRequestExecution">
|
||||
<constructor-arg ref="apiClient" />
|
||||
<constructor-arg ref="apiClient"/>
|
||||
</bean>
|
||||
|
||||
<bean id="appApiExecution" class="com.jhinno.sdk.openapi.api.app.JHAppApiExecution" init-method="init"></bean>
|
||||
<bean id="dataApiExecution" class="com.jhinno.sdk.openapi.api.data.JHDataApiExecution" init-method="init"></bean>
|
||||
<bean id="fileApiExecution" class="com.jhinno.sdk.openapi.api.file.JHFileApiExecution" init-method="init"></bean>
|
||||
<bean id="jhJobApiExecution" class="com.jhinno.sdk.openapi.api.job.JHJobApiExecution" init-method="init"></bean>
|
||||
<bean id="departmentApiExecution" class="com.jhinno.sdk.openapi.api.organization.JHDepartmentApiExecution" init-method="init"></bean>
|
||||
<bean id="userApiExecution" class="com.jhinno.sdk.openapi.api.organization.JHUserApiExecution" init-method="init"></bean>
|
||||
<bean id="appApiExecution" class="com.jhinno.sdk.openapi.api.app.JHAppApiExecution" init-method="setExecution"></bean>
|
||||
<bean id="dataApiExecution" class="com.jhinno.sdk.openapi.api.data.JHDataApiExecution" init-method="setExecution"></bean>
|
||||
<bean id="fileApiExecution" class="com.jhinno.sdk.openapi.api.file.JHFileApiExecution" init-method="setExecution"></bean>
|
||||
<bean id="jhJobApiExecution" class="com.jhinno.sdk.openapi.api.job.JHJobApiExecution" init-method="setExecution"></bean>
|
||||
<bean id="departmentApiExecution" class="com.jhinno.sdk.openapi.api.organization.JHDepartmentApiExecution"
|
||||
init-method="setExecution"></bean>
|
||||
<bean id="userApiExecution" class="com.jhinno.sdk.openapi.api.organization.JHUserApiExecution"
|
||||
init-method="setExecution"></bean>
|
||||
</beans>
|
||||
```
|
||||
|
||||
@@ -252,36 +277,95 @@ public class DemoUserSDK {
|
||||
|
||||
```java
|
||||
|
||||
public class JHApiUtile {
|
||||
public class JHClientConfig {
|
||||
|
||||
public static final JHApiRequestHandler REQUEST_HANDLER = new JHApiRequestHandler() {
|
||||
@Override
|
||||
public String getCurrentUserName() {
|
||||
return "yanlongqi";
|
||||
}
|
||||
};
|
||||
|
||||
public static final String APPFORM_SERVER_URL = "https://172.20.0.200";
|
||||
public static final String ACCESS_KEY = "8147c7470bfd4a27952fe750c6bc7cef";
|
||||
public static final String ACCESS_KEY_SECRET = "899b13f590394c3daafc6468fed4b1df";
|
||||
|
||||
|
||||
/**
|
||||
* 创建一个API执行器管理器
|
||||
*/
|
||||
public static final JHApiExecutionManage API_EXECUTION_MANAGE = new JHApiExecutionManage("https://192.168.87.24");
|
||||
public static final JHApiExecutionManage API_EXECUTION_MANAGE = new JHApiExecutionManage(APPFORM_SERVER_URL, REQUEST_HANDLER);
|
||||
|
||||
public static final String ACCESS_KEY = "3f03747f147942bd8debd81b6c9c6a80";
|
||||
|
||||
public static final String ACCESS_KEY_SECRET = "e0681859b91c499eb1d2c8e09cea3242";
|
||||
|
||||
static {
|
||||
// 配置API执行器管理器,设置认证信息等。
|
||||
API_EXECUTRON_MANAGE.configureApiExecution(t -> {
|
||||
API_EXECUTION_MANAGE.configureApiExecution(t -> {
|
||||
// 默认为使用Token模式,如何使用的Token模式,则不需要配置ACCESS_KEY和ACCESS_KEY SECRET
|
||||
// t.setAuthType(AuthType.ACCESS_KEY);
|
||||
t.setAuthType(AuthType.ACCESS_SECRET_MODE);
|
||||
t.setAccessKey(ACCESS_KEY);
|
||||
t.setAccessKeySecret(ACCESS_KEY_SECRET);
|
||||
});
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
}
|
||||
|
||||
// 从API执行器管理器取出调用应用相关接口的执行器
|
||||
JHAppApiExecution jhAppApiExecution = JHClientConfig.API_EXECUTION_MANAGE.getApiExecution(JHAppApiExecution.class);
|
||||
public class AppApiTest {
|
||||
|
||||
// 调用启动会话的接口
|
||||
jhAppApiExecution.desktopStart("jhadmin", "linux_desktop");
|
||||
/**
|
||||
* 获得一个调用应用接口的执行器
|
||||
*/
|
||||
public static final JHAppApiExecution jhAppApiExecution = JHClientConfig.API_EXECUTION_MANAGE.getApiExecution(JHAppApiExecution.class);
|
||||
|
||||
/**
|
||||
* 测测试使用自定义的参数启动jhadmin的Linux桌面
|
||||
*/
|
||||
@Test
|
||||
public void testStartApp() {
|
||||
AppStartRequest appStartRequest = new AppStartRequest();
|
||||
appStartRequest.setStartNew(true);
|
||||
AppStartedInfo appStartedInfo = jhAppApiExecution.desktopStart("linux_desktop", appStartRequest);
|
||||
System.out.println("会话ID:" + appStartedInfo.getDesktopId());
|
||||
System.out.println("JhAppURL:" + appStartedInfo.getJhappUrl());
|
||||
System.out.println("WebURL:" + appStartedInfo.getWebSessionUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试查询用户的应用列表
|
||||
*/
|
||||
@Test
|
||||
public void testGetAppList() {
|
||||
List<AppInfo> appList = jhAppApiExecution.getAppList();
|
||||
System.out.println("全部列表:");
|
||||
System.out.println(JsonUtil.objectToString(appList));
|
||||
|
||||
// 类型获取
|
||||
System.out.println("系统应用:");
|
||||
System.out.println(JsonUtil.objectToString(AppTypeConstant.AppType.SYSTEM_APP.getAppList(appList)));
|
||||
|
||||
System.out.println("计算应用:");
|
||||
System.out.println(JsonUtil.objectToString(AppTypeConstant.AppType.BATCH_APP.getAppList(appList)));
|
||||
|
||||
System.out.println("图形应用:");
|
||||
System.out.println(JsonUtil.objectToString(AppTypeConstant.AppType.DESKTOP_APP.getAppList(appList)));
|
||||
|
||||
// 操作系统分类
|
||||
System.out.println("系统应用:");
|
||||
System.out.println(JsonUtil.objectToString(AppTypeConstant.AppOsType.SYSTEM.getAppList(appList)));
|
||||
|
||||
System.out.println("Linux应用:");
|
||||
System.out.println(JsonUtil.objectToString(AppTypeConstant.AppOsType.LINUX.getAppList(appList)));
|
||||
|
||||
System.out.println("Windows应用:");
|
||||
System.out.println(JsonUtil.objectToString(AppTypeConstant.AppOsType.WINDOWS.getAppList(appList)));
|
||||
|
||||
// 应用分类
|
||||
System.out.println("系统应用:");
|
||||
System.out.println(JsonUtil.objectToString(AppTypeConstant.AppCategory.SYSTEM.getAppList(appList)));
|
||||
|
||||
System.out.println("景行发布应用:");
|
||||
System.out.println(JsonUtil.objectToString(AppTypeConstant.AppCategory.APP.getAppList(appList)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
```
|
||||
@@ -306,18 +390,11 @@ public class JHApiUtile {
|
||||
* 注意:一下代码为伪代码,需要根据实际的情况进行修改,其示例代码可参照SDK中JHDemoApiExecution子类的实现
|
||||
*/
|
||||
@Component
|
||||
public class JHDemoApiExecution extends JHApiExecution {
|
||||
|
||||
private JHRequestExecution execution;
|
||||
|
||||
@Override
|
||||
public void init(JHRequestExecution execution) {
|
||||
this.execution = execution;
|
||||
}
|
||||
public class JHDemoApiExecution extends JHApiExecutionAbstract {
|
||||
|
||||
public XxxDTO getXXXX(String username, String demoParams) {
|
||||
|
||||
return execution.get("/demo/path", username, new TypeReference<ResponseResult<XxxDTO>>() {
|
||||
return super.execution.get("/demo/path", username, new TypeReference<ResponseResult<XxxDTO>>() {
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -332,7 +409,7 @@ public class JHDemoApiExecution extends JHApiExecution {
|
||||
/**
|
||||
* 注意:一下代码为伪代码,需要根据实际的情况进行修改,其示例代码可参照SDK中JHDemoApiExecution子类的实现
|
||||
*/
|
||||
public class JHDemoApiExecution extends JHApiExecution {
|
||||
public class JHDemoApiExecution {
|
||||
|
||||
@Autowired
|
||||
private JHRequestExecution execution;
|
||||
@@ -353,18 +430,11 @@ public class JHDemoApiExecution extends JHApiExecution {
|
||||
/**
|
||||
* 注意:一下代码为伪代码,需要根据实际的情况进行修改,其示例代码可参照SDK中JHDemoApiExecution子类的实现
|
||||
*/
|
||||
public class JHDemoApiExecution extends JHApiExecution {
|
||||
|
||||
private JHRequestExecution execution;
|
||||
|
||||
@Override
|
||||
public void init(JHRequestExecution execution) {
|
||||
this.execution = execution;
|
||||
}
|
||||
public class JHDemoApiExecution extends JHApiExecutionAbstract {
|
||||
|
||||
public XxxDTO getXXXX(String username, String demoParams) {
|
||||
|
||||
return execution.get("/demo/path", username, new TypeReference<ResponseResult<XxxDTO>>() {
|
||||
return super.execution.get("/demo/path", username, new TypeReference<ResponseResult<XxxDTO>>() {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>jhinno-openapi-java-sdk</artifactId>
|
||||
<version>2.0.5</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>Jhinno OpenAPI SDK for Java</name>
|
||||
<description>The Jhinno OpenAPI SDK for Java used for accessing Jhinno OpenApi Service</description>
|
||||
@@ -14,7 +13,7 @@
|
||||
<parent>
|
||||
<groupId>com.jhinno</groupId>
|
||||
<artifactId>jhinno-openapi-java-sdk-parent</artifactId>
|
||||
<version>2.0.5</version>
|
||||
<version>2.0.8</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package com.jhinno.sdk.openapi;
|
||||
|
||||
import com.jhinno.sdk.openapi.api.JHRequestExecution;
|
||||
|
||||
public interface JHApiExecution {
|
||||
|
||||
/**
|
||||
* 初始化API执行器
|
||||
*/
|
||||
void init(JHRequestExecution execution);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.jhinno.sdk.openapi;
|
||||
|
||||
import com.jhinno.sdk.openapi.api.JHRequestExecution;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
public abstract class JHApiExecutionAbstract {
|
||||
|
||||
// 提供setter方法,支持依赖注入
|
||||
protected JHRequestExecution execution;
|
||||
|
||||
// 默认构造函数,允许子类不实现构造方法
|
||||
public JHApiExecutionAbstract() {
|
||||
}
|
||||
|
||||
// 带参数的构造函数,允许直接注入
|
||||
public JHApiExecutionAbstract(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;
|
||||
|
||||
/**
|
||||
@@ -23,13 +23,18 @@ public class JHApiExecutionManage {
|
||||
*
|
||||
* @param appformBaseUrl 景行API的URL
|
||||
*/
|
||||
public JHApiExecutionManage(String appformBaseUrl) {
|
||||
public JHApiExecutionManage(String appformBaseUrl, JHApiRequestHandler requestHandler) {
|
||||
JHApiClient client = new JHApiClient(appformBaseUrl);
|
||||
client.initDefaultApiClient();
|
||||
EXECUTION = new JHRequestExecution(client);
|
||||
EXECUTION = new JHRequestExecution(client, requestHandler);
|
||||
initApiExecution();
|
||||
}
|
||||
|
||||
public JHApiExecutionManage(String appformBaseUrl) {
|
||||
this(appformBaseUrl, new JHApiRequestHandler() {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个带有自定义HTTP客户端的API执行管理器
|
||||
*
|
||||
@@ -48,15 +53,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,8 +75,8 @@ public class JHApiExecutionManage {
|
||||
*
|
||||
* @param execution 自定义的执行器实例
|
||||
*/
|
||||
public void registerApiExecution(JHApiExecution execution) {
|
||||
execution.init(EXECUTION);
|
||||
public void registerApiExecution(JHApiExecutionAbstract execution) {
|
||||
execution.setExecution(EXECUTION);
|
||||
API_CLIENT_MAP.put(execution.getClass(), execution);
|
||||
}
|
||||
|
||||
@@ -85,14 +87,14 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* API执行器配置器接口,用于配置API执行器的参数
|
||||
*/
|
||||
public static interface ApiExecutionConfigurator {
|
||||
public interface ApiExecutionConfigurator {
|
||||
|
||||
/**
|
||||
* 配置API执行器的参数
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.jhinno.sdk.openapi;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface JHApiRequestHandler {
|
||||
|
||||
/**
|
||||
* 获取当前登录的用户名
|
||||
*
|
||||
* @return 用户名
|
||||
*/
|
||||
default String getCurrentUserName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建一个带token的请求头
|
||||
*
|
||||
* @param headers 处理器的请求头
|
||||
* @return 请求头
|
||||
*/
|
||||
default Map<String, Object> getHeaders(Map<String, Object> headers) {
|
||||
return headers;
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,11 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
@NoArgsConstructor
|
||||
public class JHRequestExecution {
|
||||
|
||||
/**
|
||||
* 用户令牌的缓存
|
||||
*/
|
||||
private static final Map<String, TokenInfo> TOKEN_INFO_MAP = new ConcurrentHashMap<>(20);
|
||||
|
||||
/**
|
||||
* JHApiClient实例
|
||||
*/
|
||||
@@ -84,29 +89,49 @@ public class JHRequestExecution {
|
||||
*/
|
||||
private String accessKeySecret;
|
||||
|
||||
private JHApiRequestHandler requestHandler;
|
||||
|
||||
/**
|
||||
* 获取一个执行器的实例
|
||||
*
|
||||
* @param jhApiClient 请求的客户端
|
||||
* @param requestHandler 请求头处理器
|
||||
*/
|
||||
public JHRequestExecution(JHApiClient jhApiClient, JHApiRequestHandler requestHandler) {
|
||||
this.jhApiClient = jhApiClient;
|
||||
this.requestHandler = requestHandler;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建一个默认的请求处理器
|
||||
*
|
||||
* @param jhApiClient 请求的客户端
|
||||
*/
|
||||
public JHRequestExecution(JHApiClient jhApiClient) {
|
||||
this.jhApiClient = jhApiClient;
|
||||
this.requestHandler = new JHApiRequestHandler() {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public String getUserName(String userName) {
|
||||
if (StringUtils.isNotBlank(userName)) {
|
||||
return userName;
|
||||
}
|
||||
return requestHandler.getCurrentUserName();
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户令牌的缓存
|
||||
*/
|
||||
private static final Map<String, TokenInfo> TOKEN_INFO_MAP = new ConcurrentHashMap<>(20);
|
||||
|
||||
/**
|
||||
* 设置是否使用服务器时间
|
||||
* 获取当前用户的token
|
||||
*
|
||||
* @param usedServerTime 是否使用服务器时间
|
||||
* @return 用户token
|
||||
*/
|
||||
public void setUsedServerTime(boolean usedServerTime) {
|
||||
isUsedServerTime = usedServerTime;
|
||||
public String getToken() {
|
||||
return getToken(requestHandler.getCurrentUserName());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户的Token
|
||||
*
|
||||
@@ -117,43 +142,62 @@ public class JHRequestExecution {
|
||||
if (StringUtils.isBlank(username)) {
|
||||
throw new ArgsException("用户名称不能为空!");
|
||||
}
|
||||
TokenInfo tokenInfo = TOKEN_INFO_MAP.get(username);
|
||||
|
||||
// 防止因为服务器时间的问题二导致token不可用,可以通过此配置提前获取token
|
||||
int tokenEffectiveTime = (tokenTimeout - tokenResidueTime) * 60 * 1000;
|
||||
|
||||
// 如果是强制获取、用户令牌为空、用户令牌过期等,则获取令牌
|
||||
if (isForceGetToken || tokenInfo == null
|
||||
|| System.currentTimeMillis() - tokenInfo.getCurrentTimestamp() > tokenEffectiveTime) {
|
||||
Map<String, Object> params = new HashMap<>(2);
|
||||
params.put("timeout", tokenTimeout);
|
||||
String currentTimeMillis = getCurrentTimeMillis();
|
||||
String beforeEncryption = String.format(CommonConstant.TokenUserFormat, username, currentTimeMillis);
|
||||
try {
|
||||
SecretKeySpec secretKey = new SecretKeySpec(
|
||||
CommonConstant.DEFAULT_AES_KEY.getBytes(StandardCharsets.UTF_8), CommonConstant.AES_ALGORITHM);
|
||||
Cipher cipher = Cipher.getInstance(CommonConstant.AES_ECB_PADDING);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
|
||||
byte[] encryptBytes = cipher.doFinal(beforeEncryption.getBytes(StandardCharsets.UTF_8));
|
||||
params.put("username", Base64.getEncoder().encodeToString(encryptBytes));
|
||||
} catch (Exception e) {
|
||||
throw new ClientException("AES加密失败,失败原因:" + e.getMessage(), e);
|
||||
}
|
||||
// 使用computeIfAbsent确保原子性操作,避免重复获取token
|
||||
TokenInfo tokenInfo = TOKEN_INFO_MAP.computeIfAbsent(username, this::createNewTokenInfo);
|
||||
|
||||
String url = JHApiClient.getUrl(AuthPathConstant.AUTH_TOKEN_PATH, params);
|
||||
Map<String, String> token = get(url, new TypeReference<ResponseResult<Map<String, String>>>() {
|
||||
});
|
||||
tokenInfo = new TokenInfo();
|
||||
tokenInfo.setUserName(username);
|
||||
tokenInfo.setToken(token.get("token"));
|
||||
tokenInfo.setCurrentTimestamp(System.currentTimeMillis());
|
||||
TOKEN_INFO_MAP.put(username, tokenInfo);
|
||||
// 检查token是否过期,如果过期则创建新token
|
||||
long currentTime = System.currentTimeMillis();
|
||||
if (isForceGetToken || currentTime - tokenInfo.getCurrentTimestamp() > tokenEffectiveTime) {
|
||||
synchronized (this) {
|
||||
// 双重检查锁定,确保在同步块中再次检查
|
||||
tokenInfo = TOKEN_INFO_MAP.get(username);
|
||||
if (tokenInfo == null || currentTime - tokenInfo.getCurrentTimestamp() > tokenEffectiveTime || isForceGetToken) {
|
||||
tokenInfo = createNewTokenInfo(username);
|
||||
TOKEN_INFO_MAP.put(username, tokenInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tokenInfo.getToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* 创建新的TokenInfo
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 新的TokenInfo
|
||||
*/
|
||||
private TokenInfo createNewTokenInfo(String username) {
|
||||
Map<String, Object> params = new HashMap<>(2);
|
||||
params.put("timeout", tokenTimeout);
|
||||
String currentTimeMillis = getCurrentTimeMillis();
|
||||
String beforeEncryption = String.format(CommonConstant.TokenUserFormat, username, currentTimeMillis);
|
||||
try {
|
||||
SecretKeySpec secretKey = new SecretKeySpec(
|
||||
CommonConstant.DEFAULT_AES_KEY.getBytes(StandardCharsets.UTF_8), CommonConstant.AES_ALGORITHM);
|
||||
Cipher cipher = Cipher.getInstance(CommonConstant.AES_ECB_PADDING);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
|
||||
byte[] encryptBytes = cipher.doFinal(beforeEncryption.getBytes(StandardCharsets.UTF_8));
|
||||
params.put("username", Base64.getEncoder().encodeToString(encryptBytes));
|
||||
} catch (Exception e) {
|
||||
throw new ClientException("AES加密失败,失败原因:" + e.getMessage(), e);
|
||||
}
|
||||
|
||||
TokenInfo tokenInfo = new TokenInfo();
|
||||
tokenInfo.setUserName(username);
|
||||
tokenInfo.setToken(requestToken(params));
|
||||
tokenInfo.setCurrentTimestamp(System.currentTimeMillis());
|
||||
return tokenInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前的时间
|
||||
*
|
||||
* @return 当前时间
|
||||
*/
|
||||
public String getCurrentTimeMillis() {
|
||||
if (authType == AuthType.ACCESS_SECRET_MODE || !isUsedServerTime) {
|
||||
@@ -162,14 +206,37 @@ public class JHRequestExecution {
|
||||
return jhApiClient.getAppformServerCurrentTimeMillis();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构建一个带token的请求头
|
||||
* 获得最终的请求头
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param isContentType 是否携带默认的Content-type,默认为{@link ContentType#APPLICATION_JSON}
|
||||
* @return 请求头
|
||||
*/
|
||||
public Map<String, Object> getHeaders(String username, boolean isContentType) {
|
||||
Map<String, Object> defaultHeaders = getDefaultHeaders(getUserName(username), isContentType);
|
||||
return requestHandler.getHeaders(defaultHeaders);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得当前用户的请求头
|
||||
*
|
||||
* @param isContentType 是否携带默认的Content-type,默认为{@link ContentType#APPLICATION_JSON}
|
||||
* @return 请求头
|
||||
*/
|
||||
public Map<String, Object> getHeaders(boolean isContentType) {
|
||||
return getHeaders(null, isContentType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建一个默认参数的请求头
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param isContentType 是否携带默认的Content-type,默认为{@link ContentType#APPLICATION_JSON}
|
||||
* @return 请求头
|
||||
*/
|
||||
private Map<String, Object> getDefaultHeaders(String username, boolean isContentType) {
|
||||
Map<String, Object> headers = new HashMap<>();
|
||||
// 默认请求json数据
|
||||
if (isContentType) {
|
||||
@@ -198,6 +265,16 @@ public class JHRequestExecution {
|
||||
return headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得一个签名
|
||||
*
|
||||
* @param currentTimeMillis 时间戳
|
||||
* @return 签名
|
||||
*/
|
||||
public String getsSignature(String currentTimeMillis) {
|
||||
return getsSignature(requestHandler.getCurrentUserName(), currentTimeMillis);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取签名
|
||||
*
|
||||
@@ -259,6 +336,17 @@ public class JHRequestExecution {
|
||||
return result.getData();
|
||||
}
|
||||
|
||||
private String requestToken(Map<String, Object> params) {
|
||||
String url = JHApiClient.getUrl(AuthPathConstant.AUTH_TOKEN_PATH, params);
|
||||
ResponseResult<Map<String, String>> result = jhApiClient.get(url, new TypeReference<ResponseResult<Map<String, String>>>() {
|
||||
});
|
||||
if (StringUtils.equals(result.getResult(), CommonConstant.FAILED)) {
|
||||
throw new ServiceException(url, result.getCode(), result.getMessage());
|
||||
}
|
||||
Map<String, String> token = result.getData();
|
||||
return token.get("token");
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起一个有返回值的POST请求
|
||||
*
|
||||
@@ -412,7 +500,7 @@ public class JHRequestExecution {
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出用户的登录,释放许可,当用户退出登录后,建议清除用户的token信息
|
||||
* 退出用户的登录,释放许可
|
||||
*
|
||||
* @param username 用户名
|
||||
*/
|
||||
@@ -420,4 +508,11 @@ public class JHRequestExecution {
|
||||
delete(AuthPathConstant.AUTH_LOGOUT, username);
|
||||
TOKEN_INFO_MAP.remove(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出当前用户的登录
|
||||
*/
|
||||
public void logout() {
|
||||
logout(requestHandler.getCurrentUserName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.jhinno.sdk.openapi.api.app;
|
||||
|
||||
import com.jhinno.sdk.openapi.api.JHRequestExecution;
|
||||
import com.jhinno.sdk.openapi.client.JHApiClient;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
@@ -29,6 +31,24 @@ public class AppInfo {
|
||||
|
||||
/**
|
||||
* 应用图标
|
||||
*
|
||||
* <p>
|
||||
* 示例数据:/appform/images/apps/app_fluent.png
|
||||
* <p>
|
||||
* 需要使用 {@link JHApiClient#getUrl(String)} 拼接景行的服务器地址;使用Spring,JHApiClient在容器中,可以使用注入的方式获得
|
||||
*
|
||||
* <pre>{@code
|
||||
* @Autoward
|
||||
* private JHApiClient apiClient;
|
||||
*
|
||||
* public String getIconUrl(String icon){
|
||||
* return apiClient.getUrl(icon);
|
||||
* }
|
||||
*
|
||||
* }</pre>
|
||||
*
|
||||
* <p>
|
||||
* 拼接后的示例数据:https://192.168.87.24/appform/images/apps/app_fluent.png
|
||||
*/
|
||||
private String icon;
|
||||
private String copyAppClass;
|
||||
@@ -67,6 +87,18 @@ public class AppInfo {
|
||||
|
||||
private String mode;
|
||||
|
||||
/**
|
||||
* 操作系统类型
|
||||
* <ul>
|
||||
* <li>空:系统应用,如:我的会话、我的作业、应用仓库等。</li>
|
||||
* <li>linux: 应用是Linux应用</li>
|
||||
* <li>windows: 应用是Windows应用</li>
|
||||
* </ul>
|
||||
*
|
||||
* @see AppTypeConstant.AppOsType 定义了 os 可能的值
|
||||
* <p>
|
||||
* 如果需要获取特定分类的应用列表,可以使用 {@link AppTypeConstant.AppOsType#getAppList(List)}
|
||||
*/
|
||||
private String os;
|
||||
|
||||
private String showin;
|
||||
@@ -77,16 +109,31 @@ public class AppInfo {
|
||||
|
||||
/**
|
||||
* 应用类型
|
||||
*
|
||||
* <ul>
|
||||
* <li>空:系统应用,如:我的会话、我的作业、应用仓库等。</li>
|
||||
* <li>batch: 计算应用,如:通用计算、Fluent等</li>
|
||||
* <li>desktop: 图形应用。如:Windows桌面、Linux桌面、Notepad等</li>
|
||||
* </ul>
|
||||
*
|
||||
* @see AppTypeConstant.AppType 定义了 os 可能的值
|
||||
* <p>
|
||||
* 如果需要获取特定分类的应用列表,可以使用 {@link AppTypeConstant.AppType#getAppList(List)}
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 应用分类
|
||||
* <p>
|
||||
* 系统应用返回system,其他为空字符串
|
||||
*/
|
||||
private String category;
|
||||
|
||||
/**
|
||||
* 应用协议
|
||||
* <p>
|
||||
* 图形会话返回jhapp,其他应用为空字符串
|
||||
* </p>
|
||||
*/
|
||||
private String protocol;
|
||||
|
||||
@@ -156,4 +203,19 @@ public class AppInfo {
|
||||
private String cwd;
|
||||
|
||||
|
||||
private String apiKey;
|
||||
|
||||
/**
|
||||
* 应用状态
|
||||
*/
|
||||
private String appStatus;
|
||||
|
||||
/**
|
||||
* 应用描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
|
||||
private Boolean used;
|
||||
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ public class AppPathConstant {
|
||||
/**
|
||||
* WEB启动会话URL
|
||||
*/
|
||||
public static final String WEB_SESSION_URL_PATH = "/pageapi/apps/webclient/gui/{desktopId}";
|
||||
public static final String WEB_SESSION_URL_PATH = "/appform/ws/api/apps/webclient/{sessionId}/connect";
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.jhinno.sdk.openapi.api.app;
|
||||
|
||||
import com.jhinno.sdk.openapi.utils.CollectionUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class AppTypeConstant {
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum AppType {
|
||||
/**
|
||||
* 系统应用
|
||||
*/
|
||||
SYSTEM_APP(StringUtils.EMPTY),
|
||||
BATCH_APP("batch"),
|
||||
DESKTOP_APP("desktop"),
|
||||
;
|
||||
|
||||
private final String type;
|
||||
|
||||
public List<AppInfo> getAppList(List<AppInfo> list) {
|
||||
if (CollectionUtil.isEmpty(list)) {
|
||||
return list;
|
||||
}
|
||||
return list.stream()
|
||||
.filter(t -> StringUtils.equals(t.getType(), this.type))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum AppOsType {
|
||||
SYSTEM(StringUtils.EMPTY),
|
||||
LINUX("linux"),
|
||||
WINDOWS("windows"),
|
||||
;
|
||||
|
||||
private final String os;
|
||||
|
||||
public List<AppInfo> getAppList(List<AppInfo> list) {
|
||||
if (CollectionUtil.isEmpty(list)) {
|
||||
return list;
|
||||
}
|
||||
return list.stream()
|
||||
.filter(t -> StringUtils.equals(t.getOs(), this.os))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum AppCategory {
|
||||
SYSTEM("system"),
|
||||
APP(StringUtils.EMPTY);
|
||||
|
||||
private final String category;
|
||||
|
||||
public List<AppInfo> getAppList(List<AppInfo> list) {
|
||||
if (CollectionUtil.isEmpty(list)) {
|
||||
return list;
|
||||
}
|
||||
return list.stream()
|
||||
.filter(t -> StringUtils.equals(t.getCategory(), this.category))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +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.AuthType;
|
||||
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;
|
||||
@@ -23,13 +18,8 @@ import java.util.Map;
|
||||
* @author yanlongqi
|
||||
* @date 2024/2/1 16:26
|
||||
*/
|
||||
public class JHAppApiExecution implements JHApiExecution {
|
||||
public class JHAppApiExecution extends JHApiExecutionAbstract {
|
||||
|
||||
private JHRequestExecution execution;
|
||||
|
||||
public void init(JHRequestExecution execution) {
|
||||
this.execution = execution;
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动一个会话
|
||||
@@ -92,21 +82,14 @@ public class JHAppApiExecution implements JHApiExecution {
|
||||
return appStartedInfo;
|
||||
}
|
||||
|
||||
public String getWebSessionUrl(String username, String desktopId) {
|
||||
String webSessionUrlPath = AppPathConstant.WEB_SESSION_URL_PATH.replace("{desktopId}", desktopId);
|
||||
String url = execution.getJhApiClient().getUrl(webSessionUrlPath);
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
AuthType authType = execution.getAuthType();
|
||||
if (authType == AuthType.TOKEN_MODE) {
|
||||
params.put(CommonConstant.TOKEN, execution.getToken(username));
|
||||
} else if (authType == AuthType.ACCESS_SECRET_MODE) {
|
||||
params.put(CommonConstant.USERNAME, username);
|
||||
params.put(CommonConstant.ACCESS_KEY, execution.getAccessKey());
|
||||
String currentTimeMillis = execution.getCurrentTimeMillis();
|
||||
params.put(CommonConstant.CURRENT_TIME_MILLIS, currentTimeMillis);
|
||||
params.put(CommonConstant.SIGNATURE, execution.getsSignature(username, currentTimeMillis));
|
||||
public String getWebSessionUrl(String username, String sessionId) {
|
||||
String webSessionUrlPath = AppPathConstant.WEB_SESSION_URL_PATH.replace("{sessionId}", sessionId);
|
||||
Map<String, String> result = execution.get(webSessionUrlPath, username, new TypeReference<ResponseResult<Map<String, String>>>() {
|
||||
});
|
||||
if (CollectionUtil.isEmpty(result)) {
|
||||
return null;
|
||||
}
|
||||
return JHApiClient.getUrl(url, params);
|
||||
return result.get("url");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,7 +202,7 @@ public class JHAppApiExecution implements JHApiExecution {
|
||||
* @param isTransfer 是否传递操作权(不确定,需要咨询产品,非必填)
|
||||
*/
|
||||
public void shareDesktop(String username, String sessionId, List<String> observers, List<String> interacts,
|
||||
String isTransfer) {
|
||||
String isTransfer) {
|
||||
if (StringUtils.isBlank(sessionId)) {
|
||||
throw new ArgsException("sessionId为必填字段");
|
||||
}
|
||||
@@ -462,4 +445,201 @@ public class JHAppApiExecution implements JHApiExecution {
|
||||
return execution.get(path, username, new TypeReference<ResponseResult<List<UseLabelInfo>>>() {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动一个会话
|
||||
*
|
||||
* @param appId 应用ID
|
||||
* @return JHClient协议链接
|
||||
*/
|
||||
public AppStartedInfo desktopStart(String appId) {
|
||||
return desktopStart(appId, new AppStartRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动一个会话
|
||||
*
|
||||
* @param appId 应用ID
|
||||
* @param appStartRequest 启动参数
|
||||
* @return JHClient协议链接
|
||||
*/
|
||||
public AppStartedInfo desktopStart(String appId, AppStartRequest appStartRequest) {
|
||||
return desktopStart(null, appId, appStartRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Web会话URL
|
||||
*
|
||||
* @param sessionId 会话ID
|
||||
* @return Web会话URL
|
||||
*/
|
||||
public String getWebSessionUrl(String sessionId) {
|
||||
return getWebSessionUrl(null, sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前用户的会话列表
|
||||
*
|
||||
* @return 会话列表
|
||||
*/
|
||||
public List<SessionInfo> getDesktopList() {
|
||||
return getDesktopList(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用参数查询会话列表
|
||||
*
|
||||
* @param sessionIds 会话ID列表(非必填)
|
||||
* @param sessionName 会话名称(非必填)
|
||||
* @return 会话列表
|
||||
*/
|
||||
public List<SessionInfo> getDesktopsByParams(List<String> sessionIds, String sessionName) {
|
||||
return getDesktopsByParams(null, sessionIds, sessionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据会话ID列表查询会话列表
|
||||
*
|
||||
* @param ids 会话ID列表
|
||||
* @return 会话列表
|
||||
*/
|
||||
public List<SessionInfo> getDesktopsById(List<String> ids) {
|
||||
return getDesktopsById(null, ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据会话名称查询会话
|
||||
*
|
||||
* @param sessionName 会话名称
|
||||
* @return 会话列表
|
||||
*/
|
||||
public List<SessionInfo> getDesktopsByName(String sessionName) {
|
||||
return getDesktopsByName(null, sessionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 会话共享
|
||||
*
|
||||
* @param sessionId 会话ID(必填)
|
||||
* @param observers 观察者列表(非必填)
|
||||
* @param interacts 协作者列表(非必填)
|
||||
* @param isTransfer 是否传递操作权(非必填)
|
||||
*/
|
||||
public void shareDesktop(String sessionId, List<String> observers, List<String> interacts, String isTransfer) {
|
||||
shareDesktop(null, sessionId, observers, interacts, isTransfer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消会话共享
|
||||
*
|
||||
* @param sessionId 会话ID
|
||||
*/
|
||||
public void cancelShare(String sessionId) {
|
||||
cancelShare(null, sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 传递会话操作权
|
||||
*
|
||||
* @param sessionId 会话ID(必填)
|
||||
* @param interact 操作权(必填)
|
||||
*/
|
||||
public void transferOperatorRight(String sessionId, String interact) {
|
||||
transferOperatorRight(null, sessionId, interact);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接会话
|
||||
*
|
||||
* @param sessionId 会话ID
|
||||
* @return JHClient协议链接信息
|
||||
*/
|
||||
public AppStartedInfo connectJhapp(String sessionId) {
|
||||
return connectJhapp(null, sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 断开会话连接
|
||||
*
|
||||
* @param sessionId 会话ID
|
||||
*/
|
||||
public void disconnectSessionInfo(String sessionId) {
|
||||
disconnectSessionInfo(null, sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过应用ID批量断开会话
|
||||
*
|
||||
* @param sessionIds 会话ID列表
|
||||
*/
|
||||
public void disconnectSessionByIds(List<String> sessionIds) {
|
||||
disconnectSessionByIds(null, sessionIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注销会话
|
||||
*
|
||||
* @param sessionId 会话ID
|
||||
*/
|
||||
public void destroySession(String sessionId) {
|
||||
destroySession(null, sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量注销会话
|
||||
*
|
||||
* @param sessionIds 会话ID列表
|
||||
*/
|
||||
public void destroySessionByIds(List<String> sessionIds) {
|
||||
destroySessionByIds(null, sessionIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户的应用列表
|
||||
*
|
||||
* @return 应用列表
|
||||
*/
|
||||
public List<AppInfo> getAppList() {
|
||||
return getAppList(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文件后缀查询应用
|
||||
*
|
||||
* @param suffixes 文件后缀列表
|
||||
* @return 应用列表
|
||||
*/
|
||||
public List<AppstoreAppInfo> getAppInfoSuffixList(String... suffixes) {
|
||||
return getAppInfoSuffixList(null, suffixes);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文件后缀查询应用
|
||||
*
|
||||
* @param suffixes 文件后缀列表
|
||||
* @return 应用列表
|
||||
*/
|
||||
public List<AppstoreAppInfo> getAppInfoSuffixList(List<String> suffixes) {
|
||||
return getAppInfoSuffixList(null, suffixes);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用途查询应用
|
||||
*
|
||||
* @param labels 用途列表
|
||||
* @return 应用列表
|
||||
*/
|
||||
public List<UseLabelInfo> getUseLabelList(String... labels) {
|
||||
return getUseLabelList(null, labels);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用途查询应用
|
||||
*
|
||||
* @param labels 用途列表
|
||||
* @return 应用列表
|
||||
*/
|
||||
public List<UseLabelInfo> getUseLabelList(List<String> labels) {
|
||||
return getUseLabelList(null, labels);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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查询数据目录列表
|
||||
@@ -143,4 +133,63 @@ public class JHDataApiExecution implements JHApiExecution {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据用户scope查询数据目录列表
|
||||
*
|
||||
* @return 用户数据目录列表
|
||||
*/
|
||||
public List<SpoolerDataInfo> getSpoolersData() {
|
||||
return getSpoolersData(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据作业id查作业数据目录信息
|
||||
*
|
||||
* @param jobId 作业id
|
||||
* @return 作业目录信息
|
||||
*/
|
||||
public SpoolerDataInfo getSpoolersDataById(String jobId) {
|
||||
return getSpoolersDataById(null, jobId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据作业id集合查询数据目录列表
|
||||
*
|
||||
* @param jobIds 作业id列表
|
||||
* @return 用户数据目录列表
|
||||
*/
|
||||
public List<SpoolerDataInfo> getSpoolersDataByIds(List<String> jobIds) {
|
||||
return getSpoolersDataByIds(null, jobIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据数据目录名称查询数据目录列表
|
||||
*
|
||||
* @param dataName 数据目录名称
|
||||
* @return 作业目录信息
|
||||
*/
|
||||
public SpoolerDataInfo getSpoolersByName(String dataName) {
|
||||
return getSpoolersByName(null, dataName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 立即删除作业数据目录
|
||||
*
|
||||
* @param jobId 作业id
|
||||
*/
|
||||
public void deleteSpoolerData(String jobId) {
|
||||
deleteSpoolerData(null, jobId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置用户数据目录的过期时间,也给以通过设置过期时间来删除用户数据区
|
||||
*
|
||||
* @param jobId 作业id
|
||||
* @param expirationTime 过期时间
|
||||
*/
|
||||
public void purgeSpooler(String jobId, Date expirationTime) {
|
||||
purgeSpooler(null, jobId, expirationTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.jhinno.sdk.openapi.api.file;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Confidential {
|
||||
|
||||
/**
|
||||
* 密级key
|
||||
*/
|
||||
private String conf;
|
||||
|
||||
/**
|
||||
* 密级英文名
|
||||
*/
|
||||
private String confEn;
|
||||
|
||||
/**
|
||||
* 密级中文名
|
||||
*/
|
||||
private String confCn;
|
||||
|
||||
/**
|
||||
* 密级权重
|
||||
*/
|
||||
private int confLevel;
|
||||
|
||||
}
|
||||
@@ -64,4 +64,9 @@ public class FilePathConstant {
|
||||
*/
|
||||
public static final String FILE_UNCOMPRESS_PATH = "/appform/ws/api/files/uncompress";
|
||||
|
||||
/**
|
||||
* 密级相关请求路径
|
||||
*/
|
||||
public static final String FILE_CONF_PATH = "/appform/ws/api/file/conf";
|
||||
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
/**
|
||||
* 重命名文件
|
||||
@@ -56,6 +46,16 @@ public class JHFileApiExecution implements JHApiExecution {
|
||||
execution.put(FilePathConstant.FILE_RENAME_PATH, username, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重命名文件
|
||||
*
|
||||
* @param sourceFileNamePath 源文件路径
|
||||
* @param targetFileName 目标文件路径
|
||||
*/
|
||||
public void renameFile(String sourceFileNamePath, String targetFileName) {
|
||||
renameFile(null, sourceFileNamePath, targetFileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
@@ -72,6 +72,15 @@ public class JHFileApiExecution implements JHApiExecution {
|
||||
execution.delete(path, username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @param sourceFilePath 源文件路径
|
||||
*/
|
||||
public void deleteFile(String sourceFilePath) {
|
||||
deleteFile(null, sourceFilePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拷贝文件到目标文件夹
|
||||
*
|
||||
@@ -92,6 +101,16 @@ public class JHFileApiExecution implements JHApiExecution {
|
||||
execution.put(FilePathConstant.FILE_COPY_PATH, username, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拷贝文件到目标文件夹
|
||||
*
|
||||
* @param sourceFilePath 源文件路径
|
||||
* @param targetDirectoryPath 目标文件路径
|
||||
*/
|
||||
public void copyFile(String sourceFilePath, String targetDirectoryPath) {
|
||||
copyFile(null, sourceFilePath, targetDirectoryPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件列表
|
||||
*
|
||||
@@ -110,6 +129,16 @@ public class JHFileApiExecution implements JHApiExecution {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件列表
|
||||
*
|
||||
* @param dirPath 文件路径
|
||||
* @return 文件列表
|
||||
*/
|
||||
public List<FileInfo> getFileList(String dirPath) {
|
||||
return getFileList(null, dirPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件夹
|
||||
*
|
||||
@@ -147,6 +176,27 @@ public class JHFileApiExecution implements JHApiExecution {
|
||||
return mkdir(username, dirPath, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件夹
|
||||
*
|
||||
* @param dirPath 文件夹路径
|
||||
* @param isForce 是否强制创建(非必传,默认:false)
|
||||
* @return 新建后的文件路径
|
||||
*/
|
||||
public String mkdir(String dirPath, Boolean isForce) {
|
||||
return mkdir(null, dirPath, isForce);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建文件夹,默认不强制新建
|
||||
*
|
||||
* @param dirPath 文件路径
|
||||
* @return 新建后的文件路径
|
||||
*/
|
||||
public String mkdir(String dirPath) {
|
||||
return mkdir(dirPath, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件
|
||||
*
|
||||
@@ -169,6 +219,16 @@ public class JHFileApiExecution implements JHApiExecution {
|
||||
return result.get("dirPath");
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件
|
||||
*
|
||||
* @param filePath 文件路径
|
||||
* @return 新的文件路径
|
||||
*/
|
||||
public String mkFile(String filePath) {
|
||||
return mkFile(null, filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* <p>
|
||||
@@ -253,8 +313,7 @@ public class JHFileApiExecution implements JHApiExecution {
|
||||
* @param uploadPath 上传路径,服务器路径
|
||||
* @param isCover 是否覆盖(非必填,默认:false)
|
||||
*/
|
||||
public void uploadFile(String username, String path, String fileName, String uploadPath, Boolean isCover)
|
||||
throws FileNotFoundException {
|
||||
public void uploadFile(String username, String path, String fileName, String uploadPath, Boolean isCover) throws FileNotFoundException {
|
||||
if (StringUtils.isBlank(path)) {
|
||||
throw new ArgsException("path是必填参数");
|
||||
}
|
||||
@@ -279,32 +338,6 @@ public class JHFileApiExecution implements JHApiExecution {
|
||||
uploadFile(username, path, fileName, uploadPath, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传一个本地的路径
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param path 本地文件路径
|
||||
* @param uploadPath 上传路径,服务器路径
|
||||
* @param isCover 是否覆盖(非必填,默认:false)
|
||||
*/
|
||||
public void uploadFile(String username, String path, String uploadPath, Boolean isCover)
|
||||
throws FileNotFoundException {
|
||||
File file = new File(path);
|
||||
uploadFile(username, path, file.getName(), uploadPath, isCover);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传一个本地的路径(不覆盖源文件)
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param path 本地文件路径
|
||||
* @param uploadPath 上传路径,服务器路径
|
||||
*/
|
||||
public void uploadFile(String username, String path, String uploadPath) throws FileNotFoundException {
|
||||
File file = new File(path);
|
||||
uploadFile(username, path, file.getName(), uploadPath, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件下载地址
|
||||
*
|
||||
@@ -392,17 +425,6 @@ public class JHFileApiExecution implements JHApiExecution {
|
||||
execution.post(path, username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件压缩
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param sourceDirName 源文件目录(多个文件适用英文逗号隔开)
|
||||
* @param targetFilePath 目标文件路径
|
||||
*/
|
||||
public void compress(String username, String sourceDirName, String targetFilePath) {
|
||||
compress(username, sourceDirName, targetFilePath, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解压文件
|
||||
*
|
||||
@@ -473,4 +495,264 @@ public class JHFileApiExecution implements JHApiExecution {
|
||||
public void uncompress(String username, String sourceFilePath, String targetDirPath) {
|
||||
uncompress(username, sourceFilePath, targetDirPath, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取可用的文件吗密级列表
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 密级列表
|
||||
*/
|
||||
public List<Confidential> getConfList(String username) {
|
||||
return execution.get(FilePathConstant.FILE_CONF_PATH, username, new TypeReference<ResponseResult<List<Confidential>>>() {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件表表标密
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param conf 密级使用{@link JHFileApiExecution#getConfList(String)}返回的{@link Confidential#conf}
|
||||
* @param path 文件路径
|
||||
*
|
||||
*
|
||||
*/
|
||||
public void markConf(String username, String conf, String path) {
|
||||
Map<String, Object> body = new HashMap<>(2);
|
||||
body.put("conf", conf);
|
||||
body.put("path", path);
|
||||
execution.post(FilePathConstant.FILE_CONF_PATH, username, body);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* <p>
|
||||
* 如果isCover为空或者为false,源文件目录下存在相同文件则会报错
|
||||
* </p>
|
||||
*
|
||||
* @param is 文件流
|
||||
* @param fileName 文件名称
|
||||
* @param uploadPath 上传路径
|
||||
* @param isCover 是否覆盖(非必填,默认:false)
|
||||
* @param fileConf 密级(只有开启了密级才需要此参数,可以是密级的中文名,也可以是密级的中文名、英文名、或者密级的key)
|
||||
*/
|
||||
public void uploadFile(InputStream is, String fileName, String uploadPath, Boolean isCover, String fileConf) {
|
||||
uploadFile(null, is, fileName, uploadPath, isCover, fileConf);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
* <p>
|
||||
* 如果isCover为空或者为false,源文件目录下存在相同文件则会报错
|
||||
* </p>
|
||||
*
|
||||
* @param is 文件流
|
||||
* @param fileName 文件名称
|
||||
* @param uploadPath 上传路径
|
||||
* @param isCover 是否覆盖(非必填,默认:false)
|
||||
*/
|
||||
public void uploadFile(InputStream is, String fileName, String uploadPath, Boolean isCover) {
|
||||
uploadFile(is, fileName, uploadPath, isCover, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件(不覆盖源文件)
|
||||
* <p>
|
||||
* 源文件目录下存在相同文件则会报错
|
||||
* </p>
|
||||
*
|
||||
* @param is 文件流
|
||||
* @param fileName 文件名
|
||||
* @param uploadPath 上传路径
|
||||
*/
|
||||
public void uploadFile(InputStream is, String fileName, String uploadPath) {
|
||||
uploadFile(is, fileName, uploadPath, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传一个本地的路径
|
||||
*
|
||||
* @param path 本地文件路径
|
||||
* @param fileName 文件名
|
||||
* @param uploadPath 上传路径,服务器路径
|
||||
* @param isCover 是否覆盖(非必填,默认:false)
|
||||
*/
|
||||
public void uploadFile(String path, String fileName, String uploadPath, Boolean isCover) throws FileNotFoundException {
|
||||
if (StringUtils.isBlank(path)) {
|
||||
throw new ArgsException("path是必填参数");
|
||||
}
|
||||
File file = new File(path);
|
||||
FileInputStream fileInputStream = new FileInputStream(file);
|
||||
if (StringUtils.isBlank(fileName)) {
|
||||
fileName = file.getName();
|
||||
}
|
||||
uploadFile(fileInputStream, fileName, uploadPath, isCover);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传一个本地的路径(不覆盖源文件)
|
||||
* <p>
|
||||
* 源文件目录下存在相同文件则会报错
|
||||
* </p>
|
||||
*
|
||||
* @param path 本地文件路径
|
||||
* @param fileName 文件名
|
||||
* @param uploadPath 上传路径,服务器路径
|
||||
*/
|
||||
public void uploadFile(String path, String fileName, String uploadPath) throws FileNotFoundException {
|
||||
uploadFile(path, fileName, uploadPath, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传一个本地的路径
|
||||
*
|
||||
* @param path 本地文件路径
|
||||
* @param uploadPath 上传路径,服务器路径
|
||||
* @param isCover 是否覆盖(非必填,默认:false)
|
||||
*/
|
||||
public void uploadFile(String path, String uploadPath, Boolean isCover) throws FileNotFoundException {
|
||||
File file = new File(path);
|
||||
uploadFile(null, path, file.getName(), uploadPath, isCover);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传一个本地的路径(不覆盖源文件)
|
||||
*
|
||||
* @param path 本地文件路径
|
||||
* @param uploadPath 上传路径,服务器路径
|
||||
*/
|
||||
public void uploadFile(String path, String uploadPath) throws FileNotFoundException {
|
||||
uploadFile(path, null, uploadPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件下载地址
|
||||
*
|
||||
* @param filePath 文件路径
|
||||
* @return 文件地址信息
|
||||
*/
|
||||
public String getFileDownloadUrl(String filePath) {
|
||||
return getFileDownloadUrl(filePath, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件下载地址
|
||||
*
|
||||
* @param filePath 文件路径
|
||||
* @param forceDownload 是否强制下载,打开密级之后未标密的文件无法下载,可以通过设置当前参数为true来强制下载,默认:false
|
||||
* @return 文件地址信息
|
||||
*/
|
||||
public String getFileDownloadUrl(String filePath, Boolean forceDownload) {
|
||||
return getFileDownloadUrl(null, filePath, forceDownload);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件输入流
|
||||
*
|
||||
* @param filePath 文件路径
|
||||
* @return 文件流
|
||||
* @throws IOException
|
||||
*/
|
||||
public InputStream getFileInputStream(String filePath) throws IOException {
|
||||
return getFileInputStream(filePath, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件输入流
|
||||
*
|
||||
* @param filePath 文件路径
|
||||
* @param forceDownload 是否强制下载,打开密级之后未标密的文件无法下载,可以通过设置当前参数为true来强制下载,默认:false
|
||||
* @return 文件流
|
||||
* @throws IOException
|
||||
*/
|
||||
public InputStream getFileInputStream(String filePath, Boolean forceDownload) throws IOException {
|
||||
return getFileInputStream(null, filePath, forceDownload);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件压缩
|
||||
*
|
||||
* @param sourceDirName 源文件目录
|
||||
* @param targetFilePath 目标文件路径
|
||||
* @param compressType 压缩类型 (未使用以后扩展)
|
||||
*/
|
||||
public void compress(String sourceDirName, String targetFilePath, String compressType) {
|
||||
compress(null, sourceDirName, targetFilePath, compressType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件压缩
|
||||
*
|
||||
* @param sourceDirName 源文件目录(多个文件适用英文逗号隔开)
|
||||
* @param targetFilePath 目标文件路径
|
||||
*/
|
||||
public void compress(String sourceDirName, String targetFilePath) {
|
||||
compress(sourceDirName, targetFilePath, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解压文件
|
||||
*
|
||||
* @param sourceFilePath 源文件路径
|
||||
* @param targetDirPath 目标文件路径
|
||||
* @param isCover 是否覆盖
|
||||
* @param password 密码
|
||||
* @param compressType 压缩类型 (未使用以后扩展)
|
||||
*/
|
||||
public void uncompress(String sourceFilePath, String targetDirPath, Boolean isCover, String password, String compressType) {
|
||||
uncompress(null, sourceFilePath, targetDirPath, isCover, password, compressType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解压文件
|
||||
*
|
||||
* @param sourceFilePath 源文件路径
|
||||
* @param targetDirPath 目标文件路径
|
||||
* @param isCover 是否覆盖
|
||||
* @param password 密码
|
||||
*/
|
||||
public void uncompress(String sourceFilePath, String targetDirPath, Boolean isCover, String password) {
|
||||
uncompress(sourceFilePath, targetDirPath, isCover, password, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解压文件
|
||||
*
|
||||
* @param sourceFilePath 源文件路径
|
||||
* @param targetDirPath 目标文件路径
|
||||
* @param isCover 是否覆盖
|
||||
*/
|
||||
public void uncompress(String sourceFilePath, String targetDirPath, Boolean isCover) {
|
||||
uncompress(sourceFilePath, targetDirPath, isCover, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解压文件
|
||||
*
|
||||
* @param sourceFilePath 源文件路径
|
||||
* @param targetDirPath 目标文件路径
|
||||
*/
|
||||
public void uncompress(String sourceFilePath, String targetDirPath) {
|
||||
uncompress(sourceFilePath, targetDirPath, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取可用的文件密级列表
|
||||
*
|
||||
* @return 密级列表
|
||||
*/
|
||||
public List<Confidential> getConfList() {
|
||||
return getConfList(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件标密
|
||||
*
|
||||
* @param conf 密级使用{@link JHFileApiExecution#getConfList(String)}返回的{@link Confidential#conf}
|
||||
* @param path 文件路径
|
||||
*/
|
||||
public void markConf(String conf, String path) {
|
||||
markConf(null, conf, path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
@@ -106,7 +96,7 @@ public class JHJobApiExecution implements JHApiExecution {
|
||||
params.put("status", status.getStatus());
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(condition)) {
|
||||
params.put("condition", JsonUtil.objectToString(params));
|
||||
params.put("condition", JsonUtil.objectToString(condition));
|
||||
}
|
||||
String path = JHApiClient.getUrl(JobPathConstant.JOB_PAGE_PATH, params);
|
||||
return execution.get(path, username, new TypeReference<ResponseResult<PageJobInfo>>() {
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
@@ -165,7 +155,7 @@ public class JHJobApiExecution implements JHApiExecution {
|
||||
params.put("status", status.getStatus());
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(condition)) {
|
||||
params.put("condition", JsonUtil.objectToString(params));
|
||||
params.put("condition", JsonUtil.objectToString(condition));
|
||||
}
|
||||
|
||||
String path = JHApiClient.getUrl(JobPathConstant.JOB_HISTORY_JOBS_PATH, params);
|
||||
@@ -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 {
|
||||
|
||||
/**
|
||||
* 查询用户列表
|
||||
@@ -40,6 +33,15 @@ public class JHDepartmentApiExecution implements JHApiExecution {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户列表
|
||||
*
|
||||
* @return 用户列表
|
||||
*/
|
||||
public List<Map<String, Object>> getDepartmentList() {
|
||||
return getDepartmentList(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加部门
|
||||
*
|
||||
@@ -50,6 +52,15 @@ public class JHDepartmentApiExecution implements JHApiExecution {
|
||||
execution.post(DepartmentPathConstant.DEPARTMENT_PATH, username, departmentInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加部门
|
||||
*
|
||||
* @param departmentInfo 部门信息
|
||||
*/
|
||||
public void addDepartment(AddUpdateDepartment departmentInfo) {
|
||||
addDepartment(null, departmentInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改部门信息
|
||||
*
|
||||
@@ -64,6 +75,15 @@ public class JHDepartmentApiExecution implements JHApiExecution {
|
||||
execution.put(path, username, departmentInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改部门信息
|
||||
*
|
||||
* @param departmentInfo 部门信息
|
||||
*/
|
||||
public void updateDepartment(AddUpdateDepartment departmentInfo) {
|
||||
updateDepartment(null, departmentInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除部门信息
|
||||
*
|
||||
@@ -77,4 +97,13 @@ public class JHDepartmentApiExecution implements JHApiExecution {
|
||||
String path = DepartmentPathConstant.DEPARTMENT_NAME_PATH.replace("{depName}", departmentName);
|
||||
execution.delete(path, username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除部门信息
|
||||
*
|
||||
* @param departmentName 部门名称
|
||||
*/
|
||||
public void deleteDepartment(String departmentName) {
|
||||
deleteDepartment(null, departmentName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
/**
|
||||
* 分页查询用户列表
|
||||
@@ -55,6 +48,18 @@ public class JHUserApiExecution implements JHApiExecution {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询用户列表
|
||||
*
|
||||
* @param keyword 检索关键字
|
||||
* @param depName 部门名称
|
||||
* @param userConf 密级
|
||||
* @return 分页的用户列表
|
||||
*/
|
||||
public PageResult<UserInfo> getUserList(String keyword, String depName, String userConf) {
|
||||
return getUserList(null, keyword, depName, userConf);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加用户
|
||||
*
|
||||
@@ -65,6 +70,15 @@ public class JHUserApiExecution implements JHApiExecution {
|
||||
execution.post(UserPathConstant.USERS_PATH, username, userInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加用户
|
||||
*
|
||||
* @param userInfo 用户信息
|
||||
*/
|
||||
public void addUser(AddUpdateUserInfo userInfo) {
|
||||
addUser(null, userInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户信息
|
||||
*
|
||||
@@ -79,6 +93,15 @@ public class JHUserApiExecution implements JHApiExecution {
|
||||
execution.put(path, username, userInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户信息
|
||||
*
|
||||
* @param userInfo 用户信息
|
||||
*/
|
||||
public void updateUser(AddUpdateUserInfo userInfo) {
|
||||
updateUser(null, userInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改或重置用户密码
|
||||
*
|
||||
@@ -95,8 +118,7 @@ public class JHUserApiExecution implements JHApiExecution {
|
||||
* @param password 新密码
|
||||
* @param type 类型,(非必填,取值见{@link UpdateUserPasswordType})
|
||||
*/
|
||||
public void updateUserPassword(String username, String updatePasswordUsername, String oldPassword, String password,
|
||||
String type) {
|
||||
public void updateUserPassword(String username, String updatePasswordUsername, String oldPassword, String password, UpdateUserPasswordType type) {
|
||||
if (StringUtils.isBlank(updatePasswordUsername)) {
|
||||
throw new ArgsException("updatePasswordUsername不能为空");
|
||||
}
|
||||
@@ -106,12 +128,30 @@ public class JHUserApiExecution implements JHApiExecution {
|
||||
params.put("oldPassword", oldPassword);
|
||||
}
|
||||
if (StringUtils.isNotBlank("type")) {
|
||||
params.put("type", type);
|
||||
params.put("type", type.getValue());
|
||||
}
|
||||
params.put("password", password);
|
||||
execution.put(path, username, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改或重置用户密码
|
||||
*
|
||||
* <ul>
|
||||
* <li>当type值为{@link UpdateUserPasswordType#FORCE_UPDATE_PASSWORD_TYPE}重置密码后用户再次登录需要修改密码</li>
|
||||
* <li>当type值为{@link UpdateUserPasswordType#RESET_UPDATE_PASSWORD_TYPE}重置用户的密码</li>
|
||||
* <li>当type值为空时修改用户密码</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param updatePasswordUsername 被修改的用户名
|
||||
* @param oldPassword 旧密码
|
||||
* @param password 新密码
|
||||
* @param type 类型,(非必填,取值见{@link UpdateUserPasswordType})
|
||||
*/
|
||||
public void updateUserPassword(String updatePasswordUsername, String oldPassword, String password, UpdateUserPasswordType type) {
|
||||
updateUserPassword(null, updatePasswordUsername, oldPassword, password, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户的密码
|
||||
*
|
||||
@@ -120,33 +160,19 @@ public class JHUserApiExecution implements JHApiExecution {
|
||||
* @param oldPassword 旧密码
|
||||
* @param password 新密码
|
||||
*/
|
||||
public void updateUserPassword(String username, String updatePasswordUsername, String oldPassword,
|
||||
String password) {
|
||||
public void updateUserPassword(String username, String updatePasswordUsername, String oldPassword, String password) {
|
||||
updateUserPassword(username, updatePasswordUsername, oldPassword, password, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置用户密码后强制用户修改密码
|
||||
* 修改用户的密码
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param updatePasswordUsername 被修改的用户名
|
||||
* @param password 新的用户密码
|
||||
* @param oldPassword 旧密码
|
||||
* @param password 新密码
|
||||
*/
|
||||
public void resetForceUpdatePassword(String username, String updatePasswordUsername, String password) {
|
||||
updateUserPassword(username, updatePasswordUsername, null, password,
|
||||
UpdateUserPasswordType.FORCE_UPDATE_PASSWORD_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置用户名
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param updatePasswordUsername 被修改的用户密码
|
||||
* @param password 新的用户密码
|
||||
*/
|
||||
public void resetPassword(String username, String updatePasswordUsername, String password) {
|
||||
updateUserPassword(username, updatePasswordUsername, null, password,
|
||||
UpdateUserPasswordType.RESET_UPDATE_PASSWORD_TYPE);
|
||||
public void updateUserPassword(String updatePasswordUsername, String oldPassword, String password) {
|
||||
updateUserPassword(updatePasswordUsername, oldPassword, password, UpdateUserPasswordType.RESET_UPDATE_PASSWORD_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,4 +188,13 @@ public class JHUserApiExecution implements JHApiExecution {
|
||||
execution.delete(UserPathConstant.USERS_USERNAME_PATH.replace("{username}", deleteUsername), username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*
|
||||
* @param deleteUsername 被删除的用户名
|
||||
*/
|
||||
public void deleteUser(String deleteUsername) {
|
||||
deleteUser(null, deleteUsername);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +1,27 @@
|
||||
package com.jhinno.sdk.openapi.api.organization;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 密码操作的类型
|
||||
*
|
||||
* @author yanlongqi
|
||||
* @date 2024/2/19 10:54
|
||||
*/
|
||||
public class UpdateUserPasswordType {
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum UpdateUserPasswordType {
|
||||
/**
|
||||
* 重置密码
|
||||
*/
|
||||
protected static final String RESET_UPDATE_PASSWORD_TYPE = "reset";
|
||||
RESET_UPDATE_PASSWORD_TYPE("reset"),
|
||||
|
||||
/**
|
||||
* 首次登录强制修改密码
|
||||
*/
|
||||
protected static final String FORCE_UPDATE_PASSWORD_TYPE = "force";
|
||||
FORCE_UPDATE_PASSWORD_TYPE("force");
|
||||
|
||||
private final String value;
|
||||
|
||||
}
|
||||
|
||||
@@ -87,8 +87,7 @@ public class JHApiClient {
|
||||
if (StringUtils.isBlank(path)) {
|
||||
throw new ArgsException("url不能为空");
|
||||
}
|
||||
try {
|
||||
InputStream content = apiHttpClient.get(getUrl(path), headers);
|
||||
try (InputStream content = apiHttpClient.get(getUrl(path), headers)) {
|
||||
return mapper.readValue(content, type);
|
||||
} catch (IOException e) {
|
||||
throw new ClientException(e.getMessage(), e);
|
||||
@@ -179,8 +178,9 @@ public class JHApiClient {
|
||||
if (body != null) {
|
||||
bodyStr = mapper.writeValueAsString(body);
|
||||
}
|
||||
InputStream content = apiHttpClient.post(getUrl(path), bodyStr, headers);
|
||||
return mapper.readValue(content, type);
|
||||
try (InputStream content = apiHttpClient.post(getUrl(path), bodyStr, headers)) {
|
||||
return mapper.readValue(content, type);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ClientException(e.getMessage(), e);
|
||||
}
|
||||
@@ -208,8 +208,9 @@ public class JHApiClient {
|
||||
if (body != null) {
|
||||
bodyStr = mapper.writeValueAsString(body);
|
||||
}
|
||||
InputStream content = apiHttpClient.put(getUrl(path), bodyStr, headers);
|
||||
return mapper.readValue(content, type);
|
||||
try (InputStream content = apiHttpClient.put(getUrl(path), bodyStr, headers)) {
|
||||
return mapper.readValue(content, type);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ClientException(e.getMessage(), e);
|
||||
}
|
||||
@@ -272,8 +273,7 @@ public class JHApiClient {
|
||||
if (StringUtils.isBlank(path)) {
|
||||
throw new ArgsException("path不能为空");
|
||||
}
|
||||
try {
|
||||
InputStream content = apiHttpClient.delete(getUrl(path), headers);
|
||||
try (InputStream content = apiHttpClient.delete(getUrl(path), headers)) {
|
||||
return mapper.readValue(content, type);
|
||||
} catch (IOException e) {
|
||||
throw new ClientException(e.getMessage(), e);
|
||||
@@ -314,8 +314,9 @@ public class JHApiClient {
|
||||
throw new ArgsException("path不能为空");
|
||||
}
|
||||
try {
|
||||
InputStream content = apiHttpClient.upload(getUrl(path), keyName, fileName, is, body, headers);
|
||||
return mapper.readValue(content, type);
|
||||
try (InputStream content = apiHttpClient.upload(getUrl(path), keyName, fileName, is, body, headers)) {
|
||||
return mapper.readValue(content, type);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ClientException(e.getMessage(), e);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.apache.http.ssl.SSLContextBuilder;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -35,6 +36,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 +65,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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 原始发送请求
|
||||
@@ -150,7 +147,9 @@ public class JHApiHttpClientImpl implements JHApiHttpClient {
|
||||
try {
|
||||
HttpResponse response = closeableHttpClient.execute(httpRequest);
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
|
||||
if (statusCode != HttpStatus.SC_OK) {
|
||||
// 确保响应实体被完全消费以释放连接
|
||||
EntityUtils.consume(response.getEntity());
|
||||
httpRequest.releaseConnection();
|
||||
throw new ClientException("发送HTTP请求失败,请求码:" + statusCode, ClientErrorCode.REQUEST_ERROR);
|
||||
}
|
||||
@@ -226,7 +225,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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.jhinno.sdk.openapi.utils;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.jhinno.sdk.openapi.CommonConstant;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -19,6 +20,7 @@ public class JsonUtil {
|
||||
OBJECT_MAPPER.setTimeZone(TimeZone.getTimeZone("GMT+8"));
|
||||
OBJECT_MAPPER.setDateFormat(new SimpleDateFormat(CommonConstant.NORM_DATETIME_PATTERN));
|
||||
OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
OBJECT_MAPPER.enable(SerializationFeature.INDENT_OUTPUT);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
|
||||
@@ -2,16 +2,7 @@ package com.jhinno.sdk.openapi.test;
|
||||
|
||||
import com.jhinno.sdk.openapi.AuthType;
|
||||
import com.jhinno.sdk.openapi.JHApiExecutionManage;
|
||||
import com.jhinno.sdk.openapi.api.app.JHAppApiExecution;
|
||||
import com.jhinno.sdk.openapi.api.data.JHDataApiExecution;
|
||||
import com.jhinno.sdk.openapi.api.file.JHFileApiExecution;
|
||||
import com.jhinno.sdk.openapi.api.job.JHJobApiExecution;
|
||||
import com.jhinno.sdk.openapi.api.organization.JHDepartmentApiExecution;
|
||||
import com.jhinno.sdk.openapi.api.organization.JHUserApiExecution;
|
||||
import com.jhinno.sdk.openapi.client.JHApiClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import com.jhinno.sdk.openapi.JHApiRequestHandler;
|
||||
|
||||
/**
|
||||
* SDK Client 的配置
|
||||
@@ -21,20 +12,28 @@ import java.util.Map;
|
||||
*/
|
||||
public class JHClientConfig {
|
||||
|
||||
public static final JHApiRequestHandler REQUEST_HANDLER = new JHApiRequestHandler() {
|
||||
@Override
|
||||
public String getCurrentUserName() {
|
||||
return "lqyan";
|
||||
}
|
||||
};
|
||||
|
||||
public static final String APPFORM_SERVER_URL = "https://172.20.0.200";
|
||||
public static final String ACCESS_KEY = "8147c7470bfd4a27952fe750c6bc7cef";
|
||||
public static final String ACCESS_KEY_SECRET = "899b13f590394c3daafc6468fed4b1df";
|
||||
|
||||
|
||||
/**
|
||||
* 创建一个API执行器管理器
|
||||
*/
|
||||
public static final JHApiExecutionManage API_EXECUTRON_MANAGE = new JHApiExecutionManage(
|
||||
"https://192.168.87.24");
|
||||
public static final JHApiExecutionManage API_EXECUTION_MANAGE = new JHApiExecutionManage(APPFORM_SERVER_URL, REQUEST_HANDLER);
|
||||
|
||||
public static final String ACCESS_KEY = "e2544957e53b4377bb4f8203a094e50b";
|
||||
|
||||
public static final String ACCESS_KEY_SECRET = "52d18cf7163047b78ea48756b8b40d28";
|
||||
|
||||
static {
|
||||
API_EXECUTRON_MANAGE.configureApiExecution(t -> {
|
||||
API_EXECUTION_MANAGE.configureApiExecution(t -> {
|
||||
// 默认为使用Token模式,如何使用的Token模式,则不需要配置ACCESS_KEY和ACCESS_KEY SECRET
|
||||
t.setAuthType(AuthType.ACCESS_SECRET_MODE);
|
||||
t.setAuthType(AuthType.ACCESS_SECRET_MODE);
|
||||
t.setAccessKey(ACCESS_KEY);
|
||||
t.setAccessKeySecret(ACCESS_KEY_SECRET);
|
||||
});
|
||||
|
||||
@@ -2,9 +2,11 @@ package com.jhinno.sdk.openapi.test.app;
|
||||
|
||||
import com.jhinno.sdk.openapi.api.app.*;
|
||||
import com.jhinno.sdk.openapi.test.JHClientConfig;
|
||||
import com.jhinno.sdk.openapi.utils.JsonUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -13,14 +15,12 @@ import java.util.List;
|
||||
* @author yanlongqi
|
||||
* @date 2024/2/1 16:47
|
||||
*/
|
||||
|
||||
public class AppApiTest {
|
||||
|
||||
/**
|
||||
* 获得一个调用应用接口的执行器
|
||||
*/
|
||||
public static final JHAppApiExecution jhAppApiExecution = JHClientConfig.API_EXECUTRON_MANAGE
|
||||
.getApiExecution(JHAppApiExecution.class);
|
||||
public static final JHAppApiExecution jhAppApiExecution = JHClientConfig.API_EXECUTION_MANAGE.getApiExecution(JHAppApiExecution.class);
|
||||
|
||||
/**
|
||||
* 测测试使用自定义的参数启动jhadmin的Linux桌面
|
||||
@@ -29,8 +29,10 @@ public class AppApiTest {
|
||||
public void testStartApp() {
|
||||
AppStartRequest appStartRequest = new AppStartRequest();
|
||||
appStartRequest.setStartNew(true);
|
||||
AppStartedInfo appStartedInfo = jhAppApiExecution.desktopStart("jhadmin", "linux_desktop", appStartRequest);
|
||||
System.out.println(appStartedInfo);
|
||||
AppStartedInfo appStartedInfo = jhAppApiExecution.desktopStart("linux_desktop", appStartRequest);
|
||||
System.out.println("会话ID:" + appStartedInfo.getDesktopId());
|
||||
System.out.println("JhAppURL:" + appStartedInfo.getJhappUrl());
|
||||
System.out.println("WebURL:" + appStartedInfo.getWebSessionUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,8 +40,8 @@ public class AppApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testDefaultParamsStartApp() {
|
||||
AppStartedInfo appStartedInfo = jhAppApiExecution.desktopStart("jhadmin", "linux_desktop");
|
||||
System.out.println(appStartedInfo);
|
||||
AppStartedInfo appStartedInfo = jhAppApiExecution.desktopStart("linux_desktop");
|
||||
System.out.println(JsonUtil.objectToString(appStartedInfo));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -47,8 +49,8 @@ public class AppApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetSessionsList() {
|
||||
List<SessionInfo> desktopList = jhAppApiExecution.getDesktopList("jhadmin");
|
||||
System.out.println(desktopList);
|
||||
List<SessionInfo> desktopList = jhAppApiExecution.getDesktopList();
|
||||
System.out.println(JsonUtil.objectToString(desktopList));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,8 +58,8 @@ public class AppApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetDesktopsByParams() {
|
||||
List<SessionInfo> desktopList = jhAppApiExecution.getDesktopsByParams("jhadmin", null, "Windows桌面");
|
||||
System.out.println(desktopList);
|
||||
List<SessionInfo> desktopList = jhAppApiExecution.getDesktopsByParams(null, "Windows桌面");
|
||||
System.out.println(JsonUtil.objectToString(desktopList));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,9 +67,8 @@ public class AppApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetDesktopsById() {
|
||||
List<SessionInfo> desktopList = jhAppApiExecution.getDesktopsById("jhadmin",
|
||||
Arrays.asList("7649", "7637", "123"));
|
||||
System.out.println(desktopList);
|
||||
List<SessionInfo> desktopList = jhAppApiExecution.getDesktopsById(Arrays.asList("151", "7637", "123"));
|
||||
System.out.println(JsonUtil.objectToString(desktopList));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,8 +76,8 @@ public class AppApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetDesktopsByName() {
|
||||
List<SessionInfo> desktopList = jhAppApiExecution.getDesktopsByName("jhadmin", "Windows桌面");
|
||||
System.out.println(desktopList);
|
||||
List<SessionInfo> desktopList = jhAppApiExecution.getDesktopsByName("Linux桌面");
|
||||
System.out.println(JsonUtil.objectToString(desktopList));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,7 +85,7 @@ public class AppApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testShareDesktop() {
|
||||
jhAppApiExecution.shareDesktop("jhadmin", "7649", null, null, null);
|
||||
jhAppApiExecution.shareDesktop("7649", null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,7 +93,7 @@ public class AppApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testCancelShare() {
|
||||
jhAppApiExecution.cancelShare("jhadmin", "7649");
|
||||
jhAppApiExecution.cancelShare("7649");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +101,7 @@ public class AppApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testTransferOperatorRight() {
|
||||
jhAppApiExecution.transferOperatorRight("jhadmin", "7649", "123");
|
||||
jhAppApiExecution.transferOperatorRight("7649", "123");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,8 +109,8 @@ public class AppApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testConnectJhapp() {
|
||||
AppStartedInfo appStartedInfo = jhAppApiExecution.connectJhapp("lqyan", "7666");
|
||||
System.out.println(appStartedInfo);
|
||||
AppStartedInfo appStartedInfo = jhAppApiExecution.connectJhapp("151");
|
||||
System.out.println(JsonUtil.objectToString(appStartedInfo));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +118,7 @@ public class AppApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testDisconnectSessionInfo() {
|
||||
jhAppApiExecution.disconnectSessionInfo("jhadmin", "7666");
|
||||
jhAppApiExecution.disconnectSessionInfo("151");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +126,7 @@ public class AppApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testDisconnectSessionByIds() {
|
||||
jhAppApiExecution.disconnectSessionByIds("jhadmin", Arrays.asList("123", "456"));
|
||||
jhAppApiExecution.disconnectSessionByIds(Arrays.asList("151", "456"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,7 +134,7 @@ public class AppApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testDestroySession() {
|
||||
jhAppApiExecution.destroySession("jhadmin", "63");
|
||||
jhAppApiExecution.destroySession("156");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,7 +142,7 @@ public class AppApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testDestroySessionByIds() {
|
||||
jhAppApiExecution.destroySessionByIds("jhadmin", Arrays.asList("123", "456"));
|
||||
jhAppApiExecution.destroySessionByIds(Arrays.asList("123", "456"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,8 +150,36 @@ public class AppApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetAppList() {
|
||||
List<AppInfo> appList = jhAppApiExecution.getAppList("jhadmin");
|
||||
System.out.println(appList);
|
||||
List<AppInfo> appList = jhAppApiExecution.getAppList();
|
||||
System.out.println("全部列表:");
|
||||
System.out.println(JsonUtil.objectToString(appList));
|
||||
|
||||
// 类型获取
|
||||
System.out.println("系统应用:");
|
||||
System.out.println(JsonUtil.objectToString(AppTypeConstant.AppType.SYSTEM_APP.getAppList(appList)));
|
||||
|
||||
System.out.println("计算应用:");
|
||||
System.out.println(JsonUtil.objectToString(AppTypeConstant.AppType.BATCH_APP.getAppList(appList)));
|
||||
|
||||
System.out.println("图形应用:");
|
||||
System.out.println(JsonUtil.objectToString(AppTypeConstant.AppType.DESKTOP_APP.getAppList(appList)));
|
||||
|
||||
// 操作系统分类
|
||||
System.out.println("系统应用:");
|
||||
System.out.println(JsonUtil.objectToString(AppTypeConstant.AppOsType.SYSTEM.getAppList(appList)));
|
||||
|
||||
System.out.println("Linux应用:");
|
||||
System.out.println(JsonUtil.objectToString(AppTypeConstant.AppOsType.LINUX.getAppList(appList)));
|
||||
|
||||
System.out.println("Windows应用:");
|
||||
System.out.println(JsonUtil.objectToString(AppTypeConstant.AppOsType.WINDOWS.getAppList(appList)));
|
||||
|
||||
// 应用分类
|
||||
System.out.println("系统应用:");
|
||||
System.out.println(JsonUtil.objectToString(AppTypeConstant.AppCategory.SYSTEM.getAppList(appList)));
|
||||
|
||||
System.out.println("景行发布应用:");
|
||||
System.out.println(JsonUtil.objectToString(AppTypeConstant.AppCategory.APP.getAppList(appList)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,7 +187,7 @@ public class AppApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetAppUrl() {
|
||||
System.out.println(jhAppApiExecution.getAppUrl("jhadmin", "myjobmana"));
|
||||
System.out.println(JsonUtil.objectToString(jhAppApiExecution.getAppUrl("jhadmin", "myjobmana")));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,7 +195,7 @@ public class AppApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetAppInfoSuffixList() {
|
||||
System.out.println(jhAppApiExecution.getAppInfoSuffixList("test", ".sh"));
|
||||
System.out.println(JsonUtil.objectToString(jhAppApiExecution.getAppInfoSuffixList(Collections.singletonList(".cas"))));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,6 +203,6 @@ public class AppApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetUseLabelList() {
|
||||
System.out.println(jhAppApiExecution.getUseLabelList("jhadmin"));
|
||||
System.out.println(JsonUtil.objectToString(jhAppApiExecution.getUseLabelList()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,15 +14,14 @@ import java.util.Arrays;
|
||||
*/
|
||||
public class DataApiTest {
|
||||
|
||||
public static final JHDataApiExecution execution =JHClientConfig.API_EXECUTRON_MANAGE
|
||||
.getApiExecution(JHDataApiExecution.class);
|
||||
public static final JHDataApiExecution execution = JHClientConfig.API_EXECUTION_MANAGE.getApiExecution(JHDataApiExecution.class);
|
||||
|
||||
/**
|
||||
* 测试获取作业数据区目录列表
|
||||
*/
|
||||
@Test
|
||||
public void testGetSpoolers() {
|
||||
System.out.println(execution.getSpoolersData("jhadmin"));
|
||||
System.out.println(execution.getSpoolersData());
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +30,7 @@ public class DataApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetSpoolersDataById() {
|
||||
System.out.println(execution.getSpoolersDataById("jhadmin", "5909"));
|
||||
System.out.println(execution.getSpoolersDataById("157"));
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +39,7 @@ public class DataApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetSpoolersDataByIds() {
|
||||
System.out.println(execution.getSpoolersDataByIds("jhadmin", Arrays.asList("6799", "6686")));
|
||||
System.out.println(execution.getSpoolersDataByIds(Arrays.asList("157", "6686")));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,7 +47,7 @@ public class DataApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetSpoolersDataByName() {
|
||||
System.out.println(execution.getSpoolersByName("jhadmin", "common_sub__t1_aaa.sh_20240206103137"));
|
||||
System.out.println(execution.getSpoolersByName("common_sub__t1_test.sh_2511221613073988875752"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.jhinno.sdk.openapi.test.file;
|
||||
|
||||
import com.jhinno.sdk.openapi.api.file.Confidential;
|
||||
import com.jhinno.sdk.openapi.api.file.FileInfo;
|
||||
import com.jhinno.sdk.openapi.api.file.JHFileApiExecution;
|
||||
import com.jhinno.sdk.openapi.test.JHClientConfig;
|
||||
import com.jhinno.sdk.openapi.utils.JsonUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import java.io.File;
|
||||
@@ -17,15 +20,14 @@ import java.util.List;
|
||||
*/
|
||||
public class FileApiTest {
|
||||
|
||||
private static final JHFileApiExecution execution = JHClientConfig.API_EXECUTRON_MANAGE
|
||||
.getApiExecution(JHFileApiExecution.class);
|
||||
private static final JHFileApiExecution execution = JHClientConfig.API_EXECUTION_MANAGE.getApiExecution(JHFileApiExecution.class);
|
||||
|
||||
/**
|
||||
* 测试重命名文件或文件夹
|
||||
*/
|
||||
@Test
|
||||
public void testRenameFile() {
|
||||
execution.renameFile("lqyan", "/apps/JHDP/lqyan/temp/PSUserService.class", "aaa.class");
|
||||
execution.renameFile("$HOME/test.sh", "test1.sh");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,7 +35,7 @@ public class FileApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testDeleteFile() {
|
||||
execution.deleteFile("lqyan", "/apps/JHDP/lqyan/temp/aaa.class");
|
||||
execution.deleteFile("$HOME/test1/test.sh");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,7 +43,7 @@ public class FileApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testCopyFile() {
|
||||
execution.copyFile("lqyan", "/apps/JHDP/lqyan/PSUserService.class", "/apps/JHDP/lqyan/temp");
|
||||
execution.copyFile("$HOME/test.sh", "$HOME/test1");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,7 +51,7 @@ public class FileApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetFileList() {
|
||||
List<FileInfo> fileList = execution.getFileList("jhadmin", "$HOME");
|
||||
List<FileInfo> fileList = execution.getFileList("$HOME");
|
||||
System.out.println(fileList);
|
||||
}
|
||||
|
||||
@@ -58,7 +60,7 @@ public class FileApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testMkdir() {
|
||||
System.out.println(execution.mkdir("jhadmin", "$HOMEtest1", true));
|
||||
System.out.println(execution.mkdir("$HOMEtest1", true));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +68,7 @@ public class FileApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testMkdirNoForce() {
|
||||
System.out.println(execution.mkdir("lqyan", "/apps/JHDP/lqyan/temp/bbb/ddd"));
|
||||
System.out.println(execution.mkdir("$HOME/temp/bbb/ddd"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +76,7 @@ public class FileApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testMkFile() {
|
||||
System.out.println(execution.mkFile("lqyan", "/apps/JHDP/lqyan/temp/ddd.txt"));
|
||||
System.out.println(execution.mkFile("$HOME/temp/ddd.txt"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,9 +84,9 @@ public class FileApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testUploadFile() throws IOException {
|
||||
File file = new File("C:\\Users\\yanlongqi\\Desktop\\LdapAdminv1830.exe");
|
||||
File file = new File("D:\\Program Files\\Java\\apache-maven-3.9.11\\conf\\settings.xml");
|
||||
FileInputStream fileInputStream = new FileInputStream(file);
|
||||
execution.uploadFile("jhadmin", fileInputStream, file.getName(), "$HOME", true);
|
||||
execution.uploadFile(fileInputStream, file.getName(), "$HOME", true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,9 +94,9 @@ public class FileApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testUploadFileNoCover() throws IOException {
|
||||
File file = new File("C:\\Users\\yanlongqi\\Desktop\\Hash.exe");
|
||||
File file = new File("D:\\Program Files\\Java\\apache-maven-3.9.11\\conf\\settings.xml");
|
||||
FileInputStream fileInputStream = new FileInputStream(file);
|
||||
execution.uploadFile("lqyan", fileInputStream, file.getName(), "$HOME/temp");
|
||||
execution.uploadFile(fileInputStream, file.getName(), "$HOME/temp");
|
||||
}
|
||||
|
||||
|
||||
@@ -103,9 +105,9 @@ public class FileApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testUploadFileConf() throws IOException {
|
||||
File file = new File("C:\\Users\\yanlongqi\\Desktop\\Hash.exe");
|
||||
File file = new File("D:\\Program Files\\Java\\apache-maven-3.9.11\\conf\\settings.xml");
|
||||
FileInputStream fileInputStream = new FileInputStream(file);
|
||||
execution.uploadFile("lqyan", fileInputStream, file.getName(), "$HOME/temp111", false,"public");
|
||||
execution.uploadFile(fileInputStream, file.getName(), "$HOME/temp111", false, "public");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,12 +115,12 @@ public class FileApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetFileDownloadUrl() {
|
||||
System.out.println(execution.getFileDownloadUrl("jhadmin", "$HOME/aa2a.sh"));
|
||||
System.out.println(execution.getFileDownloadUrl("$HOME/test.sh"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFileStream() throws IOException {
|
||||
InputStream in = execution.getFileInputStream("jhadmin", "$HOME/aaa.sh");
|
||||
InputStream in = execution.getFileInputStream("$HOME/test.sh");
|
||||
byte[] bytes = new byte[1024];
|
||||
while (in.read(bytes) != -1) {
|
||||
System.out.println(new String(bytes));
|
||||
@@ -127,11 +129,22 @@ public class FileApiTest {
|
||||
|
||||
@Test
|
||||
public void testCompress() {
|
||||
execution.compress("jhadmin", "$HOME/temp", "$HOME/temp.zip");
|
||||
execution.compress("$HOME/temp", "$HOME/temp.zip");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUncompress() {
|
||||
execution.uncompress("jhadmin", "$HOME/temp.zip", "$HOME/test");
|
||||
execution.uncompress("$HOME/temp.zip", "$HOME/test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConfList() {
|
||||
List<Confidential> confList = execution.getConfList("yanlongqi");
|
||||
System.out.println(JsonUtil.objectToString(confList));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarkConf() {
|
||||
execution.markConf("999999998", "/home/yanlongqi/test.sh");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,11 @@ package com.jhinno.sdk.openapi.test.job;
|
||||
|
||||
import com.jhinno.sdk.openapi.api.job.*;
|
||||
import com.jhinno.sdk.openapi.test.JHClientConfig;
|
||||
import com.jhinno.sdk.openapi.utils.JsonUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 作业相关测试类
|
||||
@@ -17,8 +16,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class JobApiTest {
|
||||
|
||||
private static final JHJobApiExecution execution = JHClientConfig.API_EXECUTRON_MANAGE
|
||||
.getApiExecution(JHJobApiExecution.class);
|
||||
private static final JHJobApiExecution execution = JHClientConfig.API_EXECUTION_MANAGE.getApiExecution(JHJobApiExecution.class);
|
||||
|
||||
/**
|
||||
* 测试提交作业
|
||||
@@ -26,9 +24,10 @@ public class JobApiTest {
|
||||
@Test
|
||||
public void testSubmitJob() {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("JH_CAS", "$HOME/aaa.sh");
|
||||
params.put("JH_CAS", "$HOME/test1.sh");
|
||||
params.put("JH_NCPU", "1");
|
||||
System.out.println(execution.submit("jhadmin", "common_sub", params));
|
||||
params.put("JH_JOB_CONF", "public");
|
||||
System.out.println(execution.submit("yanlongqi", "common_sub", params));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,12 +38,35 @@ public class JobApiTest {
|
||||
System.out.println(execution.getJobFilesById("jhadmin", "42"));
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Object> getCondition(List<String> ids) {
|
||||
List<Map<String, Object>> filterItem = ids.stream().map(t -> {
|
||||
Map<String, Object> filterEnum = new HashMap<>();
|
||||
filterEnum.put("field", "id");
|
||||
filterEnum.put("operator", "eq");
|
||||
filterEnum.put("ignoreCase", true);
|
||||
filterEnum.put("value", t);
|
||||
filterEnum.put("type", "string");
|
||||
return filterEnum;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
Map<String, Object> filters = new HashMap<>();
|
||||
filters.put("type", "enum");
|
||||
filters.put("operator", "contains");
|
||||
filters.put("ignoreCase", true);
|
||||
filters.put("logic", "or");
|
||||
filters.put("field", "id");
|
||||
filters.put("filters", filterItem);
|
||||
return filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试分页查询作业列表
|
||||
*/
|
||||
@Test
|
||||
public void testGetJobPage() {
|
||||
PageJobInfo pages = execution.getJobPage("jhadmin", 1, 5, null, JobStatusEnum.DONE, null);
|
||||
List<String> ids = Arrays.asList("192", "187");
|
||||
PageJobInfo pages = execution.getJobPage("lqyan", 1, 5, null, (JobStatusEnum) null, getCondition(ids));
|
||||
System.out.println(pages);
|
||||
}
|
||||
|
||||
@@ -86,7 +108,7 @@ public class JobApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetJobsByIds() {
|
||||
System.out.println(execution.getJobsByIds("jhadmin", Arrays.asList("42", "41")));
|
||||
System.out.println(JsonUtil.objectToString(execution.getJobsByIds("jhadmin", Arrays.asList("1591", "162"))));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,8 +13,7 @@ import org.junit.Test;
|
||||
*/
|
||||
public class DepartmentApiTest {
|
||||
|
||||
private static final JHDepartmentApiExecution execution = JHClientConfig.API_EXECUTRON_MANAGE
|
||||
.getApiExecution(JHDepartmentApiExecution.class);
|
||||
private static final JHDepartmentApiExecution execution = JHClientConfig.API_EXECUTION_MANAGE.getApiExecution(JHDepartmentApiExecution.class);
|
||||
|
||||
|
||||
/**
|
||||
@@ -22,7 +21,7 @@ public class DepartmentApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetDepartment() {
|
||||
System.out.println(execution.getDepartmentList("jhadmin"));
|
||||
System.out.println(execution.getDepartmentList());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,10 +30,10 @@ public class DepartmentApiTest {
|
||||
@Test
|
||||
public void testAddDepartment() {
|
||||
AddUpdateDepartment addUpdateDepartment = new AddUpdateDepartment();
|
||||
addUpdateDepartment.setDepName("test2");
|
||||
addUpdateDepartment.setDepNameCN("测试部门2");
|
||||
addUpdateDepartment.setDepName("test1");
|
||||
addUpdateDepartment.setDepNameCN("测试部门1");
|
||||
addUpdateDepartment.setParentDepName("defaultDep");
|
||||
execution.addDepartment("jhadmin", addUpdateDepartment);
|
||||
execution.addDepartment(addUpdateDepartment);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,7 +45,7 @@ public class DepartmentApiTest {
|
||||
addUpdateDepartment.setDepName("test2");
|
||||
addUpdateDepartment.setDepNameCN("测试部门2111");
|
||||
addUpdateDepartment.setParentDepName("defaultDep");
|
||||
execution.updateDepartment("jhadmin", addUpdateDepartment);
|
||||
execution.updateDepartment(addUpdateDepartment);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,6 +53,6 @@ public class DepartmentApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testDeleteDepartment() {
|
||||
execution.deleteDepartment("jhadmin", "test2");
|
||||
execution.deleteDepartment("test1");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.jhinno.sdk.openapi.api.organization.AddUpdateUserInfo;
|
||||
import com.jhinno.sdk.openapi.api.organization.JHUserApiExecution;
|
||||
import com.jhinno.sdk.openapi.api.organization.UserInfo;
|
||||
import com.jhinno.sdk.openapi.test.JHClientConfig;
|
||||
import com.jhinno.sdk.openapi.utils.JsonUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@@ -15,8 +16,7 @@ import org.junit.Test;
|
||||
*/
|
||||
public class UserApiTest {
|
||||
|
||||
private static final JHUserApiExecution execution = JHClientConfig.API_EXECUTRON_MANAGE
|
||||
.getApiExecution(JHUserApiExecution.class);
|
||||
private static final JHUserApiExecution execution = JHClientConfig.API_EXECUTION_MANAGE.getApiExecution(JHUserApiExecution.class);
|
||||
|
||||
|
||||
/**
|
||||
@@ -24,8 +24,8 @@ public class UserApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetUserList() {
|
||||
PageResult<UserInfo> result = execution.getUserList("jhadmin", null, null, null);
|
||||
System.out.println("result = " + result);
|
||||
PageResult<UserInfo> result = execution.getUserList(null, null, null);
|
||||
System.out.println(JsonUtil.objectToString(result));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,7 +38,7 @@ public class UserApiTest {
|
||||
addUpdateUserInfo.setUserNameCn("张三3");
|
||||
addUpdateUserInfo.setUserPassword("Jhadmin123");
|
||||
addUpdateUserInfo.setDepName("defaultDep");
|
||||
execution.addUser("jhadmin", addUpdateUserInfo);
|
||||
execution.addUser(addUpdateUserInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,11 +48,11 @@ public class UserApiTest {
|
||||
@Test
|
||||
public void updateUser() {
|
||||
AddUpdateUserInfo addUpdateUserInfo = new AddUpdateUserInfo();
|
||||
addUpdateUserInfo.setUserName("zhangsan");
|
||||
addUpdateUserInfo.setUserName("zhangsan3");
|
||||
addUpdateUserInfo.setUserNameCn("张三1");
|
||||
addUpdateUserInfo.setDepName("defaultDep");
|
||||
addUpdateUserInfo.setUserPassword("Jhadmin123");
|
||||
execution.updateUser("jhadmin", addUpdateUserInfo);
|
||||
execution.updateUser(addUpdateUserInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class UserApiTest {
|
||||
*/
|
||||
@Test
|
||||
public void testDeleteUser() {
|
||||
execution.deleteUser("jhadmin", "zhangsan1");
|
||||
execution.deleteUser("zhangsan3");
|
||||
}
|
||||
|
||||
|
||||
@@ -71,12 +71,7 @@ public class UserApiTest {
|
||||
@Test
|
||||
public void testUpdateUserPassword() {
|
||||
// 修改用户密码,应该是自己的密码需要自己的token修改
|
||||
execution.updateUserPassword("jhadmin", "zhangsan1", "Jhadmin123", "Jhadmin124");
|
||||
execution.updateUserPassword("zhangsan1", "Jhadmin124", "Jhadmin1241");
|
||||
|
||||
// 管理员重置密码
|
||||
execution.resetPassword("jhadmin", "zhangsan2", "Jhadmin125");
|
||||
|
||||
// 管理员重置密码后,强制让用户修改密码(改接口调用报错,不应该传入旧密码)
|
||||
execution.resetForceUpdatePassword("jhadmin", "zhangsan3", "Jhadmin127");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>cim.jhinno</groupId>
|
||||
<artifactId>jhinno-openapi-sdk-spring-boot-example</artifactId>
|
||||
<version>2.0.5</version>
|
||||
<version>2.0.7</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>Jhinno OpenAPI SDK for Java SpringBoot Example</name>
|
||||
<description>The Jhinno OpenAPI SDK for Java used for accessing Jhinno OpenApi Service</description>
|
||||
@@ -22,7 +22,7 @@
|
||||
<dependency>
|
||||
<groupId>com.jhinno</groupId>
|
||||
<artifactId>jhinno-openapi-sdk-spring-boot-starter</artifactId>
|
||||
<version>2.0.5</version>
|
||||
<version>2.0.8</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.jhinno.sdk.openapi.example;
|
||||
|
||||
import com.jhinno.sdk.openapi.JHApiRequestHandler;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class ApiConfig implements JHApiRequestHandler {
|
||||
|
||||
@Override
|
||||
public String getCurrentUserName() {
|
||||
return "yanlongqi";
|
||||
}
|
||||
}
|
||||
@@ -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,14 +11,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class JHFileApiExtendExecution implements JHApiExecution {
|
||||
|
||||
private JHRequestExecution execution;
|
||||
|
||||
@Override
|
||||
public void init(JHRequestExecution execution) {
|
||||
this.execution = execution;
|
||||
}
|
||||
public class JHFileApiExtendExecution extends JHApiExecutionAbstract {
|
||||
|
||||
public static String GET_FILE_ENV_PATH = "/appform/ws/api/files/path/{env}";
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
jhinno:
|
||||
openapi:
|
||||
server-url: https://192.168.0.22
|
||||
auth-type: token_mode
|
||||
access-key: 3f03747f147942bd8debd81b6c9c6a80
|
||||
access-key-secret: e0681859b91c499eb1d2c8e09cea3242
|
||||
server-url: https://172.20.0.200
|
||||
auth-type: access_secret_mode
|
||||
access-key: 8147c7470bfd4a27952fe750c6bc7cef
|
||||
access-key-secret: 899b13f590394c3daafc6468fed4b1df
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.jhinno.sdk.openapi.example.test.extend;
|
||||
|
||||
import com.jhinno.sdk.openapi.api.app.AppStartedInfo;
|
||||
import com.jhinno.sdk.openapi.example.api.extend.FileSystemType;
|
||||
import com.jhinno.sdk.openapi.example.api.extend.JHFileApiExtendExecution;
|
||||
import com.jhinno.sdk.openapi.utils.JsonUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -24,6 +26,7 @@ public class JHFileApiExtendTest {
|
||||
|
||||
@Test
|
||||
void testStartApp() {
|
||||
jhAppApiExecution.desktopStart("jhadmin","linux_desktop");
|
||||
AppStartedInfo linuxDesktop = jhAppApiExecution.desktopStart(null, "linux_desktop");
|
||||
System.out.println(JsonUtil.objectToString(linuxDesktop));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>jhinno-openapi-sdk-spring-boot-starter</artifactId>
|
||||
<version>2.0.5</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>Jhinno OpenAPI SDK for Java SpringBoot Starter</name>
|
||||
<description>The Jhinno OpenAPI SDK for Java used for accessing Jhinno OpenApi Service</description>
|
||||
@@ -14,14 +13,14 @@
|
||||
<parent>
|
||||
<groupId>com.jhinno</groupId>
|
||||
<artifactId>jhinno-openapi-java-sdk-parent</artifactId>
|
||||
<version>2.0.5</version>
|
||||
<version>2.0.8</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.jhinno</groupId>
|
||||
<artifactId>jhinno-openapi-java-sdk</artifactId>
|
||||
<version>2.0.5</version>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jhinno.sdk.openapi.autoconfigure;
|
||||
|
||||
import com.jhinno.sdk.openapi.JHApiRequestHandler;
|
||||
import com.jhinno.sdk.openapi.api.JHRequestExecution;
|
||||
import com.jhinno.sdk.openapi.client.JHApiClient;
|
||||
import com.jhinno.sdk.openapi.client.JHApiHttpClientImpl;
|
||||
@@ -23,20 +24,22 @@ 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;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JHRequestExecution requestExecution(JHApiClient jhApiClient, JHOpenapiProperties properties) {
|
||||
JHRequestExecution requestExecution = new JHRequestExecution(jhApiClient);
|
||||
@ConditionalOnMissingBean
|
||||
public JHApiRequestHandler defaultRequestHandler() {
|
||||
return new JHApiRequestHandler() {
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JHRequestExecution requestExecution(JHApiClient jhApiClient, JHOpenapiProperties properties, JHApiRequestHandler requestHandler) {
|
||||
JHRequestExecution requestExecution = new JHRequestExecution(jhApiClient, requestHandler);
|
||||
requestExecution.setForceGetToken(properties.isForceGetToken());
|
||||
requestExecution.setAuthType(properties.getAuthType());
|
||||
requestExecution.setAccessKey(properties.getAccessKey());
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.jhinno.sdk.openapi.autoconfigure;
|
||||
|
||||
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.app.JHAppApiExecution;
|
||||
import com.jhinno.sdk.openapi.api.data.JHDataApiExecution;
|
||||
@@ -9,11 +9,14 @@ import com.jhinno.sdk.openapi.api.job.JHJobApiExecution;
|
||||
import com.jhinno.sdk.openapi.api.organization.JHDepartmentApiExecution;
|
||||
import com.jhinno.sdk.openapi.api.organization.JHUserApiExecution;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* openapi执行器自动配置
|
||||
*
|
||||
@@ -26,39 +29,46 @@ public class JHOpenapiExecutionAutoconfigure implements BeanPostProcessor {
|
||||
|
||||
private final JHRequestExecution jhRequestExecution;
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) {
|
||||
if (bean instanceof JHApiExecution) {
|
||||
((JHApiExecution) bean).init(jhRequestExecution);
|
||||
if (bean instanceof JHApiExecutionAbstract) {
|
||||
((JHApiExecutionAbstract) bean).setExecution(jhRequestExecution);
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public JHAppApiExecution appApiExecution() {
|
||||
return new JHAppApiExecution();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public JHDataApiExecution dataApiExecution() {
|
||||
return new JHDataApiExecution();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public JHFileApiExecution fileApiExecution() {
|
||||
return new JHFileApiExecution();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public JHJobApiExecution jobApiExecution() {
|
||||
return new JHJobApiExecution();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public JHDepartmentApiExecution departmentApiExecution() {
|
||||
return new JHDepartmentApiExecution();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public JHUserApiExecution userApiExecution() {
|
||||
return new JHUserApiExecution();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.jhinno</groupId>
|
||||
<artifactId>jhinno-openapi-java-sdk-parent</artifactId>
|
||||
<version>2.0.5</version>
|
||||
<version>2.0.8</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>Jhinno OpenAPI SDK for Java parent</name>
|
||||
<description>The Jhinno OpenAPI SDK for Java used for accessing Jhinno OpenApi Service</description>
|
||||
|
||||
Reference in New Issue
Block a user