diff --git a/alfa-service/pom.xml b/alfa-service/pom.xml index 525cf2e219bd65e3edfade89158b536bd1fc71d8..67e37c00dbdaa4eaadd4696180e0a39f18ed092e 100644 --- a/alfa-service/pom.xml +++ b/alfa-service/pom.xml @@ -132,16 +132,6 @@ <artifactId>mapstruct</artifactId> </dependency> - <!-- aspectJ --> - <dependency> - <groupId>org.aspectj</groupId> - <artifactId>aspectjweaver</artifactId> - </dependency> - <dependency> - <groupId>org.aspectj</groupId> - <artifactId>aspectjrt</artifactId> - </dependency> - <!-- Dev --> <dependency> <groupId>org.projectlombok</groupId> diff --git a/goofy-server/pom.xml b/goofy-server/pom.xml index d8828e90c1595e36866312085376c49d5d71dfad..eef1d5ae068925c2f68e71b17f809dfcef184831 100644 --- a/goofy-server/pom.xml +++ b/goofy-server/pom.xml @@ -1,19 +1,20 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>de.itvsh.ozg</groupId> - <artifactId>goofy</artifactId> - <version>1.17.0-SNAPSHOT</version> - </parent> + <parent> + <groupId>de.itvsh.ozg</groupId> + <artifactId>goofy</artifactId> + <version>1.17.0-SNAPSHOT</version> + </parent> - <artifactId>goofy-server</artifactId> - <name>Goofy Server</name> - <groupId>de.itvsh.ozg</groupId> + <artifactId>goofy-server</artifactId> + <name>Goofy Server</name> + <groupId>de.itvsh.ozg</groupId> - <properties> - <maven.compiler.source>${java.version}</maven.compiler.source> - <maven.compiler.target>${java.version}</maven.compiler.target> + <properties> + <maven.compiler.source>${java.version}</maven.compiler.source> + <maven.compiler.target>${java.version}</maven.compiler.target> <spring-boot.build-image.imageName>docker.ozg-sh.de/goofy:build-latest</spring-boot.build-image.imageName> </properties> @@ -35,84 +36,96 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> + + <!-- aspectJ --> + <dependency> + <groupId>org.aspectj</groupId> + <artifactId>aspectjweaver</artifactId> + </dependency> + <dependency> + <groupId>org.aspectj</groupId> + <artifactId>aspectjrt</artifactId> + </dependency> </dependencies> - <build> - <finalName>${project.artifactId}</finalName> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - <configuration> - <docker> - <publishRegistry> - <username>${docker-username}</username> - <password>${docker-password}</password> - <url>${docker-url}</url> - </publishRegistry> - </docker> - </configuration> - </plugin> + <build> + <finalName>${project.artifactId}</finalName> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <docker> + <publishRegistry> + <username>${docker-username}</username> + <password>${docker-password}</password> + <url>${docker-url}</url> + </publishRegistry> + </docker> + </configuration> + </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-failsafe-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.jacoco</groupId> - <artifactId>jacoco-maven-plugin</artifactId> - </plugin> - <plugin> - <groupId>pl.project13.maven</groupId> - <artifactId>git-commit-id-plugin</artifactId> - </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>pl.project13.maven</groupId> + <artifactId>git-commit-id-plugin</artifactId> + </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-resources-plugin</artifactId> - <executions> - <execution> - <id>copy-client</id> - <phase>compile</phase> - <goals> - <goal>copy-resources</goal> - </goals> - <configuration> - <outputDirectory> - ${project.build.directory}/classes/META-INF/resources</outputDirectory> - <resources> - <resource> - <directory> - ../${project.parent.artifactId}-client/dist/apps/goofy/</directory> - </resource> - </resources> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <version>3.3.0</version> - <executions> - <execution> - <id>Jar Tests Package</id> - <phase>package</phase> - <goals> - <goal>test-jar</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + <executions> + <execution> + <id>copy-client</id> + <phase>compile</phase> + <goals> + <goal>copy-resources</goal> + </goals> + <configuration> + <outputDirectory> + ${project.build.directory}/classes/META-INF/resources + </outputDirectory> + <resources> + <resource> + <directory> + ../${project.parent.artifactId}-client/dist/apps/goofy/ + </directory> + </resource> + </resources> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>3.3.0</version> + <executions> + <execution> + <id>Jar Tests Package</id> + <phase>package</phase> + <goals> + <goal>test-jar</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> </project> diff --git a/goofy-server/src/main/java/de/ozgcloud/alfa/logging/AlfaAspectPointcuts.java b/goofy-server/src/main/java/de/ozgcloud/alfa/logging/AlfaAspectPointcuts.java new file mode 100644 index 0000000000000000000000000000000000000000..7f72dd6b7afa91fc5466381f258ddba7a6440003 --- /dev/null +++ b/goofy-server/src/main/java/de/ozgcloud/alfa/logging/AlfaAspectPointcuts.java @@ -0,0 +1,31 @@ +package de.ozgcloud.alfa.logging; + +import org.aspectj.lang.annotation.Pointcut; + +public class AlfaAspectPointcuts { + + @Pointcut("execution(public * *(..))") + void anyPublicMethods() { + // aspect pointcut - no implementation needed + } + + @Pointcut("within(de.ozgcloud..*)") + void anythingInOzgCloud() { + // aspect pointcut - no implementation needed + } + + @Pointcut("anyPublicMethods() && anythingInOzgCloud()") + void anyPublicMethodInOzgCloud() { + // aspect pointcut - no implementation needed + } + + @Pointcut("anyPublicMethodInOzgCloud() && @target(org.springframework.stereotype.Service)") + void anyPublicServiceMethod() { + // aspect pointcut - no implementation needed + } + + @Pointcut("anyPublicMethodInOzgCloud() && @target(org.springframework.web.bind.annotation.RestController)") + void anyPublicRestControllerMethod() { + // aspect pointcut - no implementation needed + } +} diff --git a/goofy-server/src/main/java/de/ozgcloud/alfa/logging/AlfaLoggingAspect.java b/goofy-server/src/main/java/de/ozgcloud/alfa/logging/AlfaLoggingAspect.java new file mode 100644 index 0000000000000000000000000000000000000000..2a422d1b4b3eebaea5b90f1fa9d01aab438f6a12 --- /dev/null +++ b/goofy-server/src/main/java/de/ozgcloud/alfa/logging/AlfaLoggingAspect.java @@ -0,0 +1,31 @@ +package de.ozgcloud.alfa.logging; + +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.AfterThrowing; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.springframework.stereotype.Component; + +import de.itvsh.kop.common.logging.AspectLoggingUtils; + +@Aspect +@Component +public class AlfaLoggingAspect extends AlfaAspectPointcuts { + + @Before("anyPublicServiceMethod() || anyPublicRestControllerMethod()") + public void onLoggedMethod(JoinPoint joinPoint) { + AspectLoggingUtils.log(joinPoint); + } + + @AfterThrowing(pointcut = "anyPublicServiceMethod() || anyPublicRestControllerMethod()", throwing = "ex") + public void afterExceptionInLoggedMethod(JoinPoint joinPoint, Exception ex) { + AspectLoggingUtils.logException(joinPoint, ex); + } + + @AfterReturning(pointcut = "anyPublicServiceMethod() || anyPublicRestControllerMethod()", returning = "returnValue") + public void afterLoggedMethod(JoinPoint joinPoint, Object returnValue) { + AspectLoggingUtils.logReturnValue(joinPoint, returnValue); + } + +}