应用SDK接口集成完成

This commit is contained in:
lqyan
2024-02-04 16:58:28 +08:00
parent fe8fb7f2ec
commit fd05af58e6
11 changed files with 698 additions and 55 deletions

View File

@@ -1,5 +1,7 @@
package com.jhinno.sdk.openapi; package com.jhinno.sdk.openapi;
import org.omg.CosNaming.NamingContextPackage.NotFound;
/** /**
* 客户端错误相关常亮的定义 * 客户端错误相关常亮的定义
* *
@@ -51,4 +53,10 @@ public class ClientErrorCode {
* SSL异常 * SSL异常
*/ */
public static final String SSL_EXCEPTION = "SslException"; public static final String SSL_EXCEPTION = "SslException";
/**
* 资源不存在
*/
public static final String REQUEST_ERROR = "RequestError";
} }

View File

@@ -22,10 +22,6 @@ package com.jhinno.sdk.openapi;
*/ */
public class ClientException extends RuntimeException { public class ClientException extends RuntimeException {
/**
* 请求id
*/
private String requestId;
/** /**
* 错误编号 * 错误编号
@@ -51,7 +47,7 @@ public class ClientException extends RuntimeException {
* @param errorMessage 错误信息 * @param errorMessage 错误信息
*/ */
public ClientException(String errorMessage) { public ClientException(String errorMessage) {
this(errorMessage, null); this(errorMessage, ClientErrorCode.UNKNOWN);
} }
/** /**
@@ -73,7 +69,6 @@ public class ClientException extends RuntimeException {
super(null, cause); super(null, cause);
this.errorMessage = errorMessage; this.errorMessage = errorMessage;
this.errorCode = ClientErrorCode.UNKNOWN; this.errorCode = ClientErrorCode.UNKNOWN;
this.requestId = ClientErrorCode.UNKNOWN;
} }
/** /**
@@ -81,25 +76,11 @@ public class ClientException extends RuntimeException {
* *
* @param errorMessage 错误信息 * @param errorMessage 错误信息
* @param errorCode 错误编码 * @param errorCode 错误编码
* @param requestId 请求id
*/ */
public ClientException(String errorMessage, String errorCode, String requestId) { public ClientException(String errorMessage, String errorCode) {
this(errorMessage, errorCode, requestId, null); this(errorMessage, errorCode, null);
} }
/**
* 创建包含错误消息、错误代码、请求Id和异常的实例。
*
* @param errorMessage 错误信息
* @param errorCode 错误编码
* @param requestId 请求id
* @param cause 一个异常
*/
public ClientException(String errorMessage, String errorCode, String requestId, Throwable cause) {
this(errorMessage, cause);
this.errorCode = errorCode;
this.requestId = requestId;
}
/** /**
* 创建包含错误消息、错误代码、异常的实例。 * 创建包含错误消息、错误代码、异常的实例。
@@ -113,15 +94,6 @@ public class ClientException extends RuntimeException {
this.errorCode = errorCode; this.errorCode = errorCode;
} }
/**
* 获取请求id。
*
* @return 请求Id
*/
public String getRequestId() {
return requestId;
}
/** /**
* 获取错误代码。 * 获取错误代码。
* *
@@ -142,11 +114,6 @@ public class ClientException extends RuntimeException {
@Override @Override
public String getMessage() { public String getMessage() {
return String.format( return String.format("%s\n[ErrorCode]: %s", getErrorMessage(), errorCode != null ? errorCode : "");
"%s\n[ErrorCode]: %s\n[RequestId]:%s",
getErrorMessage(),
errorCode != null ? errorCode : "",
requestId != null ? requestId : ""
);
} }
} }

View File

@@ -32,4 +32,9 @@ public class CommonConstant {
* 获取token时AES加密的默认key * 获取token时AES加密的默认key
*/ */
public static final String DEFAULT_AES_KEY = "jin5no@aqec8gtw6"; public static final String DEFAULT_AES_KEY = "jin5no@aqec8gtw6";
/**
* 字符逗号
*/
public static final String NORMAL_CHARACTER_COMMA = ",";
} }

