Merge remote-tracking branch 'eugenp/master'
This commit is contained in:
commit
e11d08b6b6
@ -133,3 +133,4 @@
|
|||||||
- [A Guide to Java Initialization](http://www.baeldung.com/java-initialization)
|
- [A Guide to Java Initialization](http://www.baeldung.com/java-initialization)
|
||||||
- [Implementing a Binary Tree in Java](http://www.baeldung.com/java-binary-tree)
|
- [Implementing a Binary Tree in Java](http://www.baeldung.com/java-binary-tree)
|
||||||
- [A Guide to ThreadLocalRandom in Java](http://www.baeldung.com/java-thread-local-random)
|
- [A Guide to ThreadLocalRandom in Java](http://www.baeldung.com/java-thread-local-random)
|
||||||
|
- [RegEx for matching Date Pattern in Java](http://www.baeldung.com/java-date-regular-expressions)
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.baeldung.iteratorguide;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
|
||||||
|
public class IteratorGuide {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
List<String> items = new ArrayList<>();
|
||||||
|
items.add("ONE");
|
||||||
|
items.add("TWO");
|
||||||
|
items.add("THREE");
|
||||||
|
Iterator<String> iter = items.iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
String next = iter.next();
|
||||||
|
System.out.println(next);
|
||||||
|
iter.remove();
|
||||||
|
}
|
||||||
|
ListIterator<String> listIterator = items.listIterator();
|
||||||
|
while(listIterator.hasNext()) {
|
||||||
|
String nextWithIndex = items.get(listIterator.nextIndex());
|
||||||
|
String next = listIterator.next();
|
||||||
|
if( "ONE".equals(next)) {
|
||||||
|
listIterator.set("SWAPPED");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
listIterator.add("FOUR");
|
||||||
|
while(listIterator.hasPrevious()) {
|
||||||
|
String previousWithIndex = items.get(listIterator.previousIndex());
|
||||||
|
String previous = listIterator.previous();
|
||||||
|
System.out.println(previous);
|
||||||
|
}
|
||||||
|
listIterator.forEachRemaining(e -> {
|
||||||
|
System.out.println(e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.baeldung.regexp.datepattern;
|
||||||
|
|
||||||
|
public interface DateMatcher {
|
||||||
|
|
||||||
|
boolean matches(String date);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.baeldung.regexp.datepattern;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
class FormattedDateMatcher implements DateMatcher {
|
||||||
|
|
||||||
|
private static final Pattern DATE_PATTERN = Pattern.compile(
|
||||||
|
"^\\d{4}-\\d{2}-\\d{2}$");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(String date) {
|
||||||
|
return DATE_PATTERN.matcher(date).matches();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.baeldung.regexp.datepattern;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
class RangedDateMatcher implements DateMatcher {
|
||||||
|
|
||||||
|
private static final Pattern DATE_PATTERN = Pattern.compile(
|
||||||
|
"^((19|2[0-9])[0-9]{2})-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(String date) {
|
||||||
|
return DATE_PATTERN.matcher(date).matches();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.baeldung.regexp.datepattern.gregorian;
|
||||||
|
|
||||||
|
import com.baeldung.regexp.datepattern.DateMatcher;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class February29thMatcher implements DateMatcher {
|
||||||
|
|
||||||
|
private static final Pattern DATE_PATTERN = Pattern.compile(
|
||||||
|
"^((2000|2400|2800|(19|2[0-9](0[48]|[2468][048]|[13579][26])))-02-29)$");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(String date) {
|
||||||
|
return DATE_PATTERN.matcher(date).matches();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.baeldung.regexp.datepattern.gregorian;
|
||||||
|
|
||||||
|
import com.baeldung.regexp.datepattern.DateMatcher;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class FebruaryGeneralMatcher implements DateMatcher {
|
||||||
|
|
||||||
|
private static final Pattern DATE_PATTERN = Pattern.compile(
|
||||||
|
"^(((19|2[0-9])[0-9]{2})-02-(0[1-9]|1[0-9]|2[0-8]))$");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(String date) {
|
||||||
|
return DATE_PATTERN.matcher(date).matches();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.baeldung.regexp.datepattern.gregorian;
|
||||||
|
|
||||||
|
import com.baeldung.regexp.datepattern.DateMatcher;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
class GregorianDateMatcher implements DateMatcher {
|
||||||
|
|
||||||
|
private static final Pattern DATE_PATTERN = Pattern.compile(
|
||||||
|
"^((2000|2400|2800|(19|2[0-9](0[48]|[2468][048]|[13579][26])))-02-29)$"
|
||||||
|
+ "|^(((19|2[0-9])[0-9]{2})-02-(0[1-9]|1[0-9]|2[0-8]))$"
|
||||||
|
+ "|^(((19|2[0-9])[0-9]{2})-(0[13578]|10|12)-(0[1-9]|[12][0-9]|3[01]))$"
|
||||||
|
+ "|^(((19|2[0-9])[0-9]{2})-(0[469]|11)-(0[1-9]|[12][0-9]|30))$");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(String date) {
|
||||||
|
return DATE_PATTERN.matcher(date).matches();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.baeldung.regexp.datepattern.gregorian;
|
||||||
|
|
||||||
|
import com.baeldung.regexp.datepattern.DateMatcher;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class MonthsOf30DaysMatcher implements DateMatcher {
|
||||||
|
|
||||||
|
private static final Pattern DATE_PATTERN = Pattern.compile(
|
||||||
|
"^(((19|2[0-9])[0-9]{2})-(0[469]|11)-(0[1-9]|[12][0-9]|30))$");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(String date) {
|
||||||
|
return DATE_PATTERN.matcher(date).matches();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.baeldung.regexp.datepattern.gregorian;
|
||||||
|
|
||||||
|
import com.baeldung.regexp.datepattern.DateMatcher;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class MonthsOf31DaysMatcher implements DateMatcher {
|
||||||
|
|
||||||
|
private static final Pattern DATE_PATTERN = Pattern.compile(
|
||||||
|
"^(((19|2[0-9])[0-9]{2})-(0[13578]|10|12)-(0[1-9]|[12][0-9]|3[01]))$");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(String date) {
|
||||||
|
return DATE_PATTERN.matcher(date).matches();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.baeldung.regexp.datepattern;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class FormattedDateMatcherUnitTest {
|
||||||
|
|
||||||
|
private DateMatcher matcher = new FormattedDateMatcher();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenUsingFormattedDateMatcher_thenFormatConstraintsSatisfied() {
|
||||||
|
Assert.assertTrue(matcher.matches("2017-12-31"));
|
||||||
|
Assert.assertTrue(matcher.matches("2018-01-01"));
|
||||||
|
Assert.assertTrue(matcher.matches("0000-00-00"));
|
||||||
|
Assert.assertTrue(matcher.matches("1029-99-72"));
|
||||||
|
|
||||||
|
Assert.assertFalse(matcher.matches("2018-01"));
|
||||||
|
Assert.assertFalse(matcher.matches("2018-01-01-01"));
|
||||||
|
Assert.assertFalse(matcher.matches("2018-01-XX"));
|
||||||
|
Assert.assertFalse(matcher.matches(" 2018-01-01"));
|
||||||
|
Assert.assertFalse(matcher.matches("2018-01-01 "));
|
||||||
|
Assert.assertFalse(matcher.matches("2018/01/01"));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package com.baeldung.regexp.datepattern;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class RangedDateMatcherUnitTest {
|
||||||
|
|
||||||
|
private DateMatcher matcher = new RangedDateMatcher();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenUsingRangedDateMatcher_thenFormatConstraintsSatisfied() {
|
||||||
|
Assert.assertFalse(matcher.matches("2018-01"));
|
||||||
|
Assert.assertFalse(matcher.matches("2018-01-01-01"));
|
||||||
|
Assert.assertFalse(matcher.matches("2018-01-XX"));
|
||||||
|
Assert.assertFalse(matcher.matches(" 2018-01-01"));
|
||||||
|
Assert.assertFalse(matcher.matches("2018-01-01 "));
|
||||||
|
Assert.assertFalse(matcher.matches("2018/01/01"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenUsingRangedDateMatcher_thenRangeConstraintsSatisfied() {
|
||||||
|
Assert.assertTrue(matcher.matches("1900-01-01"));
|
||||||
|
Assert.assertTrue(matcher.matches("2018-02-31"));
|
||||||
|
Assert.assertTrue(matcher.matches("2999-12-31"));
|
||||||
|
|
||||||
|
Assert.assertFalse(matcher.matches("1899-12-31"));
|
||||||
|
Assert.assertFalse(matcher.matches("2018-05-35"));
|
||||||
|
Assert.assertFalse(matcher.matches("2018-13-05"));
|
||||||
|
Assert.assertFalse(matcher.matches("3000-01-01"));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.baeldung.regexp.datepattern.gregorian;
|
||||||
|
|
||||||
|
import com.baeldung.regexp.datepattern.DateMatcher;
|
||||||
|
import com.baeldung.regexp.datepattern.gregorian.testhelper.GregorianDateTestHelper;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class February29thMatcherUnitTest {
|
||||||
|
|
||||||
|
private DateMatcher matcher = new February29thMatcher();
|
||||||
|
|
||||||
|
private GregorianDateTestHelper testHelper = new GregorianDateTestHelper(matcher);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenYearIsLeap_thenYearHasFebruary29th() {
|
||||||
|
testHelper.assertFebruary29th();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.baeldung.regexp.datepattern.gregorian;
|
||||||
|
|
||||||
|
import com.baeldung.regexp.datepattern.DateMatcher;
|
||||||
|
import com.baeldung.regexp.datepattern.gregorian.testhelper.GregorianDateTestHelper;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class FebruaryGeneralMatcherUnitTest {
|
||||||
|
|
||||||
|
private DateMatcher matcher = new FebruaryGeneralMatcher();
|
||||||
|
|
||||||
|
private GregorianDateTestHelper testHelper = new GregorianDateTestHelper(matcher);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenMonthIsFebruary_thenMonthContainsUpTo28Days() {
|
||||||
|
testHelper.assertFebruaryGeneralDates();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package com.baeldung.regexp.datepattern.gregorian;
|
||||||
|
|
||||||
|
import com.baeldung.regexp.datepattern.DateMatcher;
|
||||||
|
import com.baeldung.regexp.datepattern.gregorian.testhelper.GregorianDateTestHelper;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class GregorianDateMatcherUnitTest {
|
||||||
|
|
||||||
|
private DateMatcher matcher = new GregorianDateMatcher();
|
||||||
|
|
||||||
|
private GregorianDateTestHelper testHelper = new GregorianDateTestHelper(matcher);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenUsingGregorianDateMatcher_thenFormatConstraintsSatisfied() {
|
||||||
|
testHelper.assertFormat();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenUsingGregorianDateMatcher_thenRangeConstraintsSatisfied() {
|
||||||
|
testHelper.assertRange();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenYearIsLeap_thenFebruaryHas29Days() {
|
||||||
|
testHelper.assertFebruary29th();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenMonthIsFebruary_thenMonthContainsUpTo28Days() {
|
||||||
|
testHelper.assertFebruaryGeneralDates();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenMonthIsShort_thenMonthContainsUpTo30Days() {
|
||||||
|
testHelper.assertMonthsOf30Days();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenMonthIsLong_thenMonthContainsUpTo31Days() {
|
||||||
|
testHelper.assertMonthsOf31Dates();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.baeldung.regexp.datepattern.gregorian;
|
||||||
|
|
||||||
|
import com.baeldung.regexp.datepattern.DateMatcher;
|
||||||
|
import com.baeldung.regexp.datepattern.gregorian.testhelper.GregorianDateTestHelper;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class MonthsOf30DaysMatcherUnitTest {
|
||||||
|
|
||||||
|
private DateMatcher matcher = new MonthsOf30DaysMatcher();
|
||||||
|
|
||||||
|
private GregorianDateTestHelper testHelper = new GregorianDateTestHelper(matcher);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenMonthIsShort_thenMonthContainsUpTo30Days() {
|
||||||
|
testHelper.assertMonthsOf30Days();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.baeldung.regexp.datepattern.gregorian;
|
||||||
|
|
||||||
|
import com.baeldung.regexp.datepattern.DateMatcher;
|
||||||
|
import com.baeldung.regexp.datepattern.gregorian.testhelper.GregorianDateTestHelper;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class MonthsOf31DaysMatcherUnitTest {
|
||||||
|
|
||||||
|
private DateMatcher matcher = new MonthsOf31DaysMatcher();
|
||||||
|
|
||||||
|
private GregorianDateTestHelper testHelper = new GregorianDateTestHelper(matcher);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenMonthIsLong_thenMonthContainsUpTo31Days() {
|
||||||
|
testHelper.assertMonthsOf31Dates();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,102 @@
|
|||||||
|
package com.baeldung.regexp.datepattern.gregorian.testhelper;
|
||||||
|
|
||||||
|
import com.baeldung.regexp.datepattern.DateMatcher;
|
||||||
|
import org.junit.Assert;
|
||||||
|
|
||||||
|
public class GregorianDateTestHelper {
|
||||||
|
|
||||||
|
private final DateMatcher matcher;
|
||||||
|
|
||||||
|
public GregorianDateTestHelper(DateMatcher matcher) {
|
||||||
|
this.matcher = matcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void assertFormat() {
|
||||||
|
Assert.assertTrue(matcher.matches("2017-12-31"));
|
||||||
|
Assert.assertTrue(matcher.matches("2018-01-01"));
|
||||||
|
|
||||||
|
Assert.assertFalse(matcher.matches("2018-02"));
|
||||||
|
Assert.assertFalse(matcher.matches("2018-02-01-01"));
|
||||||
|
Assert.assertFalse(matcher.matches("2018-02-XX"));
|
||||||
|
Assert.assertFalse(matcher.matches(" 2018-02-01"));
|
||||||
|
Assert.assertFalse(matcher.matches("2018-02-01 "));
|
||||||
|
Assert.assertFalse(matcher.matches("2020/02/28"));
|
||||||
|
Assert.assertFalse(matcher.matches("2020.02.29"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void assertRange() {
|
||||||
|
Assert.assertTrue(matcher.matches("1900-01-01"));
|
||||||
|
Assert.assertTrue(matcher.matches("2205-05-25"));
|
||||||
|
Assert.assertTrue(matcher.matches("2999-12-31"));
|
||||||
|
|
||||||
|
Assert.assertFalse(matcher.matches("1899-12-31"));
|
||||||
|
Assert.assertFalse(matcher.matches("2018-05-35"));
|
||||||
|
Assert.assertFalse(matcher.matches("2018-13-05"));
|
||||||
|
Assert.assertFalse(matcher.matches("3000-01-01"));
|
||||||
|
Assert.assertFalse(matcher.matches("3200-02-29"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void assertFebruary29th() {
|
||||||
|
Assert.assertTrue(matcher.matches("2000-02-29"));
|
||||||
|
Assert.assertTrue(matcher.matches("2400-02-29"));
|
||||||
|
Assert.assertTrue(matcher.matches("2800-02-29"));
|
||||||
|
Assert.assertTrue(matcher.matches("2020-02-29"));
|
||||||
|
Assert.assertTrue(matcher.matches("2024-02-29"));
|
||||||
|
Assert.assertTrue(matcher.matches("2028-02-29"));
|
||||||
|
|
||||||
|
Assert.assertFalse(matcher.matches("2017-02-29"));
|
||||||
|
Assert.assertFalse(matcher.matches("2018-02-29"));
|
||||||
|
Assert.assertFalse(matcher.matches("2019-02-29"));
|
||||||
|
Assert.assertFalse(matcher.matches("2100-02-29"));
|
||||||
|
Assert.assertFalse(matcher.matches("2200-02-29"));
|
||||||
|
Assert.assertFalse(matcher.matches("2300-02-29"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void assertFebruaryGeneralDates() {
|
||||||
|
Assert.assertTrue(matcher.matches("2018-02-01"));
|
||||||
|
Assert.assertTrue(matcher.matches("2019-02-13"));
|
||||||
|
Assert.assertTrue(matcher.matches("2020-02-25"));
|
||||||
|
|
||||||
|
Assert.assertFalse(matcher.matches("2000-02-30"));
|
||||||
|
Assert.assertFalse(matcher.matches("2400-02-62"));
|
||||||
|
Assert.assertFalse(matcher.matches("2420-02-94"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void assertMonthsOf30Days() {
|
||||||
|
Assert.assertTrue(matcher.matches("2018-04-30"));
|
||||||
|
Assert.assertTrue(matcher.matches("2019-06-30"));
|
||||||
|
Assert.assertTrue(matcher.matches("2020-09-30"));
|
||||||
|
Assert.assertTrue(matcher.matches("2021-11-30"));
|
||||||
|
|
||||||
|
Assert.assertTrue(matcher.matches("2022-04-02"));
|
||||||
|
Assert.assertTrue(matcher.matches("2023-06-14"));
|
||||||
|
Assert.assertTrue(matcher.matches("2024-09-26"));
|
||||||
|
|
||||||
|
Assert.assertFalse(matcher.matches("2018-04-31"));
|
||||||
|
Assert.assertFalse(matcher.matches("2019-06-31"));
|
||||||
|
Assert.assertFalse(matcher.matches("2020-09-31"));
|
||||||
|
Assert.assertFalse(matcher.matches("2021-11-31"));
|
||||||
|
|
||||||
|
Assert.assertFalse(matcher.matches("2022-04-32"));
|
||||||
|
Assert.assertFalse(matcher.matches("2023-06-64"));
|
||||||
|
Assert.assertFalse(matcher.matches("2024-09-96"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void assertMonthsOf31Dates() {
|
||||||
|
Assert.assertTrue(matcher.matches("2018-01-31"));
|
||||||
|
Assert.assertTrue(matcher.matches("2019-03-31"));
|
||||||
|
Assert.assertTrue(matcher.matches("2020-05-31"));
|
||||||
|
Assert.assertTrue(matcher.matches("2021-07-31"));
|
||||||
|
Assert.assertTrue(matcher.matches("2022-08-31"));
|
||||||
|
Assert.assertTrue(matcher.matches("2023-10-31"));
|
||||||
|
Assert.assertTrue(matcher.matches("2024-12-31"));
|
||||||
|
|
||||||
|
Assert.assertTrue(matcher.matches("2025-01-03"));
|
||||||
|
Assert.assertTrue(matcher.matches("2026-03-15"));
|
||||||
|
Assert.assertTrue(matcher.matches("2027-05-27"));
|
||||||
|
|
||||||
|
Assert.assertFalse(matcher.matches("2018-01-32"));
|
||||||
|
Assert.assertFalse(matcher.matches("2019-03-64"));
|
||||||
|
Assert.assertFalse(matcher.matches("2020-05-96"));
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@
|
|||||||
<groupId>org.baeldung</groupId>
|
<groupId>org.baeldung</groupId>
|
||||||
<artifactId>java-lite</artifactId>
|
<artifactId>java-lite</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
@ -15,7 +16,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<jetty.maven.plugin.version>9.3.4.RC1</jetty.maven.plugin.version>
|
<jetty.maven.plugin.version>9.4.8.v20171121</jetty.maven.plugin.version>
|
||||||
<activejdbc.version>1.4.13</activejdbc.version>
|
<activejdbc.version>1.4.13</activejdbc.version>
|
||||||
<activeweb.version>1.15</activeweb.version>
|
<activeweb.version>1.15</activeweb.version>
|
||||||
<mysql.connector.java.version>5.1.45</mysql.connector.java.version>
|
<mysql.connector.java.version>5.1.45</mysql.connector.java.version>
|
||||||
@ -85,16 +86,6 @@
|
|||||||
<systemPath>${java.home}/../lib/tools.jar</systemPath>
|
<systemPath>${java.home}/../lib/tools.jar</systemPath>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.codehaus.jackson</groupId>
|
|
||||||
<artifactId>jackson-core-lgpl</artifactId>
|
|
||||||
<version>${jackson.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.codehaus.jackson</groupId>
|
|
||||||
<artifactId>jackson-mapper-lgpl</artifactId>
|
|
||||||
<version>${jackson.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
@ -9,7 +9,7 @@ import org.javalite.activeweb.controller_filters.TimingFilter;
|
|||||||
public class AppControllerConfig extends AbstractControllerConfig {
|
public class AppControllerConfig extends AbstractControllerConfig {
|
||||||
@Override
|
@Override
|
||||||
public void init(AppContext appContext) {
|
public void init(AppContext appContext) {
|
||||||
addGlobalFilters(new TimingFilter());
|
addGlobalFilters(new TimingFilter());
|
||||||
add(new DBConnectionFilter()).to(ProductsController.class);
|
add(new DBConnectionFilter()).to(ProductsController.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,6 @@ import org.javalite.activeweb.AppContext;
|
|||||||
public class DbConfig extends AbstractDBConfig {
|
public class DbConfig extends AbstractDBConfig {
|
||||||
@Override
|
@Override
|
||||||
public void init(AppContext appContext) {
|
public void init(AppContext appContext) {
|
||||||
this.configFile("/database.properties");
|
this.configFile("/database.properties");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,92 +10,94 @@ import java.util.Map;
|
|||||||
@RESTful
|
@RESTful
|
||||||
public class ProductsController extends AppController {
|
public class ProductsController extends AppController {
|
||||||
|
|
||||||
|
private ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
public void index() {
|
public void index() {
|
||||||
try {
|
try {
|
||||||
view("products", Product.findAll());
|
view("products", Product.findAll());
|
||||||
render().contentType("application/json");
|
render().contentType("application/json");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
view("message", "There was an error.", "code", 200);
|
view("message", "There was an error.", "code", 200);
|
||||||
render("message");
|
render("message");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void create() {
|
public void create() {
|
||||||
try {
|
try {
|
||||||
Map payload = new ObjectMapper().readValue(getRequestString(), Map.class);
|
Map payload = mapper.readValue(getRequestString(), Map.class);
|
||||||
Product p = new Product();
|
Product p = new Product();
|
||||||
p.fromMap(payload);
|
p.fromMap(payload);
|
||||||
p.saveIt();
|
p.saveIt();
|
||||||
view("message", "Successfully saved product id " + p.get("id"), "code", 200);
|
view("message", "Successfully saved product id " + p.get("id"), "code", 200);
|
||||||
render("message");
|
render("message");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
view("message", "There was an error.", "code", 200);
|
view("message", "There was an error.", "code", 200);
|
||||||
render("message");
|
render("message");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
try {
|
try {
|
||||||
Map payload = new ObjectMapper().readValue(getRequestString(), Map.class);
|
Map payload = mapper.readValue(getRequestString(), Map.class);
|
||||||
String id = getId();
|
String id = getId();
|
||||||
Product p = Product.findById(id);
|
Product p = Product.findById(id);
|
||||||
if (p == null) {
|
if (p == null) {
|
||||||
view("message", "Product id " + id + " not found.", "code", 200);
|
view("message", "Product id " + id + " not found.", "code", 200);
|
||||||
render("message");
|
render("message");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
p.fromMap(payload);
|
||||||
|
p.saveIt();
|
||||||
|
view("message", "Successfully updated product id " + id, "code", 200);
|
||||||
|
render("message");
|
||||||
|
} catch (Exception e) {
|
||||||
|
view("message", "There was an error.", "code", 200);
|
||||||
|
render("message");
|
||||||
}
|
}
|
||||||
p.fromMap(payload);
|
|
||||||
p.saveIt();
|
|
||||||
view("message", "Successfully updated product id " + id, "code", 200);
|
|
||||||
render("message");
|
|
||||||
} catch (Exception e) {
|
|
||||||
view("message", "There was an error.", "code", 200);
|
|
||||||
render("message");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void show() {
|
public void show() {
|
||||||
try {
|
try {
|
||||||
String id = getId();
|
String id = getId();
|
||||||
Product p = Product.findById(id);
|
Product p = Product.findById(id);
|
||||||
if (p == null) {
|
if (p == null) {
|
||||||
view("message", "Product id " + id + " not found.", "code", 200);
|
view("message", "Product id " + id + " not found.", "code", 200);
|
||||||
render("message");
|
render("message");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
view("product", p);
|
||||||
|
render("_product");
|
||||||
|
} catch (Exception e) {
|
||||||
|
view("message", "There was an error.", "code", 200);
|
||||||
|
render("message");
|
||||||
}
|
}
|
||||||
view("product", p);
|
|
||||||
render("_product");
|
|
||||||
} catch (Exception e) {
|
|
||||||
view("message", "There was an error.", "code", 200);
|
|
||||||
render("message");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
try {
|
try {
|
||||||
String id = getId();
|
String id = getId();
|
||||||
Product p = Product.findById(id);
|
Product p = Product.findById(id);
|
||||||
if (p == null) {
|
if (p == null) {
|
||||||
view("message", "Product id " + id + " not found.", "code", 200);
|
view("message", "Product id " + id + " not found.", "code", 200);
|
||||||
render("message");
|
render("message");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
p.delete();
|
||||||
|
view("message", "Successfully deleted product id " + id, "code", 200);
|
||||||
|
render("message");
|
||||||
|
} catch (Exception e) {
|
||||||
|
view("message", "There was an error.", "code", 200);
|
||||||
|
render("message");
|
||||||
}
|
}
|
||||||
p.delete();
|
|
||||||
view("message", "Successfully deleted product id " + id, "code", 200);
|
|
||||||
render("message");
|
|
||||||
} catch (Exception e) {
|
|
||||||
view("message", "There was an error.", "code", 200);
|
|
||||||
render("message");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getContentType() {
|
protected String getContentType() {
|
||||||
return "application/json";
|
return "application/json";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getLayout() {
|
protected String getLayout() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,18 +8,18 @@ public class ProductTest {
|
|||||||
|
|
||||||
//@Test
|
//@Test
|
||||||
public void givenSavedProduct_WhenFindFirst_ThenSavedProductIsReturned() {
|
public void givenSavedProduct_WhenFindFirst_ThenSavedProductIsReturned() {
|
||||||
//Open DB connection
|
//Open DB connection
|
||||||
Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/dbname", "user", "password");
|
Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/dbname", "user", "password");
|
||||||
|
|
||||||
//Create a product and save it
|
//Create a product and save it
|
||||||
Product toSaveProduct = new Product();
|
Product toSaveProduct = new Product();
|
||||||
toSaveProduct.set("name", "Bread");
|
toSaveProduct.set("name", "Bread");
|
||||||
toSaveProduct.saveIt();
|
toSaveProduct.saveIt();
|
||||||
|
|
||||||
//Find product
|
//Find product
|
||||||
Product savedProduct = Product.findFirst("name = ?", "Bread");
|
Product savedProduct = Product.findFirst("name = ?", "Bread");
|
||||||
|
|
||||||
Assert.assertEquals(toSaveProduct.get("name"), savedProduct.get("name"));
|
Assert.assertEquals(toSaveProduct.get("name"), savedProduct.get("name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -107,7 +107,7 @@
|
|||||||
<!-- /Neuroph -->
|
<!-- /Neuroph -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.7.0</version>
|
<version>3.7.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.8</source>
|
<source>1.8</source>
|
||||||
<target>1.8</target>
|
<target>1.8</target>
|
||||||
@ -639,6 +639,33 @@
|
|||||||
<version>${googleclient.version}</version>
|
<version>${googleclient.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--Java Docker API Client-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.docker-java</groupId>
|
||||||
|
<artifactId>docker-java</artifactId>
|
||||||
|
<version>${docker.version}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-log4j12</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>jcl-over-slf4j</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sun.jersey</groupId>
|
||||||
|
<artifactId>jersey-client</artifactId>
|
||||||
|
<version>1.19.4</version>
|
||||||
|
</dependency>
|
||||||
|
<!--Java Docker API Client-->
|
||||||
|
|
||||||
<!-- google api -->
|
<!-- google api -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.api-client</groupId>
|
<groupId>com.google.api-client</groupId>
|
||||||
@ -758,5 +785,6 @@
|
|||||||
<google-api.version>1.23.0</google-api.version>
|
<google-api.version>1.23.0</google-api.version>
|
||||||
<google-sheets.version>v4-rev493-1.21.0</google-sheets.version>
|
<google-sheets.version>v4-rev493-1.21.0</google-sheets.version>
|
||||||
<kafka.version>1.0.0</kafka.version>
|
<kafka.version>1.0.0</kafka.version>
|
||||||
|
<docker.version>3.0.14</docker.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
@ -0,0 +1,165 @@
|
|||||||
|
package com.baeldung.dockerapi;
|
||||||
|
|
||||||
|
import com.github.dockerjava.api.DockerClient;
|
||||||
|
import com.github.dockerjava.api.command.CreateContainerResponse;
|
||||||
|
import com.github.dockerjava.api.command.InspectContainerResponse;
|
||||||
|
import com.github.dockerjava.api.model.Container;
|
||||||
|
import com.github.dockerjava.api.model.PortBinding;
|
||||||
|
import com.github.dockerjava.core.DockerClientBuilder;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.hamcrest.Matchers.not;
|
||||||
|
import static org.hamcrest.core.Is.is;
|
||||||
|
|
||||||
|
public class ContainerLiveTest {
|
||||||
|
|
||||||
|
private static DockerClient dockerClient;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setup() {
|
||||||
|
dockerClient = DockerClientBuilder.getInstance().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenListingRunningContainers_thenReturnNonEmptyList() {
|
||||||
|
|
||||||
|
//when
|
||||||
|
List<Container> containers = dockerClient.listContainersCmd().exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertThat(containers.size(), is(not(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenListingExitedContainers_thenReturnNonEmptyList() {
|
||||||
|
|
||||||
|
//when
|
||||||
|
List<Container> containers = dockerClient.listContainersCmd()
|
||||||
|
.withShowSize(true)
|
||||||
|
.withShowAll(true)
|
||||||
|
.withStatusFilter("exited")
|
||||||
|
.exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertThat(containers.size(), is(not(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreatingContainer_thenMustReturnContainerId() {
|
||||||
|
|
||||||
|
//when
|
||||||
|
CreateContainerResponse container
|
||||||
|
= dockerClient.createContainerCmd("mongo:3.6")
|
||||||
|
.withCmd("--bind_ip_all")
|
||||||
|
.withName("mongo")
|
||||||
|
.withHostName("baeldung")
|
||||||
|
.withEnv("MONGO_LATEST_VERSION=3.6")
|
||||||
|
.withPortBindings(PortBinding.parse("9999:27017"))
|
||||||
|
.exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertThat(container.getId(), is(not(null)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenHavingContainer_thenRunContainer() throws InterruptedException {
|
||||||
|
|
||||||
|
//when
|
||||||
|
CreateContainerResponse container
|
||||||
|
= dockerClient.createContainerCmd("alpine:3.6")
|
||||||
|
.withCmd("sleep", "10000")
|
||||||
|
.exec();
|
||||||
|
|
||||||
|
Thread.sleep(3000);
|
||||||
|
//then
|
||||||
|
dockerClient.startContainerCmd(container.getId())
|
||||||
|
.exec();
|
||||||
|
|
||||||
|
dockerClient.stopContainerCmd(container.getId())
|
||||||
|
.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenRunningContainer_thenStopContainer() throws InterruptedException {
|
||||||
|
|
||||||
|
//when
|
||||||
|
CreateContainerResponse container
|
||||||
|
= dockerClient.createContainerCmd("alpine:3.6")
|
||||||
|
.withCmd("sleep", "10000")
|
||||||
|
.exec();
|
||||||
|
|
||||||
|
Thread.sleep(3000);
|
||||||
|
dockerClient.startContainerCmd(container.getId())
|
||||||
|
.exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
dockerClient.stopContainerCmd(container.getId())
|
||||||
|
.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenRunningContainer_thenKillContainer() throws InterruptedException {
|
||||||
|
|
||||||
|
//when
|
||||||
|
CreateContainerResponse container
|
||||||
|
= dockerClient.createContainerCmd("alpine:3.6")
|
||||||
|
.withCmd("sleep", "10000")
|
||||||
|
.exec();
|
||||||
|
|
||||||
|
dockerClient.startContainerCmd(container.getId())
|
||||||
|
.exec();
|
||||||
|
|
||||||
|
Thread.sleep(3000);
|
||||||
|
dockerClient.stopContainerCmd(container.getId())
|
||||||
|
.exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
dockerClient.killContainerCmd(container.getId())
|
||||||
|
.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenHavingContainer_thenInspectContainer() {
|
||||||
|
|
||||||
|
//when
|
||||||
|
CreateContainerResponse container
|
||||||
|
= dockerClient.createContainerCmd("alpine:3.6")
|
||||||
|
.withCmd("sleep", "10000")
|
||||||
|
.exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
InspectContainerResponse containerResponse
|
||||||
|
= dockerClient.inspectContainerCmd(container.getId())
|
||||||
|
.exec();
|
||||||
|
|
||||||
|
assertThat(containerResponse.getId(), is(container.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenContainer_whenCommittingContainer_thenMustReturnImageId() {
|
||||||
|
|
||||||
|
//given
|
||||||
|
CreateContainerResponse container
|
||||||
|
= dockerClient.createContainerCmd("alpine:3.6")
|
||||||
|
.withCmd("sleep", "10000")
|
||||||
|
.exec();
|
||||||
|
|
||||||
|
//when
|
||||||
|
String imageId = dockerClient.commitCmd(container.getId())
|
||||||
|
.withEnv("SNAPSHOT_YEAR=2018")
|
||||||
|
.withMessage("add git support")
|
||||||
|
.withCmd("sleep", "10000")
|
||||||
|
.withRepository("alpine")
|
||||||
|
.withTag("3.6.v2").exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertThat(imageId, is(not(null)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
package com.baeldung.dockerapi;
|
||||||
|
|
||||||
|
import com.github.dockerjava.api.DockerClient;
|
||||||
|
import com.github.dockerjava.core.DefaultDockerClientConfig;
|
||||||
|
import com.github.dockerjava.core.DockerClientBuilder;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
public class DockerClientLiveTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreatingDockerClient_thenReturnDefaultInstance() {
|
||||||
|
|
||||||
|
//when
|
||||||
|
DefaultDockerClientConfig.Builder config
|
||||||
|
= DefaultDockerClientConfig.createDefaultConfigBuilder();
|
||||||
|
DockerClient dockerClient = DockerClientBuilder.getInstance(config).build();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertNotNull(dockerClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreatingDockerClientWithDockerHost_thenReturnInstance() {
|
||||||
|
//when
|
||||||
|
DockerClient dockerClient
|
||||||
|
= DockerClientBuilder.getInstance("tcp://docker.bealdung.com:2375")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertNotNull(dockerClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreatingAdvanceDockerClient_thenReturnInstance() {
|
||||||
|
|
||||||
|
//when
|
||||||
|
DefaultDockerClientConfig config
|
||||||
|
= DefaultDockerClientConfig.createDefaultConfigBuilder()
|
||||||
|
.withRegistryEmail("info@bealdung.com")
|
||||||
|
.withRegistryUrl("register.bealdung.io/v2/")
|
||||||
|
.withRegistryPassword("strongpassword")
|
||||||
|
.withRegistryUsername("bealdung")
|
||||||
|
.withDockerCertPath("/home/bealdung/public/.docker/certs")
|
||||||
|
.withDockerConfig("/home/bealdung/public/.docker/")
|
||||||
|
.withDockerTlsVerify("1")
|
||||||
|
.withDockerHost("tcp://docker.beauldung.com:2376")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
DockerClient dockerClient = DockerClientBuilder.getInstance(config).build();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertNotNull(dockerClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreatingDockerClientWithProperties_thenReturnInstance() {
|
||||||
|
|
||||||
|
//when
|
||||||
|
Properties properties = new Properties();
|
||||||
|
properties.setProperty("registry.email", "info@bealdung.com");
|
||||||
|
properties.setProperty("registry.url", "register.bealdung.io/v2/");
|
||||||
|
properties.setProperty("registry.password", "strongpassword");
|
||||||
|
properties.setProperty("registry.username", "bealdung");
|
||||||
|
properties.setProperty("DOCKER_CERT_PATH", "/home/bealdung/public/.docker/certs");
|
||||||
|
properties.setProperty("DOCKER_CONFIG", "/home/bealdung/public/.docker/");
|
||||||
|
properties.setProperty("DOCKER_TLS_VERIFY", "1");
|
||||||
|
properties.setProperty("DOCKER_HOST", "tcp://docker.bealdung.com:2376");
|
||||||
|
|
||||||
|
DefaultDockerClientConfig config
|
||||||
|
= DefaultDockerClientConfig.createDefaultConfigBuilder()
|
||||||
|
.withProperties(properties)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
DockerClient dockerClient = DockerClientBuilder.getInstance(config).build();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertNotNull(dockerClient);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,155 @@
|
|||||||
|
package com.baeldung.dockerapi;
|
||||||
|
|
||||||
|
import com.github.dockerjava.api.DockerClient;
|
||||||
|
import com.github.dockerjava.api.command.InspectImageResponse;
|
||||||
|
import com.github.dockerjava.api.model.Image;
|
||||||
|
import com.github.dockerjava.api.model.SearchItem;
|
||||||
|
import com.github.dockerjava.core.DockerClientBuilder;
|
||||||
|
import com.github.dockerjava.core.command.BuildImageResultCallback;
|
||||||
|
import com.github.dockerjava.core.command.PullImageResultCallback;
|
||||||
|
import com.github.dockerjava.core.command.PushImageResultCallback;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.hamcrest.Matchers.greaterThan;
|
||||||
|
import static org.hamcrest.Matchers.lessThan;
|
||||||
|
import static org.hamcrest.Matchers.not;
|
||||||
|
import static org.hamcrest.core.Is.is;
|
||||||
|
|
||||||
|
public class ImageLiveTest {
|
||||||
|
|
||||||
|
private static DockerClient dockerClient;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setup() {
|
||||||
|
dockerClient = DockerClientBuilder.getInstance().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenListingImages_thenReturnNonEmptyList() {
|
||||||
|
|
||||||
|
//when
|
||||||
|
List<Image> images = dockerClient.listImagesCmd().exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertThat(images.size(), is(not(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenListingImagesWithIntermediateImages_thenReturnNonEmptyList() {
|
||||||
|
|
||||||
|
//when
|
||||||
|
List<Image> images = dockerClient.listImagesCmd()
|
||||||
|
.withShowAll(true).exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertThat(images.size(), is(not(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenListingDanglingImages_thenReturnNonNullList() {
|
||||||
|
|
||||||
|
//when
|
||||||
|
List<Image> images = dockerClient.listImagesCmd()
|
||||||
|
.withDanglingFilter(true).exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertThat(images, is(not(null)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenBuildingImage_thenMustReturnImageId() {
|
||||||
|
|
||||||
|
//when
|
||||||
|
String imageId = dockerClient.buildImageCmd()
|
||||||
|
.withDockerfile(new File("src/test/resources/dockerapi/Dockerfile"))
|
||||||
|
.withPull(true)
|
||||||
|
.withNoCache(true)
|
||||||
|
.withTag("alpine:git")
|
||||||
|
.exec(new BuildImageResultCallback())
|
||||||
|
.awaitImageId();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertThat(imageId, is(not(null)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenListOfImages_whenInspectImage_thenMustReturnObject() {
|
||||||
|
|
||||||
|
//given
|
||||||
|
List<Image> images = dockerClient.listImagesCmd().exec();
|
||||||
|
Image image = images.get(0);
|
||||||
|
|
||||||
|
//when
|
||||||
|
InspectImageResponse imageResponse
|
||||||
|
= dockerClient.inspectImageCmd(image.getId()).exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertThat(imageResponse.getId(), is(image.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenListOfImages_whenTagImage_thenListMustIncrement() {
|
||||||
|
|
||||||
|
//given
|
||||||
|
List<Image> images = dockerClient.listImagesCmd().exec();
|
||||||
|
Image image = images.get(0);
|
||||||
|
|
||||||
|
//when
|
||||||
|
dockerClient.tagImageCmd(image.getId(), "baeldung/alpine", "3.6.v2").exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
List<Image> imagesNow = dockerClient.listImagesCmd().exec();
|
||||||
|
assertThat(imagesNow.size(), is(greaterThan(images.size())));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pushingAnImage() throws InterruptedException {
|
||||||
|
|
||||||
|
dockerClient.pushImageCmd("baeldung/alpine")
|
||||||
|
.withTag("3.6.v2")
|
||||||
|
.exec(new PushImageResultCallback())
|
||||||
|
.awaitCompletion(90, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenPullingImage_thenImageListNotEmpty() throws InterruptedException {
|
||||||
|
|
||||||
|
//when
|
||||||
|
dockerClient.pullImageCmd("alpine")
|
||||||
|
.withTag("latest")
|
||||||
|
.exec(new PullImageResultCallback())
|
||||||
|
.awaitCompletion(30, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
//then
|
||||||
|
List<Image> images = dockerClient.listImagesCmd().exec();
|
||||||
|
assertThat(images.size(), is(not(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenRemovingImage_thenImageListDecrease() {
|
||||||
|
|
||||||
|
//when
|
||||||
|
List<Image> images = dockerClient.listImagesCmd().exec();
|
||||||
|
Image image = images.get(0);
|
||||||
|
dockerClient.removeImageCmd(image.getId()).exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
List<Image> imagesNow = dockerClient.listImagesCmd().exec();
|
||||||
|
assertThat(imagesNow.size(), is(lessThan(images.size())));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSearchingImage_thenMustReturn25Items() {
|
||||||
|
|
||||||
|
//when
|
||||||
|
List<SearchItem> items = dockerClient.searchImagesCmd("Java").exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertThat(items.size(), is(25));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,91 @@
|
|||||||
|
package com.baeldung.dockerapi;
|
||||||
|
|
||||||
|
import com.github.dockerjava.api.DockerClient;
|
||||||
|
import com.github.dockerjava.api.command.CreateNetworkResponse;
|
||||||
|
import com.github.dockerjava.api.model.Network;
|
||||||
|
import com.github.dockerjava.api.model.Network.Ipam;
|
||||||
|
import com.github.dockerjava.core.DockerClientBuilder;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.hamcrest.Matchers.greaterThan;
|
||||||
|
import static org.hamcrest.Matchers.not;
|
||||||
|
import static org.hamcrest.core.Is.is;
|
||||||
|
|
||||||
|
public class NetworkLiveTest {
|
||||||
|
|
||||||
|
private static DockerClient dockerClient;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setup() {
|
||||||
|
dockerClient = DockerClientBuilder.getInstance().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenListingNetworks_thenSizeMustBeGreaterThanZero() {
|
||||||
|
|
||||||
|
//when
|
||||||
|
List<Network> networks = dockerClient.listNetworksCmd().exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertThat(networks.size(), is(greaterThan(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreatingNetwork_thenRetrieveResponse() {
|
||||||
|
|
||||||
|
//when
|
||||||
|
CreateNetworkResponse networkResponse
|
||||||
|
= dockerClient.createNetworkCmd()
|
||||||
|
.withName("baeldungDefault")
|
||||||
|
.withDriver("bridge").exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertThat(networkResponse, is(not(null)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreatingAdvanceNetwork_thenRetrieveResponse() {
|
||||||
|
|
||||||
|
//when
|
||||||
|
CreateNetworkResponse networkResponse = dockerClient.createNetworkCmd()
|
||||||
|
.withName("baeldungAdvanced")
|
||||||
|
.withIpam(new Ipam()
|
||||||
|
.withConfig(new Ipam.Config()
|
||||||
|
.withSubnet("172.36.0.0/16")
|
||||||
|
.withIpRange("172.36.5.0/24")))
|
||||||
|
.withDriver("bridge").exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertThat(networkResponse, is(not(null)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenInspectingNetwork_thenSizeMustBeGreaterThanZero() {
|
||||||
|
|
||||||
|
//when
|
||||||
|
String networkName = "bridge";
|
||||||
|
Network network
|
||||||
|
= dockerClient.inspectNetworkCmd().withNetworkId(networkName).exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertThat(network.getName(), is(networkName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreatingNetwork_thenRemove() throws InterruptedException {
|
||||||
|
|
||||||
|
//when
|
||||||
|
CreateNetworkResponse networkResponse
|
||||||
|
= dockerClient.createNetworkCmd()
|
||||||
|
.withName("baeldungDefault")
|
||||||
|
.withDriver("bridge").exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
Thread.sleep(4000);
|
||||||
|
dockerClient.removeNetworkCmd(networkResponse.getId()).exec();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
package com.baeldung.dockerapi;
|
||||||
|
|
||||||
|
import com.github.dockerjava.api.DockerClient;
|
||||||
|
import com.github.dockerjava.api.command.CreateVolumeResponse;
|
||||||
|
import com.github.dockerjava.api.command.InspectVolumeResponse;
|
||||||
|
import com.github.dockerjava.api.command.ListVolumesResponse;
|
||||||
|
import com.github.dockerjava.core.DockerClientBuilder;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
import static org.hamcrest.Matchers.greaterThan;
|
||||||
|
import static org.hamcrest.Matchers.not;
|
||||||
|
import static org.hamcrest.core.Is.is;
|
||||||
|
|
||||||
|
public class VolumeLiveTest {
|
||||||
|
|
||||||
|
private static DockerClient dockerClient;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setup() {
|
||||||
|
dockerClient = DockerClientBuilder.getInstance().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenListingVolumes_thenSizeMustBeGreaterThanZero() {
|
||||||
|
|
||||||
|
//when
|
||||||
|
ListVolumesResponse volumesResponse = dockerClient.listVolumesCmd().exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
List<InspectVolumeResponse> volumes = volumesResponse.getVolumes();
|
||||||
|
assertThat(volumes.size(), is(greaterThan(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenVolumes_whenInspectingVolume_thenReturnNonNullResponse() {
|
||||||
|
|
||||||
|
//given
|
||||||
|
ListVolumesResponse volumesResponse = dockerClient.listVolumesCmd().exec();
|
||||||
|
List<InspectVolumeResponse> volumes = volumesResponse.getVolumes();
|
||||||
|
InspectVolumeResponse volume = volumes.get(0);
|
||||||
|
|
||||||
|
//when
|
||||||
|
InspectVolumeResponse volumeResponse
|
||||||
|
= dockerClient.inspectVolumeCmd(volume.getName()).exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertThat(volumeResponse, is(not(null)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreatingUnnamedVolume_thenGetVolumeId() {
|
||||||
|
|
||||||
|
//when
|
||||||
|
CreateVolumeResponse unnamedVolume = dockerClient.createVolumeCmd().exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertThat(unnamedVolume.getName(), is(not(null)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCreatingNamedVolume_thenGetVolumeId() {
|
||||||
|
|
||||||
|
//when
|
||||||
|
CreateVolumeResponse namedVolume
|
||||||
|
= dockerClient.createVolumeCmd().withName("myNamedVolume").exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assertThat(namedVolume.getName(), is(not(null)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenGettingNamedVolume_thenRemove() throws InterruptedException {
|
||||||
|
|
||||||
|
//when
|
||||||
|
CreateVolumeResponse namedVolume
|
||||||
|
= dockerClient.createVolumeCmd().withName("anotherNamedVolume").exec();
|
||||||
|
|
||||||
|
//then
|
||||||
|
Thread.sleep(4000);
|
||||||
|
dockerClient.removeVolumeCmd(namedVolume.getName()).exec();
|
||||||
|
}
|
||||||
|
}
|
8
libraries/src/test/resources/dockerapi/Dockerfile
Normal file
8
libraries/src/test/resources/dockerapi/Dockerfile
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
FROM alpine:3.6
|
||||||
|
|
||||||
|
RUN apk --update add git openssh && \
|
||||||
|
rm -rf /var/lib/apt/lists/* && \
|
||||||
|
rm /var/cache/apk/*
|
||||||
|
|
||||||
|
ENTRYPOINT ["git"]
|
||||||
|
CMD ["--help"]
|
24
mvn-wrapper/.gitignore
vendored
Normal file
24
mvn-wrapper/.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
nbproject/private/
|
||||||
|
build/
|
||||||
|
nbbuild/
|
||||||
|
dist/
|
||||||
|
nbdist/
|
||||||
|
.nb-gradle/
|
BIN
mvn-wrapper/.mvn/wrapper/maven-wrapper.jar
vendored
Executable file
BIN
mvn-wrapper/.mvn/wrapper/maven-wrapper.jar
vendored
Executable file
Binary file not shown.
1
mvn-wrapper/.mvn/wrapper/maven-wrapper.properties
vendored
Executable file
1
mvn-wrapper/.mvn/wrapper/maven-wrapper.properties
vendored
Executable file
@ -0,0 +1 @@
|
|||||||
|
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip
|
22
mvn-wrapper/README.md
Normal file
22
mvn-wrapper/README.md
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
Setting up the Maven Wrapper on an Application
|
||||||
|
==============================================
|
||||||
|
|
||||||
|
This is the code that shows the configurations of maven wrapper on a SpringBoot project.
|
||||||
|
|
||||||
|
### Requirements
|
||||||
|
|
||||||
|
- Maven
|
||||||
|
- JDK 7
|
||||||
|
|
||||||
|
### Running
|
||||||
|
|
||||||
|
To build and start the server simply type
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ ./mvn clean install
|
||||||
|
$ ./mvn spring-boot:run
|
||||||
|
```
|
||||||
|
|
||||||
|
Now with default configurations it will be available at: [http://localhost:8080](http://localhost:8080)
|
||||||
|
|
||||||
|
Enjoy it :)
|
227
mvn-wrapper/mvnw
vendored
Executable file
227
mvn-wrapper/mvnw
vendored
Executable file
@ -0,0 +1,227 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
# or more contributor license agreements. See the NOTICE file
|
||||||
|
# distributed with this work for additional information
|
||||||
|
# regarding copyright ownership. The ASF licenses this file
|
||||||
|
# to you under the Apache License, Version 2.0 (the
|
||||||
|
# "License"); you may not use this file except in compliance
|
||||||
|
# with the License. You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing,
|
||||||
|
# software distributed under the License is distributed on an
|
||||||
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
# KIND, either express or implied. See the License for the
|
||||||
|
# specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
# Maven2 Start Up Batch script
|
||||||
|
#
|
||||||
|
# Required ENV vars:
|
||||||
|
# ------------------
|
||||||
|
# JAVA_HOME - location of a JDK home dir
|
||||||
|
#
|
||||||
|
# Optional ENV vars
|
||||||
|
# -----------------
|
||||||
|
# M2_HOME - location of maven2's installed home dir
|
||||||
|
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||||
|
# e.g. to debug Maven itself, use
|
||||||
|
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||||
|
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
||||||
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
if [ -z "$MAVEN_SKIP_RC" ] ; then
|
||||||
|
|
||||||
|
if [ -f /etc/mavenrc ] ; then
|
||||||
|
. /etc/mavenrc
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "$HOME/.mavenrc" ] ; then
|
||||||
|
. "$HOME/.mavenrc"
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
# OS specific support. $var _must_ be set to either true or false.
|
||||||
|
cygwin=false;
|
||||||
|
darwin=false;
|
||||||
|
mingw=false
|
||||||
|
case "`uname`" in
|
||||||
|
CYGWIN*) cygwin=true ;;
|
||||||
|
MINGW*) mingw=true;;
|
||||||
|
Darwin*) darwin=true
|
||||||
|
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
|
||||||
|
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
|
||||||
|
if [ -z "$JAVA_HOME" ]; then
|
||||||
|
if [ -x "/usr/libexec/java_home" ]; then
|
||||||
|
export JAVA_HOME="`/usr/libexec/java_home`"
|
||||||
|
else
|
||||||
|
export JAVA_HOME="/Library/Java/Home"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -z "$JAVA_HOME" ] ; then
|
||||||
|
if [ -r /etc/gentoo-release ] ; then
|
||||||
|
JAVA_HOME=`java-config --jre-home`
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$M2_HOME" ] ; then
|
||||||
|
## resolve links - $0 may be a link to maven's home
|
||||||
|
PRG="$0"
|
||||||
|
|
||||||
|
# need this for relative symlinks
|
||||||
|
while [ -h "$PRG" ] ; do
|
||||||
|
ls=`ls -ld "$PRG"`
|
||||||
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||||
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
|
PRG="$link"
|
||||||
|
else
|
||||||
|
PRG="`dirname "$PRG"`/$link"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
saveddir=`pwd`
|
||||||
|
|
||||||
|
M2_HOME=`dirname "$PRG"`/..
|
||||||
|
|
||||||
|
# make it fully qualified
|
||||||
|
M2_HOME=`cd "$M2_HOME" && pwd`
|
||||||
|
|
||||||
|
cd "$saveddir"
|
||||||
|
# echo Using m2 at $M2_HOME
|
||||||
|
fi
|
||||||
|
|
||||||
|
# For Cygwin, ensure paths are in UNIX format before anything is touched
|
||||||
|
if $cygwin ; then
|
||||||
|
[ -n "$M2_HOME" ] &&
|
||||||
|
M2_HOME=`cygpath --unix "$M2_HOME"`
|
||||||
|
[ -n "$JAVA_HOME" ] &&
|
||||||
|
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||||
|
[ -n "$CLASSPATH" ] &&
|
||||||
|
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
|
||||||
|
fi
|
||||||
|
|
||||||
|
# For Mingw, ensure paths are in UNIX format before anything is touched
|
||||||
|
if $mingw ; then
|
||||||
|
[ -n "$M2_HOME" ] &&
|
||||||
|
M2_HOME="`(cd "$M2_HOME"; pwd)`"
|
||||||
|
[ -n "$JAVA_HOME" ] &&
|
||||||
|
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
|
||||||
|
# TODO classpath?
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$JAVA_HOME" ]; then
|
||||||
|
javaExecutable="`which javac`"
|
||||||
|
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
|
||||||
|
# readlink(1) is not available as standard on Solaris 10.
|
||||||
|
readLink=`which readlink`
|
||||||
|
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
|
||||||
|
if $darwin ; then
|
||||||
|
javaHome="`dirname \"$javaExecutable\"`"
|
||||||
|
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
|
||||||
|
else
|
||||||
|
javaExecutable="`readlink -f \"$javaExecutable\"`"
|
||||||
|
fi
|
||||||
|
javaHome="`dirname \"$javaExecutable\"`"
|
||||||
|
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
|
||||||
|
JAVA_HOME="$javaHome"
|
||||||
|
export JAVA_HOME
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$JAVACMD" ] ; then
|
||||||
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
|
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||||
|
else
|
||||||
|
JAVACMD="$JAVA_HOME/bin/java"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD="`which java`"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
echo "Error: JAVA_HOME is not defined correctly." >&2
|
||||||
|
echo " We cannot execute $JAVACMD" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$JAVA_HOME" ] ; then
|
||||||
|
echo "Warning: JAVA_HOME environment variable is not set."
|
||||||
|
fi
|
||||||
|
|
||||||
|
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
|
||||||
|
|
||||||
|
# traverses directory structure from process work directory to filesystem root
|
||||||
|
# first directory with .mvn subdirectory is considered project base directory
|
||||||
|
find_maven_basedir() {
|
||||||
|
|
||||||
|
if [ -z "$1" ]
|
||||||
|
then
|
||||||
|
echo "Path not specified to find_maven_basedir"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
basedir="$1"
|
||||||
|
wdir="$1"
|
||||||
|
while [ "$wdir" != '/' ] ; do
|
||||||
|
if [ -d "$wdir"/.mvn ] ; then
|
||||||
|
basedir=$wdir
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
|
||||||
|
if [ -d "${wdir}" ]; then
|
||||||
|
wdir=`cd "$wdir/.."; pwd`
|
||||||
|
fi
|
||||||
|
# end of workaround
|
||||||
|
done
|
||||||
|
echo "${basedir}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# concatenates all lines of a file
|
||||||
|
concat_lines() {
|
||||||
|
if [ -f "$1" ]; then
|
||||||
|
echo "$(tr -s '\n' ' ' < "$1")"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
BASE_DIR=`find_maven_basedir "$(pwd)"`
|
||||||
|
if [ -z "$BASE_DIR" ]; then
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
|
||||||
|
if [ "$MVNW_VERBOSE" = true ]; then
|
||||||
|
echo $MAVEN_PROJECTBASEDIR
|
||||||
|
fi
|
||||||
|
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
|
||||||
|
|
||||||
|
# For Cygwin, switch paths to Windows format before running java
|
||||||
|
if $cygwin; then
|
||||||
|
[ -n "$M2_HOME" ] &&
|
||||||
|
M2_HOME=`cygpath --path --windows "$M2_HOME"`
|
||||||
|
[ -n "$JAVA_HOME" ] &&
|
||||||
|
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
|
||||||
|
[ -n "$CLASSPATH" ] &&
|
||||||
|
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
|
||||||
|
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
|
||||||
|
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
|
||||||
|
fi
|
||||||
|
|
||||||
|
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||||
|
|
||||||
|
exec "$JAVACMD" \
|
||||||
|
$MAVEN_OPTS \
|
||||||
|
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
||||||
|
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||||
|
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
145
mvn-wrapper/mvnw.cmd
vendored
Executable file
145
mvn-wrapper/mvnw.cmd
vendored
Executable file
@ -0,0 +1,145 @@
|
|||||||
|
@REM ----------------------------------------------------------------------------
|
||||||
|
@REM Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
@REM or more contributor license agreements. See the NOTICE file
|
||||||
|
@REM distributed with this work for additional information
|
||||||
|
@REM regarding copyright ownership. The ASF licenses this file
|
||||||
|
@REM to you under the Apache License, Version 2.0 (the
|
||||||
|
@REM "License"); you may not use this file except in compliance
|
||||||
|
@REM with the License. You may obtain a copy of the License at
|
||||||
|
@REM
|
||||||
|
@REM http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
@REM
|
||||||
|
@REM Unless required by applicable law or agreed to in writing,
|
||||||
|
@REM software distributed under the License is distributed on an
|
||||||
|
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
@REM KIND, either express or implied. See the License for the
|
||||||
|
@REM specific language governing permissions and limitations
|
||||||
|
@REM under the License.
|
||||||
|
@REM ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@REM ----------------------------------------------------------------------------
|
||||||
|
@REM Maven2 Start Up Batch script
|
||||||
|
@REM
|
||||||
|
@REM Required ENV vars:
|
||||||
|
@REM JAVA_HOME - location of a JDK home dir
|
||||||
|
@REM
|
||||||
|
@REM Optional ENV vars
|
||||||
|
@REM M2_HOME - location of maven2's installed home dir
|
||||||
|
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
|
||||||
|
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
|
||||||
|
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||||
|
@REM e.g. to debug Maven itself, use
|
||||||
|
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||||
|
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
||||||
|
@REM ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
|
||||||
|
@echo off
|
||||||
|
@REM set title of command window
|
||||||
|
title %0
|
||||||
|
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
|
||||||
|
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
|
||||||
|
|
||||||
|
@REM set %HOME% to equivalent of $HOME
|
||||||
|
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
|
||||||
|
|
||||||
|
@REM Execute a user defined script before this one
|
||||||
|
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
|
||||||
|
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
|
||||||
|
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
|
||||||
|
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
|
||||||
|
:skipRcPre
|
||||||
|
|
||||||
|
@setlocal
|
||||||
|
|
||||||
|
set ERROR_CODE=0
|
||||||
|
|
||||||
|
@REM To isolate internal variables from possible post scripts, we use another setlocal
|
||||||
|
@setlocal
|
||||||
|
|
||||||
|
@REM ==== START VALIDATION ====
|
||||||
|
if not "%JAVA_HOME%" == "" goto OkJHome
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo Error: JAVA_HOME not found in your environment. >&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
||||||
|
echo location of your Java installation. >&2
|
||||||
|
echo.
|
||||||
|
goto error
|
||||||
|
|
||||||
|
:OkJHome
|
||||||
|
if exist "%JAVA_HOME%\bin\java.exe" goto init
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo Error: JAVA_HOME is set to an invalid directory. >&2
|
||||||
|
echo JAVA_HOME = "%JAVA_HOME%" >&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
||||||
|
echo location of your Java installation. >&2
|
||||||
|
echo.
|
||||||
|
goto error
|
||||||
|
|
||||||
|
@REM ==== END VALIDATION ====
|
||||||
|
|
||||||
|
:init
|
||||||
|
|
||||||
|
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
|
||||||
|
@REM Fallback to current working directory if not found.
|
||||||
|
|
||||||
|
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
|
||||||
|
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
|
||||||
|
|
||||||
|
set EXEC_DIR=%CD%
|
||||||
|
set WDIR=%EXEC_DIR%
|
||||||
|
:findBaseDir
|
||||||
|
IF EXIST "%WDIR%"\.mvn goto baseDirFound
|
||||||
|
cd ..
|
||||||
|
IF "%WDIR%"=="%CD%" goto baseDirNotFound
|
||||||
|
set WDIR=%CD%
|
||||||
|
goto findBaseDir
|
||||||
|
|
||||||
|
:baseDirFound
|
||||||
|
set MAVEN_PROJECTBASEDIR=%WDIR%
|
||||||
|
cd "%EXEC_DIR%"
|
||||||
|
goto endDetectBaseDir
|
||||||
|
|
||||||
|
:baseDirNotFound
|
||||||
|
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
|
||||||
|
cd "%EXEC_DIR%"
|
||||||
|
|
||||||
|
:endDetectBaseDir
|
||||||
|
|
||||||
|
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
|
||||||
|
|
||||||
|
@setlocal EnableExtensions EnableDelayedExpansion
|
||||||
|
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
|
||||||
|
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
|
||||||
|
|
||||||
|
:endReadAdditionalConfig
|
||||||
|
|
||||||
|
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
|
||||||
|
|
||||||
|
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
|
||||||
|
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||||
|
|
||||||
|
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
|
||||||
|
if ERRORLEVEL 1 goto error
|
||||||
|
goto end
|
||||||
|
|
||||||
|
:error
|
||||||
|
set ERROR_CODE=1
|
||||||
|
|
||||||
|
:end
|
||||||
|
@endlocal & set ERROR_CODE=%ERROR_CODE%
|
||||||
|
|
||||||
|
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
|
||||||
|
@REM check for post script, once with legacy .bat ending and once with .cmd ending
|
||||||
|
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
|
||||||
|
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
|
||||||
|
:skipRcPost
|
||||||
|
|
||||||
|
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
|
||||||
|
if "%MAVEN_BATCH_PAUSE%" == "on" pause
|
||||||
|
|
||||||
|
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
|
||||||
|
|
||||||
|
exit /B %ERROR_CODE%
|
45
mvn-wrapper/pom.xml
Normal file
45
mvn-wrapper/pom.xml
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<artifactId>mvn-wrapper</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>mvn-wrapper</name>
|
||||||
|
<description>Setting up the Maven Wrapper</description>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<artifactId>parent-boot-5</artifactId>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<relativePath>../parent-boot-5</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.baeldung;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class MvnWrapperApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(MvnWrapperApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
@ -1,2 +1,2 @@
|
|||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
- [Guide to CockroachDB in Java](http://www.baeldung.com/)
|
- [Guide to CockroachDB in Java](http://www.baeldung.com/cockroachdb-java)
|
||||||
|
2
pom.xml
2
pom.xml
@ -117,6 +117,7 @@
|
|||||||
<module>testing-modules/mockito-2</module>
|
<module>testing-modules/mockito-2</module>
|
||||||
<module>testing-modules/mocks</module>
|
<module>testing-modules/mocks</module>
|
||||||
<module>mustache</module>
|
<module>mustache</module>
|
||||||
|
<module>mvn-wrapper</module>
|
||||||
<module>noexception</module>
|
<module>noexception</module>
|
||||||
<module>orientdb</module>
|
<module>orientdb</module>
|
||||||
<module>osgi</module>
|
<module>osgi</module>
|
||||||
@ -160,6 +161,7 @@
|
|||||||
<module>spring-cloud</module>
|
<module>spring-cloud</module>
|
||||||
<module>spring-core</module>
|
<module>spring-core</module>
|
||||||
<module>spring-cucumber</module>
|
<module>spring-cucumber</module>
|
||||||
|
<module>spring-ejb</module>
|
||||||
<module>spring-aop</module>
|
<module>spring-aop</module>
|
||||||
<module>persistence-modules/spring-data-cassandra</module>
|
<module>persistence-modules/spring-data-cassandra</module>
|
||||||
<module>spring-data-couchbase-2</module>
|
<module>spring-data-couchbase-2</module>
|
||||||
|
4
spring-boot-actuator/.gitignore
vendored
4
spring-boot-actuator/.gitignore
vendored
@ -1,4 +0,0 @@
|
|||||||
/target/
|
|
||||||
.settings/
|
|
||||||
.classpath
|
|
||||||
.project
|
|
@ -1,122 +0,0 @@
|
|||||||
<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>
|
|
||||||
<version>3.7.0</version>
|
|
||||||
<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>
|
|
@ -1,13 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
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"));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
info.app.name=Sample application
|
|
@ -1,32 +0,0 @@
|
|||||||
package org.baeldung.config;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.test.context.TestPropertySource;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = MainConfig.class)
|
|
||||||
@TestPropertySource(properties = { "security.basic.enabled=false" })
|
|
||||||
public class ActuatorInfoIntegrationTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private TestRestTemplate restTemplate;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenGetInfo_thenAdditionalInfoReturned() throws IOException {
|
|
||||||
final String expectedResponse = new String(Files.readAllBytes(Paths.get("src/test/resources/expectedResponse.json")));
|
|
||||||
final ResponseEntity<String> responseEntity = this.restTemplate.getForEntity("/info", String.class);
|
|
||||||
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
|
|
||||||
assertEquals(expectedResponse, responseEntity.getBody());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
{"app":{"name":"Sample application"},"applicationInfo":{"ActiveUserCount":"10"}}
|
|
@ -20,7 +20,8 @@
|
|||||||
<module>spring-cloud-connectors-heroku</module>
|
<module>spring-cloud-connectors-heroku</module>
|
||||||
<module>spring-cloud-aws</module>
|
<module>spring-cloud-aws</module>
|
||||||
<module>spring-cloud-consul</module>
|
<module>spring-cloud-consul</module>
|
||||||
</modules>
|
<module>spring-cloud-zuul-eureka-integration</module>
|
||||||
|
</modules>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<name>spring-cloud</name>
|
<name>spring-cloud</name>
|
||||||
@ -45,6 +46,7 @@
|
|||||||
<spring-boot-starter-web.version>1.4.2.RELEASE</spring-boot-starter-web.version>
|
<spring-boot-starter-web.version>1.4.2.RELEASE</spring-boot-starter-web.version>
|
||||||
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
||||||
<spring-boot-maven-plugin.version>1.4.2.RELEASE</spring-boot-maven-plugin.version>
|
<spring-boot-maven-plugin.version>1.4.2.RELEASE</spring-boot-maven-plugin.version>
|
||||||
|
<spring-cloud-starter-zuul.version>1.2.3.RELEASE</spring-cloud-starter-zuul.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
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>
|
||||||
|
|
||||||
|
<artifactId>eureka-client</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>Spring Cloud Eureka Client</name>
|
||||||
|
<description>Spring Cloud Eureka Sample Client</description>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung.spring.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-zuul-eureka-integration</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-eureka</artifactId>
|
||||||
|
<version>${spring-cloud-starter-eureka.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
<version>${spring-boot-starter-web.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-parent</artifactId>
|
||||||
|
<version>${spring-cloud-dependencies.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.7.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<spring-cloud-dependencies.version>Brixton.SR7</spring-cloud-dependencies.version>
|
||||||
|
<spring-cloud-starter-eureka.version>1.2.3.RELEASE</spring-cloud-starter-eureka.version>
|
||||||
|
<spring-boot-starter-web.version>1.4.2.RELEASE</spring-boot-starter-web.version>
|
||||||
|
</properties>
|
||||||
|
</project>
|
@ -0,0 +1,13 @@
|
|||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: spring-cloud-eureka-client
|
||||||
|
|
||||||
|
server:
|
||||||
|
port: 0
|
||||||
|
|
||||||
|
eureka:
|
||||||
|
client:
|
||||||
|
serviceUrl:
|
||||||
|
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
|
||||||
|
instance:
|
||||||
|
preferIpAddress: true
|
@ -0,0 +1,68 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
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>
|
||||||
|
|
||||||
|
<artifactId>eureka-server</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>Spring Cloud Eureka Server</name>
|
||||||
|
<description>Spring Cloud Eureka Server Demo</description>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung.spring.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-zuul-eureka-integration</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-eureka-server</artifactId>
|
||||||
|
<version>${spring-cloud-starter-eureka.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-configuration</groupId>
|
||||||
|
<artifactId>commons-configuration</artifactId>
|
||||||
|
<version>${commons-config.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-parent</artifactId>
|
||||||
|
<version>${spring-cloud-dependencies.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.7.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<spring-cloud-dependencies.version>Brixton.SR7</spring-cloud-dependencies.version>
|
||||||
|
<spring-cloud-starter-eureka.version>1.2.3.RELEASE</spring-cloud-starter-eureka.version>
|
||||||
|
</properties>
|
||||||
|
</project>
|
@ -0,0 +1,7 @@
|
|||||||
|
server:
|
||||||
|
port: 8761
|
||||||
|
|
||||||
|
eureka:
|
||||||
|
client:
|
||||||
|
registerWithEureka: false
|
||||||
|
fetchRegistry: false
|
@ -0,0 +1,55 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
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.spring.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-zuul-eureka-integration</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
<name>Spring Cloud Zuul and Eureka Integration</name>
|
||||||
|
<description>Spring Cloud Zuul and Eureka Integration</description>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung.spring.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<relativePath>..</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
||||||
|
<spring-boot-maven-plugin.version>1.4.2.RELEASE</spring-boot-maven-plugin.version>
|
||||||
|
<commons-config.version>1.10</commons-config.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>${spring-boot-maven-plugin.version}</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
</build>
|
||||||
|
<modules>
|
||||||
|
<module>zuul-server</module>
|
||||||
|
<module>eureka-server</module>
|
||||||
|
<module>eureka-client</module>
|
||||||
|
</modules>
|
||||||
|
</project>
|
@ -0,0 +1,61 @@
|
|||||||
|
<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>com.baeldung.spring.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-zuul-eureka-integration</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>zuul-server</artifactId>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-zuul</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-eureka</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-configuration</groupId>
|
||||||
|
<artifactId>commons-configuration</artifactId>
|
||||||
|
<version>${commons-config.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-parent</artifactId>
|
||||||
|
<version>${spring-cloud-dependencies.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.7.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,9 @@
|
|||||||
|
server.port=8762
|
||||||
|
spring.application.name=zuul-server
|
||||||
|
eureka.instance.preferIpAddress=true
|
||||||
|
eureka.client.registerWithEureka=true
|
||||||
|
eureka.client.fetchRegistry=true
|
||||||
|
eureka.serviceurl.defaultzone=http://localhost:8761/eureka/
|
||||||
|
management.security.enabled=false
|
||||||
|
security.basic.enabled=false
|
||||||
|
hystrix.command.default.execution.timeout.enabled=false
|
@ -0,0 +1,68 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
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>
|
||||||
|
|
||||||
|
<artifactId>eureka-client</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>Spring Cloud Eureka Client</name>
|
||||||
|
<description>Spring Cloud Eureka Sample Client</description>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung.spring.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-zuul-eureka-integration</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-eureka</artifactId>
|
||||||
|
<version>${spring-cloud-starter-eureka.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
<version>${spring-boot-starter-web.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-parent</artifactId>
|
||||||
|
<version>${spring-cloud-dependencies.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.7.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<spring-cloud-dependencies.version>Brixton.SR7</spring-cloud-dependencies.version>
|
||||||
|
<spring-cloud-starter-eureka.version>1.2.3.RELEASE</spring-cloud-starter-eureka.version>
|
||||||
|
<spring-boot-starter-web.version>1.4.2.RELEASE</spring-boot-starter-web.version>
|
||||||
|
</properties>
|
||||||
|
</project>
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.baeldung.spring.cloud.eureka.client;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.netflix.discovery.EurekaClient;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableEurekaClient
|
||||||
|
@RestController
|
||||||
|
public class EurekaClientApplication implements GreetingController {
|
||||||
|
@Autowired
|
||||||
|
@Lazy
|
||||||
|
private EurekaClient eurekaClient;
|
||||||
|
|
||||||
|
@Value("${spring.application.name}")
|
||||||
|
private String appName;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(EurekaClientApplication.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String greeting() {
|
||||||
|
return String.format("Hello from '%s'!", eurekaClient.getApplication(appName).getName());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.baeldung.spring.cloud.eureka.client;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
public interface GreetingController {
|
||||||
|
@RequestMapping("/greeting")
|
||||||
|
String greeting();
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: spring-cloud-eureka-client
|
||||||
|
|
||||||
|
server:
|
||||||
|
port: 0
|
||||||
|
|
||||||
|
eureka:
|
||||||
|
client:
|
||||||
|
serviceUrl:
|
||||||
|
defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
|
||||||
|
instance:
|
||||||
|
preferIpAddress: true
|
@ -0,0 +1,68 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
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>
|
||||||
|
|
||||||
|
<artifactId>eureka-server</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>Spring Cloud Eureka Server</name>
|
||||||
|
<description>Spring Cloud Eureka Server Demo</description>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung.spring.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-zuul-eureka-integration</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-eureka-server</artifactId>
|
||||||
|
<version>${spring-cloud-starter-eureka.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-configuration</groupId>
|
||||||
|
<artifactId>commons-configuration</artifactId>
|
||||||
|
<version>${commons-config.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-parent</artifactId>
|
||||||
|
<version>${spring-cloud-dependencies.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.7.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<spring-cloud-dependencies.version>Brixton.SR7</spring-cloud-dependencies.version>
|
||||||
|
<spring-cloud-starter-eureka.version>1.2.3.RELEASE</spring-cloud-starter-eureka.version>
|
||||||
|
</properties>
|
||||||
|
</project>
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.baeldung.spring.cloud.eureka.server;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableEurekaServer
|
||||||
|
public class EurekaServerApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(EurekaServerApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
server:
|
||||||
|
port: 8761
|
||||||
|
|
||||||
|
eureka:
|
||||||
|
client:
|
||||||
|
registerWithEureka: false
|
||||||
|
fetchRegistry: false
|
56
spring-cloud/spring-cloud-zuul-eureka-integration/pom.xml
Normal file
56
spring-cloud/spring-cloud-zuul-eureka-integration/pom.xml
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
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.spring.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-zuul-eureka-integration</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
<name>Spring Cloud Zuul and Eureka Integration</name>
|
||||||
|
<description>Spring Cloud Zuul and Eureka Integration</description>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung.spring.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<relativePath>..</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
||||||
|
<spring-boot-maven-plugin.version>1.4.2.RELEASE</spring-boot-maven-plugin.version>
|
||||||
|
<commons-config.version>1.10</commons-config.version>
|
||||||
|
<rxjava.version>1.2.10</rxjava.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>${spring-boot-maven-plugin.version}</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
</build>
|
||||||
|
<modules>
|
||||||
|
<module>zuul-server</module>
|
||||||
|
<module>eureka-server</module>
|
||||||
|
<module>eureka-client</module>
|
||||||
|
</modules>
|
||||||
|
</project>
|
@ -0,0 +1,66 @@
|
|||||||
|
<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>com.baeldung.spring.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-zuul-eureka-integration</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>zuul-server</artifactId>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-zuul</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-eureka</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-configuration</groupId>
|
||||||
|
<artifactId>commons-configuration</artifactId>
|
||||||
|
<version>${commons-config.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.reactivex</groupId>
|
||||||
|
<artifactId>rxjava</artifactId>
|
||||||
|
<version>${rxjava.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-parent</artifactId>
|
||||||
|
<version>${spring-cloud-dependencies.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.7.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.baeldung.spring.cloud.zuul.config;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableZuulProxy
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
public class ZuulConfig {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(ZuulConfig.class, args);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
server.port=8762
|
||||||
|
spring.application.name=zuul-server
|
||||||
|
eureka.instance.preferIpAddress=true
|
||||||
|
eureka.client.registerWithEureka=true
|
||||||
|
eureka.client.fetchRegistry=true
|
||||||
|
eureka.serviceurl.defaultzone=http://localhost:8761/eureka/
|
||||||
|
management.security.enabled=false
|
||||||
|
security.basic.enabled=false
|
||||||
|
hystrix.command.default.execution.timeout.enabled=false
|
76
spring-ejb/ejb-remote-for-spring/pom.xml
Executable file
76
spring-ejb/ejb-remote-for-spring/pom.xml
Executable file
@ -0,0 +1,76 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<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>com.baeldung.spring.ejb</groupId>
|
||||||
|
<artifactId>ejb-for-spring</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>ejb-remote-for-spring</artifactId>
|
||||||
|
<packaging>ejb</packaging>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax</groupId>
|
||||||
|
<artifactId>javaee-api</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.assertj</groupId>
|
||||||
|
<artifactId>assertj-core</artifactId>
|
||||||
|
<version>3.9.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<!-- mvn clean package cargo:run -Pwildfly-standalone-->
|
||||||
|
<profile>
|
||||||
|
<id>wildfly-standalone</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>false</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.cargo</groupId>
|
||||||
|
<artifactId>cargo-maven2-plugin</artifactId>
|
||||||
|
<version>${cargo-maven2-plugin.version}</version>
|
||||||
|
|
||||||
|
<configuration>
|
||||||
|
|
||||||
|
<container>
|
||||||
|
<containerId>wildfly10x</containerId>
|
||||||
|
<zipUrlInstaller>
|
||||||
|
<url>http://download.jboss.org/wildfly/10.1.0.Final/wildfly-10.1.0.Final.zip</url>
|
||||||
|
</zipUrlInstaller>
|
||||||
|
</container>
|
||||||
|
|
||||||
|
<configuration>
|
||||||
|
<properties>
|
||||||
|
<cargo.hostname>127.0.0.1</cargo.hostname>
|
||||||
|
<cargo.jboss.configuration>standalone-full</cargo.jboss.configuration>
|
||||||
|
<cargo.jboss.management-http.port>9990</cargo.jboss.management-http.port>
|
||||||
|
<cargo.servlet.users>testUser:admin1234!</cargo.servlet.users>
|
||||||
|
</properties>
|
||||||
|
</configuration>
|
||||||
|
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<javaee-api.version>7.0</javaee-api.version>
|
||||||
|
<cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
||||||
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.baeldung.ejb.tutorial;
|
||||||
|
|
||||||
|
import javax.ejb.Remote;
|
||||||
|
|
||||||
|
@Remote
|
||||||
|
public interface HelloStatefulWorld {
|
||||||
|
|
||||||
|
int howManyTimes();
|
||||||
|
String getHelloWorld();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.baeldung.ejb.tutorial;
|
||||||
|
|
||||||
|
import javax.ejb.Stateful;
|
||||||
|
|
||||||
|
@Stateful(name = "HelloStatefulWorld")
|
||||||
|
public class HelloStatefulWorldBean implements HelloStatefulWorld {
|
||||||
|
|
||||||
|
private int howManyTimes = 0;
|
||||||
|
|
||||||
|
public int howManyTimes() {
|
||||||
|
return howManyTimes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHelloWorld() {
|
||||||
|
howManyTimes++;
|
||||||
|
return "Hello Stateful World!";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.baeldung.ejb.tutorial;
|
||||||
|
|
||||||
|
import javax.ejb.Remote;
|
||||||
|
|
||||||
|
@Remote
|
||||||
|
public interface HelloStatelessWorld {
|
||||||
|
|
||||||
|
String getHelloWorld();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.baeldung.ejb.tutorial;
|
||||||
|
|
||||||
|
import javax.ejb.Stateless;
|
||||||
|
|
||||||
|
@Stateless(name = "HelloStatelessWorld")
|
||||||
|
public class HelloStatelessWorldBean implements HelloStatelessWorld {
|
||||||
|
|
||||||
|
public String getHelloWorld() {
|
||||||
|
return "Hello Stateless World!";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
7
spring-ejb/ejb-remote-for-spring/src/main/resources/META-INF/ejb-jar.xml
Executable file
7
spring-ejb/ejb-remote-for-spring/src/main/resources/META-INF/ejb-jar.xml
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ejb-jar xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/ejb-jar_3_2.xsd"
|
||||||
|
version="3.2">
|
||||||
|
<module-name>ejb-remote-for-spring</module-name>
|
||||||
|
</ejb-jar>
|
||||||
|
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.baeldung.ejb.tutorial;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class HelloStatefulWorldTestUnitTest {
|
||||||
|
|
||||||
|
private HelloStatefulWorldBean statefulBean;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
statefulBean = new HelloStatefulWorldBean();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenGetHelloWorld_thenHelloStatefulWorldIsReturned() {
|
||||||
|
String helloWorld = statefulBean.getHelloWorld();
|
||||||
|
|
||||||
|
assertThat(helloWorld).isEqualTo("Hello Stateful World!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenGetHelloWorldIsCalledTwice_thenCounterIs2() {
|
||||||
|
statefulBean.getHelloWorld();
|
||||||
|
statefulBean.getHelloWorld();
|
||||||
|
|
||||||
|
assertThat(statefulBean.howManyTimes()).isEqualTo(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.baeldung.ejb.tutorial;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class HelloStatelessWorldTestUnitTest {
|
||||||
|
|
||||||
|
private HelloStatelessWorldBean statelessBean;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
statelessBean = new HelloStatelessWorldBean();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenGetHelloWorld_thenHelloStatelessWorldIsReturned() {
|
||||||
|
String helloWorld = statelessBean.getHelloWorld();
|
||||||
|
|
||||||
|
assertThat(helloWorld).isEqualTo("Hello Stateless World!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
77
spring-ejb/pom.xml
Executable file
77
spring-ejb/pom.xml
Executable file
@ -0,0 +1,77 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<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.spring.ejb</groupId>
|
||||||
|
<artifactId>ejb-for-spring</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<name>ejb</name>
|
||||||
|
<description>Spring EJB Tutorial</description>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<artifactId>parent-modules</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>jboss-public-repository-group</id>
|
||||||
|
<name>JBoss Public Maven Repository Group</name>
|
||||||
|
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
|
||||||
|
<layout>default</layout>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
<updatePolicy>never</updatePolicy>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
<updatePolicy>never</updatePolicy>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baeldung.spring.ejb</groupId>
|
||||||
|
<artifactId>ejb-remote-for-spring</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
<type>ejb</type>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax</groupId>
|
||||||
|
<artifactId>javaee-api</artifactId>
|
||||||
|
<version>7.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wildfly</groupId>
|
||||||
|
<artifactId>wildfly-ejb-client-bom</artifactId>
|
||||||
|
<version>10.1.0.Final</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-ejb-plugin</artifactId>
|
||||||
|
<version>2.4</version>
|
||||||
|
<configuration>
|
||||||
|
<ejbVersion>3.2</ejbVersion>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
<module>ejb-remote-for-spring</module>
|
||||||
|
<module>spring-ejb-client</module>
|
||||||
|
</modules>
|
||||||
|
</project>
|
100
spring-ejb/spring-ejb-client/pom.xml
Normal file
100
spring-ejb/spring-ejb-client/pom.xml
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<artifactId>spring-ejb-client</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>spring-ejb-client</name>
|
||||||
|
<description>Spring EJB Client</description>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<artifactId>parent-boot-5</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<relativePath>../../parent-boot-5</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wildfly</groupId>
|
||||||
|
<artifactId>wildfly-ejb-client-bom</artifactId>
|
||||||
|
<version>10.1.0.Final</version>
|
||||||
|
<type>pom</type>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baeldung.spring.ejb</groupId>
|
||||||
|
<artifactId>ejb-remote-for-spring</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
<type>ejb</type>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>spring-snapshots</id>
|
||||||
|
<name>Spring Snapshots</name>
|
||||||
|
<url>https://repo.spring.io/snapshot</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>spring-milestones</id>
|
||||||
|
<name>Spring Milestones</name>
|
||||||
|
<url>https://repo.spring.io/milestone</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>spring-snapshots</id>
|
||||||
|
<name>Spring Snapshots</name>
|
||||||
|
<url>https://repo.spring.io/snapshot</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</pluginRepository>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>spring-milestones</id>
|
||||||
|
<name>Spring Milestones</name>
|
||||||
|
<url>https://repo.spring.io/milestone</url>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>false</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,50 @@
|
|||||||
|
package com.baeldung.springejbclient;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import javax.naming.Context;
|
||||||
|
import javax.naming.InitialContext;
|
||||||
|
import javax.naming.NamingException;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
|
import com.baeldung.ejb.tutorial.HelloStatefulWorld;
|
||||||
|
import com.baeldung.ejb.tutorial.HelloStatelessWorld;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class SpringEjbClientApplication {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Context context() throws NamingException {
|
||||||
|
Properties jndiProps = new Properties();
|
||||||
|
jndiProps.put("java.naming.factory.initial", "org.jboss.naming.remote.client.InitialContextFactory");
|
||||||
|
jndiProps.put("jboss.naming.client.ejb.context", true);
|
||||||
|
jndiProps.put("java.naming.provider.url", "http-remoting://localhost:8080");
|
||||||
|
return new InitialContext(jndiProps);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public HelloStatelessWorld helloStatelessWorld(Context context) throws NamingException {
|
||||||
|
return (HelloStatelessWorld) context.lookup(this.getFullName(HelloStatelessWorld.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public HelloStatefulWorld helloStatefulWorld(Context context) throws NamingException {
|
||||||
|
return (HelloStatefulWorld) context.lookup(this.getFullName(HelloStatefulWorld.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
private String getFullName(Class classType) {
|
||||||
|
String moduleName = "ejb-remote-for-spring/";
|
||||||
|
String beanName = classType.getSimpleName();
|
||||||
|
String viewClassName = classType.getName();
|
||||||
|
|
||||||
|
return moduleName + beanName + "!" + viewClassName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(SpringEjbClientApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.baeldung.springejbclient.endpoint;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.baeldung.ejb.tutorial.HelloStatefulWorld;
|
||||||
|
import com.baeldung.ejb.tutorial.HelloStatelessWorld;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class HomeEndpoint {
|
||||||
|
|
||||||
|
private HelloStatelessWorld helloStatelessWorld;
|
||||||
|
private HelloStatefulWorld helloStatefulWorld;
|
||||||
|
|
||||||
|
public HomeEndpoint(HelloStatelessWorld helloStatelessWorld, HelloStatefulWorld helloStatefulWorld) {
|
||||||
|
this.helloStatelessWorld = helloStatelessWorld;
|
||||||
|
this.helloStatefulWorld = helloStatefulWorld;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/stateless")
|
||||||
|
public String getStateless() {
|
||||||
|
return helloStatelessWorld.getHelloWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/stateful")
|
||||||
|
public String getStateful() {
|
||||||
|
return helloStatefulWorld.getHelloWorld() + " called " + helloStatefulWorld.howManyTimes() + " times";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
server.port=8081
|
||||||
|
|
||||||
|
#logging.level.root=DEBUG
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.baeldung.springejbclient;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class SpringEjbClientApplicationIntegrationTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void contextLoads() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
1
spring-mvc-push/.gitignore
vendored
Normal file
1
spring-mvc-push/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/.tern-project
|
91
spring-mvc-push/pom.xml
Normal file
91
spring-mvc-push/pom.xml
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
<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/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<artifactId>spring-mvc-push</artifactId>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<name>spring-mvc-push</name>
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<maven-surefire-plugin.version>2.20</maven-surefire-plugin.version>
|
||||||
|
<maven.compiler.version>3.7.0</maven.compiler.version>
|
||||||
|
<maven-war-plugin.version>3.2.0</maven-war-plugin.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<junit.jupiter.version>5.0.2</junit.jupiter.version>
|
||||||
|
<spring.version>5.0.2.RELEASE</spring.version>
|
||||||
|
<servlet.version>4.0.0</servlet.version>
|
||||||
|
<jstl.version>1.2</jstl.version>
|
||||||
|
<jsp-api.version>2.3.2-b02</jsp-api.version>
|
||||||
|
<junit.jupiter.version>5.0.2</junit.jupiter.version>
|
||||||
|
<junit.platform.version>1.0.2</junit.platform.version>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-webmvc</artifactId>
|
||||||
|
<version>${spring.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
|
<version>${servlet.version}</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>jstl</artifactId>
|
||||||
|
<version>${jstl.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet.jsp</groupId>
|
||||||
|
<artifactId>javax.servlet.jsp-api</artifactId>
|
||||||
|
<version>${jsp-api.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<!--Testing -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-test</artifactId>
|
||||||
|
<version>${spring.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<version>${junit.jupiter.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>${maven.compiler.version}</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
|
<version>${maven-war-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<warName>spring-mvc-push</warName>
|
||||||
|
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||||
|
<outputDirectory>${deploy-path}</outputDirectory>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>${maven-surefire-plugin.version}</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.platform</groupId>
|
||||||
|
<artifactId>junit-platform-surefire-provider</artifactId>
|
||||||
|
<version>${junit.platform.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<finalName>spring-mvc-push</finalName>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,48 @@
|
|||||||
|
package com.baeldung.config;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.ServletRegistration;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.WebApplicationInitializer;
|
||||||
|
import org.springframework.web.context.ContextLoaderListener;
|
||||||
|
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||||
|
import org.springframework.web.servlet.DispatcherServlet;
|
||||||
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableWebMvc
|
||||||
|
@ComponentScan(basePackages = "com.baeldung.controller")
|
||||||
|
public class PushConfiguration implements WebApplicationInitializer, WebMvcConfigurer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStartup(ServletContext container) throws ServletException {
|
||||||
|
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
||||||
|
context.register(PushConfiguration.class);
|
||||||
|
container.addListener(new ContextLoaderListener(context));
|
||||||
|
ServletRegistration.Dynamic dispatcher = container.addServlet("DispatcherServlet", new DispatcherServlet(context));
|
||||||
|
dispatcher.setLoadOnStartup(1);
|
||||||
|
dispatcher.addMapping("/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public InternalResourceViewResolver jspViewResolver() {
|
||||||
|
InternalResourceViewResolver bean = new InternalResourceViewResolver();
|
||||||
|
bean.setPrefix("/WEB-INF/views/");
|
||||||
|
bean.setSuffix(".jsp");
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
|
registry.addResourceHandler("/resources/**")
|
||||||
|
.addResourceLocations("/resources/");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package com.baeldung.controller;
|
||||||
|
|
||||||
|
import javax.servlet.http.PushBuilder;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class PushController {
|
||||||
|
|
||||||
|
@RequestMapping(value = "/demoWithPush")
|
||||||
|
public String demoWithPush(PushBuilder pushBuilder) {
|
||||||
|
if (null != pushBuilder) {
|
||||||
|
pushBuilder.path("resources/logo.png")
|
||||||
|
.addHeader("Content-Type", "image/png")
|
||||||
|
.push();
|
||||||
|
pushBuilder.path("resources/script.js")
|
||||||
|
.addHeader("Content-Type", "text/javascript")
|
||||||
|
.push();
|
||||||
|
pushBuilder.path("resources/style.css")
|
||||||
|
.addHeader("Content-Type", "text/css")
|
||||||
|
.push();
|
||||||
|
}
|
||||||
|
return "demo";
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/demoWithoutPush")
|
||||||
|
public String demoWithoutPush() {
|
||||||
|
return "demo";
|
||||||
|
}
|
||||||
|
}
|
22
spring-mvc-push/src/main/webapp/WEB-INF/views/demo.jsp
Normal file
22
spring-mvc-push/src/main/webapp/WEB-INF/views/demo.jsp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||||
|
pageEncoding="UTF-8"%>
|
||||||
|
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
|
<title>PushBuilder demo</title>
|
||||||
|
<link href="<c:url value="/resources/style.css"/>" rel="stylesheet" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<span class="single-title">PushBuilder demo</span>
|
||||||
|
<br>
|
||||||
|
<img src="<c:url value="/resources/logo.png"/>" alt="Logo" height="126"
|
||||||
|
width="411">
|
||||||
|
<br>
|
||||||
|
<script type="text/javascript"
|
||||||
|
src="<c:url value="/resources/script.js"/>"></script>
|
||||||
|
<br> Go to
|
||||||
|
<a href="/spring-mvc-push/">index</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
14
spring-mvc-push/src/main/webapp/index.jsp
Normal file
14
spring-mvc-push/src/main/webapp/index.jsp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||||
|
pageEncoding="UTF-8"%>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
|
<title>PushBuilder demo</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h4>
|
||||||
|
Go to <a href="demoWithPush">PushBuilder demo</a><br> Go to
|
||||||
|
<a href="demoWithoutPush">Simple demo</a>
|
||||||
|
</h4>
|
||||||
|
</body>
|
||||||
|
</html>
|
BIN
spring-mvc-push/src/main/webapp/resources/logo.png
Normal file
BIN
spring-mvc-push/src/main/webapp/resources/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.2 KiB |
1
spring-mvc-push/src/main/webapp/resources/script.js
Normal file
1
spring-mvc-push/src/main/webapp/resources/script.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
console.log('Script')
|
9
spring-mvc-push/src/main/webapp/resources/style.css
Normal file
9
spring-mvc-push/src/main/webapp/resources/style.css
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
.single-title {
|
||||||
|
font-size: 30px;
|
||||||
|
color: #535353;
|
||||||
|
font-weight: 200;
|
||||||
|
letter-spacing: -1.5px;
|
||||||
|
line-height: 64px;
|
||||||
|
max-width: 750px;
|
||||||
|
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package com.baeldung.controller;
|
||||||
|
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
|
import com.baeldung.config.PushConfiguration;
|
||||||
|
|
||||||
|
@Disabled
|
||||||
|
@SpringJUnitWebConfig(PushConfiguration.class)
|
||||||
|
public class PushControllerIntegrationTest {
|
||||||
|
@Autowired
|
||||||
|
private WebApplicationContext webAppContext;
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setup() {
|
||||||
|
mockMvc = MockMvcBuilders.webAppContextSetup(webAppContext)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenDemoWithPushGETisPerformed_thenRetrievedStatusOk() throws Exception {
|
||||||
|
mockMvc.perform(get("/demoWithPush"))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenDemoWithoutPushGETisPerformed_thenRetrievedStatusOk() throws Exception {
|
||||||
|
mockMvc.perform(get("/demoWithoutPush"))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user