Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
slm-fileview
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
梁杰芳
slm-fileview
Commits
6ccc7248
Commit
6ccc7248
authored
Mar 12, 2021
by
kl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
office plugin 转换进程、任务超时可配置
parent
56cdeffa
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
39 deletions
+64
-39
application.properties
server/src/main/config/application.properties
+6
-0
ConfigConstants.java
server/src/main/java/cn/keking/config/ConfigConstants.java
+39
-37
OfficePluginManager.java
.../src/main/java/cn/keking/service/OfficePluginManager.java
+19
-2
No files found.
server/src/main/config/application.properties
View file @
6ccc7248
...
...
@@ -16,6 +16,12 @@ spring.freemarker.expose-session-attributes = true
spring.freemarker.request-context-attribute
=
request
spring.freemarker.suffix
=
.ftl
# office-plugin
## office转换服务的进程数,默认开启两个进程
office.plugin.server.ports
=
2001,2002
## office 转换服务 task 超时时间,默认五分钟
office.plugin.task.timeout
=
5m
#文件资源路径(默认为打包根路径下的file目录下)
#file.dir = D:\\kkFileview\\
file.dir
=
${KK_FILE_DIR:default}
...
...
server/src/main/java/cn/keking/config/ConfigConstants.java
View file @
6ccc7248
...
...
@@ -21,18 +21,18 @@ public class ConfigConstants {
System
.
setProperty
(
"sun.java2d.cmm"
,
"sun.java2d.cmm.kcms.KcmsServiceProvider"
);
}
private
static
Boolean
CACHE_ENABLED
;
private
static
String
[]
SIM_TEXT
=
{};
private
static
String
[]
MEDIA
=
{};
private
static
String
OFFICE_PREVIEW_TYPE
;
private
static
String
OFFICE_PREVIEW_SWITCH_DISABLED
;
private
static
String
FTP_USERNAME
;
private
static
String
FTP_PASSWORD
;
private
static
String
FTP_CONTROL_ENCODING
;
private
static
String
BASE_URL
;
private
static
String
FILE_DIR
=
ConfigUtils
.
getHomePath
()
+
File
.
separator
+
"file"
+
File
.
separator
;
private
static
CopyOnWriteArraySet
<
String
>
TRUST_HOST_SET
;
private
static
String
PDF_DOWNLOAD_DISABLE
;
private
static
Boolean
cacheEnabled
;
private
static
String
[]
simTexts
=
{};
private
static
String
[]
medias
=
{};
private
static
String
officePreviewType
;
private
static
String
officePreviewSwitchDisabled
;
private
static
String
ftpUsername
;
private
static
String
ftpPassword
;
private
static
String
ftpControlEncoding
;
private
static
String
baseUrl
;
private
static
String
fileDir
=
ConfigUtils
.
getHomePath
()
+
File
.
separator
+
"file"
+
File
.
separator
;
private
static
CopyOnWriteArraySet
<
String
>
trustHostSet
;
private
static
String
pdfDownloadDisable
;
public
static
final
String
DEFAULT_CACHE_ENABLED
=
"true"
;
public
static
final
String
DEFAULT_TXT_TYPE
=
"txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd"
;
...
...
@@ -47,8 +47,9 @@ public class ConfigConstants {
public
static
final
String
DEFAULT_TRUST_HOST
=
"default"
;
public
static
final
String
DEFAULT_PDF_DOWNLOAD_DISABLE
=
"true"
;
public
static
Boolean
isCacheEnabled
()
{
return
CACHE_ENABLED
;
return
cacheEnabled
;
}
@Value
(
"${cache.enabled:true}"
)
...
...
@@ -57,11 +58,11 @@ public class ConfigConstants {
}
public
static
void
setCacheEnabledValueValue
(
Boolean
cacheEnabled
)
{
C
ACHE_ENABLED
=
cacheEnabled
;
C
onfigConstants
.
cacheEnabled
=
cacheEnabled
;
}
public
static
String
[]
getSimText
()
{
return
SIM_TEXT
;
return
simTexts
;
}
@Value
(
"${simText:txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd}"
)
...
...
@@ -71,11 +72,11 @@ public class ConfigConstants {
}
public
static
void
setSimTextValue
(
String
[]
simText
)
{
SIM_TEXT
=
simText
;
ConfigConstants
.
simTexts
=
simText
;
}
public
static
String
[]
getMedia
()
{
return
MEDIA
;
return
medias
;
}
@Value
(
"${media:mp3,wav,mp4,flv}"
)
...
...
@@ -85,11 +86,11 @@ public class ConfigConstants {
}
public
static
void
setMediaValue
(
String
[]
Media
)
{
MEDIA
=
Media
;
ConfigConstants
.
medias
=
Media
;
}
public
static
String
getOfficePreviewType
()
{
return
OFFICE_PREVIEW_TYPE
;
return
officePreviewType
;
}
@Value
(
"${office.preview.type:image}"
)
...
...
@@ -98,11 +99,11 @@ public class ConfigConstants {
}
public
static
void
setOfficePreviewTypeValue
(
String
officePreviewType
)
{
OFFICE_PREVIEW_TYPE
=
officePreviewType
;
ConfigConstants
.
officePreviewType
=
officePreviewType
;
}
public
static
String
getFtpUsername
()
{
return
FTP_USERNAME
;
return
ftpUsername
;
}
@Value
(
"${ftp.username:}"
)
...
...
@@ -111,11 +112,11 @@ public class ConfigConstants {
}
public
static
void
setFtpUsernameValue
(
String
ftpUsername
)
{
FTP_USERNAME
=
ftpUsername
;
ConfigConstants
.
ftpUsername
=
ftpUsername
;
}
public
static
String
getFtpPassword
()
{
return
FTP_PASSWORD
;
return
ftpPassword
;
}
@Value
(
"${ftp.password:}"
)
...
...
@@ -124,11 +125,11 @@ public class ConfigConstants {
}
public
static
void
setFtpPasswordValue
(
String
ftpPassword
)
{
FTP_PASSWORD
=
ftpPassword
;
ConfigConstants
.
ftpPassword
=
ftpPassword
;
}
public
static
String
getFtpControlEncoding
()
{
return
FTP_CONTROL_ENCODING
;
return
ftpControlEncoding
;
}
@Value
(
"${ftp.control.encoding:UTF-8}"
)
...
...
@@ -137,11 +138,11 @@ public class ConfigConstants {
}
public
static
void
setFtpControlEncodingValue
(
String
ftpControlEncoding
)
{
FTP_CONTROL_ENCODING
=
ftpControlEncoding
;
ConfigConstants
.
ftpControlEncoding
=
ftpControlEncoding
;
}
public
static
String
getBaseUrl
()
{
return
BASE_URL
;
return
baseUrl
;
}
@Value
(
"${base.url:default}"
)
...
...
@@ -150,11 +151,11 @@ public class ConfigConstants {
}
public
static
void
setBaseUrlValue
(
String
baseUrl
)
{
BASE_URL
=
baseUrl
;
ConfigConstants
.
baseUrl
=
baseUrl
;
}
public
static
String
getFileDir
()
{
return
FILE_DIR
;
return
fileDir
;
}
@Value
(
"${file.dir:default}"
)
...
...
@@ -167,7 +168,7 @@ public class ConfigConstants {
if
(!
fileDir
.
endsWith
(
File
.
separator
))
{
fileDir
=
fileDir
+
File
.
separator
;
}
FILE_DIR
=
fileDir
;
ConfigConstants
.
fileDir
=
fileDir
;
}
}
...
...
@@ -189,15 +190,15 @@ public class ConfigConstants {
}
public
static
Set
<
String
>
getTrustHostSet
()
{
return
TRUST_HOST_SET
;
return
trustHostSet
;
}
private
static
void
setTrustHostSet
(
CopyOnWriteArraySet
<
String
>
trustHostSet
)
{
ConfigConstants
.
TRUST_HOST_SET
=
trustHostSet
;
ConfigConstants
.
trustHostSet
=
trustHostSet
;
}
public
static
String
getPdfDownloadDisable
()
{
return
PDF_DOWNLOAD_DISABLE
;
return
pdfDownloadDisable
;
}
...
...
@@ -206,17 +207,18 @@ public class ConfigConstants {
setPdfDownloadDisableValue
(
pdfDownloadDisable
);
}
public
static
void
setPdfDownloadDisableValue
(
String
pdfDownloadDisable
)
{
PDF_DOWNLOAD_DISABLE
=
pdfDownloadDisable
;
ConfigConstants
.
pdfDownloadDisable
=
pdfDownloadDisable
;
}
public
static
String
getOfficePreviewSwitchDisabled
()
{
return
OFFICE_PREVIEW_SWITCH_DISABLED
;
return
officePreviewSwitchDisabled
;
}
@Value
(
"${office.preview.switch.disabled:true}"
)
public
void
setOfficePreviewSwitchDisabled
(
String
officePreviewSwitchDisabled
)
{
OFFICE_PREVIEW_SWITCH_DISABLED
=
officePreviewSwitchDisabled
;
ConfigConstants
.
officePreviewSwitchDisabled
=
officePreviewSwitchDisabled
;
}
public
static
void
setOfficePreviewSwitchDisabledValue
(
String
officePreviewSwitchDisabled
)
{
OFFICE_PREVIEW_SWITCH_DISABLED
=
officePreviewSwitchDisabled
;
ConfigConstants
.
officePreviewSwitchDisabled
=
officePreviewSwitchDisabled
;
}
}
server/src/main/java/cn/keking/service/OfficePluginManager.java
View file @
6ccc7248
...
...
@@ -8,6 +8,8 @@ import org.artofsolving.jodconverter.office.OfficeManager;
import
org.artofsolving.jodconverter.office.OfficeUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.convert.DurationStyle
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.stereotype.Component
;
...
...
@@ -19,7 +21,11 @@ import java.io.File;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.charset.StandardCharsets
;
import
java.time.Duration
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Properties
;
...
...
@@ -37,6 +43,12 @@ public class OfficePluginManager {
private
OfficeManager
officeManager
;
@Value
(
"${office.plugin.server.ports:2001,2002}"
)
private
String
serverPorts
;
@Value
(
"${office.plugin.task.timeout:5m}"
)
private
String
timeOut
;
@PostConstruct
public
void
initOfficeManager
()
{
new
Thread
(
this
::
startOfficeManager
).
start
();
...
...
@@ -57,9 +69,14 @@ public class OfficePluginManager {
try
{
DefaultOfficeManagerConfiguration
configuration
=
new
DefaultOfficeManagerConfiguration
();
configuration
.
setOfficeHome
(
officeHome
);
configuration
.
setPortNumber
(
8100
);
String
[]
portsString
=
serverPorts
.
split
(
","
);
int
[]
ports
=
Arrays
.
stream
(
portsString
).
mapToInt
(
Integer:
:
parseInt
).
toArray
();
configuration
.
setPortNumbers
(
ports
);
long
timeout
=
DurationStyle
.
detectAndParse
(
timeOut
).
toMillis
();
// 设置任务执行超时为5分钟
configuration
.
setTaskExecutionTimeout
(
1000
*
60
*
5L
);
configuration
.
setTaskExecutionTimeout
(
timeout
);
// 设置任务队列超时为24小时
//configuration.setTaskQueueTimeout(1000 * 60 * 60 * 24L);
officeManager
=
configuration
.
buildOfficeManager
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment