Skip to content

Commit 2396a95

Browse files
committed
Merge remote-tracking branch 'upstream/master' into craedel-spring-cloud-config
2 parents d575b73 + 6ca37e3 commit 2396a95

309 files changed

Lines changed: 10416 additions & 852 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitmodules‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "testgitrepo"]
2+
path = testgitrepo
3+
url = /home/prd/Development/projects/idea/tutorials/spring-boot/src/main/resources/testgitrepo/

‎cdi/pom.xml‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.baeldung</groupId>
7+
<artifactId>cdi</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
10+
<dependencies>
11+
<dependency>
12+
<groupId>org.springframework</groupId>
13+
<artifactId>spring-core</artifactId>
14+
<version>${spring.version}</version>
15+
</dependency>
16+
<dependency>
17+
<groupId>org.springframework</groupId>
18+
<artifactId>spring-context</artifactId>
19+
<version>${spring.version}</version>
20+
</dependency>
21+
22+
<dependency>
23+
<groupId>org.aspectj</groupId>
24+
<artifactId>aspectjweaver</artifactId>
25+
<version>1.8.9</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.jboss.weld.se</groupId>
29+
<artifactId>weld-se-core</artifactId>
30+
<version>2.3.5.Final</version>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>junit</groupId>
35+
<artifactId>junit</artifactId>
36+
<version>4.12</version>
37+
<scope>test</scope>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.springframework</groupId>
41+
<artifactId>spring-test</artifactId>
42+
<version>${spring.version}</version>
43+
<scope>test</scope>
44+
</dependency>
45+
46+
</dependencies>
47+
48+
<properties>
49+
<spring.version>4.3.1.RELEASE</spring.version>
50+
</properties>
51+
52+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.interceptor;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
import javax.interceptor.InterceptorBinding;
9+
10+
@InterceptorBinding
11+
@Target({ ElementType.METHOD, ElementType.TYPE })
12+
@Retention(RetentionPolicy.RUNTIME)
13+
public @interface Audited {
14+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.baeldung.interceptor;
2+
3+
import javax.interceptor.AroundInvoke;
4+
import javax.interceptor.Interceptor;
5+
import javax.interceptor.InvocationContext;
6+
7+
@Audited
8+
@Interceptor
9+
public class AuditedInterceptor {
10+
public static boolean calledBefore = false;
11+
public static boolean calledAfter = false;
12+
13+
@AroundInvoke
14+
public Object auditMethod(InvocationContext ctx) throws Exception {
15+
calledBefore = true;
16+
Object result = ctx.proceed();
17+
calledAfter = true;
18+
return result;
19+
}
20+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.baeldung.service;
2+
3+
import com.baeldung.interceptor.Audited;
4+
5+
public class SuperService {
6+
@Audited
7+
public String deliverService(String uid) {
8+
return uid;
9+
}
10+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.spring.aspect;
2+
3+
import java.util.List;
4+
5+
import org.aspectj.lang.ProceedingJoinPoint;
6+
import org.aspectj.lang.annotation.Around;
7+
import org.aspectj.lang.annotation.Aspect;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
10+
@Aspect
11+
public class SpringTestAspect {
12+
@Autowired
13+
private List<String> accumulator;
14+
15+
@Around("execution(* com.baeldung.spring.service.SpringSuperService.*(..))")
16+
public Object auditMethod(ProceedingJoinPoint jp) throws Throwable {
17+
String methodName = jp.getSignature().getName();
18+
accumulator.add("Call to " + methodName);
19+
Object obj = jp.proceed();
20+
accumulator.add("Method called successfully: " + methodName);
21+
return obj;
22+
}
23+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.baeldung.spring.configuration;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Configuration;
8+
import org.springframework.context.annotation.EnableAspectJAutoProxy;
9+
10+
import com.baeldung.spring.aspect.SpringTestAspect;
11+
import com.baeldung.spring.service.SpringSuperService;
12+
13+
@Configuration
14+
@EnableAspectJAutoProxy
15+
public class AppConfig {
16+
@Bean
17+
public SpringSuperService springSuperService() {
18+
return new SpringSuperService();
19+
}
20+
21+
@Bean
22+
public SpringTestAspect springTestAspect() {
23+
return new SpringTestAspect();
24+
}
25+
26+
@Bean
27+
public List<String> getAccumulator() {
28+
return new ArrayList<String>();
29+
}
30+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.baeldung.spring.service;
2+
3+
public class SpringSuperService {
4+
public String getInfoFromService(String code) {
5+
return code;
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<beans xmlns="http://java.sun.com/xml/ns/javaee"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
4+
http://java.sun.com/xml/ns/javaee/beans_1_2.xsd">
5+
<interceptors>
6+
<class>com.baeldung.interceptor.AuditedInterceptor</class>
7+
</interceptors>
8+
</beans>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.baeldung.test;
2+
3+
import org.jboss.weld.environment.se.Weld;
4+
import org.jboss.weld.environment.se.WeldContainer;
5+
import org.junit.After;
6+
import org.junit.Assert;
7+
import org.junit.Before;
8+
import org.junit.Test;
9+
10+
import com.baeldung.interceptor.AuditedInterceptor;
11+
import com.baeldung.service.SuperService;
12+
13+
public class TestInterceptor {
14+
Weld weld;
15+
WeldContainer container;
16+
17+
@Before
18+
public void init() {
19+
weld = new Weld();
20+
container = weld.initialize();
21+
}
22+
23+
@After
24+
public void shutdown() {
25+
weld.shutdown();
26+
}
27+
28+
@Test
29+
public void givenTheService_whenMethodAndInterceptorExecuted_thenOK() {
30+
SuperService superService = container.select(SuperService.class).get();
31+
String code = "123456";
32+
superService.deliverService(code);
33+
34+
Assert.assertTrue(AuditedInterceptor.calledBefore);
35+
Assert.assertTrue(AuditedInterceptor.calledAfter);
36+
}
37+
38+
}

0 commit comments

Comments
 (0)