Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
hp-smart
Overview
Overview
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
platform
hp-smart
Commits
c8b335dc
Commit
c8b335dc
authored
Mar 12, 2024
by
宋祥
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.OSS对接
parent
7236844f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
182 additions
and
0 deletions
+182
-0
pom.xml
pom.xml
+7
-0
OssClientUtils.java
src/main/java/com/baosight/hpjx/core/oss/OssClientUtils.java
+98
-0
OssUtils.java
src/main/java/com/baosight/hpjx/core/oss/OssUtils.java
+47
-0
applicationContext-s3.xml
...main/resources/spring/framework/applicationContext-s3.xml
+13
-0
EUDM04.jsp
src/main/webapp/EU/DM/EUDM04.jsp
+17
-0
No files found.
pom.xml
View file @
c8b335dc
...
...
@@ -161,9 +161,16 @@
<artifactId>
jxl
</artifactId>
<version>
2.6.12
</version>
</dependency>
<!-- S3 OSS -->
<dependency>
<groupId>
com.baosight.iplat4j
</groupId>
<artifactId>
oss-plugin
</artifactId>
<version>
7.0.0
</version>
</dependency>
</dependencies>
<build>
<finalName>
hpjx
</finalName>
<resources>
<resource>
<directory>
src/main/java
</directory>
...
...
src/main/java/com/baosight/hpjx/core/oss/OssClientUtils.java
0 → 100644
View file @
c8b335dc
package
com
.
baosight
.
hpjx
.
core
.
oss
;
import
com.amazonaws.ClientConfiguration
;
import
com.amazonaws.auth.AWSStaticCredentialsProvider
;
import
com.amazonaws.auth.BasicAWSCredentials
;
import
com.amazonaws.client.builder.AwsClientBuilder
;
import
com.amazonaws.services.s3.AmazonS3
;
import
com.amazonaws.services.s3.AmazonS3ClientBuilder
;
import
com.baosight.hpjx.util.StringUtils
;
import
com.baosight.iplat4j.core.ioc.spring.PlatApplicationContext
;
import
lombok.extern.slf4j.Slf4j
;
/**
* OSS凭证
*
* @author:songx
* @date:2023/8/28,11:26
*/
@Slf4j
public
class
OssClientUtils
{
private
OssClientUtils
()
{
}
/**
* 初始化配置信息(纯粹就打印日志而已,因为会加载该类的全局变量)
*/
public
static
void
init
()
{
AmazonS3
s3Client
=
Instance
.
s3Client
;
log
.
info
(
"初始化OSS客户端完成:isReady -> {}"
,
s3Client
!=
null
);
}
/**
* 获取S3客户端
*
* @return
*/
public
static
AmazonS3
getS3Client
()
{
return
Instance
.
s3Client
;
}
/**
* 刷新客户端
*/
public
static
void
refresh
()
{
Instance
.
refresh
();
}
/**
* 初始化Instance
*
* @author:songx
* @date:2022/4/2,9:58
*/
private
static
class
Instance
{
/**
* 客户端实例
*/
private
static
AmazonS3
s3Client
=
buildAmazonS3
();
/**
* 刷新S3客户端
*/
private
static
void
refresh
()
{
s3Client
=
buildAmazonS3
();
log
.
info
(
"刷新OSS客户端完成:isReady->{}"
,
s3Client
!=
null
);
}
/**
* 获取AmazonS3Client实例
*
* @return
*/
private
static
synchronized
AmazonS3
buildAmazonS3
()
{
String
accessKey
=
PlatApplicationContext
.
getProperty
(
"iplat4j.admin.objectStorage.s3.accessKey"
);
String
secretKey
=
PlatApplicationContext
.
getProperty
(
"iplat4j.admin.objectStorage.s3.secretKey"
);
String
endpoint
=
PlatApplicationContext
.
getProperty
(
"iplat4j.admin.objectStorage.s3.endpoint"
);
if
(
StringUtils
.
isBlank
(
accessKey
)
||
StringUtils
.
isBlank
(
secretKey
)
||
StringUtils
.
isBlank
(
endpoint
))
{
return
null
;
}
AmazonS3ClientBuilder
client
=
AmazonS3ClientBuilder
.
standard
();
ClientConfiguration
config
=
new
ClientConfiguration
();
config
.
setProtocol
(
com
.
amazonaws
.
Protocol
.
HTTPS
);
config
.
setConnectionTimeout
(
10001
);
config
.
setSignerOverride
(
"S3SignerType"
);
client
.
setClientConfiguration
(
config
);
client
.
setCredentials
(
new
AWSStaticCredentialsProvider
(
new
BasicAWSCredentials
(
accessKey
,
secretKey
)));
String
url
=
endpoint
+
":"
+
80
;
client
.
setEndpointConfiguration
(
new
AwsClientBuilder
.
EndpointConfiguration
(
endpoint
,
null
));
return
client
.
build
();
}
}
}
src/main/java/com/baosight/hpjx/core/oss/OssUtils.java
0 → 100644
View file @
c8b335dc
package
com
.
baosight
.
hpjx
.
core
.
oss
;
import
com.amazonaws.services.s3.AmazonS3
;
import
com.baosight.hpjx.util.AssertUtils
;
import
com.baosight.iplat4j.core.ioc.spring.PlatApplicationContext
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.jsp.PageContext
;
import
java.io.File
;
/**
* OSS工具类
*
* @author:songx
* @date:2023/8/28,11:25
*/
public
class
OssUtils
{
// 桶名称
private
static
final
String
bucketName
=
PlatApplicationContext
.
getProperty
(
"iplat4j.admin.objectStorage.s3.bucket"
);
/**
* 前端上传文件
*
* @param pageContext
* @return
* @throws Exception
*/
public
static
String
uploadFile
(
PageContext
pageContext
)
throws
Exception
{
HttpServletRequest
request
=
(
HttpServletRequest
)
pageContext
.
getRequest
();
return
null
;
}
/**
* 上传文件
*
* @param key 默认不指定key的情况下,以文件内容的hash值作为文件名
* @param file
*/
public
static
void
uploadFile
(
String
key
,
File
file
)
{
AmazonS3
client
=
OssClientUtils
.
getS3Client
();
AssertUtils
.
isNull
(
client
,
"上传失败,OSS客户端未初始化,请检查"
);
client
.
putObject
(
bucketName
,
key
,
file
);
}
}
src/main/resources/spring/framework/applicationContext-s3.xml
0 → 100644
View file @
c8b335dc
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
>
<bean
id=
"platFileUploader"
class=
"com.baosight.iplat4j.eu.dm.util.PlatFileUploader"
>
<property
name=
"dao"
ref=
"platDao"
/>
</bean>
<bean
id=
"fileUpLoadManager"
class=
"com.baosight.iplat4j.eu.dm.PlatFileUploadManagerByAmazonS3"
>
<property
name=
"fileUploader"
ref=
"platFileUploader"
/>
</bean>
</beans>
src/main/webapp/EU/DM/EUDM04.jsp
0 → 100644
View file @
c8b335dc
<%@ page contentType="text/html;charset=UTF-8" trimDirectiveWhitespaces="true" %>
<%@ page import="com.baosight.iplat4j.config.AdminFactoryConfig" %>
<%@ page import="com.baosight.iplat4j.eu.dm.util.IFileUploadManager" %>
<%@ page import="org.slf4j.LoggerFactory" %>
<%@ page import="org.slf4j.Logger" %>
<%
Logger log = LoggerFactory.getLogger(IFileUploadManager.class);
try {
String result = AdminFactoryConfig.getFileUpLoadInterface().uploadFile(pageContext);
log.info("uploadFile result:{}", result);
} catch (Exception e) {
log.error("附件上传时出现异常{}", e.getMessage(), e);
response.sendError(500, e.getMessage());
return;
}
%>
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