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:
12
pom.xml
12
pom.xml
@@ -55,9 +55,15 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.fastjson2</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>fastjson2</artifactId>
|
<artifactId>jackson-core</artifactId>
|
||||||
<version>2.0.25</version>
|
<version>2.15.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>2.15.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -1,8 +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.AES;
|
||||||
import cn.hutool.crypto.symmetric.SymmetricCrypto;
|
import com.fasterxml.jackson.core.type.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;
|
||||||
import com.jhinno.sdk.openapi.ServiceException;
|
import com.jhinno.sdk.openapi.ServiceException;
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package com.jhinno.sdk.openapi.api;
|
package com.jhinno.sdk.openapi.api;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yanlongqi
|
* @author yanlongqi
|
||||||
* @date 2024/1/31 10:16
|
* @date 2024/1/31 10:16
|
||||||
*/
|
*/
|
||||||
|
@Data
|
||||||
public class ResponseResult<T> {
|
public class ResponseResult<T> {
|
||||||
|
|
||||||
|
|
||||||
@@ -27,76 +30,4 @@ public class ResponseResult<T> {
|
|||||||
*/
|
*/
|
||||||
private T data;
|
private T data;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取请求编号
|
|
||||||
*
|
|
||||||
* @return 请求编号
|
|
||||||
*/
|
|
||||||
public int getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置请求编号
|
|
||||||
*
|
|
||||||
* @param code 请求编号
|
|
||||||
*/
|
|
||||||
public void setCode(int code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取请求状态
|
|
||||||
*
|
|
||||||
* @return 请求状态
|
|
||||||
*/
|
|
||||||
public String getResult() {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置请求状态
|
|
||||||
*
|
|
||||||
* @param result 请求状态
|
|
||||||
*/
|
|
||||||
public void setResult(String result) {
|
|
||||||
this.result = result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取请求信息
|
|
||||||
*
|
|
||||||
* @return 请求信息
|
|
||||||
*/
|
|
||||||
public String getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置请求信息
|
|
||||||
*
|
|
||||||
* @param message 请求信息
|
|
||||||
*/
|
|
||||||
public void setMessage(String message) {
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取请求数据
|
|
||||||
*
|
|
||||||
* @return 请求数据
|
|
||||||
*/
|
|
||||||
public T getData() {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置去就去数据
|
|
||||||
*
|
|
||||||
* @param data 请求数据
|
|
||||||
*/
|
|
||||||
public void setData(T data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.jhinno.sdk.openapi.api.app;
|
package com.jhinno.sdk.openapi.api.app;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 会话启动信息
|
* 会话启动信息
|
||||||
@@ -9,7 +8,7 @@ import lombok.Getter;
|
|||||||
* @author yanlongqi
|
* @author yanlongqi
|
||||||
* @date 2024/2/1 18:39
|
* @date 2024/2/1 18:39
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Data
|
||||||
public class AppStartedInfo {
|
public class AppStartedInfo {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,9 +29,4 @@ public class AppStartedInfo {
|
|||||||
* 会话id
|
* 会话id
|
||||||
*/
|
*/
|
||||||
private String desktopId;
|
private String desktopId;
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public String toString() {
|
|
||||||
// return JSON.toJSONString(this);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.jhinno.sdk.openapi.api.app;
|
package com.jhinno.sdk.openapi.api.app;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import com.alibaba.fastjson2.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
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.JHApiExecution;
|
import com.jhinno.sdk.openapi.api.JHApiExecution;
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
package com.jhinno.sdk.openapi.api.auth;
|
package com.jhinno.sdk.openapi.api.auth;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求令牌,用户请求其他接口
|
* 请求令牌,用户请求其他接口
|
||||||
*
|
*
|
||||||
* @author yanlongqi
|
* @author yanlongqi
|
||||||
* @date 2024/1/31 10:30
|
* @date 2024/1/31 10:30
|
||||||
*/
|
*/
|
||||||
|
@Data
|
||||||
public class Token {
|
public class Token {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,21 +16,4 @@ public class Token {
|
|||||||
*/
|
*/
|
||||||
private String token;
|
private String token;
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取令牌
|
|
||||||
*
|
|
||||||
* @return 令牌
|
|
||||||
*/
|
|
||||||
public String getToken() {
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置令牌
|
|
||||||
*
|
|
||||||
* @param token 令牌
|
|
||||||
*/
|
|
||||||
public void setToken(String token) {
|
|
||||||
this.token = token;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.jhinno.sdk.openapi.client;
|
package com.jhinno.sdk.openapi.client;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.alibaba.fastjson2.TypeReference;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.jhinno.sdk.openapi.ClientErrorCode;
|
import com.jhinno.sdk.openapi.ClientErrorCode;
|
||||||
import com.jhinno.sdk.openapi.ClientException;
|
import com.jhinno.sdk.openapi.ClientException;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@@ -21,9 +21,9 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
|||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||||
import org.apache.http.ssl.SSLContextBuilder;
|
import org.apache.http.ssl.SSLContextBuilder;
|
||||||
import org.apache.http.util.EntityUtils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
||||||
@@ -216,8 +216,9 @@ public class JHApiClient {
|
|||||||
*/
|
*/
|
||||||
public <T> T request(HttpRequestBase httpRequest, Map<String, String> headers, TypeReference<T> type) {
|
public <T> T request(HttpRequestBase httpRequest, Map<String, String> headers, TypeReference<T> type) {
|
||||||
try {
|
try {
|
||||||
String result = EntityUtils.toString(request(httpRequest, headers));
|
InputStream content = request(httpRequest, headers).getContent();
|
||||||
return type.parseObject(result);
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
return mapper.readValue(content, type);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ClientException(e.getMessage());
|
throw new ClientException(e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -309,7 +310,9 @@ public class JHApiClient {
|
|||||||
HttpPost httpPost = new HttpPost(baseUrl + path);
|
HttpPost httpPost = new HttpPost(baseUrl + path);
|
||||||
try {
|
try {
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
httpPost.setEntity(new StringEntity(JSONObject.toJSONString(body), "utf-8"));
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
String bodyStr = mapper.writeValueAsString(body);
|
||||||
|
httpPost.setEntity(new StringEntity(bodyStr, "utf-8"));
|
||||||
}
|
}
|
||||||
return request(httpPost, headers, type);
|
return request(httpPost, headers, type);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -336,7 +339,9 @@ public class JHApiClient {
|
|||||||
HttpPut httpPost = new HttpPut(baseUrl + path);
|
HttpPut httpPost = new HttpPut(baseUrl + path);
|
||||||
try {
|
try {
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
httpPost.setEntity(new StringEntity(JSONObject.toJSONString(body), "utf-8"));
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
String bodyStr = mapper.writeValueAsString(body);
|
||||||
|
httpPost.setEntity(new StringEntity(bodyStr, "utf-8"));
|
||||||
}
|
}
|
||||||
return request(httpPost, headers, type);
|
return request(httpPost, headers, type);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
package com.jhinno.sdk.openapi.client;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson2.TypeReference;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author yanlongqi
|
|
||||||
* @date 2024/1/30 19:35
|
|
||||||
*/
|
|
||||||
public class ResultType<T> extends TypeReference<T> {
|
|
||||||
}
|
|
||||||
@@ -6,9 +6,6 @@ import com.jhinno.sdk.openapi.api.app.JHAppApiExecution;
|
|||||||
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.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 会话启动相关单元测试
|
* 会话启动相关单元测试
|
||||||
*
|
*
|
||||||
@@ -18,12 +15,13 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class AppApiTest {
|
public class AppApiTest {
|
||||||
|
|
||||||
|
public static final JHApiClient client = JHApiClient.build("https://192.168.87.25/appform");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试获取"jhadmin"的Linux桌面会话的JHClient链接
|
* 测试获取"jhadmin"的Linux桌面会话的JHClient链接
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testStartApp() {
|
public void testStartApp() {
|
||||||
JHApiClient client = JHApiClient.build("https://192.168.87.25/appform");
|
|
||||||
JHAppApiExecution jhAppApiExecution = new JHAppApiExecution(client);
|
JHAppApiExecution jhAppApiExecution = new JHAppApiExecution(client);
|
||||||
AppStartedInfo appStartedInfo = jhAppApiExecution.desktopStart("jhadmin", "linux_desktop", new AppStartRequest());
|
AppStartedInfo appStartedInfo = jhAppApiExecution.desktopStart("jhadmin", "linux_desktop", new AppStartRequest());
|
||||||
System.out.println(appStartedInfo);
|
System.out.println(appStartedInfo);
|
||||||
|
|||||||
@@ -6,19 +6,21 @@ import org.junit.Test;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 鉴权相关测试累
|
* 鉴权相关测试累
|
||||||
|
*
|
||||||
* @author yanlongqi
|
* @author yanlongqi
|
||||||
* @date 2024/2/1 18:06
|
* @date 2024/2/1 18:06
|
||||||
*/
|
*/
|
||||||
public class AuthApiTest {
|
public class AuthApiTest {
|
||||||
|
|
||||||
|
public static final JHApiClient client = JHApiClient.build("https://192.168.87.25/appform");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动会话
|
* 测试获取token
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testStartApp() {
|
public void testGetToken() {
|
||||||
JHApiClient client = JHApiClient.build("https://192.168.87.25/appform");
|
|
||||||
JHAppApiExecution jhAppApiExecution = new JHAppApiExecution(client);
|
JHAppApiExecution jhAppApiExecution = new JHAppApiExecution(client);
|
||||||
String token = jhAppApiExecution.getToken("jhadmin");
|
String token = jhAppApiExecution.getToken("jhadmin");
|
||||||
System.out.println(token);
|
System.out.println("token:" + token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user