change HttpMessage location
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package com.synebula.gaea.app
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.synebula.gaea.app.struct.HttpMessage
|
||||
import com.synebula.gaea.data.message.HttpMessage
|
||||
import com.synebula.gaea.data.message.Status
|
||||
import com.synebula.gaea.log.ILogger
|
||||
import org.springframework.security.core.context.SecurityContextHolder
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.synebula.gaea.app.cmd
|
||||
|
||||
import com.synebula.gaea.app.IApplication
|
||||
import com.synebula.gaea.app.struct.HttpMessage
|
||||
import com.synebula.gaea.data.message.HttpMessage
|
||||
import com.synebula.gaea.data.message.Status
|
||||
import com.synebula.gaea.data.serialization.json.IJsonSerializer
|
||||
import com.synebula.gaea.domain.service.ICommand
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.synebula.gaea.app.cmd
|
||||
|
||||
import com.synebula.gaea.app.IApplication
|
||||
import com.synebula.gaea.app.struct.HttpMessage
|
||||
import com.synebula.gaea.data.message.HttpMessage
|
||||
import com.synebula.gaea.data.message.Status
|
||||
import com.synebula.gaea.data.serialization.json.IJsonSerializer
|
||||
import com.synebula.gaea.domain.model.IAggregateRoot
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.synebula.gaea.app.component.security
|
||||
|
||||
import com.synebula.gaea.app.struct.HttpMessage
|
||||
import com.synebula.gaea.app.struct.exception.TokenCloseExpireException
|
||||
import com.synebula.gaea.data.message.HttpMessage
|
||||
import com.synebula.gaea.data.message.Status
|
||||
import org.springframework.security.authentication.AuthenticationManager
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.synebula.gaea.app.component.security
|
||||
|
||||
import com.synebula.gaea.app.struct.HttpMessage
|
||||
import com.synebula.gaea.data.message.HttpMessage
|
||||
import com.synebula.gaea.data.message.Status
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.context.annotation.Bean
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.synebula.gaea.app.query
|
||||
|
||||
import com.synebula.gaea.app.IApplication
|
||||
import com.synebula.gaea.app.struct.HttpMessage
|
||||
import com.synebula.gaea.data.message.HttpMessage
|
||||
import com.synebula.gaea.query.IQuery
|
||||
import com.synebula.gaea.query.Params
|
||||
import com.synebula.gaea.spring.aop.annotation.Method
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.synebula.gaea.spring.aop
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.synebula.gaea.data.message.DataMessage
|
||||
import com.synebula.gaea.data.message.HttpMessage
|
||||
import com.synebula.gaea.data.message.Status
|
||||
import com.synebula.gaea.exception.NoticeUserException
|
||||
import com.synebula.gaea.log.ILogger
|
||||
@@ -36,37 +36,37 @@ abstract class AppAspect {
|
||||
*/
|
||||
@Around("func()")
|
||||
fun around(point: ProceedingJoinPoint): Any? {
|
||||
val clazz = point.`this`.javaClass //获取实际对象的类型避免获取到父类
|
||||
val func = point.signature.declaringType.methods.find {
|
||||
it.name == point.signature.name
|
||||
}!!//获取声明类型中的方法信息
|
||||
val funcAnnotations = func.annotations ?: arrayOf()
|
||||
|
||||
var funcName = func.name
|
||||
//遍历方法注解
|
||||
for (funcAnnotation in funcAnnotations) {
|
||||
val annotations = funcAnnotation.annotationClass.annotations
|
||||
|
||||
//尝试寻找方法注解的处理类
|
||||
val handler = annotations.find { it is Handler }
|
||||
if (handler != null && handler is Handler) {
|
||||
val handleClazz = applicationContext.getBean(handler.value.java)
|
||||
handleClazz.handle(clazz, func, point.args)
|
||||
}
|
||||
if (funcAnnotation is Method)
|
||||
funcName = funcAnnotation.name
|
||||
}
|
||||
|
||||
return try {
|
||||
point.proceed()
|
||||
} catch (ex: Throwable) {
|
||||
val clazz = point.`this`.javaClass //获取实际对象的类型避免获取到父类
|
||||
val func = point.signature.declaringType.methods.find {
|
||||
it.name == point.signature.name
|
||||
}!!//获取声明类型中的方法信息
|
||||
val funcAnnotations = func.annotations ?: arrayOf()
|
||||
|
||||
var funcName = func.name
|
||||
//遍历方法注解
|
||||
for (funcAnnotation in funcAnnotations) {
|
||||
val annotations = funcAnnotation.annotationClass.annotations
|
||||
|
||||
//尝试寻找方法注解的处理类
|
||||
val handler = annotations.find { it is Handler }
|
||||
if (handler != null && handler is Handler) {
|
||||
val handleClazz = applicationContext.getBean(handler.value.java)
|
||||
handleClazz.handle(clazz, func, point.args)
|
||||
}
|
||||
if (funcAnnotation is Method)
|
||||
funcName = funcAnnotation.name
|
||||
}
|
||||
|
||||
//找到类的模块名称,否则使用类名
|
||||
var moduleName = clazz.simpleName
|
||||
val module = clazz.annotations.find { it is Module }
|
||||
if (module != null && module is Module) {
|
||||
moduleName = module.name
|
||||
}
|
||||
var message = "$moduleName - $funcName 异常"
|
||||
var message = "$moduleName - ${funcName}异常"
|
||||
message = if (ex is NoticeUserException || ex is Error) {
|
||||
"$message: ${ex.message}"
|
||||
} else {
|
||||
@@ -80,7 +80,7 @@ abstract class AppAspect {
|
||||
gson.toJson(point.args)
|
||||
}"
|
||||
)
|
||||
return gson.toJson(DataMessage<Any>(Status.Error, message))
|
||||
return HttpMessage(Status.Error, message)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.synebula.gaea.app.struct
|
||||
package com.synebula.gaea.data.message
|
||||
|
||||
import com.synebula.gaea.data.serialization.json.IJsonSerializer
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.synebula.gaea.data.message.DataMessage
|
||||
|
||||
class HttpMessage() : DataMessage<Any>() {
|
||||
|
||||
var serializer: IJsonSerializer? = null
|
||||
|
||||
constructor(data: Any) : this() {
|
||||
this.data = data
|
||||
}
|
||||
@@ -25,6 +27,6 @@ class HttpMessage() : DataMessage<Any>() {
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return Gson().toJson(this)
|
||||
return serializer?.serialize(this) ?: super.toString()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user