forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BAEL-18364] - moved the findBugs link to testing-modules/testing-lib…
…raries, and copied over the sample code from the article
- Loading branch information
Showing
5 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...g-libraries/src/main/java/com/baeldung/sampleapp/web/controller/SimplePostController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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."; | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
testing-modules/testing-libraries/src/main/java/com/baeldung/sampleapp/web/dto/Foo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |