mirror of
https://github.com/yanlongqi/jhinno-openapi-java-sdk.git
synced 2026-03-22 06:15:10 +08:00
会话启动接口器的集成
This commit is contained in:
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
@@ -1,4 +1,3 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="MavenProjectsManager">
|
<component name="MavenProjectsManager">
|
||||||
|
|||||||
124
.idea/uiDesigner.xml
generated
Normal file
124
.idea/uiDesigner.xml
generated
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Palette2">
|
||||||
|
<group name="Swing">
|
||||||
|
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Button" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="RadioButton" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="CheckBox" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||||
|
<initial-values>
|
||||||
|
<property name="text" value="Label" />
|
||||||
|
</initial-values>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||||
|
<preferred-size width="150" height="-1" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||||
|
<preferred-size width="150" height="50" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||||
|
<preferred-size width="-1" height="20" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||||
|
</item>
|
||||||
|
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||||
|
</item>
|
||||||
|
</group>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
28
README.md
28
README.md
@@ -19,6 +19,34 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 使用
|
||||||
|
```java
|
||||||
|
|
||||||
|
public class DemoUserSDK {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JHApiClient 是一个HTTP连接池,开发者需要复用
|
||||||
|
* 其中https://192.168.87.25/appform为景行API服务的地址
|
||||||
|
*/
|
||||||
|
private static final JHApiClient client = JHApiClient.build("https://192.168.87.25/appform");
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
// 初始化一个调用调用景行会话服务接口执行器
|
||||||
|
JHAppApiExecution jhAppApiExecution = new JHAppApiExecution(client);
|
||||||
|
|
||||||
|
// 调用启动会话的接口
|
||||||
|
AppStartedInfo appStartedInfo = jhAppApiExecution.desktopStart("jhadmin", "linux_desktop", new AppStartRequest());
|
||||||
|
|
||||||
|
// 打印接口的调用结果
|
||||||
|
System.out.println(appStartedInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
## 构建
|
## 构建
|
||||||
一旦您检出代码,就可以使用Maven构建它。使用以下命令进行构建:
|
一旦您检出代码,就可以使用Maven构建它。使用以下命令进行构建:
|
||||||
```shell
|
```shell
|
||||||
|
|||||||
32
pom.xml
32
pom.xml
@@ -40,6 +40,18 @@
|
|||||||
<groupId>org.apache.httpcomponents</groupId>
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
<artifactId>httpclient</artifactId>
|
<artifactId>httpclient</artifactId>
|
||||||
<version>4.5.13</version>
|
<version>4.5.13</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>commons-codec</groupId>
|
||||||
|
<artifactId>commons-codec</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-codec</groupId>
|
||||||
|
<artifactId>commons-codec</artifactId>
|
||||||
|
<version>1.15</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -48,6 +60,19 @@
|
|||||||
<version>2.0.25</version>
|
<version>2.0.25</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
<version>5.8.25</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.28</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
@@ -132,14 +157,7 @@
|
|||||||
<license>
|
<license>
|
||||||
<name>The Apache License, Version 2.0</name>
|
<name>The Apache License, Version 2.0</name>
|
||||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||||
<distribution></distribution>
|
|
||||||
</license>
|
</license>
|
||||||
</licenses>
|
</licenses>
|
||||||
|
|
||||||
<scm>
|
|
||||||
<url></url>
|
|
||||||
<connection></connection>
|
|
||||||
</scm>
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.jhinno.sdk.openapi;
|
package com.jhinno.sdk.openapi;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 这个异常标识传入的SDK方法的参数错误
|
* 这个异常标识传入的SDK方法的参数错误
|
||||||
@@ -17,13 +19,9 @@ package com.jhinno.sdk.openapi;
|
|||||||
* @author yanlongqi
|
* @author yanlongqi
|
||||||
* @date 2024/1/31 10:36
|
* @date 2024/1/31 10:36
|
||||||
*/
|
*/
|
||||||
|
@Getter
|
||||||
public class ArgsException extends RuntimeException {
|
public class ArgsException extends RuntimeException {
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户名
|
|
||||||
*/
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 错误信息
|
* 错误信息
|
||||||
*/
|
*/
|
||||||
@@ -69,15 +67,6 @@ public class ArgsException extends RuntimeException {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return String.format("[ErrorMessage]:%s", errorMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取一个错误信息
|
|
||||||
*
|
|
||||||
* @return 错误信息
|
|
||||||
*/
|
|
||||||
public String getErrorMessage() {
|
|
||||||
return errorMessage;
|
return errorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,4 +21,15 @@ public class CommonConstant {
|
|||||||
* 默认的token有效时间(单位:分钟)
|
* 默认的token有效时间(单位:分钟)
|
||||||
*/
|
*/
|
||||||
public static final int DEFAULT_TOKEN_EFFECTIVE_TIME = 30;
|
public static final int DEFAULT_TOKEN_EFFECTIVE_TIME = 30;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* token 默认剩余时间
|
||||||
|
*/
|
||||||
|
public static final int DEFAULT_TOKEN_RESIDUE_TIME = 5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取token时AES加密的默认key
|
||||||
|
*/
|
||||||
|
public static final String DEFAULT_AES_KEY = "jin5no@aqec8gtw6";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,11 +28,21 @@ package com.jhinno.sdk.openapi;
|
|||||||
*/
|
*/
|
||||||
public class ServiceException extends RuntimeException {
|
public class ServiceException extends RuntimeException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求错误码
|
||||||
|
*/
|
||||||
|
private int errorCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 错误信息
|
* 错误信息
|
||||||
*/
|
*/
|
||||||
private String errorMessage;
|
private String errorMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求的路径
|
||||||
|
*/
|
||||||
|
private String requestPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个默认的实例
|
* 创建一个默认的实例
|
||||||
*/
|
*/
|
||||||
@@ -44,21 +54,60 @@ public class ServiceException extends RuntimeException {
|
|||||||
/**
|
/**
|
||||||
* 创建一个包含错误消息的实例。
|
* 创建一个包含错误消息的实例。
|
||||||
*
|
*
|
||||||
|
* @param requestPath 请求路径
|
||||||
|
* @param errorCode 错误码
|
||||||
* @param errorMessage 错误信息
|
* @param errorMessage 错误信息
|
||||||
*/
|
*/
|
||||||
public ServiceException(String errorMessage) {
|
public ServiceException(String requestPath, int errorCode, String errorMessage) {
|
||||||
this(errorMessage, null);
|
this(requestPath, errorCode, errorMessage, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个包含错误消息和异常的实例
|
* 创建一个包含错误消息和异常的实例
|
||||||
*
|
*
|
||||||
|
* @param requestPath 请求路径
|
||||||
|
* @param errorCode 错误码
|
||||||
* @param errorMessage 错误信息
|
* @param errorMessage 错误信息
|
||||||
* @param cause 一个异常
|
* @param cause 一个异常
|
||||||
*/
|
*/
|
||||||
public ServiceException(String errorMessage, Throwable cause) {
|
public ServiceException(String requestPath, int errorCode, String errorMessage, Throwable cause) {
|
||||||
super(null, cause);
|
super(null, cause);
|
||||||
this.errorMessage = errorMessage;
|
this.errorMessage = errorMessage;
|
||||||
|
this.requestPath = requestPath;
|
||||||
|
this.errorCode = errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取请求码
|
||||||
|
*
|
||||||
|
* @return 请求码
|
||||||
|
*/
|
||||||
|
public int getErrorCode() {
|
||||||
|
return errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取错信息
|
||||||
|
*
|
||||||
|
* @return 错误信息
|
||||||
|
*/
|
||||||
|
public String getErrorMessage() {
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取请求路径
|
||||||
|
*
|
||||||
|
* @return 请求路径
|
||||||
|
*/
|
||||||
|
public String getRequestPath() {
|
||||||
|
return requestPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return String.format("%s\n[请求路径]: %s\n[错误码]: %s", errorMessage, requestPath, errorCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.jhinno.sdk.openapi.api;
|
package com.jhinno.sdk.openapi.api;
|
||||||
|
|
||||||
|
import cn.hutool.crypto.symmetric.AES;
|
||||||
|
import cn.hutool.crypto.symmetric.SymmetricCrypto;
|
||||||
import com.alibaba.fastjson2.TypeReference;
|
import com.alibaba.fastjson2.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;
|
||||||
@@ -13,6 +15,8 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 定义一个请求的执行器,
|
||||||
|
*
|
||||||
* @author yanlongqi
|
* @author yanlongqi
|
||||||
* @date 2024/1/30 19:39
|
* @date 2024/1/30 19:39
|
||||||
*/
|
*/
|
||||||
@@ -21,8 +25,27 @@ public class JHApiExecution {
|
|||||||
/**
|
/**
|
||||||
* JHApiClient实例
|
* JHApiClient实例
|
||||||
*/
|
*/
|
||||||
private static JHApiClient JH_API_CLIENT;
|
public JHApiClient jhApiClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* token的超时时间
|
||||||
|
*/
|
||||||
|
private int tokenTimeout = CommonConstant.DEFAULT_TOKEN_EFFECTIVE_TIME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* token提前获取的时间
|
||||||
|
*/
|
||||||
|
private int tokenResidueTime = CommonConstant.DEFAULT_TOKEN_RESIDUE_TIME;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取一个执行器的实例
|
||||||
|
*
|
||||||
|
* @param jhApiClient 请求的客户端
|
||||||
|
*/
|
||||||
|
protected JHApiExecution(JHApiClient jhApiClient) {
|
||||||
|
this.jhApiClient = jhApiClient;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户令牌的缓存
|
* 用户令牌的缓存
|
||||||
@@ -35,14 +58,33 @@ public class JHApiExecution {
|
|||||||
* @param jhApiClient 客户端实例
|
* @param jhApiClient 客户端实例
|
||||||
*/
|
*/
|
||||||
public void setJHApiClient(JHApiClient jhApiClient) {
|
public void setJHApiClient(JHApiClient jhApiClient) {
|
||||||
this.JH_API_CLIENT = jhApiClient;
|
this.jhApiClient = jhApiClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置token超时的时间,单位:分钟
|
||||||
|
*
|
||||||
|
* @param tokenTimeout token的超时时间
|
||||||
|
*/
|
||||||
|
public void setTokenTimeout(int tokenTimeout) {
|
||||||
|
this.tokenTimeout = tokenTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置提前获取token的时间,单位:分钟
|
||||||
|
*
|
||||||
|
* @param tokenResidueTime 提前获取token的时间
|
||||||
|
*/
|
||||||
|
public void setTokenResidueTime(int tokenResidueTime) {
|
||||||
|
this.tokenResidueTime = tokenResidueTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户的Token
|
* 获取用户的Token
|
||||||
*
|
*
|
||||||
* @param username 用户名
|
* @param username 用户名
|
||||||
* @param isForce 是否强制获取token
|
* @param isForce 是否强制获取toke
|
||||||
* @return 用户的token
|
* @return 用户的token
|
||||||
*/
|
*/
|
||||||
public String getToken(String username, boolean isForce) {
|
public String getToken(String username, boolean isForce) {
|
||||||
@@ -50,15 +92,22 @@ public class JHApiExecution {
|
|||||||
throw new ArgsException("用户名称不能为空!");
|
throw new ArgsException("用户名称不能为空!");
|
||||||
}
|
}
|
||||||
TokenInfo tokenInfo = TOKEN_INFO_MAP.get(username);
|
TokenInfo tokenInfo = TOKEN_INFO_MAP.get(username);
|
||||||
// 如果是强制获取、用户令牌为空、用户令牌过期等,则获取令牌
|
|
||||||
if (isForce || tokenInfo == null || System.currentTimeMillis() - tokenInfo.getCurrentTimestamp() <= CommonConstant.DEFAULT_TOKEN_EFFECTIVE_TIME * 60 * 1000) {
|
|
||||||
Map<String, Object> params = new HashMap<>(2);
|
|
||||||
|
|
||||||
String url = JHApiClient.getUrl(AuthPathConstant.AUTH_TOKEN, params);
|
// 防止因为服务器时间的问题二导致token不可用,可以通过此配置提前获取token
|
||||||
ResponseResult<Token> result = JH_API_CLIENT.get(url, new TypeReference<ResponseResult<Token>>() {
|
int tokenEffectiveTime = (tokenTimeout - tokenResidueTime) * 60 * 1000;
|
||||||
|
// 如果是强制获取、用户令牌为空、用户令牌过期等,则获取令牌
|
||||||
|
if (isForce || tokenInfo == null || System.currentTimeMillis() - tokenInfo.getCurrentTimestamp() < tokenEffectiveTime) {
|
||||||
|
Map<String, Object> params = new HashMap<>(2);
|
||||||
|
params.put("timeout", tokenTimeout);
|
||||||
|
|
||||||
|
AES aes = new AES(CommonConstant.DEFAULT_AES_KEY.getBytes());
|
||||||
|
String base64 = aes.encryptBase64(String.format("%s,%s", username, System.currentTimeMillis()));
|
||||||
|
params.put("username", base64);
|
||||||
|
String url = JHApiClient.getUrl(AuthPathConstant.AUTH_TOKEN_PATH, params);
|
||||||
|
ResponseResult<Token> result = jhApiClient.get(url, new TypeReference<ResponseResult<Token>>() {
|
||||||
});
|
});
|
||||||
if (StringUtils.equals(result.getResult(), CommonConstant.FAILED)) {
|
if (StringUtils.equals(result.getResult(), CommonConstant.FAILED)) {
|
||||||
throw new ServiceException("获取token失败");
|
throw new ServiceException(AuthPathConstant.AUTH_TOKEN_PATH, result.getCode(), result.getMessage());
|
||||||
}
|
}
|
||||||
Token token = result.getData();
|
Token token = result.getData();
|
||||||
tokenInfo = new TokenInfo();
|
tokenInfo = new TokenInfo();
|
||||||
@@ -70,5 +119,27 @@ public class JHApiExecution {
|
|||||||
return tokenInfo.getToken();
|
return tokenInfo.getToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户的Token,获取缓存,不强制获取
|
||||||
|
*
|
||||||
|
* @param username 用户名
|
||||||
|
* @return 用户的token
|
||||||
|
*/
|
||||||
|
public String getToken(String username) {
|
||||||
|
return getToken(username, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建一个带token的请求头
|
||||||
|
*
|
||||||
|
* @param username 用户名
|
||||||
|
* @return 请求头
|
||||||
|
*/
|
||||||
|
protected Map<String, String> getHeaders(String username) {
|
||||||
|
Map<String, String> headers = new HashMap<>();
|
||||||
|
headers.put("token", getToken(username));
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.jhinno.sdk.openapi.api.app;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yanlongqi
|
||||||
|
* @date 2024/2/1 16:27
|
||||||
|
*/
|
||||||
|
public class AppPathConstant {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 申请会话
|
||||||
|
*/
|
||||||
|
public static final String APPS_START_PATH = "/ws/api/apps/{appId}/start";
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
package com.jhinno.sdk.openapi.api.app;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动会话的请求参数
|
||||||
|
*
|
||||||
|
* @author yanlongqi
|
||||||
|
* @date 2024/2/1 16:31
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class AppStartRequest {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否启动一个新的会话(非必填:默认:false)
|
||||||
|
* <p>
|
||||||
|
* 如果是true则会启动一个新的会话,否则复用已经启动好的会话
|
||||||
|
*/
|
||||||
|
private boolean startNew;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工作路径
|
||||||
|
*/
|
||||||
|
private String cwd;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工作文件
|
||||||
|
*/
|
||||||
|
private String workFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指标
|
||||||
|
*/
|
||||||
|
private String metrics;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 请求获取到的JHClient协议链接的过期目标时间。(必填)
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* 注意:
|
||||||
|
* </p>
|
||||||
|
* 1. 该时间戳是获取到的加密串的过期时间,需要传入一个未来的时间
|
||||||
|
* (如:当前是2024-02-01 17:53:12,假设加密串5分钟之后过期,则该参数为:20240101175812)
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* 2. 该时间错由景行的JHClient进行验证,并不是在服务端进行验证,
|
||||||
|
* 所以为了防止客户端的时间和服务器的时间不一致而导会话不能启动,
|
||||||
|
* 因此此字段尽量在浏览器的生成
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
private String currentTimestamp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会话类型
|
||||||
|
*/
|
||||||
|
private String sessionType;
|
||||||
|
|
||||||
|
private String sessionOwner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动参数
|
||||||
|
* <p>
|
||||||
|
* 例如启动一个demo.exe 该demo.exe需要传入用户名,在命令行的的操作为 demo.exe -u admin
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* 此处传入的参数则为:"-u admin"
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
private String param;
|
||||||
|
|
||||||
|
private String loginUser;
|
||||||
|
|
||||||
|
private String sessionId;
|
||||||
|
|
||||||
|
private String remoteAddr;
|
||||||
|
|
||||||
|
private String remotePort;
|
||||||
|
|
||||||
|
private boolean isInMeetingRoom;
|
||||||
|
|
||||||
|
private String currentMeetingId;
|
||||||
|
|
||||||
|
private boolean jhClientInstalled;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.jhinno.sdk.openapi.api.app;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会话启动信息
|
||||||
|
*
|
||||||
|
* @author yanlongqi
|
||||||
|
* @date 2024/2/1 18:39
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public class AppStartedInfo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JHClient的地址(用于拉起对应会话的JHClient客户端)
|
||||||
|
*
|
||||||
|
* <ul>
|
||||||
|
* <li>
|
||||||
|
* 测试时:可将其粘贴纸浏览器的地址栏里面拉起JHClient客户端
|
||||||
|
* </li>
|
||||||
|
* <li>
|
||||||
|
* 开发时:通过使用a标签,或者使用iframe的方式拉起JHClient客户端
|
||||||
|
* </li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
|
private String jhappUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会话id
|
||||||
|
*/
|
||||||
|
private String desktopId;
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public String toString() {
|
||||||
|
// return JSON.toJSONString(this);
|
||||||
|
// }
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package com.jhinno.sdk.openapi.api.app;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import com.alibaba.fastjson2.TypeReference;
|
||||||
|
import com.jhinno.sdk.openapi.CommonConstant;
|
||||||
|
import com.jhinno.sdk.openapi.ServiceException;
|
||||||
|
import com.jhinno.sdk.openapi.api.JHApiExecution;
|
||||||
|
import com.jhinno.sdk.openapi.api.ResponseResult;
|
||||||
|
import com.jhinno.sdk.openapi.client.JHApiClient;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yanlongqi
|
||||||
|
* @date 2024/2/1 16:26
|
||||||
|
*/
|
||||||
|
public class JHAppApiExecution extends JHApiExecution {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取一个执行器的实例
|
||||||
|
*
|
||||||
|
* @param jhApiClient 请求的客户端
|
||||||
|
*/
|
||||||
|
public JHAppApiExecution(JHApiClient jhApiClient) {
|
||||||
|
super(jhApiClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动一个会话
|
||||||
|
*
|
||||||
|
* @param username 用户名
|
||||||
|
* @param appId 应用拆
|
||||||
|
* @param appStartRequest 启动参数
|
||||||
|
* @return JHClient协议链接
|
||||||
|
*/
|
||||||
|
public AppStartedInfo desktopStart(String username, String appId, AppStartRequest appStartRequest) {
|
||||||
|
String path = AppPathConstant.APPS_START_PATH.replace("{appId}", appId);
|
||||||
|
ResponseResult<List<AppStartedInfo>> result = jhApiClient.post(path, appStartRequest, getHeaders(username), new TypeReference<ResponseResult<List<AppStartedInfo>>>() {
|
||||||
|
});
|
||||||
|
if (StringUtils.equals(result.getResult(), CommonConstant.FAILED)) {
|
||||||
|
throw new ServiceException(path, result.getCode(), result.getMessage());
|
||||||
|
}
|
||||||
|
List<AppStartedInfo> data = result.getData();
|
||||||
|
if (CollectionUtil.isEmpty(data)) {
|
||||||
|
throw new ServiceException(path, result.getCode(), "获取到的会话信息为空");
|
||||||
|
}
|
||||||
|
return data.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.jhinno.sdk.openapi.api.auth;
|
|
||||||
|
|
||||||
import com.jhinno.sdk.openapi.api.JHApiExecution;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author yanlongqi
|
|
||||||
* @date 2024/1/30 19:47
|
|
||||||
*/
|
|
||||||
public class AuthJHApiClientExecution extends JHApiExecution {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,7 @@ public class AuthPathConstant {
|
|||||||
/**
|
/**
|
||||||
* 获取用户token
|
* 获取用户token
|
||||||
*/
|
*/
|
||||||
public static final String AUTH_TOKEN = "/ws/api/auth/token";
|
public static final String AUTH_TOKEN_PATH = "/ws/api/auth/token";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注销token
|
* 注销token
|
||||||
|
|||||||
@@ -20,17 +20,17 @@ public class DefaultHttpClientConfig {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认socket连接超时的时间
|
* 默认socket连接超时的时间(单位:秒)
|
||||||
*/
|
*/
|
||||||
public static final int SOCKET_TIMEOUT = 5000;
|
public static final int SOCKET_TIMEOUT = 5000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认连接超时的时间
|
* 默认连接超时的时间(单位:秒)
|
||||||
*/
|
*/
|
||||||
public static final int CONNECT_TIMEOUT = 5000;
|
public static final int CONNECT_TIMEOUT = 5000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认请求超时的时间
|
* 默认请求超时的时间(单位:秒)
|
||||||
*/
|
*/
|
||||||
public static final int CONNECTION_REQUEST_TIMEOUT = 5000;
|
public static final int CONNECTION_REQUEST_TIMEOUT = 5000;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,12 +42,14 @@ public class JHApiClient {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 基础的请求URL地址
|
* 基础的请求URL地址
|
||||||
* 如:https://192.168.3.12/appform
|
* <p>
|
||||||
|
* 如:<a href="https://192.168.3.12/appform">https://192.168.3.12/appform</a>
|
||||||
|
* </p>
|
||||||
*/
|
*/
|
||||||
private String baseUrl;
|
private final String baseUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化一个JHApiClient的实例,值得注意的是该实例只能内部创建
|
* 初始化一个JHApiClient的实例,可使用自定义的客户端
|
||||||
*
|
*
|
||||||
* @param baseUrl 景行接口服务的基础地址
|
* @param baseUrl 景行接口服务的基础地址
|
||||||
* @param closeableHttpClient 可关闭的HTTP客户端
|
* @param closeableHttpClient 可关闭的HTTP客户端
|
||||||
@@ -66,7 +68,7 @@ public class JHApiClient {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 每次发送请求的配置,如果该配置未进行设置则走{@link DefaultHttpClientConfig}中的默认配置
|
* 每次发送请求的配置,如果该配置未进行设置则走 {@link DefaultHttpClientConfig} 中的默认配置
|
||||||
*/
|
*/
|
||||||
private RequestConfig requestConfig;
|
private RequestConfig requestConfig;
|
||||||
|
|
||||||
@@ -85,7 +87,7 @@ public class JHApiClient {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 通过{@link DefaultHttpClientConfig}默认配置的最大连接数和服务每次能并行接收的请求数量构建一个JHApiClient实例
|
* 通过 {@link DefaultHttpClientConfig} 默认配置的最大连接数和服务每次能并行接收的请求数量构建一个JHApiClient实例
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param baseUrl 景行接口服务的基础地址
|
* @param baseUrl 景行接口服务的基础地址
|
||||||
@@ -96,7 +98,7 @@ public class JHApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过外部传入的{@link CloseableHttpClient}构建一个请求客户端
|
* 通过外部传入的 {@link CloseableHttpClient} 构建一个请求客户端
|
||||||
* <p>
|
* <p>
|
||||||
*
|
*
|
||||||
* @param httpClient 请求连接池
|
* @param httpClient 请求连接池
|
||||||
@@ -151,9 +153,9 @@ public class JHApiClient {
|
|||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* {@link JHApiClient } 默认只配置了 socket连接超时的时间(socketTimeout) 、连接超时的时间(connectTimeout)、
|
* {@link JHApiClient} 默认只配置了 socket连接超时的时间(socketTimeout) 、连接超时的时间(connectTimeout)、
|
||||||
* 请求超时的时间(connectionRequestTimeout)这三项,其默认配置在{@link DefaultHttpClientConfig}中。
|
* 请求超时的时间(connectionRequestTimeout)这三项,其默认配置在{@link DefaultHttpClientConfig} 中。
|
||||||
* 如果你要自定义你自己的配置,则可以通过{@link HttpClients}构建自己的RequestConfig来请求接口
|
* 如果你要自定义你自己的配置,则可以通过{@link HttpClients} 构建自己的RequestConfig来请求接口
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param requestConfig HTTP请求的配置
|
* @param requestConfig HTTP请求的配置
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.jhinno.sdk.openapi.test.app;
|
||||||
|
|
||||||
|
import com.jhinno.sdk.openapi.api.app.AppStartRequest;
|
||||||
|
import com.jhinno.sdk.openapi.api.app.AppStartedInfo;
|
||||||
|
import com.jhinno.sdk.openapi.api.app.JHAppApiExecution;
|
||||||
|
import com.jhinno.sdk.openapi.client.JHApiClient;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会话启动相关单元测试
|
||||||
|
*
|
||||||
|
* @author yanlongqi
|
||||||
|
* @date 2024/2/1 16:47
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class AppApiTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试获取"jhadmin"的Linux桌面会话的JHClient链接
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testStartApp() {
|
||||||
|
JHApiClient client = JHApiClient.build("https://192.168.87.25/appform");
|
||||||
|
JHAppApiExecution jhAppApiExecution = new JHAppApiExecution(client);
|
||||||
|
AppStartedInfo appStartedInfo = jhAppApiExecution.desktopStart("jhadmin", "linux_desktop", new AppStartRequest());
|
||||||
|
System.out.println(appStartedInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.jhinno.sdk.openapi.test.auth;
|
||||||
|
|
||||||
|
import com.jhinno.sdk.openapi.api.app.JHAppApiExecution;
|
||||||
|
import com.jhinno.sdk.openapi.client.JHApiClient;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 鉴权相关测试累
|
||||||
|
* @author yanlongqi
|
||||||
|
* @date 2024/2/1 18:06
|
||||||
|
*/
|
||||||
|
public class AuthApiTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动会话
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testStartApp() {
|
||||||
|
JHApiClient client = JHApiClient.build("https://192.168.87.25/appform");
|
||||||
|
JHAppApiExecution jhAppApiExecution = new JHAppApiExecution(client);
|
||||||
|
String token = jhAppApiExecution.getToken("jhadmin");
|
||||||
|
System.out.println(token);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user