增加测试项目
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package com.optima.document.test;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DocumentServerTest {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DocumentServerTest.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.optima.document.test.bean;
|
||||
|
||||
import com.optima.document.api.DocumentService;
|
||||
import com.optima.document.test.config.DocumentServiceConfig;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
@Component
|
||||
public class DocumentConverter {
|
||||
@Resource
|
||||
private DocumentServiceConfig documentServiceConfig;
|
||||
@Resource
|
||||
private DocumentService documentService;
|
||||
|
||||
@PostConstruct
|
||||
public void init() throws IOException {
|
||||
String sourceFilePath = documentServiceConfig.getSourceFile();
|
||||
String targetFilePath = documentServiceConfig.getTargetFile();
|
||||
|
||||
File sourceFile = new File(sourceFilePath);
|
||||
File targetFile = new File(targetFilePath);
|
||||
|
||||
if (targetFile.exists()) {
|
||||
targetFile.delete();
|
||||
}
|
||||
|
||||
String sourceExtension = sourceFile.getName().substring(sourceFile.getName().lastIndexOf("."));
|
||||
String targetExtension = targetFile.getName().substring(targetFile.getName().lastIndexOf("."));
|
||||
|
||||
byte[] converted = documentService.convert(Files.readAllBytes(sourceFile.toPath()), sourceExtension, targetExtension);
|
||||
Files.write(targetFile.toPath(), converted);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.optima.document.test.config;
|
||||
|
||||
import com.optima.document.api.DocumentService;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
|
||||
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "document")
|
||||
public class DocumentServiceConfig {
|
||||
private String server;
|
||||
private String sourceFile;
|
||||
private String targetFile;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Bean
|
||||
public DocumentService documentService() {
|
||||
// 创建客户端代理
|
||||
HttpInvokerProxyFactoryBean factoryBean = new HttpInvokerProxyFactoryBean();
|
||||
String serviceUrl;
|
||||
if (server.endsWith("/")) {
|
||||
serviceUrl = server + "document-service";
|
||||
} else {
|
||||
serviceUrl = server + "/document-service";
|
||||
}
|
||||
factoryBean.setServiceUrl(serviceUrl);
|
||||
factoryBean.setServiceInterface(DocumentService.class);
|
||||
factoryBean.afterPropertiesSet();
|
||||
|
||||
return (DocumentService) factoryBean.getObject();
|
||||
}
|
||||
}
|
||||
4
document-test/src/main/resources/application.yml
Normal file
4
document-test/src/main/resources/application.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
document:
|
||||
server: http://127.0.0.1:9004
|
||||
source-file: /Users/yanghuanglin/Downloads/test.docx
|
||||
target-file: /Users/yanghuanglin/Downloads/test.pdf
|
||||
Reference in New Issue
Block a user