View File

@@ -5,15 +5,12 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.jhinno.sdk.openapi.ArgsException; import com.jhinno.sdk.openapi.ArgsException;
import com.jhinno.sdk.openapi.CommonConstant; import com.jhinno.sdk.openapi.CommonConstant;
import com.jhinno.sdk.openapi.ServiceException; import com.jhinno.sdk.openapi.ServiceException;
import com.jhinno.sdk.openapi.api.app.AppStartedInfo;
import com.jhinno.sdk.openapi.api.auth.AuthPathConstant; import com.jhinno.sdk.openapi.api.auth.AuthPathConstant;
import com.jhinno.sdk.openapi.api.auth.Token; import com.jhinno.sdk.openapi.api.auth.Token;
import com.jhinno.sdk.openapi.client.JHApiClient; import com.jhinno.sdk.openapi.client.JHApiClient;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.lang.reflect.Type;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@@ -167,7 +164,7 @@ public class JHApiExecution {
public <T> T get(String path, String username, TypeReference<ResponseResult<T>> type) { public <T> T get(String path, String username, TypeReference<ResponseResult<T>> type) {
ResponseResult<T> result = jhApiClient.get(path, getHeaders(username), type); ResponseResult<T> result = jhApiClient.get(path, getHeaders(username), type);
if (StringUtils.equals(result.getResult(), CommonConstant.FAILED)) { if (StringUtils.equals(result.getResult(), CommonConstant.FAILED)) {
throw new ServiceException(AuthPathConstant.AUTH_TOKEN_PATH, result.getCode(), result.getMessage()); throw new ServiceException(path, result.getCode(), result.getMessage());
} }
return result.getData(); return result.getData();
} }
@@ -209,4 +206,62 @@ public class JHApiExecution {
} }
} }
/**
* 发起一个没有请求体没有数据返回的POST请求
*
* @param path 请求路径
* @param username 用户名
*/
public void post(String path, String username) {
post(path, username, null);
}
/**
* 发起一个有返回值的PUT请求
*
* @param path 请求路径
* @param username 用户名
* @param body 请求体数据
* @param type 响应数据类型
* @param <R> 返回数据
* @param <B> 请求体数据
* @return 返回数据
*/
public <R, B> R put(String path, String username, B body, TypeReference<ResponseResult<R>> type) {
ResponseResult<R> result = jhApiClient.put(path, body, getHeaders(username), type);
if (StringUtils.equals(result.getResult(), CommonConstant.FAILED)) {
throw new ServiceException(path, result.getCode(), result.getMessage());
}
return result.getData();
}
/**
* 发一个没有返回值的PUT请求
*
* @param path 请求路径
* @param username 用户名
* @param body 请求体数据
* @param <B> 请求体数据类型
*/
public <B> void put(String path, String username, B body) {
ResponseResult<?> result = jhApiClient.put(path, body, getHeaders(username), new TypeReference<ResponseResult<?>>() {
});
if (StringUtils.equals(result.getResult(), CommonConstant.FAILED)) {
throw new ServiceException(path, result.getCode(), result.getMessage());
}
}
/**
* 发起一个没有请求体没有数据返回的PUT请求
*
* @param path 请求路径
* @param username 用户名
*/
public void put(String path, String username) {
put(path, username, null);
}
} }

View File

