Skip to content

Commit 599df3c

Browse files
committed
[BAEL-18364] - moved the findBugs link to testing-modules/testing-libraries, and copied over the sample code from the article
1 parent d2fd54f commit 599df3c

File tree

5 files changed

+124
-1
lines changed

5 files changed

+124
-1
lines changed

spring-resttemplate/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
1616
- [Using the Spring RestTemplate Interceptor](https://www.baeldung.com/spring-rest-template-interceptor)
1717
- [Uploading MultipartFile with Spring RestTemplate](https://www.baeldung.com/spring-rest-template-multipart-upload)
1818
- [Get and Post Lists of Objects with RestTemplate](https://www.baeldung.com/spring-rest-template-list)
19-
- [Introduction to FindBugs](https://www.baeldung.com/intro-to-findbugs)
2019
- [Copy of RestTemplate Post Request with JSON](https://www.baeldung.com/spring-resttemplate-post-json-test)

testing-modules/testing-libraries/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
- [Cucumber Java 8 Support](http://www.baeldung.com/cucumber-java-8-support)
88
- [Introduction to Lambda Behave](http://www.baeldung.com/lambda-behave)
99
- [Introduction to CheckStyle](https://www.baeldung.com/checkstyle-java)
10+
- [Introduction to FindBugs](https://www.baeldung.com/intro-to-findbugs)
1011

1112

testing-modules/testing-libraries/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535
<version>${cucumber.version}</version>
3636
<scope>test</scope>
3737
</dependency>
38+
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-starter-web</artifactId>
42+
<version>2.2.0.RELEASE</version>
43+
</dependency>
44+
3845
</dependencies>
3946

4047
<build>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.baeldung.sampleapp.web.controller;
2+
3+
import java.io.BufferedOutputStream;
4+
import java.io.File;
5+
import java.io.FileOutputStream;
6+
import java.text.DateFormat;
7+
import java.text.SimpleDateFormat;
8+
import java.util.Date;
9+
10+
import org.springframework.web.bind.annotation.RequestBody;
11+
import org.springframework.web.bind.annotation.RequestMapping;
12+
import org.springframework.web.bind.annotation.RequestMethod;
13+
import org.springframework.web.bind.annotation.RequestParam;
14+
import org.springframework.web.bind.annotation.RestController;
15+
import org.springframework.web.multipart.MultipartFile;
16+
17+
import com.baeldung.sampleapp.web.dto.Foo;
18+
19+
// used to test HttpClientPostingTest
20+
@RestController
21+
public class SimplePostController {
22+
23+
@RequestMapping(value = "/users", method = RequestMethod.POST)
24+
public String postUser(@RequestParam final String username, @RequestParam final String password) {
25+
return "Success" + username;
26+
}
27+
28+
@RequestMapping(value = "/users/detail", method = RequestMethod.POST)
29+
public String postUserDetail(@RequestBody final Foo entity) {
30+
return "Success" + entity.getId();
31+
}
32+
33+
@RequestMapping(value = "/users/multipart", method = RequestMethod.POST)
34+
public String uploadFile(@RequestParam final String username, @RequestParam final String password, @RequestParam("file") final MultipartFile file) {
35+
if (!file.isEmpty()) {
36+
try {
37+
final DateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_HH.mm.ss");
38+
final String fileName = dateFormat.format(new Date());
39+
final File fileServer = new File(fileName);
40+
fileServer.createNewFile();
41+
final byte[] bytes = file.getBytes();
42+
final BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(fileServer));
43+
stream.write(bytes);
44+
stream.close();
45+
return "You successfully uploaded " + username;
46+
} catch (final Exception e) {
47+
return "You failed to upload " + e.getMessage();
48+
}
49+
} else {
50+
return "You failed to upload because the file was empty.";
51+
}
52+
}
53+
54+
@RequestMapping(value = "/users/upload", method = RequestMethod.POST)
55+
public String postMultipart(@RequestParam("file") final MultipartFile file) {
56+
if (!file.isEmpty()) {
57+
try {
58+
final DateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_HH.mm.ss");
59+
final String fileName = dateFormat.format(new Date());
60+
final File fileServer = new File(fileName);
61+
fileServer.createNewFile();
62+
final byte[] bytes = file.getBytes();
63+
final BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(fileServer));
64+
stream.write(bytes);
65+
stream.close();
66+
return "You successfully uploaded ";
67+
} catch (final Exception e) {
68+
return "You failed to upload " + e.getMessage();
69+
}
70+
} else {
71+
return "You failed to upload because the file was empty.";
72+
}
73+
}
74+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.baeldung.sampleapp.web.dto;
2+
3+
public class Foo {
4+
private long id;
5+
private String name;
6+
7+
public Foo() {
8+
super();
9+
}
10+
11+
public Foo(final String name) {
12+
super();
13+
14+
this.name = name;
15+
}
16+
17+
public Foo(final long id, final String name) {
18+
super();
19+
20+
this.id = id;
21+
this.name = name;
22+
}
23+
24+
// API
25+
26+
public long getId() {
27+
return id;
28+
}
29+
30+
public void setId(final long id) {
31+
this.id = id;
32+
}
33+
34+
public String getName() {
35+
return name;
36+
}
37+
38+
public void setName(final String name) {
39+
this.name = name;
40+
}
41+
42+
}

0 commit comments

Comments
 (0)