diff --git a/core-java/src/main/java/com/baeldung/networking/proxies/CommandLineProxyDemo.java b/core-java/src/main/java/com/baeldung/networking/proxies/CommandLineProxyDemo.java
new file mode 100644
index 0000000000..bbc8a81c98
--- /dev/null
+++ b/core-java/src/main/java/com/baeldung/networking/proxies/CommandLineProxyDemo.java
@@ -0,0 +1,17 @@
+package com.baeldung.networking.proxies;
+
+import java.net.URL;
+import java.net.URLConnection;
+
+public class CommandLineProxyDemo {
+
+ public static final String RESOURCE_URL = "http://www.google.com";
+
+ public static void main(String[] args) throws Exception {
+
+ URL url = new URL(RESOURCE_URL);
+ URLConnection con = url.openConnection();
+ System.out.println(UrlConnectionUtils.contentAsString(con));
+ }
+
+}
\ No newline at end of file
diff --git a/core-java/src/main/java/com/baeldung/networking/proxies/DirectProxyDemo.java b/core-java/src/main/java/com/baeldung/networking/proxies/DirectProxyDemo.java
new file mode 100644
index 0000000000..07a7880886
--- /dev/null
+++ b/core-java/src/main/java/com/baeldung/networking/proxies/DirectProxyDemo.java
@@ -0,0 +1,20 @@
+package com.baeldung.networking.proxies;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.Proxy;
+import java.net.URL;
+
+public class DirectProxyDemo {
+
+ private static final String URL_STRING = "http://www.google.com";
+
+ public static void main(String... args) throws IOException {
+
+ URL weburl = new URL(URL_STRING);
+ HttpURLConnection directConnection
+ = (HttpURLConnection) weburl.openConnection(Proxy.NO_PROXY);
+ System.out.println(UrlConnectionUtils.contentAsString(directConnection));
+ }
+
+}
diff --git a/core-java/src/main/java/com/baeldung/networking/proxies/SocksProxyDemo.java b/core-java/src/main/java/com/baeldung/networking/proxies/SocksProxyDemo.java
new file mode 100644
index 0000000000..e7ac3c0264
--- /dev/null
+++ b/core-java/src/main/java/com/baeldung/networking/proxies/SocksProxyDemo.java
@@ -0,0 +1,32 @@
+package com.baeldung.networking.proxies;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.Socket;
+import java.net.URL;
+
+public class SocksProxyDemo {
+
+ private static final String URL_STRING = "http://www.google.com";
+ private static final String SOCKET_SERVER_HOST = "someserver.baeldung.com";
+ private static final int SOCKET_SERVER_PORT = 1111;
+
+ public static void main(String... args) throws IOException {
+
+ URL weburl = new URL(URL_STRING);
+ Proxy socksProxy
+ = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 1080));
+ HttpURLConnection socksConnection
+ = (HttpURLConnection) weburl.openConnection(socksProxy);
+ System.out.println(UrlConnectionUtils.contentAsString(socksConnection));
+
+ Socket proxySocket = new Socket(socksProxy);
+ InetSocketAddress socketHost
+ = new InetSocketAddress(SOCKET_SERVER_HOST, SOCKET_SERVER_PORT);
+ proxySocket.connect(socketHost);
+ // do stuff with the socket
+ }
+
+}
diff --git a/core-java/src/main/java/com/baeldung/networking/proxies/SystemPropertyProxyDemo.java b/core-java/src/main/java/com/baeldung/networking/proxies/SystemPropertyProxyDemo.java
new file mode 100644
index 0000000000..1f589eac58
--- /dev/null
+++ b/core-java/src/main/java/com/baeldung/networking/proxies/SystemPropertyProxyDemo.java
@@ -0,0 +1,23 @@
+package com.baeldung.networking.proxies;
+
+import java.net.URL;
+import java.net.URLConnection;
+
+public class SystemPropertyProxyDemo {
+
+ public static final String RESOURCE_URL = "http://www.google.com";
+
+ public static void main(String[] args) throws Exception {
+
+ System.setProperty("http.proxyHost", "127.0.0.1");
+ System.setProperty("http.proxyPort", "3128");
+
+ URL url = new URL(RESOURCE_URL);
+ URLConnection con = url.openConnection();
+ System.out.println(UrlConnectionUtils.contentAsString(con));
+
+ System.setProperty("http.proxyHost", null);
+ // proxy will no longer be used for http connections
+ }
+
+}
diff --git a/core-java/src/main/java/com/baeldung/networking/proxies/UrlConnectionUtils.java b/core-java/src/main/java/com/baeldung/networking/proxies/UrlConnectionUtils.java
new file mode 100644
index 0000000000..aa12824a90
--- /dev/null
+++ b/core-java/src/main/java/com/baeldung/networking/proxies/UrlConnectionUtils.java
@@ -0,0 +1,21 @@
+package com.baeldung.networking.proxies;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URLConnection;
+
+class UrlConnectionUtils {
+
+ public static String contentAsString(URLConnection con) throws IOException {
+ StringBuilder builder = new StringBuilder();
+ try (BufferedReader reader
+ = new BufferedReader(new InputStreamReader(con.getInputStream()))){
+ while (reader.ready()) {
+ builder.append(reader.readLine());
+ }
+ }
+ return builder.toString();
+ }
+
+}
diff --git a/core-java/src/main/java/com/baeldung/networking/proxies/WebProxyDemo.java b/core-java/src/main/java/com/baeldung/networking/proxies/WebProxyDemo.java
new file mode 100644
index 0000000000..41caaf3439
--- /dev/null
+++ b/core-java/src/main/java/com/baeldung/networking/proxies/WebProxyDemo.java
@@ -0,0 +1,23 @@
+package com.baeldung.networking.proxies;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.URL;
+
+public class WebProxyDemo {
+
+ private static final String URL_STRING = "http://www.google.com";
+
+ public static void main(String... args) throws IOException {
+
+ URL weburl = new URL(URL_STRING);
+ Proxy webProxy
+ = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 3128));
+ HttpURLConnection webProxyConnection
+ = (HttpURLConnection) weburl.openConnection(webProxy);
+ System.out.println(UrlConnectionUtils.contentAsString(webProxyConnection));
+ }
+
+}
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/random/RandomStringUnitTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/random/RandomStringUnitTest.kt
index 74085367e8..62e8dfe720 100644
--- a/core-kotlin/src/test/kotlin/com/baeldung/random/RandomStringUnitTest.kt
+++ b/core-kotlin/src/test/kotlin/com/baeldung/random/RandomStringUnitTest.kt
@@ -52,7 +52,7 @@ class RandomStringUnitTest {
random.nextBytes(bytes)
var randomString = (0..bytes.size - 1).map { i ->
- charPool.get((bytes[i] and 0xFF.toByte() and charPool.size.toByte()).toInt())
+ charPool.get((bytes[i] and 0xFF.toByte() and (charPool.size-1).toByte()).toInt())
}.joinToString("")
assert(randomString.matches(Regex(ALPHANUMERIC_REGEX)))
diff --git a/core-java/src/main/java/com/baeldung/string/AddingNewLineToString.java b/java-strings/src/main/java/com/baeldung/string/AddingNewLineToString.java
similarity index 100%
rename from core-java/src/main/java/com/baeldung/string/AddingNewLineToString.java
rename to java-strings/src/main/java/com/baeldung/string/AddingNewLineToString.java
diff --git a/spring-boot/.attach_pid12812 b/spring-boot/.attach_pid12812
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml
index ac9873a770..87c782b044 100644
--- a/spring-boot/pom.xml
+++ b/spring-boot/pom.xml
@@ -1,4 +1,5 @@
-
4.0.0
spring-boot
@@ -55,6 +56,14 @@
org.springframework.boot
spring-boot-starter-data-jpa
+
+ org.ehcache
+ ehcache
+
+
+ org.hibernate
+ hibernate-ehcache
+
org.springframework.boot
spring-boot-starter-actuator
@@ -148,10 +157,10 @@
chaos-monkey-spring-boot
${chaos.monkey.version}
-
+
- javax.validation
- validation-api
+ javax.validation
+ validation-api
@@ -175,6 +184,26 @@
pl.project13.maven
git-commit-id-plugin
${git-commit-id-plugin.version}
+
+
+ get-the-git-infos
+
+ revision
+
+ initialize
+
+
+ validate-the-git-infos
+
+ validateRevision
+
+ package
+
+
+
+ true
+ ${project.build.outputDirectory}/git.properties
+
@@ -229,7 +258,7 @@
5.0.2
5.2.4
18.0
- 2.2.4
+ 2.2.4
diff --git a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java
index e079b9a665..cc05fd4fbd 100644
--- a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java
+++ b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java
@@ -30,7 +30,7 @@ public class ContactInfoValidator implements ConstraintValidator {
- Optional findOne(String id);
+ Optional findById(String id);
}
diff --git a/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java b/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java
index 3489732b6f..7bd5c36786 100644
--- a/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java
+++ b/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java
@@ -9,7 +9,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
public class FailureAnalyzerApplication {
@RolesAllowed("*")
public static void main(String[] args) {
- System.setProperty("security.basic.enabled", "false");
SpringApplication.run(FailureAnalyzerApplication.class, args);
}
}
diff --git a/spring-boot/src/main/java/com/baeldung/internationalization/InternationalizationApp.java b/spring-boot/src/main/java/com/baeldung/internationalization/InternationalizationApp.java
index c92d1c32e6..c3af611f3b 100644
--- a/spring-boot/src/main/java/com/baeldung/internationalization/InternationalizationApp.java
+++ b/spring-boot/src/main/java/com/baeldung/internationalization/InternationalizationApp.java
@@ -9,7 +9,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
public class InternationalizationApp {
@RolesAllowed("*")
public static void main(String[] args) {
- System.setProperty("security.basic.enabled", "false");
SpringApplication.run(InternationalizationApp.class, args);
}
}
diff --git a/spring-boot/src/main/java/com/baeldung/rss/RssApp.java b/spring-boot/src/main/java/com/baeldung/rss/RssApp.java
index d3d3d0241f..e067d3cfd1 100644
--- a/spring-boot/src/main/java/com/baeldung/rss/RssApp.java
+++ b/spring-boot/src/main/java/com/baeldung/rss/RssApp.java
@@ -1,18 +1,17 @@
package com.baeldung.rss;
+import javax.annotation.security.RolesAllowed;
+
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
-import javax.annotation.security.RolesAllowed;
-
@SpringBootApplication
@ComponentScan(basePackages = "com.baeldung.rss")
public class RssApp {
@RolesAllowed("*")
public static void main(String[] args) {
- System.setProperty("security.basic.enabled", "false");
SpringApplication.run(RssApp.class, args);
}
diff --git a/spring-boot/src/main/java/com/baeldung/toggle/ToggleApplication.java b/spring-boot/src/main/java/com/baeldung/toggle/ToggleApplication.java
index 27be6b7cca..fa84cf0d9b 100644
--- a/spring-boot/src/main/java/com/baeldung/toggle/ToggleApplication.java
+++ b/spring-boot/src/main/java/com/baeldung/toggle/ToggleApplication.java
@@ -9,7 +9,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
public class ToggleApplication {
@RolesAllowed("*")
public static void main(String[] args) {
- System.setProperty("security.basic.enabled", "false");
SpringApplication.run(ToggleApplication.class, args);
}
}
diff --git a/spring-boot/src/main/java/org/baeldung/session/exception/Application.java b/spring-boot/src/main/java/org/baeldung/session/exception/Application.java
index 9132e710d1..354c64c258 100644
--- a/spring-boot/src/main/java/org/baeldung/session/exception/Application.java
+++ b/spring-boot/src/main/java/org/baeldung/session/exception/Application.java
@@ -4,8 +4,6 @@ import org.baeldung.demo.model.Foo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
-import org.springframework.context.annotation.Bean;
-import org.springframework.orm.jpa.vendor.HibernateJpaSessionFactoryBean;
@EntityScan(basePackageClasses = Foo.class)
@SpringBootApplication
@@ -15,9 +13,4 @@ public class Application {
System.setProperty("spring.profiles.active", "exception");
SpringApplication.run(Application.class, args);
}
-
- @Bean
- public HibernateJpaSessionFactoryBean sessionFactory() {
- return new HibernateJpaSessionFactoryBean();
- }
}
diff --git a/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepositoryImpl.java b/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepositoryImpl.java
index 52407a2117..607bae83ba 100644
--- a/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepositoryImpl.java
+++ b/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepositoryImpl.java
@@ -1,5 +1,7 @@
package org.baeldung.session.exception.repository;
+import javax.persistence.EntityManagerFactory;
+
import org.baeldung.demo.model.Foo;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -10,16 +12,15 @@ import org.springframework.stereotype.Repository;
@Repository
public class FooRepositoryImpl implements FooRepository {
@Autowired
- private SessionFactory sessionFactory;
+ private EntityManagerFactory emf;
@Override
public void save(Foo foo) {
- sessionFactory.getCurrentSession().saveOrUpdate(foo);
+ emf.unwrap(SessionFactory.class).getCurrentSession().saveOrUpdate(foo);
}
@Override
public Foo get(Integer id) {
- return sessionFactory.getCurrentSession().get(Foo.class, id);
+ return emf.unwrap(SessionFactory.class).getCurrentSession().get(Foo.class, id);
}
-
}
\ No newline at end of file
diff --git a/spring-boot/src/main/resources/application.properties b/spring-boot/src/main/resources/application.properties
index 629e880940..6a52dd1f70 100644
--- a/spring-boot/src/main/resources/application.properties
+++ b/spring-boot/src/main/resources/application.properties
@@ -7,7 +7,7 @@ spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto = update
management.endpoints.jmx.domain=Spring Sample Application
-management.endpoints.jmx.uniqueNames=true
+spring.jmx.unique-names=true
management.endpoints.web.exposure.include=*
management.endpoint.shutdown.enabled=true
@@ -17,7 +17,6 @@ management.endpoint.shutdown.enabled=true
##endpoints.jolokia.path=jolokia
spring.jmx.enabled=true
-management.endpoints.jmx.enabled=true
## for pretty printing of json when endpoints accessed over HTTP
http.mappers.jsonPrettyPrint=true
diff --git a/spring-boot/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithServletComponentIntegrationTest.java b/spring-boot/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithServletComponentIntegrationTest.java
index 2c3ac2e159..8c85934fac 100644
--- a/spring-boot/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithServletComponentIntegrationTest.java
+++ b/spring-boot/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithServletComponentIntegrationTest.java
@@ -20,7 +20,6 @@ import static org.junit.Assert.assertTrue;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SpringBootAnnotatedApp.class)
-@TestPropertySource(properties = { "security.basic.enabled=false" })
public class SpringBootWithServletComponentIntegrationTest {
@Autowired
diff --git a/spring-boot/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithoutServletComponentIntegrationTest.java b/spring-boot/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithoutServletComponentIntegrationTest.java
index a30d3ed3f2..c29cd75e9d 100644
--- a/spring-boot/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithoutServletComponentIntegrationTest.java
+++ b/spring-boot/src/test/java/com/baeldung/annotation/servletcomponentscan/SpringBootWithoutServletComponentIntegrationTest.java
@@ -19,7 +19,6 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SpringBootPlainApp.class)
-@TestPropertySource(properties = { "security.basic.enabled=false" })
public class SpringBootWithoutServletComponentIntegrationTest {
@Autowired
diff --git a/spring-boot/src/test/java/com/baeldung/displayallbeans/DisplayBeanIntegrationTest.java b/spring-boot/src/test/java/com/baeldung/displayallbeans/DisplayBeanIntegrationTest.java
index aab4836b6f..e933920a96 100644
--- a/spring-boot/src/test/java/com/baeldung/displayallbeans/DisplayBeanIntegrationTest.java
+++ b/spring-boot/src/test/java/com/baeldung/displayallbeans/DisplayBeanIntegrationTest.java
@@ -1,31 +1,34 @@
package com.baeldung.displayallbeans;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.BDDAssertions.then;
+
+import java.net.URI;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.actuate.beans.BeansEndpoint.ContextBeans;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.context.WebApplicationContext;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-import static org.assertj.core.api.BDDAssertions.then;
-import static org.hamcrest.CoreMatchers.hasItem;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
-@TestPropertySource(properties = { "management.port=0", "endpoints.beans.id=springbeans", "endpoints.beans.sensitive=false" })
+@TestPropertySource(properties = { "management.port=0", "management.endpoints.web.exposure.include=*" })
public class DisplayBeanIntegrationTest {
@LocalServerPort
@@ -40,6 +43,8 @@ public class DisplayBeanIntegrationTest {
@Autowired
private WebApplicationContext context;
+ private static final String ACTUATOR_PATH = "/actuator";
+
@Test
public void givenRestTemplate_whenAccessServerUrl_thenHttpStatusOK() throws Exception {
ResponseEntity entity = this.testRestTemplate.getForEntity("http://localhost:" + this.port + "/displayallbeans", String.class);
@@ -49,22 +54,27 @@ public class DisplayBeanIntegrationTest {
@Test
public void givenRestTemplate_whenAccessEndpointUrl_thenHttpStatusOK() throws Exception {
- @SuppressWarnings("rawtypes")
- ResponseEntity entity = this.testRestTemplate.getForEntity("http://localhost:" + this.mgt + "/springbeans", List.class);
+ ParameterizedTypeReference