@@ -0,0 +1,159 @@
package com.jhinno.sdk.openapi.api.app;
import lombok.Data;
import java.util.List;
/**
* 应用信息
*
* @author yanlongqi
* @date 2024/2/4 16:13
*/
@Data
public class AppInfo {
/**
* 应用拆
*/
private String id;
/**
* 应用名称
*/
private String name;
/**
* 英文名
*/
private String enName;
/**
* 应用图标
*/
private String icon;
private String copyAppClass;
/**
* 是否多个
*/
private Boolean mutiple;
/**
* 最大化
*/
private Boolean maximize;
private Boolean maximized;
/**
* 宽度
*/
private Integer width;
/**
* 高度
*/
private Integer height;
private String appFeature;
private String acl;
/**
* 应用链接地址
*/
private String url;
private Boolean allowContext;
private String mode;
private String os;
private String showin;
private String splashImg;
private Boolean uneditable;
/**
* 应用类型
*/
private String type;
/**
* 应用分类
*/
private String category;
/**
* 应用协议
*/
private String protocol;
/**
* 帮助文档类型
*/
private Integer helpDocumentType;
/**
* 帮助文档
*/
private String helpDocument;
private Boolean resizable;
private Boolean simpleApp;
/**
* 系统
*/
private Boolean system;
/**
* 资源
*/
private String resource;
/**
* 上下文配置
*/
private String contextConfig;
/**
* x
*/
private Integer x;
/**
* y
*/
private Integer y;
/**
* 会话列表
*/
private List<String> sessionIds;
/**
* 开始前缀
*/
private String startPrefix;
/**
* 应用名称
*/
private String appname;
/**
* 路径
*/
private String path;
/**
* 工作路径
*/
private String cwd;
}

View File

@@ -22,4 +22,73 @@ public class AppPathConstant {
* 使用参数查询会话列表 * 使用参数查询会话列表
*/ */
public static final String APPS_SESSIONS_PATH = "/ws/api/apps/sessions"; public static final String APPS_SESSIONS_PATH = "/ws/api/apps/sessions";
/**
* 根据会话id列表查询会话列表
*/
public static final String APPS_SESSIONS_IDS_PATH = "/ws/api/apps/listBySessionIds";
/**
* 根据会话名称查询会话列表
*/
public static final String APPS_SESSIONS_NAME_PATH = "/ws/api/apps/listBySessionName";
/**
* 会话共享
*/
public static final String APPS_SESSIONS_SHARE_PATH = "/ws/api/apps/sessions/{sessionId}/share";
/**
* 取消会话共享
*/
public static final String APPS_SESSIONS_CANCEL_SHARE_PATH = "/ws/api/apps/sessions/{sessionId}/share_cancel";
/**
* 传递会话的操作权
*/
public static final String APPS_SESSIONS_OPERATION_TRANSFER_PATH = "/ws/api/apps/sessions/{sessionId}/operation_transfer";
/**
* 连接会话
*/
public static final String APPS_SESSIONS_CONNECT_JHAPP_PATH = "/ws/api/apps/sessions/{sessionId}/connect";
/**
* 断开会话连接(作业/应用)
*/
public static final String APPS_SESSIONS_DISCONNECT_PATH = "/ws/api/apps/sessions/{sessionId}/disconnect";
/**
* 批量断开会话
*/
public static final String APPS_SESSIONS_DISCONNECT_IDS_PATH = "/ws/api/apps/sessions/disconnect";
/**
* 注销会话
*/
public static final String APPS_SESSIONS_DESTROY_PATH = "/ws/api/apps/sessions/{sessionId}/close";
/**
* 批量注销会话
*/
public static final String APPS_SESSIONS_DESTROY_IDS_PATH = "/ws/api/apps/sessions/close";
/**
* 查询应用列表
*/
public static final String APPS_LIST_PATH = "/ws/api/apps";
/**
* 获取应用链接URL
*/
public static final String APPS_GET_URL_PATH = "/ws/api/apps/{appName}/url";
} }

View File

@@ -29,4 +29,9 @@ public class AppStartedInfo {
* 会话id * 会话id
*/ */
private String desktopId; private String desktopId;
/**
* 作业id有可能出现但不是太明白
*/
private String jobId;
} }

View File

