Merge pull request #8038 from sjmillington/rest-move-1
[BAEL-18364] move spring-rest-*** articles - 1
This commit is contained in:
commit
6a6b58a280
|
@ -12,8 +12,6 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com
|
|||
- [Integration Testing with the Maven Cargo plugin](https://www.baeldung.com/integration-testing-with-the-maven-cargo-plugin)
|
||||
- [Project Configuration with Spring](https://www.baeldung.com/project-configuration-with-spring)
|
||||
- [Metrics for your Spring REST API](https://www.baeldung.com/spring-rest-api-metrics)
|
||||
- [Spring Security Expressions - hasRole Example](https://www.baeldung.com/spring-security-expressions-basic)
|
||||
|
||||
|
||||
### Build the Project
|
||||
```
|
||||
|
|
|
@ -10,16 +10,11 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
|||
- [Returning Custom Status Codes from Spring Controllers](https://www.baeldung.com/spring-mvc-controller-custom-http-status-code)
|
||||
- [Binary Data Formats in a Spring REST API](https://www.baeldung.com/spring-rest-api-with-binary-data-formats)
|
||||
- [Guide to UriComponentsBuilder in Spring](https://www.baeldung.com/spring-uricomponentsbuilder)
|
||||
- [Introduction to FindBugs](https://www.baeldung.com/intro-to-findbugs)
|
||||
- [A Custom Media Type for a Spring REST API](https://www.baeldung.com/spring-rest-custom-media-type)
|
||||
- [HTTP PUT vs HTTP PATCH in a REST API](https://www.baeldung.com/http-put-patch-difference-spring)
|
||||
- [Spring – Log Incoming Requests](https://www.baeldung.com/spring-http-logging)
|
||||
- [Introduction to CheckStyle](https://www.baeldung.com/checkstyle-java)
|
||||
- [How to Change the Default Port in Spring Boot](https://www.baeldung.com/spring-boot-change-port)
|
||||
- [Guide to DeferredResult in Spring](https://www.baeldung.com/spring-deferred-result)
|
||||
- [Spring Custom Property Editor](https://www.baeldung.com/spring-mvc-custom-property-editor)
|
||||
- [Using the Spring RestTemplate Interceptor](https://www.baeldung.com/spring-rest-template-interceptor)
|
||||
- [Get and Post Lists of Objects with RestTemplate](https://www.baeldung.com/spring-rest-template-list)
|
||||
- [How to Set a Header on a Response with Spring 5](https://www.baeldung.com/spring-response-header)
|
||||
- [Uploading MultipartFile with Spring RestTemplate](https://www.baeldung.com/spring-rest-template-multipart-upload)
|
||||
- [Download an Image or a File with Spring MVC](https://www.baeldung.com/spring-controller-return-image-file)
|
||||
|
|
|
@ -20,10 +20,7 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
|
@ -141,11 +138,7 @@
|
|||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>au.com.dius</groupId>
|
||||
<artifactId>pact-jvm-provider-junit_2.11</artifactId>
|
||||
<version>${pact.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
|
@ -176,21 +169,7 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>${checkstyle-maven-plugin.version}</version>
|
||||
<configuration>
|
||||
<configLocation>checkstyle.xml</configLocation>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
@ -250,18 +229,7 @@
|
|||
|
||||
</profiles>
|
||||
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>${checkstyle-maven-plugin.version}</version>
|
||||
<configuration>
|
||||
<configLocation>checkstyle.xml</configLocation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
|
||||
|
||||
<properties>
|
||||
<commons-fileupload.version>1.3.2</commons-fileupload.version>
|
||||
|
@ -275,7 +243,7 @@
|
|||
<!-- Maven plugins -->
|
||||
<cargo-maven2-plugin.version>1.6.0</cargo-maven2-plugin.version>
|
||||
<findbugs-maven-plugin.version>3.0.4</findbugs-maven-plugin.version>
|
||||
<checkstyle-maven-plugin.version>3.0.0</checkstyle-maven-plugin.version>
|
||||
|
||||
<dependency.locations.enabled>false</dependency.locations.enabled>
|
||||
|
||||
<json.path.version>2.2.0</json.path.version>
|
||||
|
|
|
@ -13,4 +13,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
|||
- [Mocking a RestTemplate in Spring](https://www.baeldung.com/spring-mock-rest-template)
|
||||
- [RestTemplate Post Request with JSON](https://www.baeldung.com/spring-resttemplate-post-json)
|
||||
- [Download a Large File Through a Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-download-large-file)
|
||||
- [Using the Spring RestTemplate Interceptor](https://www.baeldung.com/spring-rest-template-interceptor)
|
||||
- [Uploading MultipartFile with Spring RestTemplate](https://www.baeldung.com/spring-rest-template-multipart-upload)
|
||||
- [Get and Post Lists of Objects with RestTemplate](https://www.baeldung.com/spring-rest-template-list)
|
||||
- [Copy of RestTemplate Post Request with JSON](https://www.baeldung.com/spring-resttemplate-post-json-test)
|
||||
|
|
|
@ -21,6 +21,10 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
|
@ -32,7 +36,13 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>au.com.dius</groupId>
|
||||
<artifactId>pact-jvm-provider-junit_2.11</artifactId>
|
||||
<version>${pact.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring -->
|
||||
|
@ -111,11 +121,13 @@
|
|||
|
||||
<!-- test scoped -->
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/junit/junit -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
<version>4.12</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
|
@ -295,6 +307,7 @@
|
|||
|
||||
<!-- okhttp -->
|
||||
<com.squareup.okhttp3.version>3.4.1</com.squareup.okhttp3.version>
|
||||
<pact.version>3.5.11</pact.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -15,3 +15,4 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com
|
|||
- [Servlet 3 Async Support with Spring MVC and Spring Security](https://www.baeldung.com/spring-mvc-async-security)
|
||||
- [Intro to Spring Security Expressions](https://www.baeldung.com/spring-security-expressions)
|
||||
- [Spring Security for a REST API](https://www.baeldung.com/securing-a-restful-web-service-with-spring-security)
|
||||
- [Spring Security Expressions - hasRole Example](https://www.baeldung.com/spring-security-expressions-basic)
|
||||
|
|
|
@ -6,5 +6,7 @@
|
|||
- [Cucumber and Scenario Outline](http://www.baeldung.com/cucumber-scenario-outline)
|
||||
- [Cucumber Java 8 Support](http://www.baeldung.com/cucumber-java-8-support)
|
||||
- [Introduction to Lambda Behave](http://www.baeldung.com/lambda-behave)
|
||||
- [Introduction to CheckStyle](https://www.baeldung.com/checkstyle-java)
|
||||
- [Introduction to FindBugs](https://www.baeldung.com/intro-to-findbugs)
|
||||
|
||||
|
||||
|
|
|
@ -35,11 +35,60 @@
|
|||
<version>${cucumber.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>2.2.0.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>testing-libraries</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>${checkstyle-maven-plugin.version}</version>
|
||||
<configuration>
|
||||
<configLocation>checkstyle.xml</configLocation>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>${checkstyle-maven-plugin.version}</version>
|
||||
<configuration>
|
||||
<configLocation>checkstyle.xml</configLocation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
|
||||
<properties>
|
||||
<lambda-behave.version>0.4</lambda-behave.version>
|
||||
<cucumber.version>1.2.5</cucumber.version>
|
||||
<checkstyle-maven-plugin.version>3.0.0</checkstyle-maven-plugin.version>
|
||||
</properties>
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
package com.baeldung.sampleapp.web.controller;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.baeldung.sampleapp.web.dto.Foo;
|
||||
|
||||
// used to test HttpClientPostingTest
|
||||
@RestController
|
||||
public class SimplePostController {
|
||||
|
||||
@RequestMapping(value = "/users", method = RequestMethod.POST)
|
||||
public String postUser(@RequestParam final String username, @RequestParam final String password) {
|
||||
return "Success" + username;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/users/detail", method = RequestMethod.POST)
|
||||
public String postUserDetail(@RequestBody final Foo entity) {
|
||||
return "Success" + entity.getId();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/users/multipart", method = RequestMethod.POST)
|
||||
public String uploadFile(@RequestParam final String username, @RequestParam final String password, @RequestParam("file") final MultipartFile file) {
|
||||
if (!file.isEmpty()) {
|
||||
try {
|
||||
final DateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_HH.mm.ss");
|
||||
final String fileName = dateFormat.format(new Date());
|
||||
final File fileServer = new File(fileName);
|
||||
fileServer.createNewFile();
|
||||
final byte[] bytes = file.getBytes();
|
||||
final BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(fileServer));
|
||||
stream.write(bytes);
|
||||
stream.close();
|
||||
return "You successfully uploaded " + username;
|
||||
} catch (final Exception e) {
|
||||
return "You failed to upload " + e.getMessage();
|
||||
}
|
||||
} else {
|
||||
return "You failed to upload because the file was empty.";
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/users/upload", method = RequestMethod.POST)
|
||||
public String postMultipart(@RequestParam("file") final MultipartFile file) {
|
||||
if (!file.isEmpty()) {
|
||||
try {
|
||||
final DateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_HH.mm.ss");
|
||||
final String fileName = dateFormat.format(new Date());
|
||||
final File fileServer = new File(fileName);
|
||||
fileServer.createNewFile();
|
||||
final byte[] bytes = file.getBytes();
|
||||
final BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(fileServer));
|
||||
stream.write(bytes);
|
||||
stream.close();
|
||||
return "You successfully uploaded ";
|
||||
} catch (final Exception e) {
|
||||
return "You failed to upload " + e.getMessage();
|
||||
}
|
||||
} else {
|
||||
return "You failed to upload because the file was empty.";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package com.baeldung.sampleapp.web.dto;
|
||||
|
||||
public class Foo {
|
||||
private long id;
|
||||
private String name;
|
||||
|
||||
public Foo() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Foo(final String name) {
|
||||
super();
|
||||
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Foo(final long id, final String name) {
|
||||
super();
|
||||
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(final long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue