diff --git a/deeplearning4j/pom.xml b/deeplearning4j/pom.xml index c63e67d573..01bac93214 100644 --- a/deeplearning4j/pom.xml +++ b/deeplearning4j/pom.xml @@ -57,11 +57,20 @@ httpclient ${httpclient.version} + + + org.projectlombok + lombok + ${lombok.version} + provided + + 0.9.1 4.3.5 + 1.18.20 \ No newline at end of file diff --git a/geotools/pom.xml b/geotools/pom.xml index 05cae922a4..6edb344c8c 100644 --- a/geotools/pom.xml +++ b/geotools/pom.xml @@ -39,12 +39,19 @@ gt-swing ${geotools-swing.version} + + org.locationtech.jts + jts-core + 1.19.0 + + + - 15.2 - 15.2 - 15.2 + 28.1 + 28.1 + 28.1 \ No newline at end of file diff --git a/geotools/src/main/java/com/baeldung/geotools/ShapeFile.java b/geotools/src/main/java/com/baeldung/geotools/ShapeFile.java index de789918cd..64650fb486 100644 --- a/geotools/src/main/java/com/baeldung/geotools/ShapeFile.java +++ b/geotools/src/main/java/com/baeldung/geotools/ShapeFile.java @@ -1,8 +1,8 @@ package com.baeldung.geotools; -import com.vividsolutions.jts.geom.Coordinate; -import com.vividsolutions.jts.geom.GeometryFactory; -import com.vividsolutions.jts.geom.Point; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.GeometryFactory; +import org.locationtech.jts.geom.Point; import org.geotools.data.DataUtilities; import org.geotools.data.DefaultTransaction; import org.geotools.data.Transaction; @@ -35,7 +35,7 @@ public class ShapeFile { DefaultFeatureCollection collection = new DefaultFeatureCollection(); - GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null); + GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null); SimpleFeatureType TYPE = DataUtilities.createType("Location", "location:Point:srid=4326," + "name:String"); diff --git a/pom.xml b/pom.xml index 15db6e4cd1..db857f8533 100644 --- a/pom.xml +++ b/pom.xml @@ -341,16 +341,9 @@ core-java-modules couchbase custom-pmd - data-structures - deeplearning4j + drools - - - - - geotools - gradle-modules/gradle/maven-to-gradle @@ -469,7 +462,6 @@ server-modules spf4j spring-4 - spring-reactive-modules spring-aop spring-aop-2 spring-batch @@ -617,16 +609,8 @@ core-java-modules couchbase custom-pmd - data-structures - deeplearning4j drools - - - - - geotools - gradle-modules/gradle/maven-to-gradle @@ -737,7 +721,6 @@ server-modules spf4j spring-4 - spring-reactive-modules spring-aop spring-aop-2 spring-batch @@ -938,7 +921,9 @@ core-java-modules/core-java-strings core-java-modules/core-java-httpclient spring-core-6 + data-structures ddd-contexts + deeplearning4j docker-modules apache-httpclient-2 kubernetes-modules/kubernetes-spring @@ -957,11 +942,13 @@ spring-boot-modules/spring-boot-3-native spring-boot-modules/spring-boot-3-observation spring-boot-modules/spring-boot-3-test-pitfalls + spring-reactive-modules spring-swagger-codegen/custom-validations-opeanpi-codegen testing-modules/testing-assertions persistence-modules/fauna lightrun tablesaw + geotools @@ -1144,7 +1131,9 @@ core-java-modules/core-java-strings core-java-modules/core-java-httpclient spring-core-6 + data-structures ddd-contexts + deeplearning4j docker-modules apache-httpclient-2 kubernetes-modules/kubernetes-spring @@ -1163,11 +1152,13 @@ spring-boot-modules/spring-boot-3-native spring-boot-modules/spring-boot-3-observation spring-boot-modules/spring-boot-3-test-pitfalls + spring-reactive-modules spring-swagger-codegen/custom-validations-opeanpi-codegen testing-modules/testing-assertions persistence-modules/fauna lightrun tablesaw + geotools diff --git a/spring-web-modules/spring-resttemplate-3/README.md b/spring-web-modules/spring-resttemplate-3/README.md index 52eba522a5..3add0073b2 100644 --- a/spring-web-modules/spring-resttemplate-3/README.md +++ b/spring-web-modules/spring-resttemplate-3/README.md @@ -11,3 +11,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Download a Large File Through a Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-download-large-file) - [Access HTTPS REST Service Using Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-secure-https-service) - [Encoding of URI Variables on RestTemplate](https://www.baeldung.com/spring-resttemplate-uri-variables-encode) +- [Difference Between exchange(), postForEntity() and execute() in RestTemplate](https://www.baeldung.com/difference-between-exchange-postForEntity-and-execute) diff --git a/spring-web-modules/spring-resttemplate-3/pom.xml b/spring-web-modules/spring-resttemplate-3/pom.xml index b036a5ffcb..5ce7d348a2 100644 --- a/spring-web-modules/spring-resttemplate-3/pom.xml +++ b/spring-web-modules/spring-resttemplate-3/pom.xml @@ -26,4 +26,4 @@ - \ No newline at end of file + diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/methods/RestTemplateMethodsApplication.java b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/methods/RestTemplateMethodsApplication.java new file mode 100644 index 0000000000..72201aa5c9 --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/methods/RestTemplateMethodsApplication.java @@ -0,0 +1,102 @@ +package com.baeldung.resttemplate.methods; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.ClientHttpRequest; +import org.springframework.http.client.ClientHttpResponse; +import org.springframework.web.client.RequestCallback; +import org.springframework.web.client.ResponseExtractor; +import org.springframework.web.client.RestTemplate; + +import java.io.IOException; + +/** + * Examples of making the same call with RestTemplate + * using postForEntity(), exchange(), and execute(). + */ +@SpringBootApplication +public class RestTemplateMethodsApplication { + private final static RestTemplate restTemplate = new RestTemplate(); + + public static void main(String[] args) { + + } + + private static void postForEntity() { + Book book = new Book( + "Cruising Along with Java", + "Venkat Subramaniam", + 2023); + + ResponseEntity response = restTemplate.postForEntity( + "https://api.bookstore.com", + book, + Book.class); + } + + private static void exchange() { + Book book = new Book( + "Effective Java", + "Joshua Bloch", + 2001); + + HttpHeaders headers = new HttpHeaders(); + headers.setBasicAuth("username", "password"); + + ResponseEntity response = restTemplate.exchange( + "https://api.bookstore.com", + HttpMethod.POST, + new HttpEntity<>(book, headers), + Book.class); + } + + private static void execute() { + ResponseEntity response = restTemplate.execute( + "https://api.bookstore.com", + HttpMethod.POST, + new RequestCallback() { + @Override + public void doWithRequest(ClientHttpRequest request) throws IOException { + // Create or decorate the request object as needed + } + }, + new ResponseExtractor>() { + @Override + public ResponseEntity extractData(ClientHttpResponse response) throws IOException { + // extract required data from response + return null; + } + } + ); + + // Could also use some factory methods in RestTemplate for + // the request callback and/or response extractor + + Book book = new Book( + "Reactive Spring", + "Josh Long", + 2020); + + response = restTemplate.execute( + "https://api.bookstore.com", + HttpMethod.POST, + restTemplate.httpEntityCallback(book), + restTemplate.responseEntityExtractor(Book.class) + ); + } + + private static class Book { + String title; + String author; + int yearPublished; + + public Book(String title, String author, int yearPublished) { + this.title = title; + this.author = author; + this.yearPublished = yearPublished; + } + } +} diff --git a/spring-web-modules/spring-resttemplate-3/src/test/java/com/baeldung/resttemplate/methods/RestTemplateMethodsUnitTest.java b/spring-web-modules/spring-resttemplate-3/src/test/java/com/baeldung/resttemplate/methods/RestTemplateMethodsUnitTest.java new file mode 100644 index 0000000000..c7a2880f9d --- /dev/null +++ b/spring-web-modules/spring-resttemplate-3/src/test/java/com/baeldung/resttemplate/methods/RestTemplateMethodsUnitTest.java @@ -0,0 +1,86 @@ +package com.baeldung.resttemplate.methods; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.http.*; +import org.springframework.test.web.client.MockRestServiceServer; +import org.springframework.test.web.client.response.MockRestResponseCreators; +import org.springframework.web.client.RestTemplate; + +import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; + +/** + * Unit tests for different ways to send POST with RestTemplate. + */ +public class RestTemplateMethodsUnitTest +{ + + private final RestTemplate restTemplate = new RestTemplate(); + + private final String URL = "https://localhost:8080"; + + private MockRestServiceServer mockServer; + + @BeforeEach + public void setup() { + mockServer = MockRestServiceServer.createServer(restTemplate); + } + + /** + * Test that postForEntity sends a POST to the desired URL. + */ + @Test + public void testPostForEntity() { + + mockServer.expect(requestTo(URL)) + .andExpect(method(HttpMethod.POST)) + .andRespond(MockRestResponseCreators.withStatus(HttpStatus.OK) + .contentType(MediaType.TEXT_PLAIN) + .body("Ok")); + + restTemplate.postForEntity( + URL, + "Test Body", + String.class); + + mockServer.verify(); + } + + /** + * Test that exchange with POST method sends a POST to the desired URL. + */ + @Test + public void testPostExchange() { + mockServer.expect(requestTo(URL)) + .andExpect(method(HttpMethod.POST)) + .andRespond(MockRestResponseCreators.withStatus(HttpStatus.OK) + .contentType(MediaType.TEXT_PLAIN) + .body("Ok")); + + restTemplate.exchange( + URL, + HttpMethod.POST, + new HttpEntity<>("Test Body"), + String.class); + + mockServer.verify(); + } + + @Test + public void testPostExecute() { + mockServer.expect(requestTo(URL)) + .andExpect(method(HttpMethod.POST)) + .andRespond(MockRestResponseCreators.withStatus(HttpStatus.OK) + .contentType(MediaType.TEXT_PLAIN) + .body("Ok")); + + restTemplate.execute( + URL, + HttpMethod.POST, + restTemplate.httpEntityCallback("Test body"), + restTemplate.responseEntityExtractor(String.class)); + + mockServer.verify(); + } +}