@@ -0,0 +1,19 @@
package com.jhinno.sdk.openapi.api.app;
import lombok.Data;
/**
* 应用链接URL信息
*
* @author yanlongqi
* @date 2024/2/4 16:44
*/
@Data
public class AppUrlInfo {
/**
* 应用的url
*/
private String url;
}

View File

@@ -2,6 +2,8 @@ package com.jhinno.sdk.openapi.api.app;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.jhinno.sdk.openapi.ArgsException;
import com.jhinno.sdk.openapi.CommonConstant;
import com.jhinno.sdk.openapi.ServiceException; import com.jhinno.sdk.openapi.ServiceException;
import com.jhinno.sdk.openapi.api.JHApiExecution; import com.jhinno.sdk.openapi.api.JHApiExecution;
import com.jhinno.sdk.openapi.api.ResponseResult; import com.jhinno.sdk.openapi.api.ResponseResult;
@@ -72,10 +74,10 @@ public class JHAppApiExecution extends JHApiExecution {
/** /**
* 使用参数查询会话列表 * 使用参数查询会话列表
* * <ul>
* <p> * <li>sessionIds 和 sessionName 不能同时为空</li>
* sessionIds 和 sessionName 不能同时为空 * <li>开启密级后,仅能查看比自己密级低以及和自己密级一致的会话</li>
* </p> * </ul>
* *
* @param username 用户名 * @param username 用户名
* @param sessionIds 会话id列表 (非必填) * @param sessionIds 会话id列表 (非必填)
@@ -85,7 +87,7 @@ public class JHAppApiExecution extends JHApiExecution {
public List<SessionInfo> getDesktopsByParams(String username, List<String> sessionIds, String sessionName) { public List<SessionInfo> getDesktopsByParams(String username, List<String> sessionIds, String sessionName) {
Map<String, Object> params = new HashMap<>(2); Map<String, Object> params = new HashMap<>(2);
if (CollectionUtil.isNotEmpty(sessionIds)) { if (CollectionUtil.isNotEmpty(sessionIds)) {
params.put("sessionIds", String.join(",", sessionIds)); params.put("sessionIds", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, sessionIds));
} }
if (StringUtils.isNotBlank(sessionName)) { if (StringUtils.isNotBlank(sessionName)) {
params.put("sessionName", sessionName); params.put("sessionName", sessionName);
@@ -95,4 +97,249 @@ public class JHAppApiExecution extends JHApiExecution {
}); });
} }
/**
* 根据会话列表查询会话列表
* <p>
* 注:开启密集后,仅能查看自己的会话和比自己密级低的会话
* </p>
*
* @param username 用户名
* @param ids 会话id列表
* @return 会话列表
*/
public List<SessionInfo> getDesktopsById(String username, List<String> ids) {
Map<String, Object> params = new HashMap<>(2);
if (CollectionUtil.isEmpty(ids)) {
throw new ArgsException("会话id列表不能为空");
}
params.put("sessionIds", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, ids));
String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_IDS_PATH, params);
return get(path, username, new TypeReference<ResponseResult<List<SessionInfo>>>() {
});
}
/**
* 根据会话名称查询会话
* <p>
* 注:开启密集后,仅能查看自己的会话和比自己密级低的会话
* </p>
*
* @param username 用户名
* @param sessionName 会话名称
* @return 会话列表
*/
public List<SessionInfo> getDesktopsByName(String username, String sessionName) {
Map<String, Object> params = new HashMap<>(1);
if (StringUtils.isEmpty(sessionName)) {
throw new ArgsException("会话id列表不能为空");
}
params.put("sessionName", sessionName);
String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_NAME_PATH, params);
return get(path, username, new TypeReference<ResponseResult<List<SessionInfo>>>() {
});
}
/**
* 会话共享
* <ul>
* <li>调用该接口需要打开景行会话共享的功能</li>
* <li>observers 和 interacts 不能同时为空</li>
* <li>会话共享有密级限制,仅能将会话共享给比会话密级高的用户</li>
* </ul>
*
* @param username 用户名
* @param sessionId 会话id (必填)
* @param observers 观察者列表 (非必填)
* @param interacts 协作者列表 (非必填)
* @param isTransfer 是否传递操作权(不确定,需要咨询产品,非必填)
*/
public void shareDesktop(String username, String sessionId, List<String> observers, List<String> interacts, String isTransfer) {
if (StringUtils.isBlank(sessionId)) {
throw new ArgsException("sessionId为必填字段");
}
Map<String, Object> params = new HashMap<>(4);
if (CollectionUtil.isNotEmpty(observers)) {
params.put("observer", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, observers));
}
if (CollectionUtil.isNotEmpty(interacts)) {
params.put("interact", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, interacts));
}
if (StringUtils.isBlank(isTransfer)) {
params.put("isTransfer", isTransfer);
}
String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_SHARE_PATH.replace("{sessionId}", sessionId), params);
post(path, username);
}
/**
* 取消会话共享
* <ul>
* <li>调用该接口需要打开景行会话共享的功能</li>
* <li>开启密级后,仅能操作比自己密级低或者和自己密级一致的会话</li>
* </ul>
*
* @param username 用户名
* @param sessionId 会话id
*/
public void cancelShare(String username, String sessionId) {
if (StringUtils.isBlank(sessionId)) {
throw new ArgsException("sessionId为必填字段");
}
String path = AppPathConstant.APPS_SESSIONS_CANCEL_SHARE_PATH.replace("{sessionId}", sessionId);
put(path, username);
}
/**
* 传递会话操作权
* <ul>
* <li>调用该接口需要打开景行会话共享的功能</li>
* <li>开启密级后,仅能操作比自己密级低或者和自己密级一致的会话</li>
* </ul>
*
* @param username 用户名
* @param sessionId 会话id必填
* @param interact 操作权(必填)
*/
public void transferOperatorRight(String username, String sessionId, String interact) {
if (StringUtils.isBlank(sessionId)) {
throw new ArgsException("sessionId为必填字段");
}
if (StringUtils.isBlank(interact)) {
throw new ArgsException("interact为必填字段");
}
String path = AppPathConstant.APPS_SESSIONS_OPERATION_TRANSFER_PATH.replace("{sessionId}", sessionId);
Map<String, Object> params = new HashMap<>(1);
params.put("interact", interact);
path = JHApiClient.getUrl(path, params);
put(path, username);
}
/**
* 连接会话
*
* @param sessionId 会话拆
* @return JHClient协议链接信息
*/
public AppStartedInfo connectJhapp(String username, String sessionId) {
if (StringUtils.isBlank(sessionId)) {
throw new ArgsException("sessionId为必填字段");
}
String path = AppPathConstant.APPS_SESSIONS_CONNECT_JHAPP_PATH.replace("{sessionId}", sessionId);
List<AppStartedInfo> list = get(path, username, new TypeReference<ResponseResult<List<AppStartedInfo>>>() {
});
if (CollectionUtil.isEmpty(list)) {
throw new ServiceException(path, 500, "获取到的会话信息为空");
}
return list.get(0);
}
/**
* 断开会话连接(作业/应用)
* <p>
* 注:开启密级后,仅能操作比自己密级低或者和自己密级一致的会话
* </p>
*
* @param username 用户名
* @param sessionId 会话ID
*/
public void disconnectSessionInfo(String username, String sessionId) {
if (StringUtils.isBlank(sessionId)) {
throw new ArgsException("sessionId为必填字段");
}
String path = AppPathConstant.APPS_SESSIONS_DISCONNECT_PATH.replace("{sessionId}", sessionId);
put(path, username);
}
/**
* 通过应用id批量断开会话作业/应用)
* <p>
* 注:开启密级后,仅能操作比自己密级低或者和自己密级一致的会话
* </p>
*
* @param username 用户名
* @param sessionIds 用户表id列表
*/
public void disconnectSessionByIds(String username, List<String> sessionIds) {
if (CollectionUtil.isEmpty(sessionIds)) {
throw new ArgsException("sessionIds不能为空");
}
Map<String, Object> params = new HashMap<>(1);
params.put("sessionIds", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, sessionIds));
String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_DISCONNECT_IDS_PATH, params);
put(path, username);
}
/**
* 注销会话
* <p>
* 注:开启密级后,仅能操作比自己密级低或者和自己密级一致的会话
* </p>
*
* @param username 用户名
* @param sessionId 会话id
*/
public void destroySession(String username, String sessionId) {
if (StringUtils.isBlank(sessionId)) {
throw new ArgsException("sessionId为必填字段");
}
String path = AppPathConstant.APPS_SESSIONS_DESTROY_PATH.replace("{sessionId}", sessionId);
put(path, username);
}
/**
* 批量注销会话
*
* @param username 用户名
* @param sessionIds 会话id列表
*/
public void destroySessionByIds(String username, List<String> sessionIds) {
if (CollectionUtil.isEmpty(sessionIds)) {
throw new ArgsException("sessionIds不能为空");
}
Map<String, Object> params = new HashMap<>(1);
params.put("sessionIds", String.join(CommonConstant.NORMAL_CHARACTER_COMMA, sessionIds));
String path = JHApiClient.getUrl(AppPathConstant.APPS_SESSIONS_DESTROY_IDS_PATH, params);
put(path, username);
}
/**
* 获取当前用户的应用列表
*
* @param username 用户名
* @return 应用列表
*/
public List<AppInfo> getAppList(String username) {
return get(AppPathConstant.APPS_LIST_PATH, username, new TypeReference<ResponseResult<List<AppInfo>>>() {
});
}
/**
* 获取应用链接
*
* @param username 应户名
* @param appName 应用名
* @return 应用链接信息
*/
public AppUrlInfo getAppUrl(String username, String appName) {
if (StringUtils.isBlank(appName)) {
throw new ArgsException("appName为必填字段");
}
String path = AppPathConstant.APPS_GET_URL_PATH.replace("{appName}", appName);
List<AppUrlInfo> apps = get(path, username, new TypeReference<ResponseResult<List<AppUrlInfo>>>() {
});
if (CollectionUtil.isEmpty(apps)) {
throw new ServiceException(path, 500, "应用信息为空!");
}
return apps.get(0);
}
} }

