Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lcj-btp-java-app
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
郭智朋
lcj-btp-java-app
Commits
381807bd
Commit
381807bd
authored
Feb 10, 2025
by
guozhipeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
authorization添加
parent
6d2de307
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
11 deletions
+33
-11
xs-app.json
app/router/xs-app.json
+2
-2
HttpClientUtil.java
...va/customer/lianchuangjie/common/util/HttpClientUtil.java
+14
-6
CommonController.java
...mer/lianchuangjie/master/controller/CommonController.java
+4
-0
CommonServiceImpl.java
.../lianchuangjie/master/service/impl/CommonServiceImpl.java
+13
-3
HttpClientUtilTest.java
...ustomer/lianchuangjie/common/util/HttpClientUtilTest.java
+0
-0
No files found.
app/router/xs-app.json
View file @
381807bd
...
@@ -3,8 +3,8 @@
...
@@ -3,8 +3,8 @@
"routes"
:
[
"routes"
:
[
{
{
"source"
:
"^/index.html(#.*)?$"
,
"source"
:
"^/index.html(#.*)?$"
,
"target"
:
"/
main/webapp/
index.html$1"
,
"target"
:
"/index.html$1"
,
"localDir"
:
"."
,
"localDir"
:
".
/main/webapp
"
,
"cacheControl"
:
"no-cache, no-store, must-revalidate"
"cacheControl"
:
"no-cache, no-store, must-revalidate"
},
},
{
{
...
...
srv/src/main/java/customer/lianchuangjie/common/util/HttpClientUtil.java
View file @
381807bd
...
@@ -326,7 +326,7 @@ public class HttpClientUtil {
...
@@ -326,7 +326,7 @@ public class HttpClientUtil {
/**
/**
* OData批量操作,可以使用超长OData拼接的URL
* OData批量操作,可以使用超长OData拼接的URL
*/
*/
public
static
String
odataV4Batch
(
String
url
)
throws
Exception
{
public
static
String
odataV4Batch
(
String
url
,
String
authorization
)
throws
Exception
{
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
try
{
try
{
url
=
HTTPUtil
.
urlEncode
(
url
);
url
=
HTTPUtil
.
urlEncode
(
url
);
...
@@ -393,6 +393,10 @@ public class HttpClientUtil {
...
@@ -393,6 +393,10 @@ public class HttpClientUtil {
String
resStr
=
null
;
String
resStr
=
null
;
HttpPost
httppost
=
new
HttpPost
(
serviceUrl
+
"$batch"
);
HttpPost
httppost
=
new
HttpPost
(
serviceUrl
+
"$batch"
);
if
(
authorization
!=
null
&&
!
""
.
equals
(
authorization
))
{
//添加鉴权 authorization Basic c2FiaW5lOnBhc3Nfc2FiaW5l
httppost
.
setHeader
(
"authorization"
,
authorization
);
}
// 请求参数配置
// 请求参数配置
RequestConfig
requestConfig
=
RequestConfig
.
custom
()
RequestConfig
requestConfig
=
RequestConfig
.
custom
()
...
@@ -444,7 +448,7 @@ public class HttpClientUtil {
...
@@ -444,7 +448,7 @@ public class HttpClientUtil {
* 带参数的视图只能使用get请求
* 带参数的视图只能使用get请求
* 参数值中如果有#需要转义
* 参数值中如果有#需要转义
*/
*/
public
static
String
odataV4BatchGet
(
String
url
)
throws
Exception
{
public
static
String
odataV4BatchGet
(
String
url
,
String
authorization
)
throws
Exception
{
try
{
try
{
url
=
HTTPUtil
.
urlEncode
(
url
);
url
=
HTTPUtil
.
urlEncode
(
url
);
if
(
true
)
{
// odata v4 query处理
if
(
true
)
{
// odata v4 query处理
...
@@ -512,6 +516,10 @@ public class HttpClientUtil {
...
@@ -512,6 +516,10 @@ public class HttpClientUtil {
HttpClient
client
=
HttpClients
.
createDefault
();
HttpClient
client
=
HttpClients
.
createDefault
();
log
.
info
(
"[odataV4BatchGet-url]"
+
url
);
log
.
info
(
"[odataV4BatchGet-url]"
+
url
);
HttpGet
httpGet
=
new
HttpGet
(
url
);
// 创建Get请求
HttpGet
httpGet
=
new
HttpGet
(
url
);
// 创建Get请求
if
(
authorization
!=
null
&&
!
""
.
equals
(
authorization
))
{
//添加鉴权 authorization Basic c2FiaW5lOnBhc3Nfc2FiaW5l
httpGet
.
setHeader
(
"authorization"
,
authorization
);
}
HttpResponse
response
=
client
.
execute
(
httpGet
);
HttpResponse
response
=
client
.
execute
(
httpGet
);
int
status
=
response
.
getStatusLine
().
getStatusCode
();
int
status
=
response
.
getStatusLine
().
getStatusCode
();
HttpEntity
resEntity
=
response
.
getEntity
();
HttpEntity
resEntity
=
response
.
getEntity
();
...
@@ -548,8 +556,8 @@ public class HttpClientUtil {
...
@@ -548,8 +556,8 @@ public class HttpClientUtil {
* @return
* @return
* @throws Exception
* @throws Exception
*/
*/
public
static
String
odataV4BatchLocal
(
String
url
)
throws
Exception
{
public
static
String
odataV4BatchLocal
(
String
url
,
String
authorization
)
throws
Exception
{
return
odataV4Batch
(
"http://localhost:"
+
getHttpPort
+
"/odata/v4/"
+
url
);
return
odataV4Batch
(
"http://localhost:"
+
getHttpPort
+
"/odata/v4/"
+
url
,
authorization
);
}
}
/**
/**
...
@@ -559,8 +567,8 @@ public class HttpClientUtil {
...
@@ -559,8 +567,8 @@ public class HttpClientUtil {
* @return
* @return
* @throws Exception
* @throws Exception
*/
*/
public
static
String
odataV4BatchLocalGet
(
String
url
)
throws
Exception
{
public
static
String
odataV4BatchLocalGet
(
String
url
,
String
authorization
)
throws
Exception
{
return
odataV4BatchGet
(
"http://localhost:"
+
getHttpPort
+
"/odata/v4/"
+
url
);
return
odataV4BatchGet
(
"http://localhost:"
+
getHttpPort
+
"/odata/v4/"
+
url
,
authorization
);
}
}
/**
/**
...
...
srv/src/main/java/customer/lianchuangjie/master/controller/CommonController.java
View file @
381807bd
...
@@ -216,7 +216,9 @@ public class CommonController {
...
@@ -216,7 +216,9 @@ public class CommonController {
*/
*/
@PostMapping
(
value
=
"/getRuleCdsList"
)
@PostMapping
(
value
=
"/getRuleCdsList"
)
public
Result
<?>
getRuleCdsList
(
@RequestBody
JSONObject
jsonObject
,
HttpServletRequest
req
)
{
public
Result
<?>
getRuleCdsList
(
@RequestBody
JSONObject
jsonObject
,
HttpServletRequest
req
)
{
String
authorization
=
req
.
getHeader
(
"authorization"
);
//鉴权
String
language
=
req
.
getHeader
(
"language"
);
//语言
String
language
=
req
.
getHeader
(
"language"
);
//语言
jsonObject
.
put
(
"authorization"
,
authorization
);
Result
<?>
re
=
commonService
.
getUserLogin
(
jsonObject
,
req
);
Result
<?>
re
=
commonService
.
getUserLogin
(
jsonObject
,
req
);
if
(
re
.
isSuccess
())
{
if
(
re
.
isSuccess
())
{
String
userLoginPartyId
=
((
UserLogin
)
re
.
getResult
()).
getPartyId
();
String
userLoginPartyId
=
((
UserLogin
)
re
.
getResult
()).
getPartyId
();
...
@@ -292,6 +294,8 @@ public class CommonController {
...
@@ -292,6 +294,8 @@ public class CommonController {
@PostMapping
(
value
=
"/invokeByCdsView"
)
@PostMapping
(
value
=
"/invokeByCdsView"
)
public
Result
<?>
invokeByCdsView
(
@RequestBody
JSONObject
jsonObject
,
HttpServletRequest
req
)
{
public
Result
<?>
invokeByCdsView
(
@RequestBody
JSONObject
jsonObject
,
HttpServletRequest
req
)
{
String
language
=
req
.
getHeader
(
"language"
);
//语言
String
language
=
req
.
getHeader
(
"language"
);
//语言
String
authorization
=
req
.
getHeader
(
"authorization"
);
//鉴权
jsonObject
.
put
(
"authorization"
,
authorization
);
//return Result.ok("该接口不对外开放,禁止调用!");
//return Result.ok("该接口不对外开放,禁止调用!");
return
commonService
.
invokeByCdsView
(
jsonObject
,
language
);
return
commonService
.
invokeByCdsView
(
jsonObject
,
language
);
}
}
...
...
srv/src/main/java/customer/lianchuangjie/master/service/impl/CommonServiceImpl.java
View file @
381807bd
...
@@ -124,6 +124,8 @@ public class CommonServiceImpl implements CommonService {
...
@@ -124,6 +124,8 @@ public class CommonServiceImpl implements CommonService {
*/
*/
@Override
@Override
public
Result
<?>
getRuleCdsList
(
JSONObject
jsonObject
,
String
language
)
{
public
Result
<?>
getRuleCdsList
(
JSONObject
jsonObject
,
String
language
)
{
String
authorization
=
jsonObject
.
getString
(
"authorization"
);
// 鉴权
//log.info("[getRuleCdsList-language]" + language);
//log.info("[getRuleCdsList-language]" + language);
// 分页
// 分页
int
pageNo
=
1
;
// pageNo: 1 当前页
int
pageNo
=
1
;
// pageNo: 1 当前页
...
@@ -293,6 +295,8 @@ public class CommonServiceImpl implements CommonService {
...
@@ -293,6 +295,8 @@ public class CommonServiceImpl implements CommonService {
if
(
urlRule2
.
contains
(
"."
))
{
//服务查询 (视图查询封装在方法invokeByCdsView中)
if
(
urlRule2
.
contains
(
"."
))
{
//服务查询 (视图查询封装在方法invokeByCdsView中)
try
{
try
{
JSONObject
paramRule2Json
=
JSONObject
.
parseObject
(
paramRule2
);
JSONObject
paramRule2Json
=
JSONObject
.
parseObject
(
paramRule2
);
//authorization
paramRule2Json
.
put
(
"authorization"
,
authorization
);
JSONObject
jsonObject2
=
new
JSONObject
();
JSONObject
jsonObject2
=
new
JSONObject
();
jsonObject2
.
put
(
"classMethod"
,
urlRule2
);
//类名.方法名
jsonObject2
.
put
(
"classMethod"
,
urlRule2
);
//类名.方法名
jsonObject2
.
put
(
"param"
,
paramRule2Json
);
//参数
jsonObject2
.
put
(
"param"
,
paramRule2Json
);
//参数
...
@@ -416,9 +420,9 @@ public class CommonServiceImpl implements CommonService {
...
@@ -416,9 +420,9 @@ public class CommonServiceImpl implements CommonService {
try
{
try
{
String
resStr
=
null
;
String
resStr
=
null
;
if
(
isOdataGet
)
{
if
(
isOdataGet
)
{
resStr
=
HttpClientUtil
.
odataV4BatchLocalGet
(
url1
);
//GET请求 带参数的视图
resStr
=
HttpClientUtil
.
odataV4BatchLocalGet
(
url1
,
authorization
);
//GET请求 带参数的视图
}
else
{
}
else
{
resStr
=
HttpClientUtil
.
odataV4BatchLocal
(
url1
);
//POST请求
resStr
=
HttpClientUtil
.
odataV4BatchLocal
(
url1
,
authorization
);
//POST请求
}
}
resultJson1
=
JSONObject
.
parseObject
(
resStr
);
resultJson1
=
JSONObject
.
parseObject
(
resStr
);
//失败!
//失败!
...
@@ -465,6 +469,8 @@ public class CommonServiceImpl implements CommonService {
...
@@ -465,6 +469,8 @@ public class CommonServiceImpl implements CommonService {
colParamRuleJson
=
JSONObject
.
parseObject
(
colParamRule
);
colParamRuleJson
=
JSONObject
.
parseObject
(
colParamRule
);
}
}
colParamRuleJson
.
put
(
"list"
,
list
);
//类型 List<Object>
colParamRuleJson
.
put
(
"list"
,
list
);
//类型 List<Object>
//authorization
colParamRuleJson
.
put
(
"authorization"
,
authorization
);
JSONObject
colJson
=
new
JSONObject
();
JSONObject
colJson
=
new
JSONObject
();
colJson
.
put
(
"classMethod"
,
colUrlRule
);
//类名.方法名
colJson
.
put
(
"classMethod"
,
colUrlRule
);
//类名.方法名
colJson
.
put
(
"param"
,
colParamRuleJson
);
//参数
colJson
.
put
(
"param"
,
colParamRuleJson
);
//参数
...
@@ -591,6 +597,7 @@ public class CommonServiceImpl implements CommonService {
...
@@ -591,6 +597,7 @@ public class CommonServiceImpl implements CommonService {
*/
*/
@Override
@Override
public
Result
<?>
getRequestParamRuleCdsList
(
JSONObject
jsonObject
,
String
language
)
{
public
Result
<?>
getRequestParamRuleCdsList
(
JSONObject
jsonObject
,
String
language
)
{
String
authorization
=
jsonObject
.
getString
(
"authorization"
);
//鉴权
String
ruleMsg
=
""
;
String
ruleMsg
=
""
;
// 权限
// 权限
...
@@ -716,6 +723,8 @@ public class CommonServiceImpl implements CommonService {
...
@@ -716,6 +723,8 @@ public class CommonServiceImpl implements CommonService {
if
(
urlRule2
.
contains
(
"."
))
{
//服务查询 (视图查询封装在方法invokeByCdsView中)
if
(
urlRule2
.
contains
(
"."
))
{
//服务查询 (视图查询封装在方法invokeByCdsView中)
try
{
try
{
JSONObject
paramRule2Json
=
JSONObject
.
parseObject
(
paramRule2
);
JSONObject
paramRule2Json
=
JSONObject
.
parseObject
(
paramRule2
);
//authorization
paramRule2Json
.
put
(
"authorization"
,
authorization
);
JSONObject
jsonObject2
=
new
JSONObject
();
JSONObject
jsonObject2
=
new
JSONObject
();
jsonObject2
.
put
(
"classMethod"
,
urlRule2
);
//类名.方法名
jsonObject2
.
put
(
"classMethod"
,
urlRule2
);
//类名.方法名
jsonObject2
.
put
(
"param"
,
paramRule2Json
);
//参数
jsonObject2
.
put
(
"param"
,
paramRule2Json
);
//参数
...
@@ -1058,13 +1067,14 @@ public class CommonServiceImpl implements CommonService {
...
@@ -1058,13 +1067,14 @@ public class CommonServiceImpl implements CommonService {
*/
*/
@Override
@Override
public
Result
<?>
invokeByCdsView
(
JSONObject
jsonObject
,
String
language
)
{
public
Result
<?>
invokeByCdsView
(
JSONObject
jsonObject
,
String
language
)
{
String
authorization
=
jsonObject
.
getString
(
"authorization"
);
//鉴权
try
{
try
{
String
urlRule
=
(
String
)
jsonObject
.
get
(
"url"
);
String
urlRule
=
(
String
)
jsonObject
.
get
(
"url"
);
String
paramRule
=
(
String
)
jsonObject
.
get
(
"param"
);
String
paramRule
=
(
String
)
jsonObject
.
get
(
"param"
);
String
url2
=
urlRule
+
"?"
+
paramRule
;
String
url2
=
urlRule
+
"?"
+
paramRule
;
log
.
info
(
"[odata-url2]"
+
url2
);
log
.
info
(
"[odata-url2]"
+
url2
);
JSONObject
resultJson2
=
null
;
JSONObject
resultJson2
=
null
;
String
resStr
=
HttpClientUtil
.
odataV4BatchLocal
(
url2
);
String
resStr
=
HttpClientUtil
.
odataV4BatchLocal
(
url2
,
authorization
);
resultJson2
=
JSONObject
.
parseObject
(
resStr
);
resultJson2
=
JSONObject
.
parseObject
(
resStr
);
log
.
info
(
"[odata-value2]"
+
resultJson2
.
get
(
"value"
));
log
.
info
(
"[odata-value2]"
+
resultJson2
.
get
(
"value"
));
List
<
Object
>
list
=
(
List
<
Object
>)
resultJson2
.
get
(
"value"
);
List
<
Object
>
list
=
(
List
<
Object
>)
resultJson2
.
get
(
"value"
);
...
...
srv/src/test/java/customer/lianchuangjie/common/util/HttpClientUtilTest.java
View file @
381807bd
This diff is collapsed.
Click to expand it.
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