diff --git a/README.md b/README.md index 6eab094..16a5f40 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ angular-rest-springsecurity =========================== +The difference from master is added Spring AOP example for logging and monitoring. [![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=shoxrocks&url=http://sorst.net/github/angular-rest-springsecurity&title=AngularJS REST Spring Security Example&language=&tags=github&category=software) @@ -39,4 +40,4 @@ Make sure [Maven](http://maven.apache.org/) >= 2.2.1 is installed on your system License ------- -[The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt) \ No newline at end of file +[The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt) diff --git a/src/main/java/net/dontdrinkandroot/example/angularrestspringsecurity/aop/DoAroundMethod.java b/src/main/java/net/dontdrinkandroot/example/angularrestspringsecurity/aop/DoAroundMethod.java new file mode 100644 index 0000000..20a38b3 --- /dev/null +++ b/src/main/java/net/dontdrinkandroot/example/angularrestspringsecurity/aop/DoAroundMethod.java @@ -0,0 +1,39 @@ +package net.dontdrinkandroot.example.angularrestspringsecurity.aop; + +import java.util.Arrays; + +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DoAroundMethod implements MethodInterceptor { + private static final Logger LOG = LoggerFactory.getLogger(DoAroundMethod.class); + + public Object invoke(MethodInvocation methodInvocation) throws Throwable { + + LOG.info("****SPRING AOP**** DoAroundMethod: Method name : " + + methodInvocation.getMethod().getName()); + + LOG.info("****SPRING AOP**** DoAroundMethod: Method name : " + + methodInvocation.getMethod().getName()); + LOG.info("****SPRING AOP**** DoAroundMethod: Method arguments : " + + Arrays.toString(methodInvocation.getArguments())); + // same with MethodBeforeAdvice + LOG.info("****SPRING AOP**** DoAroundMethod: Before method executing!"); + + try { + // proceed to original method call + Object result = methodInvocation.proceed(); + // same with AfterReturningAdvice + LOG.info("****SPRING AOP**** DoAroundMethod: After method executing!"); + return result; + + } catch (IllegalArgumentException e) { + // same with ThrowsAdvice + LOG.info("****SPRING AOP**** DoAroundMethod: When method throws Exception!"); + throw e; + } + } + +} \ No newline at end of file diff --git a/src/main/resources/context.xml b/src/main/resources/context.xml index b7a3284..96a7ea9 100644 --- a/src/main/resources/context.xml +++ b/src/main/resources/context.xml @@ -6,13 +6,15 @@ xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:security="http://www.springframework.org/schema/security" + xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd - http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd"> + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd + http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd"> @@ -54,6 +56,31 @@ + + + + + + + .* + + + + + + + + + *Dao + + + + + regexAdvisor + + + diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties index d448d60..be4dd8a 100644 --- a/src/main/resources/log4j.properties +++ b/src/main/resources/log4j.properties @@ -4,4 +4,4 @@ log4j.appender.stdout.Target = System.out log4j.appender.stdout.layout = org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern = %d{ABSOLUTE} %3p %c{1}.%M():%L - %m%n -log4j.rootLogger = INFO, stdout \ No newline at end of file +log4j.rootLogger = INFO, stdout