本文整理匯總了Java中org.aspectj.lang.Signature.getDeclaringTypeName方法的典型用法代碼示例。如果您正苦於以下問題:Java Signature.getDeclaringTypeName方法的具體用法?Java Signature.getDeclaringTypeName怎麽用?Java Signature.getDeclaringTypeName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.aspectj.lang.Signature
的用法示例。
在下文中一共展示了Signature.getDeclaringTypeName方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: afterAnyMethodThrowingException
import org.aspectj.lang.Signature; //導入方法依賴的package包/類
@AfterThrowing(pointcut = "anyMethodCall(joinPoint)", throwing = "exception")
public void afterAnyMethodThrowingException(JoinPoint joinPoint, Throwable exception) {
if (log.isDebugEnabled()) {
log.debug("aspect start: afterAnyMethodThrowingException");
}
Signature signature = joinPoint.getSignature();
String className = signature.getDeclaringTypeName();
String methodName = signature.getName();
String arguments = Arrays.toString(joinPoint.getArgs());
StackTraceElement[] stackTrace = exception.getStackTrace();
if (stackTrace.length == 0 ||
!methodName.equals(stackTrace[0].getMethodName()) ||
!className.equals(stackTrace[0].getClassName())) {
return;
}
if (log.isDebugEnabled()) {
log.debug("We have caught exception in method: "
+ methodName + " with arguments "
+ arguments + "\nand the full toString: " + "\nthe exception is: "
+ exception.toString());
}
ExceptionInfo exceptionInfo =
new ExceptionInfo()
.setException(exception)
.setName(exception.getClass().toString())
.setClassName(className)
.setFileName(stackTrace[0].getFileName())
.setLineNumber(stackTrace[0].getLineNumber())
.setMethodName(methodName)
.setArguments(Arrays.asList(joinPoint.getArgs()));
ExceptionEventPublisher exceptionEventPublisher = new ExceptionEventPublisher();
exceptionEventPublisher.publishEvent(exceptionInfo);
}
示例2: stop
import org.aspectj.lang.Signature; //導入方法依賴的package包/類
/**
* Save invocation/execution time associated with the method to StatsD in the format: com.mypackage.myMethod
*/
@Override
public void stop(TimerContext context) {
Signature sig = context.getJoinPoint().getSignature();
String className = sig.getDeclaringTypeName(); // package name: com.my.package
String methodName = sig.getName(); // method name: myMethod
String label = className+"."+methodName;
statsdClient.recordExecutionTime(label, context.stop());
}
示例3: buildLog
import org.aspectj.lang.Signature; //導入方法依賴的package包/類
/**
* 構建日誌參數
* @param joinPoint
* @return
*/
private SysUserLog buildLog(ProceedingJoinPoint joinPoint) throws Throwable {
SysUserLog userLog = new SysUserLog();
try{
Object principal = SecurityUtils.getSubject().getPrincipal();
if (principal != null) {
userLog.setCreator(SecurityUtils.getSubject().getPrincipal().toString());
}
SysUser user = (SysUser) SecurityUtils.getSubject().getSession(true).getAttribute(SysUser.SYS_USER);
if (user != null) {
userLog.setUserId(user.getUserId());
userLog.setUserName(user.getUserName());
}
userLog.setIp(SecurityUtils.getSubject().getSession(true).getHost());
}catch (Exception e){
//TODO No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid application configuration.
}
userLog.setCreateTime(new Date());
//將日誌信息打印在控製台
Signature signature = joinPoint.getSignature();
String method=signature.getDeclaringTypeName() + " " + signature.getName();
userLog.setMethod(method);
//String parameter=StringUtils.join(joinPoint.getArgs(),",");
StringBuilder builder=new StringBuilder();
Object[] joinPointArgs = joinPoint.getArgs();
for (Object arg:joinPointArgs){
if(arg instanceof HttpServletRequest||arg instanceof HttpServletResponse){
continue;
}
if(arg instanceof Serializable){
builder.append(gson.toJson(arg)+",");
}else{
builder.append(arg+",");
}
}
int lastIndexOf = builder.lastIndexOf(",");
if(lastIndexOf>-1){
builder.deleteCharAt(lastIndexOf);
}
userLog.setParameter(builder.toString());
long start = System.currentTimeMillis();
Object proceed = joinPoint.proceed();
long end = System.currentTimeMillis();
String result=gson.toJson(proceed);
userLog.setResult(result);
userLog.setProceed(proceed);
String usetime=(end - start) + "ms";
userLog.setUsetime(usetime);
return userLog;
}
示例4: log
import org.aspectj.lang.Signature; //導入方法依賴的package包/類
/**
* Advice that will be executed around each join point that has been selected by the
* 'loggingPointcut()' pointcut. This advice will log the entry, exit of the joint put
* including the available contextual information.
* @param call exposes the proceed(..) method in order to support around advice in @AJ aspects
* @return the method return value
* @throws Throwable any throwable thrown by the execution
*/
@Pointcut("be.gerard.common.aop.PointCutLibrary.springServiceOperation()")
public Object log(final ProceedingJoinPoint call) throws Throwable {
// Get the logger that handles the target instance of the method execution.
Signature signature = call.getSignature();
Logger logger = LogManager.getLogger(signature.getDeclaringType());
// This aspect is only valid for method calls
if (!(signature instanceof MethodSignature)) {
throw new IllegalArgumentException("call not valid [method call expected]");
}
MethodSignature methodSignature = (MethodSignature) signature;
// Compute the method information
String methodName = signature.toShortString();
String targetName = signature.getDeclaringTypeName();
Type returnType = methodSignature.getReturnType();
// AspectJ compiler has to be used to retrieve the parameter names
//String[] pp = methodSignature.getParameterNames();
// Compute the method parameters and trace the method entry
if (logger.isInfoEnabled()) {
logger.info(signature.toLongString());
logger.info(String.format("Invoke method [%s] on service [%s]", methodName, targetName));
Object[] parameterValues = call.getArgs();
String[] parameterNames = new String[parameterValues.length];
if ((methodSignature.getParameterNames() != null) && methodSignature.getParameterNames().length == parameterNames.length) {
parameterNames = methodSignature.getParameterNames();
}
for (int i = 0; i < parameterValues.length; i++) {
String parameterName = (parameterNames[i] == null ? String.valueOf(i) : parameterNames[i]);
String parameterValue;
if ((parameterValues[i] instanceof byte[]) && (parameterValues[i] != null)) {
parameterValue = String.format("byte array length [%s]", ((byte[]) parameterValues[i]).length);
} else {
parameterValue = String.valueOf(parameterValues[i]);
}
logger.info(String.format("|---parameter [%s] = [%s]", parameterName, parameterValue));
}
}
// Prepare a StopWath for computing the method statistic
final StopWatch stopWatch = new StopWatch();
stopWatch.start();
String methodStatus = "SUCCESSFULLY";
Object methodResult = null;
try {
// Proceed with the next advice or target method invocation
methodResult = call.proceed();
return methodResult;
} catch (Exception throwable) {
logger.info(String.format("Method [%s] raised the following exception :\n%s.", methodName, String.valueOf(throwable)));
methodStatus = "UNSUCCESSFULLY";
throw throwable;
} finally {
stopWatch.stop();
final long millis = stopWatch.getTotalTimeMillis();
if (logger.isInfoEnabled()) {
if (returnType != null) {
logger.info(String.format("|---parameter [return]= [%s]", String.valueOf(methodResult)));
}
logger.info(String.format("Method [%s] on service [%s] %s invoked in %s milliseconds.", methodName, targetName, methodStatus, millis));
}
}
}
示例5: handleException
import org.aspectj.lang.Signature; //導入方法依賴的package包/類
@AfterThrowing(pointcut = "be.gerard.common.aop.PointCutLibrary.springServiceOperation()", throwing = "exception")
public void handleException(final JoinPoint call, final Throwable exception) throws Throwable {
if (exception instanceof BusinessException) {
throw exception;
}
// Get the logger that handles the target instance of the method execution.
Signature signature = call.getSignature();
Logger logger = LogManager.getLogger(signature.getDeclaringType());
MethodSignature methodSignature = (MethodSignature) signature;
// Compute the method information
String methodName = signature.toShortString();
String targetName = signature.getDeclaringTypeName();
Type returnType = methodSignature.getReturnType();
// Compute the method parameters and prepare the exception context
Map<String, String> exceptionContext = new LinkedHashMap<>();
exceptionContext.put("request", call.getSignature().toLongString());
exceptionContext.put("service name", targetName);
exceptionContext.put("method name", methodName);
if (returnType != null) {
exceptionContext.put("return parameter", String.valueOf(returnType.getClass().getCanonicalName()));
}
// AspectJ compiler has to be used to retrieve the parameter names
Object[] parameterValues = call.getArgs();
String[] parameterNames = new String[parameterValues.length];
if ((methodSignature.getParameterNames() != null) && methodSignature.getParameterNames().length == parameterNames.length) {
parameterNames = methodSignature.getParameterNames();
}
for (int i = 0; i < parameterValues.length; i++) {
String parameterName = (parameterNames[i] == null ? String.valueOf(i) : parameterNames[i]);
exceptionContext.put(String.format("method parameter [%s]", parameterName), String.valueOf(parameterValues[i]));
}
// Prepare the contextual exception to be logged.
String exceptionText = "An unexpected error was encountered while processing the service request.";
ContextualException contextualException = new ContextualException(exceptionText, exception, exceptionContext);
// Log the exception
logger.error(contextualException.toString());
// Throw the technical exception with the facadeException id.
throw new TechnicalException(exceptionText, technicalError, String.format("#%s", contextualException.getId()));
}