Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
2496218
BAL-36 File size api in java and apache commons IO
eralmas7 Dec 11, 2016
f482296
BAEL-282 grep in java - fixes after code review
eralmas7 Dec 18, 2016
4f8eb01
Merge https://github.com/eugenp/tutorials
eralmas7 Jan 1, 2017
f0ba4e7
Merge https://github.com/eugenp/tutorials
eralmas7 Jan 1, 2017
7052600
BAEL-519 Added support for disruptor library
eralmas7 Jan 1, 2017
902e7ee
BAEL-519 Added support for disruptor library
eralmas7 Jan 1, 2017
3115469
BAEL-519 Added support for disruptor library
eralmas7 Jan 1, 2017
4a30e52
BAEL-519 Added support for disruptor library
eralmas7 Jan 1, 2017
346648e
BAEL-519 Added support for disruptor library
eralmas7 Jan 1, 2017
9ad759f
BAEL-519 Added support for disruptor library
eralmas7 Jan 1, 2017
bbac8db
BAEL-519 Added support for disruptor
eralmas7 Jan 1, 2017
244a6f1
BAEL-519 Moved all supporting classes to main source
eralmas7 Jan 2, 2017
dd0ce16
BAEL-519 Moved all supporting classes to main source
eralmas7 Jan 2, 2017
a6fe012
BAEL-519 Moved asserts and test classes in test folder.
eralmas7 Jan 12, 2017
d6f42d9
BAEL-519 moved test related producer and consumer to src.
eralmas7 Jan 14, 2017
9d502d5
Merge branch 'master' of https://github.com/eugenp/tutorials.git
eralmas7 Jan 14, 2017
325856c
BAEL-586 Guide to Guava BiMap.
eralmas7 Jan 14, 2017
09bf5fe
BAEL-587 formatted code.
eralmas7 Jan 15, 2017
68fe2f1
BAEL-519 LMAX Disruptor
eralmas7 Jan 15, 2017
9c89f20
Merge branch 'master' of https://github.com/eugenp/tutorials.git
eralmas7 Jan 15, 2017
3c2b217
BAEL-587 resolved merge
eralmas7 Jan 15, 2017
70d247e
BAEL-587 Resolved merge
eralmas7 Jan 15, 2017
745c1ea
Merge branch 'master' of https://github.com/eugenp/tutorials.git
eralmas7 Jan 15, 2017
9e8f482
BAEL-519 Removed disruptor link.
eralmas7 Jan 15, 2017
f47bbcd
Merge branch 'master' of https://github.com/eugenp/tutorials.git
eralmas7 Jan 15, 2017
1bfcc17
BAEL-519 Reverted Guava changes
eralmas7 Jan 15, 2017
40ba898
Merge branch 'master' of https://github.com/eugenp/tutorials.git
eralmas7 Jan 19, 2017
3398b0a
RFQ-587 Added disruptor as a separate module.
eralmas7 Jan 19, 2017
7cab632
BAEL-519 Disruptor changes.
eralmas7 Jan 19, 2017
d8caaf7
BAEL-519 Removed disruptor from core-java module.
eralmas7 Jan 19, 2017
4586c30
Merge branch 'master' of https://github.com/eugenp/tutorials.git
eralmas7 Jan 20, 2017
f8e5725
Merge branch 'master' of https://github.com/eugenp/tutorials.git
eralmas7 Jan 21, 2017
af86b34
Merge branch 'master' of https://github.com/eugenp/tutorials.git
eralmas7 Jan 21, 2017
ad19b3d
Merge branch 'master' of https://github.com/eugenp/tutorials.git
eralmas7 Jan 26, 2017
aa9c07f
Merge branch 'master' of https://github.com/eugenp/tutorials.git
eralmas7 Jan 28, 2017
8a39749
Merge branch 'master' of https://github.com/eugenp/tutorials.git
eralmas7 Jan 30, 2017
d9a5156
Merge branch 'master' of https://github.com/eugenp/tutorials.git
eralmas7 Feb 5, 2017
5d7b487
Merge branch 'master' of https://github.com/eugenp/tutorials.git
eralmas7 Mar 14, 2017
1704d6b
BAEL-729 Expose additional information programmatically in /info
eralmas7 Mar 14, 2017
4423648
Merge branch 'master' of https://github.com/eugenp/tutorials.git
eralmas7 May 7, 2017
cc9f135
BAEL-1240 Introduction to Spring AOP
eralmas7 Oct 14, 2017
f021b89
BAEL-1240 - Spring AOP using configuration in XML.
eralmas7 Oct 15, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions spring-aop/src/main/java/org/baeldung/logger/AdderAfterAspect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.baeldung.logger;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AdderAfterAspect {

private final Logger logger = LoggerFactory.getLogger(this.getClass());

public void afterAdvice() throws Throwable {
logger.info("I'm done calling the method");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.baeldung.logger;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AdderAfterReturnAspect {

private final Logger logger = LoggerFactory.getLogger(this.getClass());

public void afterReturn(final Object returnValue) throws Throwable {
logger.info("value return was {}", returnValue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.baeldung.logger;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AdderAfterThrowAspect {

private final Logger logger = LoggerFactory.getLogger(this.getClass());

public void afterThrow(final Exception exception) throws Throwable {
logger.info("Exception thrown was {}", exception.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.baeldung.logger;

import java.util.Arrays;
import org.aspectj.lang.ProceedingJoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AdderAroundAspect {

private final Logger logger = LoggerFactory.getLogger(this.getClass());

public Object aroundAdvice(final ProceedingJoinPoint joinPoint) throws Throwable {
logger.info("Arguments passed to method are: " + Arrays.toString(joinPoint.getArgs()));
final Object result = joinPoint.proceed();
logger.info("Result from method is: " + result);
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.baeldung.logger;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AdderBeforeAspect {

private final Logger logger = LoggerFactory.getLogger(this.getClass());

public void beforeAdvice() throws Throwable {
logger.info("I would be executed just before method starts");
}
}
12 changes: 12 additions & 0 deletions spring-aop/src/main/java/org/baeldung/logger/SampleAdder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.baeldung.logger;

public class SampleAdder {

public int add(int a, int b) {
if (a < 0 || b < 0) {
throw new IllegalArgumentException("Make sure all the arguments are greater than zero.");
}
return a + b;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 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/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">

<bean id="sampleAdder"
class="org.baeldung.logger.SampleAdder" />

<bean id="doBeforeAspect" class="org.baeldung.logger.AdderBeforeAspect" />
<bean id="doAfterAspect" class="org.baeldung.logger.AdderAfterAspect" />
<bean id="doAfterThrowingAspect" class="org.baeldung.logger.AdderAfterThrowAspect" />
<bean id="doAfterReturningAspect" class="org.baeldung.logger.AdderAfterReturnAspect" />
<bean id="doAroundAspect" class="org.baeldung.logger.AdderAroundAspect" />

<aop:config>

<aop:aspect id="aspects" ref="doBeforeAspect">
<aop:pointcut id="pointCutBefore"
expression="execution(* org.baeldung.logger.SampleAdder+.*(..))" />
<aop:before method="beforeAdvice" pointcut-ref="pointCutBefore" />
</aop:aspect>

<aop:aspect id="aspects" ref="doAfterAspect">
<aop:pointcut id="pointCutAfter"
expression="execution(* org.baeldung.logger.SampleAdder+.*(..))" />
<aop:after method="afterAdvice" pointcut-ref="pointCutAfter" />
</aop:aspect>

<aop:aspect id="aspects" ref="doAfterReturningAspect">
<aop:pointcut id="pointCutAfterReturning"
expression="execution(* org.baeldung.logger.SampleAdder+.*(..))" />
<aop:after-returning method="afterReturn"
returning="returnValue" pointcut-ref="pointCutAfterReturning" />
</aop:aspect>

<aop:aspect id="aspects" ref="doAfterThrowingAspect">
<aop:pointcut id="pointCutAfterThrowing"
expression="execution(* org.baeldung.logger.SampleAdder+.*(..))" />
<aop:after-throwing method="afterThrow"
throwing="error" pointcut-ref="pointCutAfterThrowing" />
</aop:aspect>

<aop:aspect id="aspects" ref="doAroundAspect">
<aop:pointcut id="pointCutAround"
expression="execution(* org.baeldung.logger.SampleAdder+.*(..))" />
<aop:around method="aroundAdvice" pointcut-ref="pointCutAround" />
</aop:aspect>


</aop:config>

</beans>
29 changes: 29 additions & 0 deletions spring-aop/src/test/java/org/baeldung/logger/CalculatorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.baeldung.logger;

import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(value = {"classpath:springAop-applicationContext.xml"})
public class CalculatorTest {

@Autowired
private SampleAdder sampleAdder;

@Test
public void whenAddValidValues_returnsSucessfully() {
final int addedValue = sampleAdder.add(12, 12);

assertEquals(24, addedValue);
}

@Test (expected = IllegalArgumentException.class)
public void whenAddInValidValues_throwsException() {
sampleAdder.add(12, -12);
}

}
54 changes: 54 additions & 0 deletions spring-aop/src/test/resources/springAop-applicationContext.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 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/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">

<bean id="sampleAdder"
class="org.baeldung.logger.SampleAdder" />

<bean id="doBeforeAspect" class="org.baeldung.logger.AdderBeforeAspect" />
<bean id="doAfterAspect" class="org.baeldung.logger.AdderAfterAspect" />
<bean id="doAfterThrowingAspect" class="org.baeldung.logger.AdderAfterThrowAspect" />
<bean id="doAfterReturningAspect" class="org.baeldung.logger.AdderAfterReturnAspect" />
<bean id="doAroundAspect" class="org.baeldung.logger.AdderAroundAspect" />

<aop:config>

<aop:aspect id="aspects" ref="doBeforeAspect">
<aop:pointcut id="pointCutBefore"
expression="execution(* org.baeldung.logger.SampleAdder+.*(..))" />
<aop:before method="beforeAdvice" pointcut-ref="pointCutBefore" />
</aop:aspect>

<aop:aspect id="aspects" ref="doAfterAspect">
<aop:pointcut id="pointCutAfter"
expression="execution(* org.baeldung.logger.SampleAdder+.*(..))" />
<aop:after method="afterAdvice" pointcut-ref="pointCutAfter" />
</aop:aspect>

<aop:aspect id="aspects" ref="doAfterReturningAspect">
<aop:pointcut id="pointCutAfterReturning"
expression="execution(* org.baeldung.logger.SampleAdder+.*(..))" />
<aop:after-returning method="afterReturn"
returning="returnValue" pointcut-ref="pointCutAfterReturning" />
</aop:aspect>

<aop:aspect id="aspects" ref="doAfterThrowingAspect">
<aop:pointcut id="pointCutAfterThrowing"
expression="execution(* org.baeldung.logger.SampleAdder+.*(..))" />
<aop:after-throwing method="afterThrow"
throwing="exception" pointcut-ref="pointCutAfterThrowing" />
</aop:aspect>

<aop:aspect id="aspects" ref="doAroundAspect">
<aop:pointcut id="pointCutAround"
expression="execution(* org.baeldung.logger.SampleAdder+.*(..))" />
<aop:around method="aroundAdvice" pointcut-ref="pointCutAround" />
</aop:aspect>


</aop:config>

</beans>
4 changes: 4 additions & 0 deletions spring-boot-actuator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/target/
.settings/
.classpath
.project
Empty file added spring-boot-actuator/README.MD
Empty file.
121 changes: 121 additions & 0 deletions spring-boot-actuator/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<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>
<groupId>com.baeldung</groupId>
<artifactId>spring-boot-actuator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-boot</name>
<description>This is simple boot application for Spring boot actuator test</description>

<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<finalName>spring-boot-actuator</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>

<plugins>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
</configuration>
</plugin>

</plugins>

</build>

<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>


<properties>
<start-class>org.baeldung.MainApplication</start-class>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.baeldung;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.baeldung.config.MainConfig;

@SpringBootApplication
public class MainApplication {

public static void main(String args[]) {
SpringApplication.run(MainConfig.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.baeldung.config;

import java.util.Collections;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;

@EnableAutoConfiguration
public class MainConfig {

public MainConfig() {}

@Bean
public InfoContributor getInfoContributor() {
return (infoBuilder) -> infoBuilder.withDetail("applicationInfo", Collections.singletonMap("ActiveUserCount", "10"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
info.app.name=Sample application
Loading