Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sqlrest
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
comm
sqlrest
Commits
5c4be730
Commit
5c4be730
authored
Jul 17, 2025
by
inrgihc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
反馈问题修复
parent
2674df7a
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
92 additions
and
28 deletions
+92
-28
sqlrest-common/src/main/java/com/gitee/sqlrest/common/exception/CommonException.java
+9
-3
sqlrest-core/src/main/java/com/gitee/sqlrest/core/exec/ApiExecuteService.java
+3
-7
sqlrest-core/src/main/java/com/gitee/sqlrest/core/executor/UnifyAlarmOpsService.java
+4
-1
sqlrest-core/src/main/java/com/gitee/sqlrest/core/filter/AuthenticationFilter.java
+5
-5
sqlrest-core/src/main/java/com/gitee/sqlrest/core/servlet/ApiServletService.java
+0
-3
sqlrest-core/src/main/java/com/gitee/sqlrest/core/servlet/ApiSwaggerService.java
+67
-6
sqlrest-manager/src/main/java/com/gitee/sqlrest/manager/model/McpToolCallHandler.java
+4
-3
No files found.
sqlrest-common/src/main/java/com/gitee/sqlrest/common/exception/CommonException.java
View file @
5c4be730
...
@@ -9,14 +9,20 @@
...
@@ -9,14 +9,20 @@
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
package
com
.
gitee
.
sqlrest
.
common
.
exception
;
package
com
.
gitee
.
sqlrest
.
common
.
exception
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.Data
;
@Data
@Data
@AllArgsConstructor
public
class
CommonException
extends
RuntimeException
{
public
class
CommonException
extends
RuntimeException
{
private
ResponseErrorCode
code
;
private
ResponseErrorCode
code
;
private
String
message
;
public
CommonException
(
ResponseErrorCode
code
,
String
message
)
{
super
(
message
);
this
.
code
=
code
;
}
public
CommonException
(
ResponseErrorCode
code
,
Throwable
cause
)
{
super
(
cause
);
this
.
code
=
code
;
}
}
}
sqlrest-core/src/main/java/com/gitee/sqlrest/core/exec/ApiExecuteService.java
View file @
5c4be730
...
@@ -9,7 +9,6 @@
...
@@ -9,7 +9,6 @@
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
package
com
.
gitee
.
sqlrest
.
core
.
exec
;
package
com
.
gitee
.
sqlrest
.
core
.
exec
;
import
cn.hutool.core.exceptions.ExceptionUtil
;
import
cn.hutool.crypto.digest.DigestUtil
;
import
cn.hutool.crypto.digest.DigestUtil
;
import
com.gitee.sqlrest.cache.CacheFactory
;
import
com.gitee.sqlrest.cache.CacheFactory
;
import
com.gitee.sqlrest.cache.DistributedCache
;
import
com.gitee.sqlrest.cache.DistributedCache
;
...
@@ -87,12 +86,9 @@ public class ApiExecuteService {
...
@@ -87,12 +86,9 @@ public class ApiExecuteService {
throw
new
CommonException
(
ResponseErrorCode
.
ERROR_INVALID_ARGUMENT
,
convertInvalidArgs
(
invalidArgs
));
throw
new
CommonException
(
ResponseErrorCode
.
ERROR_INVALID_ARGUMENT
,
convertInvalidArgs
(
invalidArgs
));
}
}
return
execute
(
config
,
paramValues
);
return
execute
(
config
,
paramValues
);
}
catch
(
CommonException
e
)
{
}
catch
(
IOException
e
)
{
log
.
warn
(
"Failed to valid parameters for {}, error:{}"
,
resourceName
,
e
.
getMessage
());
log
.
warn
(
"Failed read input body parameters for {}, error:{}"
,
resourceName
,
e
.
getMessage
());
return
ResultEntity
.
failed
(
e
.
getCode
(),
e
.
getMessage
());
throw
new
CommonException
(
ResponseErrorCode
.
ERROR_INTERNAL_ERROR
,
e
);
}
catch
(
Throwable
t
)
{
log
.
warn
(
"Failed to execute for {}, error:{}"
,
resourceName
,
t
.
getMessage
());
return
ResultEntity
.
failed
(
ResponseErrorCode
.
ERROR_INTERNAL_ERROR
,
ExceptionUtil
.
getMessage
(
t
));
}
}
}
}
...
...
sqlrest-core/src/main/java/com/gitee/sqlrest/core/executor/UnifyAlarmOpsService.java
View file @
5c4be730
...
@@ -111,6 +111,9 @@ public class UnifyAlarmOpsService {
...
@@ -111,6 +111,9 @@ public class UnifyAlarmOpsService {
private
ResponseEntity
<
String
>
handleAlarm
(
UnifyAlarmEntity
config
,
Map
<
String
,
String
>
dataModel
)
{
private
ResponseEntity
<
String
>
handleAlarm
(
UnifyAlarmEntity
config
,
Map
<
String
,
String
>
dataModel
)
{
StrSubstitutor
strSubstitutor
=
new
StrSubstitutor
(
escape
(
dataModel
));
StrSubstitutor
strSubstitutor
=
new
StrSubstitutor
(
escape
(
dataModel
));
String
bodyStr
=
strSubstitutor
.
replace
(
config
.
getInputTemplate
());
String
bodyStr
=
strSubstitutor
.
replace
(
config
.
getInputTemplate
());
if
(
log
.
isDebugEnabled
())
{
log
.
debug
(
"Send alarm message body:\n{}"
,
bodyStr
);
}
ResponseEntity
<
String
>
ret
=
sentAlarm
(
config
,
bodyStr
);
ResponseEntity
<
String
>
ret
=
sentAlarm
(
config
,
bodyStr
);
if
(
ret
.
getStatusCodeValue
()
!=
HttpStatus
.
OK
.
value
())
{
if
(
ret
.
getStatusCodeValue
()
!=
HttpStatus
.
OK
.
value
())
{
log
.
warn
(
"Error when send alarm message http status: {} ,body: {}"
,
ret
.
getStatusCode
(),
ret
.
getBody
());
log
.
warn
(
"Error when send alarm message http status: {} ,body: {}"
,
ret
.
getStatusCode
(),
ret
.
getBody
());
...
@@ -124,7 +127,7 @@ public class UnifyAlarmOpsService {
...
@@ -124,7 +127,7 @@ public class UnifyAlarmOpsService {
HttpHeaders
headers
=
new
HttpHeaders
();
HttpHeaders
headers
=
new
HttpHeaders
();
MediaType
type
=
MediaType
.
parseMediaType
(
config
.
getContentType
().
replace
(
";"
,
""
)
+
"; charset=UTF-8"
);
MediaType
type
=
MediaType
.
parseMediaType
(
config
.
getContentType
().
replace
(
";"
,
""
)
+
"; charset=UTF-8"
);
headers
.
setContentType
(
type
);
headers
.
setContentType
(
type
);
headers
.
add
(
"Accept"
,
MediaType
.
ALL_VALUE
.
toString
()
);
headers
.
add
(
"Accept"
,
MediaType
.
ALL_VALUE
);
HttpEntity
<
String
>
httpEntity
=
new
HttpEntity
<>(
bodyStr
,
headers
);
HttpEntity
<
String
>
httpEntity
=
new
HttpEntity
<>(
bodyStr
,
headers
);
return
restTemplate
.
exchange
(
config
.
getEndpoint
(),
HttpMethod
.
POST
,
httpEntity
,
String
.
class
);
return
restTemplate
.
exchange
(
config
.
getEndpoint
(),
HttpMethod
.
POST
,
httpEntity
,
String
.
class
);
}
}
...
...
sqlrest-core/src/main/java/com/gitee/sqlrest/core/filter/AuthenticationFilter.java
View file @
5c4be730
...
@@ -171,12 +171,12 @@ public class AuthenticationFilter implements Filter {
...
@@ -171,12 +171,12 @@ public class AuthenticationFilter implements Filter {
dataModel
.
put
(
"method"
,
apiConfigEntity
.
getMethod
().
name
());
dataModel
.
put
(
"method"
,
apiConfigEntity
.
getMethod
().
name
());
dataModel
.
put
(
"contentType"
,
apiConfigEntity
.
getContentType
());
dataModel
.
put
(
"contentType"
,
apiConfigEntity
.
getContentType
());
dataModel
.
put
(
"name"
,
apiConfigEntity
.
getName
());
dataModel
.
put
(
"name"
,
apiConfigEntity
.
getName
());
dataModel
.
put
(
"description"
,
apiConfigEntity
.
getDescription
(
));
dataModel
.
put
(
"description"
,
StringUtils
.
defaultString
(
apiConfigEntity
.
getDescription
()
));
dataModel
.
put
(
"open"
,
apiConfigEntity
.
getOpen
().
toString
());
dataModel
.
put
(
"open"
,
apiConfigEntity
.
getOpen
().
toString
());
dataModel
.
put
(
"clientKey"
,
accessRecord
.
getClientKey
(
));
dataModel
.
put
(
"clientKey"
,
StringUtils
.
defaultString
(
accessRecord
.
getClientKey
()
));
dataModel
.
put
(
"ipAddr"
,
accessRecord
.
getIpAddr
(
));
dataModel
.
put
(
"ipAddr"
,
StringUtils
.
defaultString
(
accessRecord
.
getIpAddr
()
));
dataModel
.
put
(
"userAgent"
,
accessRecord
.
getUserAgent
(
));
dataModel
.
put
(
"userAgent"
,
StringUtils
.
defaultString
(
accessRecord
.
getUserAgent
()
));
dataModel
.
put
(
"exception"
,
accessRecord
.
getException
(
));
dataModel
.
put
(
"exception"
,
StringUtils
.
defaultString
(
accessRecord
.
getException
()
));
dataModel
.
put
(
"accessTime"
,
sdFormatter
.
format
(
new
Date
(
accessTimestamp
)));
dataModel
.
put
(
"accessTime"
,
sdFormatter
.
format
(
new
Date
(
accessTimestamp
)));
unifyAlarmOpsService
.
triggerAlarm
(
dataModel
);
unifyAlarmOpsService
.
triggerAlarm
(
dataModel
);
...
...
sqlrest-core/src/main/java/com/gitee/sqlrest/core/servlet/ApiServletService.java
View file @
5c4be730
...
@@ -38,9 +38,6 @@ public class ApiServletService {
...
@@ -38,9 +38,6 @@ public class ApiServletService {
String
path
=
request
.
getRequestURI
().
substring
(
Constants
.
API_PATH_PREFIX
.
length
()
+
2
);
String
path
=
request
.
getRequestURI
().
substring
(
Constants
.
API_PATH_PREFIX
.
length
()
+
2
);
ApiAssignmentEntity
apiConfigEntity
=
apiAssignmentDao
.
getByUk
(
method
,
path
);
ApiAssignmentEntity
apiConfigEntity
=
apiAssignmentDao
.
getByUk
(
method
,
path
);
ResultEntity
result
=
apiExecuteService
.
execute
(
apiConfigEntity
,
request
);
ResultEntity
result
=
apiExecuteService
.
execute
(
apiConfigEntity
,
request
);
if
(
0
!=
result
.
getCode
())
{
response
.
setStatus
(
HttpServletResponse
.
SC_INTERNAL_SERVER_ERROR
);
}
String
json
=
JacksonUtils
.
toJsonStr
(
result
,
apiConfigEntity
.
getResponseFormat
());
String
json
=
JacksonUtils
.
toJsonStr
(
result
,
apiConfigEntity
.
getResponseFormat
());
response
.
getWriter
().
append
(
json
);
response
.
getWriter
().
append
(
json
);
}
}
...
...
sqlrest-core/src/main/java/com/gitee/sqlrest/core/servlet/ApiSwaggerService.java
View file @
5c4be730
...
@@ -12,6 +12,7 @@ package com.gitee.sqlrest.core.servlet;
...
@@ -12,6 +12,7 @@ package com.gitee.sqlrest.core.servlet;
import
com.gitee.sqlrest.common.consts.Constants
;
import
com.gitee.sqlrest.common.consts.Constants
;
import
com.gitee.sqlrest.common.dto.BaseParam
;
import
com.gitee.sqlrest.common.dto.BaseParam
;
import
com.gitee.sqlrest.common.dto.ItemParam
;
import
com.gitee.sqlrest.common.dto.ItemParam
;
import
com.gitee.sqlrest.common.dto.OutParam
;
import
com.gitee.sqlrest.common.enums.HttpMethodEnum
;
import
com.gitee.sqlrest.common.enums.HttpMethodEnum
;
import
com.gitee.sqlrest.common.enums.ParamTypeEnum
;
import
com.gitee.sqlrest.common.enums.ParamTypeEnum
;
import
com.gitee.sqlrest.persistence.dao.ApiAssignmentDao
;
import
com.gitee.sqlrest.persistence.dao.ApiAssignmentDao
;
...
@@ -248,7 +249,7 @@ public class ApiSwaggerService {
...
@@ -248,7 +249,7 @@ public class ApiSwaggerService {
}
}
// 响应
// 响应
operation
.
setResponses
(
getApiResponses
());
operation
.
setResponses
(
getApiResponses
(
assignment
.
getOutputs
()
));
operation
.
security
(
Collections
.
singletonList
(
new
SecurityRequirement
().
addList
(
AUTHORIZATION
)));
operation
.
security
(
Collections
.
singletonList
(
new
SecurityRequirement
().
addList
(
AUTHORIZATION
)));
openAPI
.
path
(
path
,
pathItem
);
openAPI
.
path
(
path
,
pathItem
);
...
@@ -326,16 +327,54 @@ public class ApiSwaggerService {
...
@@ -326,16 +327,54 @@ public class ApiSwaggerService {
return
pathItem
;
return
pathItem
;
}
}
private
ApiResponses
getApiResponses
()
{
private
ApiResponses
getApiResponses
(
List
<
OutParam
>
outputs
)
{
Schema
rootSchema
=
new
ObjectSchema
()
.
addProperties
(
"code"
,
new
NumberSchema
())
.
addProperties
(
"message"
,
new
StringSchema
());
if
(!
CollectionUtils
.
isEmpty
(
outputs
))
{
ObjectSchema
objectSchema
=
new
ObjectSchema
();
for
(
OutParam
param
:
outputs
)
{
ParamTypeEnum
typeItem
=
param
.
getType
();
if
(
Optional
.
ofNullable
(
param
.
getIsArray
()).
orElse
(
false
))
{
Schema
subSchema
=
new
Schema
().
type
(
param
.
getType
().
getJsType
())
.
description
(
param
.
getRemark
())
.
format
(
getTypeFormat
(
param
.
getType
()));
ArraySchema
subArraySchema
=
new
ArraySchema
().
items
(
subSchema
);
objectSchema
.
addProperties
(
param
.
getName
(),
subArraySchema
);
}
else
{
Schema
propertiesItem
;
if
(
Optional
.
ofNullable
(
typeItem
.
isObject
()).
orElse
(
false
))
{
propertiesItem
=
new
ObjectSchema
().
description
(
param
.
getRemark
());
if
(!
CollectionUtils
.
isEmpty
(
param
.
getChildren
()))
{
for
(
OutParam
subParam
:
param
.
getChildren
())
{
Schema
subSchema
=
new
Schema
().
type
(
subParam
.
getType
().
getJsType
())
.
description
(
subParam
.
getRemark
())
.
format
(
getTypeFormat
(
subParam
.
getType
()));
if
(
Optional
.
ofNullable
(
subParam
.
getIsArray
()).
orElse
(
false
))
{
ArraySchema
subArraySchema
=
new
ArraySchema
().
items
(
subSchema
);
propertiesItem
.
addProperties
(
subParam
.
getName
(),
subArraySchema
);
}
else
{
propertiesItem
.
addProperties
(
subParam
.
getName
(),
subSchema
);
}
}
}
}
else
{
propertiesItem
=
new
Schema
().
type
(
typeItem
.
getJsType
())
.
description
(
param
.
getRemark
())
.
format
(
getTypeFormat
(
typeItem
));
}
objectSchema
.
addProperties
(
param
.
getName
(),
propertiesItem
);
}
}
rootSchema
.
addProperties
(
"data"
,
objectSchema
);
}
ApiResponses
apiResponses
=
new
ApiResponses
();
ApiResponses
apiResponses
=
new
ApiResponses
();
apiResponses
.
addApiResponse
(
"200"
,
apiResponses
.
addApiResponse
(
"200"
,
new
ApiResponse
().
description
(
"OK"
).
content
(
new
ApiResponse
().
description
(
"OK"
).
content
(
new
Content
().
addMediaType
(
new
Content
().
addMediaType
(
"*/*"
,
"*/*"
,
new
MediaType
().
schema
(
new
MediaType
().
schema
(
rootSchema
)
new
Schema
().
name
(
"type"
)
.
type
(
"object"
)
)
)
)
)
)
);
);
...
@@ -353,4 +392,26 @@ public class ApiSwaggerService {
...
@@ -353,4 +392,26 @@ public class ApiSwaggerService {
);
);
return
apiResponses
;
return
apiResponses
;
}
}
private
String
getTypeFormat
(
ParamTypeEnum
type
)
{
String
format
=
null
;
switch
(
type
)
{
case
LONG:
format
=
"int64"
;
break
;
case
DOUBLE:
format
=
"float32"
;
break
;
case
DATE:
format
=
"date-time"
;
break
;
case
TIME:
format
=
"time"
;
break
;
case
BOOLEAN:
default
:
break
;
}
return
format
;
}
}
}
sqlrest-manager/src/main/java/com/gitee/sqlrest/manager/model/McpToolCallHandler.java
View file @
5c4be730
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
package
com
.
gitee
.
sqlrest
.
manager
.
model
;
package
com
.
gitee
.
sqlrest
.
manager
.
model
;
import
cn.hutool.core.exceptions.ExceptionUtil
;
import
cn.hutool.extra.spring.SpringUtil
;
import
cn.hutool.extra.spring.SpringUtil
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
...
@@ -116,13 +117,13 @@ public class McpToolCallHandler {
...
@@ -116,13 +117,13 @@ public class McpToolCallHandler {
public
CallToolResult
executeTool
(
McpSyncServerExchange
exchange
,
Map
<
String
,
Object
>
arguments
)
{
public
CallToolResult
executeTool
(
McpSyncServerExchange
exchange
,
Map
<
String
,
Object
>
arguments
)
{
prepareArgumentsPageSizeParameter
(
arguments
);
prepareArgumentsPageSizeParameter
(
arguments
);
try
{
ResultEntity
<
Object
>
resultEntity
=
apiExecuteService
.
execute
(
config
,
arguments
);
ResultEntity
<
Object
>
resultEntity
=
apiExecuteService
.
execute
(
config
,
arguments
);
if
(
0
==
resultEntity
.
getCode
())
{
String
json
=
JacksonUtils
.
toJsonStr
(
resultEntity
.
getData
(),
config
.
getResponseFormat
());
String
json
=
JacksonUtils
.
toJsonStr
(
resultEntity
.
getData
(),
config
.
getResponseFormat
());
McpSchema
.
TextContent
content
=
new
McpSchema
.
TextContent
(
"操作成功,JSON格式的响应数据为:\n "
+
json
);
McpSchema
.
TextContent
content
=
new
McpSchema
.
TextContent
(
"操作成功,JSON格式的响应数据为:\n "
+
json
);
return
new
McpSchema
.
CallToolResult
(
Lists
.
newArrayList
(
content
),
false
);
return
new
McpSchema
.
CallToolResult
(
Lists
.
newArrayList
(
content
),
false
);
}
else
{
}
catch
(
Throwable
t
)
{
String
message
=
resultEntity
.
getMessage
(
);
String
message
=
null
!=
t
.
getMessage
()
?
t
.
getMessage
()
:
ExceptionUtil
.
getRootCauseMessage
(
t
);
McpSchema
.
TextContent
content
=
new
McpSchema
.
TextContent
(
"操作异常,JSON格式的响应数据为:\n "
+
message
);
McpSchema
.
TextContent
content
=
new
McpSchema
.
TextContent
(
"操作异常,JSON格式的响应数据为:\n "
+
message
);
return
new
McpSchema
.
CallToolResult
(
Lists
.
newArrayList
(
content
),
true
);
return
new
McpSchema
.
CallToolResult
(
Lists
.
newArrayList
(
content
),
true
);
}
}
...
...
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