View File

@@ -9,6 +9,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig; import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.*; import org.apache.http.client.methods.*;
import org.apache.http.config.Registry; import org.apache.http.config.Registry;
@@ -216,12 +217,13 @@ public class JHApiClient {
} }
try { try {
HttpResponse response = closeableHttpClient.execute(httpRequest); HttpResponse response = closeableHttpClient.execute(httpRequest);
int statusCode = response.getStatusLine().getStatusCode();
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
httpRequest.releaseConnection(); httpRequest.releaseConnection();
throw new ClientException("发送HTTP请求失败"); throw new ClientException("发送HTTP请求失败,请求码:" + statusCode, ClientErrorCode.REQUEST_ERROR);
} }
return response.getEntity(); return response.getEntity();
} catch (Exception e) { } catch (IOException e) {
throw new ClientException(e.getMessage()); throw new ClientException(e.getMessage());
} }
@@ -240,7 +242,7 @@ public class JHApiClient {
try { try {
InputStream content = request(httpRequest, headers).getContent(); InputStream content = request(httpRequest, headers).getContent();
return mapper.readValue(content, type); return mapper.readValue(content, type);
} catch (Exception e) { } catch (IOException e) {
throw new ClientException(e.getMessage()); throw new ClientException(e.getMessage());
} }
@@ -306,7 +308,7 @@ public class JHApiClient {
} }
urlBuilder.append("&"); urlBuilder.append("&");
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
throw new ClientException("url参数编码失败", ClientErrorCode.UNKNOWN_HOST, e); throw new ClientException("url参数编码失败", ClientErrorCode.UNKNOWN, e);
} }
} }
urlBuilder.setLength(urlBuilder.length() - 1); urlBuilder.setLength(urlBuilder.length() - 1);

