Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx-performance
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
姜武杰
clx-performance
Commits
d8370ca3
提交
d8370ca3
authored
9月 20, 2024
作者:
jiangwujie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(jdk17springboot3): 增加类和日志排查读取jar包失败的问题
上级
a36e876a
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
382 行增加
和
0 行删除
+382
-0
NBOpenSDK.java
performance-web/src/main/java/com/nbopen/api/NBOpenSDK.java
+382
-0
没有找到文件。
performance-web/src/main/java/com/nbopen/api/NBOpenSDK.java
0 → 100644
浏览文件 @
d8370ca3
package
com
.
nbopen
.
api
;
import
com.nbopen.cl.NBClassLoader
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.lang.reflect.Method
;
import
java.net.URL
;
import
java.util.Enumeration
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarFile
;
public
final
class
NBOpenSDK
{
private
static
final
int
BUFFER_SIZE
=
512
;
private
static
final
String
openSDKName
=
"com.nbopen.sdk.OpenSDK"
;
private
static
Class
openSDK
=
null
;
private
static
Boolean
isInit
=
false
;
private
static
NBClassLoader
nbClassLoader
=
null
;
public
NBOpenSDK
()
{
}
public
static
String
getVersionInfo
()
{
try
{
obtionOpenSDKClass
();
Method
method
=
openSDK
.
getMethod
(
"getVersionInfo"
);
return
(
String
)
method
.
invoke
(
openSDK
.
newInstance
());
}
catch
(
Exception
var1
)
{
var1
.
printStackTrace
();
return
null
;
}
}
public
static
String
getCurrentDate
()
{
try
{
obtionOpenSDKClass
();
Method
method
=
openSDK
.
getMethod
(
"getCurrentDate"
);
return
(
String
)
method
.
invoke
(
openSDK
.
newInstance
());
}
catch
(
Exception
var1
)
{
var1
.
printStackTrace
();
return
""
;
}
}
public
static
String
getCurrentTime
()
{
try
{
obtionOpenSDKClass
();
Method
method
=
openSDK
.
getMethod
(
"getCurrentTime"
);
return
(
String
)
method
.
invoke
(
openSDK
.
newInstance
());
}
catch
(
Exception
var1
)
{
var1
.
printStackTrace
();
return
""
;
}
}
public
static
String
getRandom
()
{
try
{
obtionOpenSDKClass
();
Method
method
=
openSDK
.
getMethod
(
"getRandom"
);
return
(
String
)
method
.
invoke
(
openSDK
.
newInstance
());
}
catch
(
Exception
var1
)
{
var1
.
printStackTrace
();
return
""
;
}
}
public
static
boolean
init
(
InputStream
stream
)
{
try
{
if
(!
isInit
)
{
obtionOpenSDKClass
();
Method
method
=
openSDK
.
getMethod
(
"init"
,
InputStream
.
class
);
isInit
=
(
Boolean
)
method
.
invoke
(
openSDK
.
newInstance
(),
stream
);
}
}
catch
(
Exception
var2
)
{
var2
.
printStackTrace
();
isInit
=
false
;
}
return
isInit
;
}
public
static
boolean
init
(
String
pathOrContent
)
{
try
{
if
(!
isInit
)
{
obtionOpenSDKClass
();
Method
method
=
openSDK
.
getMethod
(
"init"
,
String
.
class
);
isInit
=
(
Boolean
)
method
.
invoke
(
openSDK
.
newInstance
(),
pathOrContent
);
}
}
catch
(
Exception
var2
)
{
var2
.
printStackTrace
();
isInit
=
false
;
}
return
isInit
;
}
public
static
boolean
updateConfig
(
Object
configInfo
)
{
try
{
obtionOpenSDKClass
();
Method
method
=
openSDK
.
getMethod
(
"updateConfig"
,
Object
.
class
);
isInit
=
(
Boolean
)
method
.
invoke
(
openSDK
.
newInstance
(),
configInfo
);
}
catch
(
Exception
var2
)
{
var2
.
printStackTrace
();
}
return
isInit
;
}
public
static
SDKResponse
send
(
SDKRequest
request
)
throws
Exception
{
try
{
obtionOpenSDKClass
();
Method
method
=
openSDK
.
getMethod
(
"send"
,
SDKRequest
.
class
);
return
(
SDKResponse
)
method
.
invoke
(
openSDK
.
newInstance
(),
request
);
}
catch
(
Exception
var2
)
{
var2
.
printStackTrace
();
throw
var2
;
}
}
public
static
SDKResponse
encryptMessage
(
SDKRequest
request
)
throws
Exception
{
try
{
obtionOpenSDKClass
();
Method
method
=
openSDK
.
getMethod
(
"encryptMessage"
,
SDKRequest
.
class
);
return
(
SDKResponse
)
method
.
invoke
(
openSDK
.
newInstance
(),
request
);
}
catch
(
Exception
var2
)
{
var2
.
printStackTrace
();
throw
var2
;
}
}
public
static
SDKResponse
decryptMessage
(
SDKRequest
request
)
throws
Exception
{
try
{
obtionOpenSDKClass
();
Method
method
=
openSDK
.
getMethod
(
"decryptMessage"
,
SDKRequest
.
class
);
return
(
SDKResponse
)
method
.
invoke
(
openSDK
.
newInstance
(),
request
);
}
catch
(
Exception
var2
)
{
var2
.
printStackTrace
();
throw
var2
;
}
}
public
static
SDKResponse
getFile
(
SDKRequest
request
)
throws
Exception
{
try
{
obtionOpenSDKClass
();
Method
method
=
openSDK
.
getMethod
(
"getFileByHttp"
,
SDKRequest
.
class
);
return
(
SDKResponse
)
method
.
invoke
(
openSDK
.
newInstance
(),
request
);
}
catch
(
Exception
var2
)
{
var2
.
printStackTrace
();
throw
var2
;
}
}
public
static
SDKResponse
putFile
(
SDKRequest
request
)
throws
Exception
{
try
{
obtionOpenSDKClass
();
Method
method
=
openSDK
.
getMethod
(
"putFileByHttp"
,
SDKRequest
.
class
);
return
(
SDKResponse
)
method
.
invoke
(
openSDK
.
newInstance
(),
request
);
}
catch
(
Exception
var2
)
{
var2
.
printStackTrace
();
throw
var2
;
}
}
private
static
void
obtionOpenSDKClass
()
throws
ClassNotFoundException
{
if
(
openSDK
==
null
)
{
openSDK
=
nbClassLoader
.
loadClass
(
"com.nbopen.sdk.OpenSDK"
);
}
}
private
static
String
readCurrentJar
(
String
jarPath
)
{
if
(!
jarPath
.
contains
(
"!"
))
{
return
jarPath
;
}
else
{
if
(
jarPath
.
endsWith
(
"!"
))
{
jarPath
=
jarPath
.
substring
(
0
,
jarPath
.
length
()
-
1
);
}
String
userDir
=
System
.
getProperty
(
"user.dir"
);
System
.
out
.
println
(
"nbsdk-userDir: "
+
userDir
);
File
folder
=
new
File
(
userDir
+
File
.
separator
+
"nbsdk"
+
File
.
separator
+
"lib"
);
if
(!
folder
.
exists
())
{
try
{
folder
.
mkdirs
();
}
catch
(
Exception
var7
)
{
throw
new
RuntimeException
(
"mkdir failed "
+
folder
.
getPath
());
}
}
folder
.
deleteOnExit
();
String
[]
path
=
jarPath
.
split
(
"!"
);
String
jar
=
path
[
0
];
String
temp
=
path
[
1
];
if
(
temp
.
contains
(
"openBasicSDK"
))
{
temp
=
temp
.
split
(
"openBasicSDK"
)[
0
];
}
printMsg
(
"nbsdk-temp="
+
temp
);
printMsg
(
"nbsdk-temp.startWith="
+
temp
.
startsWith
(
File
.
separator
));
if
(
temp
.
startsWith
(
"/"
))
{
temp
=
temp
.
substring
(
1
,
temp
.
length
());
}
unzipJarJar
(
jar
,
temp
,
folder
.
getAbsolutePath
());
String
currentJarPath
=
folder
.
getPath
()
+
File
.
separator
+
path
[
1
].
split
(
temp
)[
1
];
printMsg
(
"nbsdk-currentJarPath:"
+
currentJarPath
);
return
currentJarPath
;
}
}
private
static
void
unzipJarJar
(
String
jarPath
,
String
srcPath
,
String
dstPath
)
{
try
{
JarFile
jarFile
=
new
JarFile
(
jarPath
);
Enumeration
<
JarEntry
>
entries
=
jarFile
.
entries
();
while
(
entries
.
hasMoreElements
())
{
JarEntry
jarEntry
=
(
JarEntry
)
entries
.
nextElement
();
String
name
=
jarEntry
.
getName
();
printMsg
(
"nbsdk-unzipJarJar-name="
+
name
+
" srcPath="
+
srcPath
);
String
[]
split
=
name
.
split
(
srcPath
);
printMsg
(
"nbsdk-unzipJarJar-split.length = "
+
split
.
length
);
if
(
name
.
startsWith
(
srcPath
)
&&
split
.
length
==
2
)
{
String
jarName
=
split
[
1
];
printMsg
(
"nbsdk-unzipJarJar-split[0]="
+
split
[
0
]);
printMsg
(
"nbsdk-unzipJarJar-split[1]="
+
jarName
);
if
(
jarName
.
startsWith
(
"openBasicSDK"
))
{
printMsg
(
"nbsdk-unzipJarJar-start unzip jar="
+
name
);
printMsg
(
"nbsdk-unzipJarJar-dstPath="
+
dstPath
);
File
file
=
new
File
(
dstPath
,
jarName
);
unpack
(
jarFile
,
jarEntry
,
file
);
break
;
}
}
}
}
catch
(
Exception
var10
)
{
var10
.
printStackTrace
();
}
}
private
static
File
unpackToFolder
(
File
jarPath
,
NBClassLoader
classLoader
)
{
try
{
String
userDir
=
System
.
getProperty
(
"user.dir"
);
System
.
out
.
println
(
"nbsdk-userDir: "
+
userDir
);
File
folder
=
new
File
(
userDir
+
File
.
separator
+
"nbsdk"
+
File
.
separator
+
"lib"
);
if
(!
folder
.
exists
())
{
try
{
folder
.
mkdirs
();
}
catch
(
Exception
var11
)
{
throw
new
RuntimeException
(
"mkdir failed "
+
folder
.
getPath
());
}
}
folder
.
deleteOnExit
();
JarFile
jarFile
=
new
JarFile
(
jarPath
);
Enumeration
<
JarEntry
>
entries
=
jarFile
.
entries
();
while
(
entries
.
hasMoreElements
())
{
JarEntry
jarEntry
=
(
JarEntry
)
entries
.
nextElement
();
String
name
=
jarEntry
.
getName
();
String
[]
split
=
name
.
split
(
"/"
);
if
(
name
.
startsWith
(
"sdklib/"
)
&&
split
.
length
>
1
)
{
File
file
=
new
File
(
folder
,
split
[
1
]);
printMsg
(
"nbsdk- unpack: "
+
file
.
getPath
());
unpack
(
jarFile
,
jarEntry
,
file
);
URL
url
=
file
.
toURI
().
toURL
();
printMsg
(
"add jar to classLoader: "
+
url
.
toString
());
classLoader
.
addURL
(
url
);
}
}
return
folder
;
}
catch
(
Exception
var12
)
{
System
.
out
.
println
(
"nbsdk- unpack to folder error"
+
var12
);
throw
new
RuntimeException
(
var12
);
}
}
private
static
void
unpack
(
JarFile
jarFile
,
JarEntry
entry
,
File
file
)
throws
IOException
{
printMsg
(
"unpack jarPath = "
+
file
.
getPath
());
InputStream
inputStream
=
jarFile
.
getInputStream
(
entry
);
Throwable
var4
=
null
;
try
{
OutputStream
outputStream
=
new
FileOutputStream
(
file
);
Throwable
var6
=
null
;
try
{
byte
[]
buffer
=
new
byte
[
512
];
int
bytesRead
;
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
outputStream
.
write
(
buffer
,
0
,
bytesRead
);
}
outputStream
.
flush
();
}
catch
(
Throwable
var30
)
{
var6
=
var30
;
throw
var30
;
}
finally
{
if
(
outputStream
!=
null
)
{
if
(
var6
!=
null
)
{
try
{
outputStream
.
close
();
}
catch
(
Throwable
var29
)
{
var6
.
addSuppressed
(
var29
);
}
}
else
{
outputStream
.
close
();
}
}
}
}
catch
(
Throwable
var32
)
{
var4
=
var32
;
throw
var32
;
}
finally
{
if
(
inputStream
!=
null
)
{
if
(
var4
!=
null
)
{
try
{
inputStream
.
close
();
}
catch
(
Throwable
var28
)
{
var4
.
addSuppressed
(
var28
);
}
}
else
{
inputStream
.
close
();
}
}
}
}
private
static
void
deleteFile
(
File
file
)
{
if
(
file
.
exists
())
{
if
(
file
.
isFile
())
{
file
.
delete
();
}
else
{
File
[]
listFiles
=
file
.
listFiles
();
File
[]
var2
=
listFiles
;
int
var3
=
listFiles
.
length
;
for
(
int
var4
=
0
;
var4
<
var3
;
++
var4
)
{
File
f
=
var2
[
var4
];
deleteFile
(
f
);
}
}
file
.
delete
();
}
}
private
static
void
printMsg
(
String
data
)
{
String
debuged
=
System
.
getProperty
(
"nbsdk.sys.debug"
,
"false"
);
if
(
Boolean
.
parseBoolean
(
debuged
))
{
System
.
out
.
println
(
data
);
}
}
static
{
File
files
=
null
;
try
{
String
path
=
NBOpenSDK
.
class
.
getProtectionDomain
().
getCodeSource
().
getLocation
().
getPath
();
if
(
path
.
startsWith
(
"file:"
))
{
path
=
path
.
substring
(
"file:"
.
length
(),
path
.
length
());
}
System
.
out
.
println
(
"nbsdk-jarpath1111:"
+
path
);
nbClassLoader
=
new
NBClassLoader
(
new
URL
[
0
],
NBOpenSDK
.
class
.
getClassLoader
());
printMsg
(
"SDK-classLoader: "
+
nbClassLoader
);
path
=
readCurrentJar
(
path
);
files
=
unpackToFolder
(
new
File
(
path
),
nbClassLoader
);
}
catch
(
Exception
var2
)
{
var2
.
printStackTrace
();
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论