Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rs-cloud-platform
Project
Project
Details
Activity
Releases
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
周健威
rs-cloud-platform
Commits
0aab7837
Commit
0aab7837
authored
Dec 10, 2020
by
周健威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加gtdata
parent
817fa0f3
Changes
16
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
3081 additions
and
4 deletions
+3081
-4
pom.xml
ace-common/pom.xml
+6
-0
Digests.java
.../src/main/java/com/upyuns/platform/rs/gtdata/Digests.java
+130
-0
Encodes.java
.../src/main/java/com/upyuns/platform/rs/gtdata/Encodes.java
+127
-0
Exceptions.java
...c/main/java/com/upyuns/platform/rs/gtdata/Exceptions.java
+73
-0
ExecLinuxCmd.java
...main/java/com/upyuns/platform/rs/gtdata/ExecLinuxCmd.java
+43
-0
GtDataRestClient.java
.../java/com/upyuns/platform/rs/gtdata/GtDataRestClient.java
+1928
-0
GtDataRestException.java
...va/com/upyuns/platform/rs/gtdata/GtDataRestException.java
+35
-0
GtPathUtil.java
...c/main/java/com/upyuns/platform/rs/gtdata/GtPathUtil.java
+79
-0
GtdataCondition.java
...n/java/com/upyuns/platform/rs/gtdata/GtdataCondition.java
+19
-0
GtdataFile.java
...c/main/java/com/upyuns/platform/rs/gtdata/GtdataFile.java
+67
-0
HttpUtils.java
...rc/main/java/com/upyuns/platform/rs/gtdata/HttpUtils.java
+189
-0
JsonMapper.java
...c/main/java/com/upyuns/platform/rs/gtdata/JsonMapper.java
+184
-0
ShareFile.java
...rc/main/java/com/upyuns/platform/rs/gtdata/ShareFile.java
+73
-0
WebConfiguration.java
...pyuns/platform/rs/datacenter/config/WebConfiguration.java
+64
-0
RscpImageDataTotalController.java
...form/rs/datacenter/rest/RscpImageDataTotalController.java
+0
-4
WebConfiguration.java
...m/upyuns/platform/rs/website/config/WebConfiguration.java
+64
-0
No files found.
ace-common/pom.xml
View file @
0aab7837
...
...
@@ -39,6 +39,12 @@
<poi.version>
3.15
</poi.version>
</properties>
<dependencies>
<dependency>
<groupId>
com.fasterxml.jackson.module
</groupId>
<artifactId>
jackson-module-jaxb-annotations
</artifactId>
<optional>
true
</optional>
<version>
2.8.3
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
ace-common/src/main/java/com/upyuns/platform/rs/gtdata/Digests.java
0 → 100644
View file @
0aab7837
package
com
.
upyuns
.
platform
.
rs
.
gtdata
;
import
org.apache.commons.lang3.Validate
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.security.GeneralSecurityException
;
import
java.security.MessageDigest
;
import
java.security.SecureRandom
;
/**
*
* Description:支持SHA-1/MD5消息摘要的工具类(返回ByteSource,可进一步被编码为Hex, Base64或UrlSafeBase64)
*
* @author JhYao 2014年10月20日
*
* @version v1.0
*
*/
public
class
Digests
{
private
static
final
String
SHA1
=
"SHA-1"
;
private
static
final
String
MD5
=
"MD5"
;
private
static
SecureRandom
random
=
new
SecureRandom
();
/**
* 对输入字符串进行sha1散列.
*/
public
static
byte
[]
sha1
(
byte
[]
input
)
{
return
digest
(
input
,
SHA1
,
null
,
1
);
}
public
static
byte
[]
sha1
(
byte
[]
input
,
byte
[]
salt
)
{
return
digest
(
input
,
SHA1
,
salt
,
1
);
}
public
static
byte
[]
sha1
(
byte
[]
input
,
byte
[]
salt
,
int
iterations
)
{
return
digest
(
input
,
SHA1
,
salt
,
iterations
);
}
/**
* 对字符串进行散列, 支持md5与sha1算法.
*/
private
static
byte
[]
digest
(
byte
[]
input
,
String
algorithm
,
byte
[]
salt
,
int
iterations
)
{
try
{
MessageDigest
digest
=
MessageDigest
.
getInstance
(
algorithm
);
if
(
salt
!=
null
)
{
digest
.
update
(
salt
);
}
byte
[]
result
=
digest
.
digest
(
input
);
for
(
int
i
=
1
;
i
<
iterations
;
i
++)
{
digest
.
reset
();
result
=
digest
.
digest
(
result
);
}
return
result
;
}
catch
(
GeneralSecurityException
e
)
{
throw
Exceptions
.
unchecked
(
e
);
}
}
/**
* 对字符串进行散列, 支持md5与sha1算法.
*/
private
static
byte
[]
digest
(
byte
[]
input
,
String
algorithm
)
{
try
{
MessageDigest
digest
=
MessageDigest
.
getInstance
(
algorithm
);
byte
[]
result
=
digest
.
digest
(
input
);
return
result
;
}
catch
(
GeneralSecurityException
e
)
{
throw
Exceptions
.
unchecked
(
e
);
}
}
/**
* 生成随机的Byte[]作为salt.
*
* @param numBytes byte数组的大小
*/
public
static
byte
[]
generateSalt
(
int
numBytes
)
{
Validate
.
isTrue
(
numBytes
>
0
,
"numBytes argument must be a positive integer (1 or larger)"
,
numBytes
);
byte
[]
bytes
=
new
byte
[
numBytes
];
random
.
nextBytes
(
bytes
);
return
bytes
;
}
/**
* 对字符串进行md5散列.
*/
public
static
byte
[]
md5
(
InputStream
input
)
throws
IOException
{
return
digest
(
input
,
MD5
);
}
/**
* 对文件进行md5散列.
*/
public
static
byte
[]
md5
(
byte
[]
input
)
throws
IOException
{
return
digest
(
input
,
MD5
);
}
/**
* 对文件进行sha1散列.
*/
public
static
byte
[]
sha1
(
InputStream
input
)
throws
IOException
{
return
digest
(
input
,
SHA1
);
}
private
static
byte
[]
digest
(
InputStream
input
,
String
algorithm
)
throws
IOException
{
try
{
MessageDigest
messageDigest
=
MessageDigest
.
getInstance
(
algorithm
);
int
bufferLength
=
8
*
1024
;
byte
[]
buffer
=
new
byte
[
bufferLength
];
int
read
=
input
.
read
(
buffer
,
0
,
bufferLength
);
while
(
read
>
-
1
)
{
messageDigest
.
update
(
buffer
,
0
,
read
);
read
=
input
.
read
(
buffer
,
0
,
bufferLength
);
}
return
messageDigest
.
digest
();
}
catch
(
GeneralSecurityException
e
)
{
throw
Exceptions
.
unchecked
(
e
);
}
}
}
ace-common/src/main/java/com/upyuns/platform/rs/gtdata/Encodes.java
0 → 100644
View file @
0aab7837
package
com
.
upyuns
.
platform
.
rs
.
gtdata
;
import
org.apache.commons.codec.DecoderException
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.codec.binary.Hex
;
import
org.apache.commons.lang3.StringEscapeUtils
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLDecoder
;
import
java.net.URLEncoder
;
/**
*
* Description:封装各种格式的编码解码工具类(1.Commons-Codec的 hex/base64 编码;2.自制的base62 编码;3.Commons-Lang的xml/html
* escape;4.JDK提供的URLEncoder)
*
* @author JhYao 2014年10月20日
*
* @version v1.0
*
*/
public
class
Encodes
{
private
static
final
String
DEFAULT_URL_ENCODING
=
"UTF-8"
;
private
static
final
char
[]
BASE62
=
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
.
toCharArray
();
/**
* Hex编码.
*/
public
static
String
encodeHex
(
byte
[]
input
)
{
return
Hex
.
encodeHexString
(
input
);
}
/**
* Hex解码.
*/
public
static
byte
[]
decodeHex
(
String
input
)
{
try
{
return
Hex
.
decodeHex
(
input
.
toCharArray
());
}
catch
(
DecoderException
e
)
{
throw
Exceptions
.
unchecked
(
e
);
}
}
/**
* Base64编码.
*/
public
static
String
encodeBase64
(
byte
[]
input
)
{
return
Base64
.
encodeBase64String
(
input
);
}
/**
* Base64编码, URL安全(将Base64中的URL非法字符'+'和'/'转为'-'和'_', 见RFC3548).
*/
public
static
String
encodeUrlSafeBase64
(
byte
[]
input
)
{
return
Base64
.
encodeBase64URLSafeString
(
input
);
}
/**
* Base64解码.
*/
public
static
byte
[]
decodeBase64
(
String
input
)
{
return
Base64
.
decodeBase64
(
input
);
}
/**
* Base62编码。
*/
public
static
String
encodeBase62
(
byte
[]
input
)
{
char
[]
chars
=
new
char
[
input
.
length
];
for
(
int
i
=
0
;
i
<
input
.
length
;
i
++)
{
chars
[
i
]
=
BASE62
[(
input
[
i
]
&
0xFF
)
%
BASE62
.
length
];
}
return
new
String
(
chars
);
}
/**
* Html 转码.
*/
public
static
String
escapeHtml
(
String
html
)
{
return
StringEscapeUtils
.
escapeHtml4
(
html
);
}
/**
* Html 解码.
*/
public
static
String
unescapeHtml
(
String
htmlEscaped
)
{
return
StringEscapeUtils
.
unescapeHtml4
(
htmlEscaped
);
}
/**
* Xml 转码.
*/
public
static
String
escapeXml
(
String
xml
)
{
return
StringEscapeUtils
.
escapeXml
(
xml
);
}
/**
* Xml 解码.
*/
public
static
String
unescapeXml
(
String
xmlEscaped
)
{
return
StringEscapeUtils
.
unescapeXml
(
xmlEscaped
);
}
/**
* URL 编码, Encode默认为UTF-8.
*/
public
static
String
urlEncode
(
String
part
)
{
try
{
return
URLEncoder
.
encode
(
part
,
DEFAULT_URL_ENCODING
);
}
catch
(
UnsupportedEncodingException
e
)
{
throw
Exceptions
.
unchecked
(
e
);
}
}
/**
* URL 解码, Encode默认为UTF-8.
*/
public
static
String
urlDecode
(
String
part
)
{
try
{
return
URLDecoder
.
decode
(
part
,
DEFAULT_URL_ENCODING
);
}
catch
(
UnsupportedEncodingException
e
)
{
throw
Exceptions
.
unchecked
(
e
);
}
}
}
ace-common/src/main/java/com/upyuns/platform/rs/gtdata/Exceptions.java
0 → 100644
View file @
0aab7837
package
com
.
upyuns
.
platform
.
rs
.
gtdata
;
import
java.io.PrintWriter
;
import
java.io.StringWriter
;
/**
*
* Description:关于异常的工具类(参考了guava的Throwables)
*
* @author JhYao 2014年10月20日
*
* @version v1.0
*
*/
public
class
Exceptions
{
/**
* 将CheckedException转换为UncheckedException.
*/
public
static
RuntimeException
unchecked
(
Throwable
ex
)
{
if
(
ex
instanceof
RuntimeException
)
{
return
(
RuntimeException
)
ex
;
}
else
{
return
new
RuntimeException
(
ex
);
}
}
/**
* 将ErrorStack转化为String.
*/
public
static
String
getStackTraceAsString
(
Throwable
ex
)
{
StringWriter
stringWriter
=
new
StringWriter
();
ex
.
printStackTrace
(
new
PrintWriter
(
stringWriter
));
return
stringWriter
.
toString
();
}
/**
* 获取组合本异常信息与底层异常信息的异常描述, 适用于本异常为统一包装异常类,底层异常才是根本原因的情况。
*/
public
static
String
getErrorMessageWithNestedException
(
Throwable
ex
)
{
Throwable
nestedException
=
ex
.
getCause
();
return
new
StringBuilder
().
append
(
ex
.
getMessage
()).
append
(
" nested exception is "
)
.
append
(
nestedException
.
getClass
().
getName
()).
append
(
":"
).
append
(
nestedException
.
getMessage
())
.
toString
();
}
/**
* 获取异常的Root Cause.
*/
public
static
Throwable
getRootCause
(
Throwable
ex
)
{
Throwable
cause
;
while
((
cause
=
ex
.
getCause
())
!=
null
)
{
ex
=
cause
;
}
return
ex
;
}
/**
* 判断异常是否由某些底层的异常引起.
*/
public
static
boolean
isCausedBy
(
Exception
ex
,
Class
<?
extends
Exception
>...
causeExceptionClasses
)
{
Throwable
cause
=
ex
;
while
(
cause
!=
null
)
{
for
(
Class
<?
extends
Exception
>
causeClass
:
causeExceptionClasses
)
{
if
(
causeClass
.
isInstance
(
cause
))
{
return
true
;
}
}
cause
=
cause
.
getCause
();
}
return
false
;
}
}
ace-common/src/main/java/com/upyuns/platform/rs/gtdata/ExecLinuxCmd.java
0 → 100644
View file @
0aab7837
package
com
.
upyuns
.
platform
.
rs
.
gtdata
;
import
java.io.InputStreamReader
;
import
java.io.LineNumberReader
;
/**
*
* Description:java在linux环境下执行linux命令
*
* @author JhYao 2015年1月12日
*
* @version v1.0
*
*/
public
class
ExecLinuxCmd
{
/**
*
* Description:java在linux环境下执行linux命令
*
* @param cmd
* @return 返回命令返回值
*
*/
public
static
String
exec
(
String
cmd
)
{
try
{
String
[]
cmdA
=
{
"/bin/sh"
,
"-c"
,
cmd
};
Process
process
=
Runtime
.
getRuntime
().
exec
(
cmdA
);
LineNumberReader
br
=
new
LineNumberReader
(
new
InputStreamReader
(
process
.
getInputStream
()));
StringBuffer
sb
=
new
StringBuffer
();
String
line
;
while
((
line
=
br
.
readLine
())
!=
null
)
{
// System.out.println(line);
sb
.
append
(
line
).
append
(
"\n"
);
}
return
sb
.
toString
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
}
ace-common/src/main/java/com/upyuns/platform/rs/gtdata/GtDataRestClient.java
0 → 100644
View file @
0aab7837
This diff is collapsed.
Click to expand it.
ace-common/src/main/java/com/upyuns/platform/rs/gtdata/GtDataRestException.java
0 → 100644
View file @
0aab7837
/**
*
* Copyright zkyg
*/
package
com
.
upyuns
.
platform
.
rs
.
gtdata
;
/**
*
* Description:GtDataRest的Exception
*
* @author JhYao 2014年11月11日
*
* @version v1.0
*
*/
public
class
GtDataRestException
extends
RuntimeException
{
private
static
final
long
serialVersionUID
=
265637423335344668L
;
public
GtDataRestException
()
{
super
();
}
public
GtDataRestException
(
String
message
)
{
super
(
message
);
}
public
GtDataRestException
(
Throwable
cause
)
{
super
(
cause
);
}
public
GtDataRestException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
}
\ No newline at end of file
ace-common/src/main/java/com/upyuns/platform/rs/gtdata/GtPathUtil.java
0 → 100644
View file @
0aab7837
package
com
.
upyuns
.
platform
.
rs
.
gtdata
;
import
org.apache.commons.lang3.StringUtils
;
import
java.io.UnsupportedEncodingException
;
/**
* 用于多gt-data路径转化的相关工具
* @author wugq
*
*/
public
class
GtPathUtil
{
private
final
String
[]
paths
;
private
String
displayPath
;
/**
* 对外隐藏默认构造函数
*/
private
GtPathUtil
(){
paths
=
null
;
}
public
GtPathUtil
(
String
path
){
while
(
path
.
endsWith
(
"/"
)
&&
path
.
length
()>
1
){
path
=
path
.
substring
(
0
,
path
.
length
()-
1
);
}
paths
=
StringUtils
.
splitByWholeSeparator
(
path
,
"/"
);
}
public
GtPathUtil
(
String
path
,
String
filename
){
path
=
path
+
"/"
+
filename
;
while
(
path
.
endsWith
(
"/"
)
&&
path
.
length
()>
1
){
path
=
path
.
substring
(
0
,
path
.
length
()-
1
);
}
paths
=
StringUtils
.
splitByWholeSeparator
(
path
,
"/"
);
}
public
String
getFileName
(){
String
name
=
paths
[
paths
.
length
-
1
];
return
name
;
}
public
String
getPath
()
{
if
(
displayPath
==
null
){
displayPath
=
"/"
+
StringUtils
.
join
(
paths
,
"/"
);
}
return
displayPath
;
}
public
String
getParentPath
()
{
String
path
=
""
;
if
(
paths
.
length
<=
1
)
path
=
"/"
;
else
{
path
=
getPath
();
path
=
path
.
substring
(
0
,
path
.
lastIndexOf
(
"/"
));
}
return
path
;
}
/**
* @param args
* @throws UnsupportedEncodingException
*/
public
static
void
main
(
String
[]
args
){
// TODO Auto-generated method stub
for
(
String
str
:
StringUtils
.
splitByWholeSeparator
(
"//sdasda///dsadas///aaaa"
,
"/"
)){
if
(
str
.
isEmpty
()){
System
.
out
.
println
(
"error"
);
}
// System.out.println(str);
}
System
.
out
.
println
(
new
GtPathUtil
(
"//sdasda///dsadas//aaaa//dddd///"
).
getFileName
());
System
.
out
.
println
(
new
GtPathUtil
(
"//sdasda///dsadas//aaaa//dddd///"
).
getParentPath
());
System
.
out
.
println
(
new
GtPathUtil
(
"//sdasda///dsadas//aaaa//dddd///"
).
getPath
());
}
}
ace-common/src/main/java/com/upyuns/platform/rs/gtdata/GtdataCondition.java
0 → 100644
View file @
0aab7837
package
com
.
upyuns
.
platform
.
rs
.
gtdata
;
import
cn.hutool.core.util.StrUtil
;
import
org.springframework.context.annotation.Condition
;
import
org.springframework.context.annotation.ConditionContext
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.type.AnnotatedTypeMetadata
;
public
class
GtdataCondition
implements
Condition
{
@Override
public
boolean
matches
(
ConditionContext
conditionContext
,
AnnotatedTypeMetadata
annotatedTypeMetadata
)
{
Environment
environment
=
conditionContext
.
getEnvironment
();
String
sign
=
environment
.
getProperty
(
"gtdata.use"
);
if
(
StrUtil
.
isNotBlank
(
sign
)
&&
"true"
.
equals
(
sign
)){
return
true
;
}
return
false
;
}
}
\ No newline at end of file
ace-common/src/main/java/com/upyuns/platform/rs/gtdata/GtdataFile.java
0 → 100644
View file @
0aab7837
/**
*
* Copyright zkyg
*/
package
com
.
upyuns
.
platform
.
rs
.
gtdata
;
import
java.io.Serializable
;
import
java.util.List
;
/**
* Description:个人中心我的空间,gtdata的文件属性
*
* @author ljw 2014-6-19
*
* @version v1.0
*
*/
public
class
GtdataFile
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
1068754518809085144L
;
private
String
path
;
// 文件路径
private
String
size
;
// 文件大小,大小是-1就是文件夹
private
String
time
;
// 修改日期
private
String
filename
;
// 文件名字
private
List
<
GtdataFile
>
child
;
public
List
<
GtdataFile
>
getChild
()
{
return
child
;
}
public
void
setChild
(
List
<
GtdataFile
>
child
)
{
this
.
child
=
child
;
}
public
String
getPath
()
{
return
path
;
}
public
void
setPath
(
String
path
)
{
this
.
path
=
path
;
}
public
String
getSize
()
{
return
size
;
}
public
void
setSize
(
String
size
)
{
this
.
size
=
size
;
}
public
String
getTime
()
{
return
time
;
}
public
void
setTime
(
String
time
)
{
this
.
time
=
time
;
}
public
String
getFilename
()
{
return
filename
;
}
public
void
setFilename
(
String
filename
)
{
this
.
filename
=
filename
;
}
}
ace-common/src/main/java/com/upyuns/platform/rs/gtdata/HttpUtils.java
0 → 100644
View file @
0aab7837
package
com
.
upyuns
.
platform
.
rs
.
gtdata
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpStatus
;
import
org.apache.http.NameValuePair
;
import
org.apache.http.client.entity.UrlEncodedFormEntity
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.client.methods.HttpPut
;
import
org.apache.http.entity.FileEntity
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
public
class
HttpUtils
{
private
static
JsonMapper
jsonMapper
=
JsonMapper
.
buildNormalMapper
();
public
static
Map
<
String
,
Object
>
doGet
(
String
URLString
)
throws
IOException
{
CloseableHttpResponse
response
=
null
;
HttpGet
httpGet
=
new
HttpGet
(
URLString
);
Map
<
String
,
Object
>
ret
=
new
HashMap
<
String
,
Object
>();
try
{
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
response
=
httpclient
.
execute
(
httpGet
);
HttpEntity
entity
=
response
.
getEntity
();
ret
.
put
(
"HttpStatusCode"
,
response
.
getStatusLine
().
getStatusCode
());
if
(
entity
!=
null
)
{
ret
.
put
(
"response"
,
IOUtils
.
toString
(
entity
.
getContent
()));
}
}
finally
{
IOUtils
.
closeQuietly
((
InputStream
)
response
);
httpGet
.
abort
();
}
return
ret
;
}
public
static
Map
<
String
,
Object
>
doPost
(
String
URLString
)
throws
IOException
{
CloseableHttpResponse
response
=
null
;
HttpPost
httpPost
=
new
HttpPost
(
URLString
);
Map
<
String
,
Object
>
ret
=
new
HashMap
<
String
,
Object
>();
try
{
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
response
=
httpclient
.
execute
(
httpPost
);
HttpEntity
entity
=
response
.
getEntity
();
ret
.
put
(
"HttpStatusCode"
,
response
.
getStatusLine
().
getStatusCode
());
if
(
entity
!=
null
)
{
ret
.
put
(
"response"
,
IOUtils
.
toString
(
entity
.
getContent
()));
}
}
finally
{
IOUtils
.
closeQuietly
((
InputStream
)
response
);
httpPost
.
abort
();
}
return
ret
;
}
/**
* Description:HTTP的PUT请求
*
* @author WuWenSheng 2016.06.02
* @param url
* @param params
* @return
* @throws IOException
*/
public
static
Map
<
String
,
Object
>
doPut
(
String
url
,
List
<
NameValuePair
>
params
)
throws
IOException
{
CloseableHttpResponse
response
=
null
;
HttpPut
httpPut
=
new
HttpPut
(
url
);
httpPut
.
setEntity
(
new
UrlEncodedFormEntity
(
params
));
Map
<
String
,
Object
>
ret
=
new
HashMap
<
String
,
Object
>();
try
{
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
response
=
httpclient
.
execute
(
httpPut
);
HttpEntity
entity
=
response
.
getEntity
();
ret
.
put
(
"HttpStatusCode"
,
response
.
getStatusLine
().
getStatusCode
());
if
(
entity
!=
null
)
{
ret
.
put
(
"response"
,
IOUtils
.
toString
(
entity
.
getContent
()));
}
}
finally
{
IOUtils
.
closeQuietly
((
InputStream
)
response
);
httpPut
.
abort
();
}
return
ret
;
}
/**
* Description:HTTP的PUT请求(单属性,不传key)
*
* @author WuWenSheng 2016.06.02
* @param url
* @return
* @throws IOException
*/
public
static
Map
<
String
,
Object
>
doPut
(
String
url
,
String
param
)
throws
IOException
{
CloseableHttpResponse
response
=
null
;
HttpPut
httpPut
=
new
HttpPut
(
url
);
httpPut
.
setEntity
(
new
StringEntity
(
param
));
Map
<
String
,
Object
>
ret
=
new
HashMap
<
String
,
Object
>();
try
{
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
response
=
httpclient
.
execute
(
httpPut
);
HttpEntity
entity
=
response
.
getEntity
();
ret
.
put
(
"HttpStatusCode"
,
response
.
getStatusLine
().
getStatusCode
());
if
(
entity
!=
null
)
{
ret
.
put
(
"response"
,
IOUtils
.
toString
(
entity
.
getContent
()));
}
}
finally
{
IOUtils
.
closeQuietly
((
InputStream
)
response
);
httpPut
.
abort
();
}
return
ret
;
}
public
static
Map
<
String
,
Object
>
putFile
(
String
URLString
,
File
file
)
throws
IOException
{
CloseableHttpResponse
response
=
null
;
Map
<
String
,
Object
>
ret
=
new
HashMap
<
String
,
Object
>();
InputStream
instream
=
null
;
HttpPut
httpPut
=
new
HttpPut
(
URLString
);
try
{
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
FileEntity
reqEntity
=
new
FileEntity
(
file
);
httpPut
.
setEntity
(
reqEntity
);
response
=
httpclient
.
execute
(
httpPut
);
HttpEntity
entity
=
response
.
getEntity
();
ret
.
put
(
"HttpStatusCode"
,
response
.
getStatusLine
().
getStatusCode
());
if
(
entity
!=
null
)
{
instream
=
entity
.
getContent
();
ret
.
putAll
(
jsonMapper
.
fromJson
(
IOUtils
.
toString
(
instream
,
"utf-8"
),
Map
.
class
));
}
}
finally
{
IOUtils
.
closeQuietly
(
instream
);
IOUtils
.
closeQuietly
((
InputStream
)
response
);
httpPut
.
abort
();
}
return
ret
;
}
public
static
Map
<
String
,
Object
>
GetFile
(
String
url
,
OutputStream
output
)
throws
IOException
{
CloseableHttpResponse
response
=
null
;
InputStream
input
=
null
;
Map
<
String
,
Object
>
ret
=
new
HashMap
<
String
,
Object
>();
try
{
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
HttpGet
httpGet
=
new
HttpGet
(
url
);
response
=
httpclient
.
execute
(
httpGet
);
HttpEntity
entity
=
response
.
getEntity
();
if
(
entity
!=
null
)
{
ret
.
put
(
"HttpStatusCode"
,
response
.
getStatusLine
()
.
getStatusCode
());
if
(
response
.
getStatusLine
().
getStatusCode
()
==
HttpStatus
.
SC_OK
)
{
input
=
entity
.
getContent
();
IOUtils
.
copyLarge
(
input
,
output
);
}
else
{
if
(
input
!=
null
)
ret
.
putAll
(
jsonMapper
.
fromJson
(
IOUtils
.
toString
(
input
,
"utf-8"
),
Map
.
class
));
}
}
}
finally
{
IOUtils
.
closeQuietly
(
input
);
IOUtils
.
closeQuietly
(
output
);
IOUtils
.
closeQuietly
((
InputStream
)
response
);
}
return
ret
;
}
public
static
void
main
(
String
[]
args
)
{
// TODO Auto-generated method stub
}
}
ace-common/src/main/java/com/upyuns/platform/rs/gtdata/JsonMapper.java
0 → 100644
View file @
0aab7837
package
com
.
upyuns
.
platform
.
rs
.
gtdata
;
import
com.fasterxml.jackson.annotation.JsonInclude.Include
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.DeserializationFeature
;
import
com.fasterxml.jackson.databind.JavaType
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
com.fasterxml.jackson.databind.util.JSONPObject
;
import
com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
java.util.Collection
;
import
java.util.Map
;
/**
*
* Description:简单封装Jackson,实现JSON String<->Java Object的Mapper(封装不同的输出风格, 使用不同的builder函数创建实例)
*
* @author JhYao 2014年10月20日
*
* @version v1.0
*
*/
public
class
JsonMapper
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
JsonMapper
.
class
);
private
ObjectMapper
mapper
;
public
JsonMapper
()
{
this
(
null
);
}
public
JsonMapper
(
Include
include
)
{
mapper
=
new
ObjectMapper
();
// 设置输出时包含属性的风格
if
(
include
!=
null
)
{
mapper
.
setSerializationInclusion
(
include
);
}
// 设置输入时忽略在JSON字符串中存在但Java对象实际没有的属性
mapper
.
disable
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
);
}
/**
* 创建输出全部属性到Json字符串的Mapper.
*/
public
static
JsonMapper
buildNormalMapper
()
{
return
new
JsonMapper
(
Include
.
ALWAYS
);
}
/**
* 创建只输出非Null且非Empty(如List.isEmpty)的属性到Json字符串的Mapper,建议在外部接口中使用.
*/
public
static
JsonMapper
nonEmptyMapper
()
{
return
new
JsonMapper
(
Include
.
NON_EMPTY
);
}
/**
* 创建只输出初始值被改变的属性到Json字符串的Mapper, 最节约的存储方式,建议在内部接口中使用。
*/
public
static
JsonMapper
nonDefaultMapper
()
{
return
new
JsonMapper
(
Include
.
NON_DEFAULT
);
}
/**
* Object可以是POJO,也可以是Collection或数组。
* 如果对象为Null, 返回"null".
* 如果集合为空集合, 返回"[]".
*/
public
String
toJson
(
Object
object
)
{
try
{
return
mapper
.
writeValueAsString
(
object
);
}
catch
(
IOException
e
)
{
logger
.
warn
(
"write to json string error:"
+
object
,
e
);
return
null
;
}
}
/**
* 反序列化POJO或简单Collection如List<String>.
*
* 如果JSON字符串为Null或"null"字符串, 返回Null.
* 如果JSON字符串为"[]", 返回空集合.
*
* 如需反序列化复杂Collection如List<MyBean>, 请使用fromJson(String, JavaType)
*
* @see #fromJson(String, JavaType)
*/
public
<
T
>
T
fromJson
(
String
jsonString
,
Class
<
T
>
clazz
)
{
if
(
StringUtils
.
isEmpty
(
jsonString
))
{
return
null
;
}
try
{
return
mapper
.
readValue
(
jsonString
,
clazz
);
}
catch
(
IOException
e
)
{
logger
.
warn
(
"parse json string error:"
+
jsonString
,
e
);
return
null
;
}
}
/**
* 反序列化复杂Collection如List<Bean>, 先使用createCollectionType()或contructMapType()构造类型, 然后调用本函数.
*
* @see
*/
public
<
T
>
T
fromJson
(
String
jsonString
,
JavaType
javaType
)
{
if
(
StringUtils
.
isEmpty
(
jsonString
))
{
return
null
;
}
try
{
return
(
T
)
mapper
.
readValue
(
jsonString
,
javaType
);
}
catch
(
IOException
e
)
{
logger
.
warn
(
"parse json string error:"
+
jsonString
,
e
);
return
null
;
}
}
/**
* 构造Collection类型.
*/
public
JavaType
contructCollectionType
(
Class
<?
extends
Collection
>
collectionClass
,
Class
<?>
elementClass
)
{
return
mapper
.
getTypeFactory
().
constructCollectionType
(
collectionClass
,
elementClass
);
}
/**
* 构造Map类型.
*/
public
JavaType
contructMapType
(
Class
<?
extends
Map
>
mapClass
,
Class
<?>
keyClass
,
Class
<?>
valueClass
)
{
return
mapper
.
getTypeFactory
().
constructMapType
(
mapClass
,
keyClass
,
valueClass
);
}
/**
* 当JSON里只含有Bean的部分屬性時,更新一個已存在Bean,只覆蓋該部分的屬性.
*/
public
void
update
(
String
jsonString
,
Object
object
)
{
try
{
mapper
.
readerForUpdating
(
object
).
readValue
(
jsonString
);
}
catch
(
JsonProcessingException
e
)
{
logger
.
warn
(
"update json string:"
+
jsonString
+
" to object:"
+
object
+
" error."
,
e
);
}
catch
(
IOException
e
)
{
logger
.
warn
(
"update json string:"
+
jsonString
+
" to object:"
+
object
+
" error."
,
e
);
}
}
/**
* 輸出JSONP格式數據.
*/
public
String
toJsonP
(
String
functionName
,
Object
object
)
{
return
toJson
(
new
JSONPObject
(
functionName
,
object
));
}
/**
* 設定是否使用Enum的toString函數來讀寫Enum,
* 為False時時使用Enum的name()函數來讀寫Enum, 默認為False.
* 注意本函數一定要在Mapper創建後, 所有的讀寫動作之前調用.
*/
public
void
enableEnumUseToString
()
{
mapper
.
enable
(
SerializationFeature
.
WRITE_ENUMS_USING_TO_STRING
);
mapper
.
enable
(
DeserializationFeature
.
READ_ENUMS_USING_TO_STRING
);
}
/**
* 支持使用Jaxb的Annotation,使得POJO上的annotation不用与Jackson耦合。
* 默认会先查找jaxb的annotation,如果找不到再找jackson的。
*/
public
void
enableJaxbAnnotation
()
{
JaxbAnnotationModule
module
=
new
JaxbAnnotationModule
();
mapper
.
registerModule
(
module
);
}
/**
* 取出Mapper做进一步的设置或使用其他序列化API.
*/
public
ObjectMapper
getMapper
()
{
return
mapper
;
}
}
ace-common/src/main/java/com/upyuns/platform/rs/gtdata/ShareFile.java
0 → 100644
View file @
0aab7837
package
com
.
upyuns
.
platform
.
rs
.
gtdata
;
import
java.io.Serializable
;
import
java.util.List
;
/**
* Description:个人云盘分享文件的属性
* @author zhengmaopan 2015-6-18
* @version v1.0
*/
public
class
ShareFile
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
1068754518809085144L
;
private
String
id
;
private
String
name
;
//分享or 组名
private
String
user
;
//用户名
private
String
sharetime
;
//分享时间
private
String
size
;
//文件大小
private
String
isdir
;
//是否路径
private
String
path
;
//文件路径
private
List
<
ShareFile
>
child
;
public
List
<
ShareFile
>
getChild
()
{
return
child
;
}
public
void
setChild
(
List
<
ShareFile
>
child
)
{
this
.
child
=
child
;
}
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getUser
()
{
return
user
;
}
public
void
setUser
(
String
user
)
{
this
.
user
=
user
;
}
public
String
getSharetime
()
{
return
sharetime
;
}
public
void
setSharetime
(
String
sharetime
)
{
this
.
sharetime
=
sharetime
;
}
public
String
getSize
()
{
return
size
;
}
public
void
setSize
(
String
size
)
{
this
.
size
=
size
;
}
public
String
getIsdir
()
{
return
isdir
;
}
public
void
setIsdir
(
String
isdir
)
{
this
.
isdir
=
isdir
;
}
public
String
getPath
()
{
return
path
;
}
public
void
setPath
(
String
path
)
{
this
.
path
=
path
;
}
}
rs-datacenter/rs-datacenter-server/src/main/java/com/upyuns/platform/rs/datacenter/config/WebConfiguration.java
0 → 100644
View file @
0aab7837
package
com
.
upyuns
.
platform
.
rs
.
datacenter
.
config
;
import
com.github.wxiaoqi.security.auth.client.interceptor.ServiceAuthRestInterceptor
;
import
com.github.wxiaoqi.security.auth.client.interceptor.UserAuthRestInterceptor
;
import
com.github.wxiaoqi.security.common.handler.GlobalExceptionHandler
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
java.util.ArrayList
;
import
java.util.Collections
;
/**
*
* @author ace
* @date 2017/9/8
*/
@Configuration
(
"datacenterWebConfig"
)
@Primary
public
class
WebConfiguration
implements
WebMvcConfigurer
{
@Bean
GlobalExceptionHandler
getGlobalExceptionHandler
()
{
return
new
GlobalExceptionHandler
();
}
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
registry
.
addInterceptor
(
getServiceAuthRestInterceptor
()).
addPathPatterns
(
getIncludePathPatterns
()).
addPathPatterns
(
"/api/user/validate"
);
registry
.
addInterceptor
(
getUserAuthRestInterceptor
()).
addPathPatterns
(
getIncludePathPatterns
());
}
@Bean
ServiceAuthRestInterceptor
getServiceAuthRestInterceptor
()
{
return
new
ServiceAuthRestInterceptor
();
}
@Bean
UserAuthRestInterceptor
getUserAuthRestInterceptor
()
{
return
new
UserAuthRestInterceptor
();
}
/**
* 需要用户和服务认证判断的路径
* @return
*/
private
ArrayList
<
String
>
getIncludePathPatterns
()
{
ArrayList
<
String
>
list
=
new
ArrayList
<>();
String
[]
urls
=
{
};
Collections
.
addAll
(
list
,
urls
);
return
list
;
}
@Bean
public
RestTemplate
restTemplate
(){
return
new
RestTemplate
();
}
}
rs-datacenter/rs-datacenter-server/src/main/java/com/upyuns/platform/rs/datacenter/rest/RscpImageDataTotalController.java
View file @
0aab7837
...
...
@@ -86,10 +86,6 @@ public class RscpImageDataTotalController extends BaseController<RscpImageDataTo
String
startDateTime
;
String
endDateTime
;
String
geom
;
Double
leftLon
;
Double
rightLon
;
Double
topLat
;
Double
bottomLat
;
String
areaNo
;
String
provinceNo
;
List
<
satelliteDTO
>
saSensor
;
...
...
rs-website/rs-website-server/src/main/java/com/upyuns/platform/rs/website/config/WebConfiguration.java
0 → 100644
View file @
0aab7837
package
com
.
upyuns
.
platform
.
rs
.
website
.
config
;
import
com.github.wxiaoqi.security.auth.client.interceptor.ServiceAuthRestInterceptor
;
import
com.github.wxiaoqi.security.auth.client.interceptor.UserAuthRestInterceptor
;
import
com.github.wxiaoqi.security.common.handler.GlobalExceptionHandler
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
java.util.ArrayList
;
import
java.util.Collections
;
/**
*
* @author ace
* @date 2017/9/8
*/
@Configuration
(
"websiteWebConfig"
)
@Primary
public
class
WebConfiguration
implements
WebMvcConfigurer
{
@Bean
GlobalExceptionHandler
getGlobalExceptionHandler
()
{
return
new
GlobalExceptionHandler
();
}
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
registry
.
addInterceptor
(
getServiceAuthRestInterceptor
()).
addPathPatterns
(
getIncludePathPatterns
()).
addPathPatterns
(
"/api/user/validate"
);
registry
.
addInterceptor
(
getUserAuthRestInterceptor
()).
addPathPatterns
(
getIncludePathPatterns
());
}
@Bean
ServiceAuthRestInterceptor
getServiceAuthRestInterceptor
()
{
return
new
ServiceAuthRestInterceptor
();
}
@Bean
UserAuthRestInterceptor
getUserAuthRestInterceptor
()
{
return
new
UserAuthRestInterceptor
();
}
/**
* 需要用户和服务认证判断的路径
* @return
*/
private
ArrayList
<
String
>
getIncludePathPatterns
()
{
ArrayList
<
String
>
list
=
new
ArrayList
<>();
String
[]
urls
=
{
};
Collections
.
addAll
(
list
,
urls
);
return
list
;
}
@Bean
public
RestTemplate
restTemplate
(){
return
new
RestTemplate
();
}
}
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