View File

@@ -1,13 +1,11 @@
package com.jhinno.sdk.openapi.test.app; package com.jhinno.sdk.openapi.test.app;
import com.jhinno.sdk.openapi.api.app.AppStartRequest; import com.jhinno.sdk.openapi.api.app.*;
import com.jhinno.sdk.openapi.api.app.AppStartedInfo;
import com.jhinno.sdk.openapi.api.app.JHAppApiExecution;
import com.jhinno.sdk.openapi.api.app.SessionInfo;
import com.jhinno.sdk.openapi.client.JHApiClient; import com.jhinno.sdk.openapi.client.JHApiClient;
import org.junit.Test; import org.junit.Test;
import java.util.*; import java.util.Arrays;
import java.util.List;
/** /**
* 会话启动相关单元测试 * 会话启动相关单元测试
@@ -67,4 +65,113 @@ public class AppApiTest {
List<SessionInfo> desktopList = jhAppApiExecution.getDesktopsByParams("jhadmin", null, "Windows桌面"); List<SessionInfo> desktopList = jhAppApiExecution.getDesktopsByParams("jhadmin", null, "Windows桌面");
System.out.println(desktopList); System.out.println(desktopList);
} }
/**
* 测试根据会话列表查询会话列表
*/
@Test
public void testGetDesktopsById() {
List<SessionInfo> desktopList = jhAppApiExecution.getDesktopsById("jhadmin", Arrays.asList("7649", "7637", "123"));
System.out.println(desktopList);
}
/**
* 测试根据会话名称查询会话列表
*/
@Test
public void testGetDesktopsByName() {
List<SessionInfo> desktopList = jhAppApiExecution.getDesktopsByName("jhadmin", "Windows桌面");
System.out.println(desktopList);
}
/**
* 测试会话共享
*/
@Test
public void testShareDesktop() {
jhAppApiExecution.shareDesktop("jhadmin", "7649", null, null, null);
}
/**
* 测试取消会话共享
*/
@Test
public void testCancelShare() {
jhAppApiExecution.cancelShare("jhadmin", "7649");
}
/**
* 测试传递会话操作权
*/
@Test
public void testTransferOperatorRight() {
jhAppApiExecution.transferOperatorRight("jhadmin", "7649", "123");
}
/**
* 测试链接会话
*/
@Test
public void testConnectJhapp() {
AppStartedInfo appStartedInfo = jhAppApiExecution.connectJhapp("lqyan", "7666");
System.out.println(appStartedInfo);
}
/**
* 测试断开会话的连接
*/
@Test
public void testDisconnectSessionInfo() {
jhAppApiExecution.disconnectSessionInfo("jhadmin", "7666");
}
/**
* 测试批量断开会话
*/
@Test
public void testDisconnectSessionByIds() {
jhAppApiExecution.disconnectSessionByIds("jhadmin", Arrays.asList("123", "456"));
}
/**
* 测试注销会话
*/
@Test
public void testDestroySession() {
jhAppApiExecution.destroySession("jhadmin", "4856");
}
/**
* 测试批量注销会话
*/
@Test
public void testDestroySessionByIds() {
jhAppApiExecution.destroySessionByIds("jhadmin", Arrays.asList("123", "456"));
}
/**
* 测试查询用户的应用列表
*/
@Test
public void testGetAppList() {
List<AppInfo> appList = jhAppApiExecution.getAppList("lqyan");
System.out.println(appList);
}
/**
* 测试获取应用链接
*/
@Test
public void testGetAppUrl() {
AppUrlInfo appUrl = jhAppApiExecution.getAppUrl("lqyan", "myjobmana");
System.out.println(appUrl);
}
} }