(empty log message)
@@ -1,31 +0,0 @@ | ||
1 | -/* | |
2 | - * Stored Framework | |
3 | - * | |
4 | - * Copyright (C) 2006 Satoshi Nagashiba, All Rights Reserved. | |
5 | - */ | |
6 | -package org.stored.sample.service.interceptor; | |
7 | - | |
8 | -/* $Id: ExceptionInterceptor.java 407 2009-01-23 06:51:15Z nagashiba $ */ | |
9 | - | |
10 | -import org.springframework.aop.ThrowsAdvice; | |
11 | -import org.stored.sample.exception.SampleException; | |
12 | - | |
13 | -/** | |
14 | - * 例外用インターセプタクラスです。 | |
15 | - * | |
16 | - * @author <a href="mailto:sato-vista@tbb.t-com.ne.jp">Satoshi Nagashiba</a> | |
17 | - * @version $Revision: 407 $ $Date: 2009-01-23 15:51:15 +0900 $ | |
18 | - */ | |
19 | -public class ExceptionInterceptor implements ThrowsAdvice { | |
20 | - | |
21 | - /** | |
22 | - * 一般例外をスローします | |
23 | - * @param e 例外 | |
24 | - * @throws SampleException 一般例外 | |
25 | - */ | |
26 | - public void afterThrowing(Throwable e) throws SampleException { | |
27 | - SampleException exception = new SampleException(e); | |
28 | - exception.printStackTrace(); | |
29 | - throw exception; | |
30 | - } | |
31 | -} |
@@ -1,104 +0,0 @@ | ||
1 | -/* | |
2 | - * Stored Framework | |
3 | - * | |
4 | - * Copyright (C) 2006 Satoshi Nagashiba, All Rights Reserved. | |
5 | - */ | |
6 | -package org.stored.sample.service.interceptor; | |
7 | - | |
8 | -/* $Id: MethodTraceInterceptor.java 407 2009-01-23 06:51:15Z nagashiba $ */ | |
9 | - | |
10 | -import java.text.MessageFormat; | |
11 | - | |
12 | -import org.aopalliance.intercept.MethodInterceptor; | |
13 | -import org.aopalliance.intercept.MethodInvocation; | |
14 | -import org.apache.commons.lang.ObjectUtils; | |
15 | -import org.apache.commons.logging.Log; | |
16 | -import org.apache.commons.logging.LogFactory; | |
17 | -import org.springframework.util.ClassUtils; | |
18 | -import org.stored.sample.util.StringUtils; | |
19 | - | |
20 | -/** | |
21 | - * 実行メソッドの開始/終了をロギングするインターセプタークラスです。 | |
22 | - * | |
23 | - * @author <a href="mailto:sato-vista@tbb.t-com.ne.jp">Satoshi Nagashiba</a> | |
24 | - * @version $Revision: 407 $ $Date: 2009-01-23 15:51:15 +0900 $ | |
25 | - */ | |
26 | -public class MethodTraceInterceptor implements MethodInterceptor { | |
27 | - | |
28 | - /** 開始ログメッセージ. */ | |
29 | - private String enterMessage = "Start - class[{0}] method[{1}],"; | |
30 | - /** 終了ログメッセージ. */ | |
31 | - private String exitMessage = "End - class[{0}] method[{1}],"; | |
32 | - | |
33 | - /** | |
34 | - * メソッドをインターセプトします。 | |
35 | - * @param invocation 実行メソッド | |
36 | - */ | |
37 | - public Object invoke(MethodInvocation invocation) throws Throwable { | |
38 | - Log logger = LogFactory.getLog(invocation.getThis().getClass()); | |
39 | - | |
40 | - long before = 0; | |
41 | - long after = 0; | |
42 | - Object[] param = null; | |
43 | - | |
44 | - param = initMessageFormatParameters(invocation); | |
45 | - logger.info(MessageFormat.format(enterMessage, param)); | |
46 | - before = System.currentTimeMillis(); | |
47 | - try { | |
48 | - return invocation.proceed(); | |
49 | - } | |
50 | - finally { | |
51 | - String emsg = MessageFormat.format(exitMessage, param); | |
52 | - after = System.currentTimeMillis(); | |
53 | - emsg += " Time = " + (after - before) + "msec.,"; | |
54 | - logger.info(emsg); | |
55 | - } | |
56 | - } | |
57 | - | |
58 | - /** | |
59 | - * インターセプト情報を取得する。<br>. | |
60 | - * @param invocation メソッド呼び出し | |
61 | - * @return プレースホルダー用メッセージ配列 | |
62 | - */ | |
63 | - private Object[] initMessageFormatParameters(MethodInvocation invocation) { | |
64 | - String className = invocation.getMethod().getDeclaringClass().getName(); | |
65 | - String methodName = invocation.getMethod().getName(); | |
66 | - String argumentStr = getMethodArguments(invocation); | |
67 | - String parameterTypeStr = getMethodParameterTypess(invocation); | |
68 | - return new Object[]{className, methodName, argumentStr, parameterTypeStr}; | |
69 | - } | |
70 | - | |
71 | - /** | |
72 | - * メソッドの引数を取得します。<br>. | |
73 | - * @param invocation メソッド呼び出し | |
74 | - * @return メソッド引数文字列 | |
75 | - */ | |
76 | - private String getMethodArguments(MethodInvocation invocation) { | |
77 | - String[] arguments = new String[invocation.getArguments().length]; | |
78 | - for (int i = 0; i < invocation.getArguments().length; i++) { | |
79 | - arguments[i] = ObjectUtils.toString(invocation.getArguments()[i]); | |
80 | - } | |
81 | - return (invocation.getArguments() == null) ? "()" : "(" | |
82 | - + StringUtils.toCommaDelimitedString(arguments) + ")"; | |
83 | - } | |
84 | - | |
85 | - /** | |
86 | - * メソッドの引数タイプを取得します。<br>. | |
87 | - * @param invocation メソッド呼び出し | |
88 | - * @return メソッド引数タイプ文字列 | |
89 | - */ | |
90 | - private String getMethodParameterTypess(MethodInvocation invocation) { | |
91 | - if (invocation.getMethod().getParameterTypes().length == 0) { | |
92 | - return "()"; | |
93 | - } | |
94 | - else { | |
95 | - Class<?>[] types = invocation.getMethod().getParameterTypes(); | |
96 | - String[] names = new String[types.length]; | |
97 | - for (int i = 0; i < types.length; i++) { | |
98 | - Class<?> type = types[i]; | |
99 | - names[i] = ClassUtils.getShortName(type); | |
100 | - } | |
101 | - return "(" + StringUtils.toCommaDelimitedString(names) + ")"; | |
102 | - } | |
103 | - } | |
104 | -} |