docs: 完善README文档和优化测试代码格式

- 更新版本信息,添加JH_Appform_6.5_Release支持
- 完善Spring配置示例,修正init-method为setExecution
- 新增全局用户获取方式配置示例(JHApiRequestHandler)
- 更新依赖版本号到2.0.6
- 优化测试代码格式,统一API执行器获取方式
- 改进文档结构和代码示例的可读性

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
yanlongqi
2025-11-22 18:17:27 +08:00
parent 5c5b9c198e
commit db26e8fae6
7 changed files with 122 additions and 58 deletions

162
README.md
View File

@@ -17,7 +17,8 @@
3. JH_Appform_6.1_Release 3. JH_Appform_6.1_Release
4. JH_Appform_6.2_Release(使用: release-2.0.3 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.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. 快速开始 # 2. 快速开始
@@ -64,13 +65,15 @@ mvn clean install
<dependency> <dependency>
<groupId>com.jhinno</groupId> <groupId>com.jhinno</groupId>
<artifactId>jhinno-openapi-sdk-spring-boot-starter</artifactId> <artifactId>jhinno-openapi-sdk-spring-boot-starter</artifactId>
<version>${最新的版本号}</version> <version>2.0.6</version>
</dependency> </dependency>
``` ```
#### 方法三:直接使用 jar 包 #### 方法三:直接使用 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 包。 `这两个 jar 包。
### 2.1.3 配置 ### 2.1.3 配置
@@ -101,14 +104,30 @@ jhinno.openapi.auth-type=access_secret_mode
> 注: > 注:
> >
> - 其中`jhinno.openapi.server-url`为景行接口服务的 BaseUrl > - 其中`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` 作为访问接口的凭证,需要提供集成商名称、系统名称、负责人姓名、负责电话电话信息申请。 > - `access-key` 和 `access-key-secret` 作为访问接口的凭证,需要提供集成商名称、系统名称、负责人姓名、负责电话电话信息申请。
> - 更多配置见`com.jhinno.sdk.openapi.autoconfigure.JHOpenapiProperties`源码。 > - 更多配置见`com.jhinno.sdk.openapi.autoconfigure.JHOpenapiProperties`源码。
```java
// 新增全局用户获取方式
@Configuration
public class ApiConfig implements JHApiRequestHandler {
@Override
public String getCurrentUserName() {
return "yanlongqi";
}
}
```
### 2.1.4 使用 ### 2.1.4 使用
`com.jhinno.sdk.openapi.api`包下面对应`app``data``file``job``organization`这几个子包,分别代表景行`Appform` `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"); List<FileInfo> list = fileApiExecution.getFileList("jhadmin", "$HOME");
System.out.println(list); System.out.println(list);
// 如果配置全局的 JHApiRequestHandler 方式获取用户名可以不用传userName
List<FileInfo> list1 = fileApiExecution.getFileList("$HOME");
System.out.println(list1);
} }
} }
``` ```
@@ -185,15 +208,17 @@ spring.xml 添加以下内容
</bean> </bean>
<bean id="requestExecution" class="com.jhinno.sdk.openapi.api.JHRequestExecution"> <bean id="requestExecution" class="com.jhinno.sdk.openapi.api.JHRequestExecution">
<constructor-arg ref="apiClient" /> <constructor-arg ref="apiClient"/>
</bean> </bean>
<bean id="appApiExecution" class="com.jhinno.sdk.openapi.api.app.JHAppApiExecution" 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="init"></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="init"></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="init"></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="init"></bean> <bean id="departmentApiExecution" class="com.jhinno.sdk.openapi.api.organization.JHDepartmentApiExecution"
<bean id="userApiExecution" class="com.jhinno.sdk.openapi.api.organization.JHUserApiExecution" init-method="init"></bean> init-method="setExecution"></bean>
<bean id="userApiExecution" class="com.jhinno.sdk.openapi.api.organization.JHUserApiExecution"
init-method="setExecution"></bean>
</beans> </beans>
``` ```
@@ -252,36 +277,95 @@ public class DemoUserSDK {
```java ```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执行器管理器 * 创建一个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 { static {
// 配置API执行器管理器设置认证信息等。 API_EXECUTION_MANAGE.configureApiExecution(t -> {
API_EXECUTRON_MANAGE.configureApiExecution(t -> {
// 默认为使用Token模式如何使用的Token模式则不需要配置ACCESS_KEY和ACCESS_KEY SECRET // 默认为使用Token模式如何使用的Token模式则不需要配置ACCESS_KEY和ACCESS_KEY SECRET
// t.setAuthType(AuthType.ACCESS_KEY); t.setAuthType(AuthType.ACCESS_SECRET_MODE);
t.setAccessKey(ACCESS_KEY); t.setAccessKey(ACCESS_KEY);
t.setAccessKeySecret(ACCESS_KEY_SECRET); t.setAccessKeySecret(ACCESS_KEY_SECRET);
}); });
} }
public static void main(String[] args) { }
// 从API执行器管理器取出调用应用相关接口的执行器 public class AppApiTest {
JHAppApiExecution jhAppApiExecution = JHClientConfig.API_EXECUTION_MANAGE.getApiExecution(JHAppApiExecution.class);
// 调用启动会话的接口 /**
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子类的实现 * 注意一下代码为伪代码需要根据实际的情况进行修改其示例代码可参照SDK中JHDemoApiExecution子类的实现
*/ */
@Component @Component
public class JHDemoApiExecution extends JHApiExecution { public class JHDemoApiExecution extends JHApiExecutionAbstract {
private JHRequestExecution execution;
@Override
public void init(JHRequestExecution execution) {
this.execution = execution;
}
public XxxDTO getXXXX(String username, String demoParams) { 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子类的实现 * 注意一下代码为伪代码需要根据实际的情况进行修改其示例代码可参照SDK中JHDemoApiExecution子类的实现
*/ */
public class JHDemoApiExecution extends JHApiExecution { public class JHDemoApiExecution {
@Autowired @Autowired
private JHRequestExecution execution; private JHRequestExecution execution;
@@ -353,18 +430,11 @@ public class JHDemoApiExecution extends JHApiExecution {
/** /**
* 注意一下代码为伪代码需要根据实际的情况进行修改其示例代码可参照SDK中JHDemoApiExecution子类的实现 * 注意一下代码为伪代码需要根据实际的情况进行修改其示例代码可参照SDK中JHDemoApiExecution子类的实现
*/ */
public class JHDemoApiExecution extends JHApiExecution { public class JHDemoApiExecution extends JHApiExecutionAbstract {
private JHRequestExecution execution;
@Override
public void init(JHRequestExecution execution) {
this.execution = execution;
}
public XxxDTO getXXXX(String username, String demoParams) { 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>>() {
}); });
} }
} }

View File

@@ -20,8 +20,7 @@ public class AppApiTest {
/** /**
* 获得一个调用应用接口的执行器 * 获得一个调用应用接口的执行器
*/ */
public static final JHAppApiExecution jhAppApiExecution = JHClientConfig.API_EXECUTION_MANAGE public static final JHAppApiExecution jhAppApiExecution = JHClientConfig.API_EXECUTION_MANAGE.getApiExecution(JHAppApiExecution.class);
.getApiExecution(JHAppApiExecution.class);
/** /**
* 测测试使用自定义的参数启动jhadmin的Linux桌面 * 测测试使用自定义的参数启动jhadmin的Linux桌面

View File

@@ -14,8 +14,7 @@ import java.util.Arrays;
*/ */
public class DataApiTest { public class DataApiTest {
public static final JHDataApiExecution execution = JHClientConfig.API_EXECUTION_MANAGE public static final JHDataApiExecution execution = JHClientConfig.API_EXECUTION_MANAGE.getApiExecution(JHDataApiExecution.class);
.getApiExecution(JHDataApiExecution.class);
/** /**
* 测试获取作业数据区目录列表 * 测试获取作业数据区目录列表

View File

@@ -20,8 +20,7 @@ import java.util.List;
*/ */
public class FileApiTest { public class FileApiTest {
private static final JHFileApiExecution execution = JHClientConfig.API_EXECUTION_MANAGE private static final JHFileApiExecution execution = JHClientConfig.API_EXECUTION_MANAGE.getApiExecution(JHFileApiExecution.class);
.getApiExecution(JHFileApiExecution.class);
/** /**
* 测试重命名文件或文件夹 * 测试重命名文件或文件夹

View File

@@ -17,8 +17,7 @@ import java.util.Map;
*/ */
public class JobApiTest { public class JobApiTest {
private static final JHJobApiExecution execution = JHClientConfig.API_EXECUTION_MANAGE private static final JHJobApiExecution execution = JHClientConfig.API_EXECUTION_MANAGE.getApiExecution(JHJobApiExecution.class);
.getApiExecution(JHJobApiExecution.class);
/** /**
* 测试提交作业 * 测试提交作业

View File

@@ -13,8 +13,7 @@ import org.junit.Test;
*/ */
public class DepartmentApiTest { public class DepartmentApiTest {
private static final JHDepartmentApiExecution execution = JHClientConfig.API_EXECUTION_MANAGE private static final JHDepartmentApiExecution execution = JHClientConfig.API_EXECUTION_MANAGE.getApiExecution(JHDepartmentApiExecution.class);
.getApiExecution(JHDepartmentApiExecution.class);
/** /**

View File

@@ -16,8 +16,7 @@ import org.junit.Test;
*/ */
public class UserApiTest { public class UserApiTest {
private static final JHUserApiExecution execution = JHClientConfig.API_EXECUTION_MANAGE private static final JHUserApiExecution execution = JHClientConfig.API_EXECUTION_MANAGE.getApiExecution(JHUserApiExecution.class);
.getApiExecution(JHUserApiExecution.class);
/** /**