mirror of
https://github.com/yanlongqi/jhinno-openapi-java-sdk.git
synced 2026-03-22 06:15:10 +08:00
feat(示例): 增加SpringBoot示例以及SDK扩展逻辑的优化
This commit is contained in:
75
jhinno-openapi-sdk-spring-boot-example/pom.xml
Normal file
75
jhinno-openapi-sdk-spring-boot-example/pom.xml
Normal file
@@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>cim.jhinno</groupId>
|
||||
<artifactId>jhinno-openapi-sdk-spring-boot-example</artifactId>
|
||||
<version>2.0.3</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>
|
||||
<url>http://jhinno.com</url>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.7.18</version>
|
||||
</parent>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.jhinno</groupId>
|
||||
<artifactId>jhinno-openapi-sdk-spring-boot-starter</artifactId>
|
||||
<version>2.0.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<includeSystemScope>true</includeSystemScope>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<id>lqyan</id>
|
||||
<name>lqyan</name>
|
||||
<email>lqyan@jhinno.com</email>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache License, Version 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.jhinno.sdk.openapi.example;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ExampleApplication {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ExampleApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.jhinno.sdk.openapi.example.api.extend;
|
||||
|
||||
public enum FileEnvType {
|
||||
|
||||
HOME_ENV{
|
||||
@Override
|
||||
public String getEnv() {
|
||||
return "home";
|
||||
}
|
||||
},
|
||||
SPOOLER_ENV{
|
||||
@Override
|
||||
public String getEnv() {
|
||||
return "spooler";
|
||||
}
|
||||
};
|
||||
|
||||
public abstract String getEnv();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.jhinno.sdk.openapi.example.api.extend;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class FilePath {
|
||||
|
||||
/**
|
||||
* 文件路径
|
||||
*/
|
||||
private String path;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.jhinno.sdk.openapi.example.api.extend;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum FileSystemType {
|
||||
|
||||
SYSTEM_TYPE_LINUX {
|
||||
@Override
|
||||
public String getType() {
|
||||
return "linux";
|
||||
}
|
||||
},
|
||||
SYSTEM_TYPE_WINDOWS {
|
||||
@Override
|
||||
public String getType() {
|
||||
return "windows";
|
||||
}
|
||||
};
|
||||
|
||||
public abstract String getType();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.jhinno.sdk.openapi.example.api.extend;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
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.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class JHFileApiExtendExecution extends JHApiExecution {
|
||||
|
||||
public static String GET_FILE_ENV_PATH = "/ws/api/files/path/{env}";
|
||||
|
||||
public FilePath getFileEnvPath(String username, FileEnvType env, FileSystemType type) {
|
||||
Map<String, Object> params = new HashMap<>(1);
|
||||
if (StringUtils.isNotBlank(type.getType())) {
|
||||
params.put("type", type.getType());
|
||||
}
|
||||
String url = JHApiClient.getUrl(GET_FILE_ENV_PATH.replace("{env}", env.getEnv()), params);
|
||||
return get(url, username, new TypeReference<ResponseResult<FilePath>>() {
|
||||
});
|
||||
}
|
||||
|
||||
public FilePath getFileHomeEnvPath(String username, FileSystemType type) {
|
||||
return getFileEnvPath(username, FileEnvType.HOME_ENV, type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.jhinno.sdk.openapi.example.config;
|
||||
|
||||
import com.jhinno.sdk.openapi.example.api.extend.JHFileApiExtendExecution;
|
||||
import com.jhinno.sdk.openapi.utils.JHOpenApiConfig;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class JHOpenapiExecutionConfig {
|
||||
|
||||
|
||||
@Bean
|
||||
public JHFileApiExtendExecution fileApiExtendExecution(JHOpenApiConfig jhOpenApiConfig) {
|
||||
return jhOpenApiConfig.configJHApiExecution(new JHFileApiExtendExecution());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
jhinno:
|
||||
openapi:
|
||||
server-url: https://172.17.0.5/appform
|
||||
auth-type: access_secret_mode
|
||||
access-key: 3f03747f147942bd8debd81b6c9c6a80
|
||||
access-key-secret: e0681859b91c499eb1d2c8e09cea3242
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.jhinno.sdk.openapi.example.test.extend;
|
||||
|
||||
import com.jhinno.sdk.openapi.example.api.extend.FileSystemType;
|
||||
import com.jhinno.sdk.openapi.example.api.extend.JHFileApiExtendExecution;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
public class JHFileApiExtendTest {
|
||||
|
||||
@Autowired
|
||||
private JHFileApiExtendExecution jhFileApiExtendExecution;
|
||||
|
||||
@Test
|
||||
void testGetFileHomeEnvPath() {
|
||||
System.out.println(jhFileApiExtendExecution.getFileHomeEnvPath("jhadmin", FileSystemType.SYSTEM_TYPE_LINUX));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.jhinno.sdk.openapi.utils;
|
||||
|
||||
import com.jhinno.sdk.openapi.api.JHApiExecution;
|
||||
import com.jhinno.sdk.openapi.autoconfigure.JHOpenapiProperties;
|
||||
import com.jhinno.sdk.openapi.client.JHApiClient;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class JHOpenApiConfig {
|
||||
|
||||
private final JHApiClient client;
|
||||
private final JHOpenapiProperties properties;
|
||||
|
||||
public <T extends JHApiExecution> T initJHApiExecution(T execution) {
|
||||
execution.setJhApiClient(client);
|
||||
execution.setForceGetToken(properties.isForceGetToken());
|
||||
execution.setAuthType(properties.getAuthType());
|
||||
execution.setAccessKey(properties.getAccessKey());
|
||||
execution.setAccessKeySecret(properties.getAccessKeySecret());
|
||||
execution.setTokenTimeout(properties.getTokenTimeout());
|
||||
execution.setTokenResidueTime(properties.getTokenResidueTime());
|
||||
execution.setUsedServerTime(properties.isUsedServerTime());
|
||||
return execution;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user