updated Java8 spring sample with CompletableFuture feature #3190

This commit is contained in:
Jean Detoeuf 2016-06-26 11:25:54 +02:00
parent 2b22efcea9
commit 4183bfc90c
3 changed files with 43 additions and 50 deletions

View File

@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.CompletableFuture;
@Api(value = "pet", description = "the pet API") @Api(value = "pet", description = "the pet API")
@ -35,9 +35,9 @@ public interface PetApi {
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
consumes = { "application/json", "application/xml" }, consumes = { "application/json", "application/xml" },
method = RequestMethod.POST) method = RequestMethod.POST)
default Callable<ResponseEntity<Void>> addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @RequestBody Pet body) { default CompletableFuture<ResponseEntity<Void>> addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @RequestBody Pet body) {
// do some magic! // do some magic!
return () -> new ResponseEntity<Void>(HttpStatus.OK); return CompletableFuture.completedFuture(new ResponseEntity<Void>(HttpStatus.OK));
} }
@ -52,10 +52,9 @@ public interface PetApi {
@RequestMapping(value = "/pet/{petId}", @RequestMapping(value = "/pet/{petId}",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.DELETE) method = RequestMethod.DELETE)
default Callable<ResponseEntity<Void>> deletePet(@ApiParam(value = "Pet id to delete",required=true ) @PathVariable("petId") Long petId, default CompletableFuture<ResponseEntity<Void>> deletePet(@ApiParam(value = "Pet id to delete",required=true ) @PathVariable("petId") Long petId,@ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) String apiKey) {
@ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) String apiKey) {
// do some magic! // do some magic!
return () -> new ResponseEntity<Void>(HttpStatus.OK); return CompletableFuture.completedFuture(new ResponseEntity<Void>(HttpStatus.OK));
} }
@ -71,9 +70,9 @@ public interface PetApi {
@RequestMapping(value = "/pet/findByStatus", @RequestMapping(value = "/pet/findByStatus",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.GET) method = RequestMethod.GET)
default Callable<ResponseEntity<List<Pet>>> findPetsByStatus(@ApiParam(value = "Status values that need to be considered for filter", required = true) @RequestParam(value = "status", required = true) List<String> status) { default CompletableFuture<ResponseEntity<List<Pet>>> findPetsByStatus(@ApiParam(value = "Status values that need to be considered for filter", required = true) @RequestParam(value = "status", required = true) List<String> status) {
// do some magic! // do some magic!
return () -> new ResponseEntity<List<Pet>>(HttpStatus.OK); return CompletableFuture.completedFuture(new ResponseEntity<List<Pet>>(HttpStatus.OK));
} }
@ -89,9 +88,9 @@ public interface PetApi {
@RequestMapping(value = "/pet/findByTags", @RequestMapping(value = "/pet/findByTags",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.GET) method = RequestMethod.GET)
default Callable<ResponseEntity<List<Pet>>> findPetsByTags(@ApiParam(value = "Tags to filter by", required = true) @RequestParam(value = "tags", required = true) List<String> tags) { default CompletableFuture<ResponseEntity<List<Pet>>> findPetsByTags(@ApiParam(value = "Tags to filter by", required = true) @RequestParam(value = "tags", required = true) List<String> tags) {
// do some magic! // do some magic!
return () -> new ResponseEntity<List<Pet>>(HttpStatus.OK); return CompletableFuture.completedFuture(new ResponseEntity<List<Pet>>(HttpStatus.OK));
} }
@ -105,9 +104,9 @@ public interface PetApi {
@RequestMapping(value = "/pet/{petId}", @RequestMapping(value = "/pet/{petId}",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.GET) method = RequestMethod.GET)
default Callable<ResponseEntity<Pet>> getPetById(@ApiParam(value = "ID of pet to return",required=true ) @PathVariable("petId") Long petId) { default CompletableFuture<ResponseEntity<Pet>> getPetById(@ApiParam(value = "ID of pet to return",required=true ) @PathVariable("petId") Long petId) {
// do some magic! // do some magic!
return () -> new ResponseEntity<Pet>(HttpStatus.OK); return CompletableFuture.completedFuture(new ResponseEntity<Pet>(HttpStatus.OK));
} }
@ -125,9 +124,9 @@ public interface PetApi {
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
consumes = { "application/json", "application/xml" }, consumes = { "application/json", "application/xml" },
method = RequestMethod.PUT) method = RequestMethod.PUT)
default Callable<ResponseEntity<Void>> updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @RequestBody Pet body) { default CompletableFuture<ResponseEntity<Void>> updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @RequestBody Pet body) {
// do some magic! // do some magic!
return () -> new ResponseEntity<Void>(HttpStatus.OK); return CompletableFuture.completedFuture(new ResponseEntity<Void>(HttpStatus.OK));
} }
@ -143,11 +142,9 @@ public interface PetApi {
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
consumes = { "application/x-www-form-urlencoded" }, consumes = { "application/x-www-form-urlencoded" },
method = RequestMethod.POST) method = RequestMethod.POST)
default Callable<ResponseEntity<Void>> updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated",required=true ) @PathVariable("petId") Long petId, default CompletableFuture<ResponseEntity<Void>> updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated",required=true ) @PathVariable("petId") Long petId,@ApiParam(value = "Updated name of the pet" ) @RequestPart(value="name", required=false) String name,@ApiParam(value = "Updated status of the pet" ) @RequestPart(value="status", required=false) String status) {
@ApiParam(value = "Updated name of the pet" ) @RequestPart(value="name", required=false) String name,
@ApiParam(value = "Updated status of the pet" ) @RequestPart(value="status", required=false) String status) {
// do some magic! // do some magic!
return () -> new ResponseEntity<Void>(HttpStatus.OK); return CompletableFuture.completedFuture(new ResponseEntity<Void>(HttpStatus.OK));
} }
@ -163,11 +160,9 @@ public interface PetApi {
produces = { "application/json" }, produces = { "application/json" },
consumes = { "multipart/form-data" }, consumes = { "multipart/form-data" },
method = RequestMethod.POST) method = RequestMethod.POST)
default Callable<ResponseEntity<ModelApiResponse>> uploadFile(@ApiParam(value = "ID of pet to update",required=true ) @PathVariable("petId") Long petId, default CompletableFuture<ResponseEntity<ModelApiResponse>> uploadFile(@ApiParam(value = "ID of pet to update",required=true ) @PathVariable("petId") Long petId,@ApiParam(value = "Additional data to pass to server" ) @RequestPart(value="additionalMetadata", required=false) String additionalMetadata,@ApiParam(value = "file detail") @RequestPart("file") MultipartFile file) {
@ApiParam(value = "Additional data to pass to server" ) @RequestPart(value="additionalMetadata", required=false) String additionalMetadata,
@ApiParam(value = "file detail") @RequestPart("file") MultipartFile file) {
// do some magic! // do some magic!
return () -> new ResponseEntity<ModelApiResponse>(HttpStatus.OK); return CompletableFuture.completedFuture(new ResponseEntity<ModelApiResponse>(HttpStatus.OK));
} }
} }

View File

@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.CompletableFuture;
@Api(value = "store", description = "the store API") @Api(value = "store", description = "the store API")
@ -29,9 +29,9 @@ public interface StoreApi {
@RequestMapping(value = "/store/order/{orderId}", @RequestMapping(value = "/store/order/{orderId}",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.DELETE) method = RequestMethod.DELETE)
default Callable<ResponseEntity<Void>> deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted",required=true ) @PathVariable("orderId") String orderId) { default CompletableFuture<ResponseEntity<Void>> deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted",required=true ) @PathVariable("orderId") String orderId) {
// do some magic! // do some magic!
return () -> new ResponseEntity<Void>(HttpStatus.OK); return CompletableFuture.completedFuture(new ResponseEntity<Void>(HttpStatus.OK));
} }
@ -43,9 +43,9 @@ public interface StoreApi {
@RequestMapping(value = "/store/inventory", @RequestMapping(value = "/store/inventory",
produces = { "application/json" }, produces = { "application/json" },
method = RequestMethod.GET) method = RequestMethod.GET)
default Callable<ResponseEntity<Map<String, Integer>>> getInventory() { default CompletableFuture<ResponseEntity<Map<String, Integer>>> getInventory() {
// do some magic! // do some magic!
return () -> new ResponseEntity<Map<String, Integer>>(HttpStatus.OK); return CompletableFuture.completedFuture(new ResponseEntity<Map<String, Integer>>(HttpStatus.OK));
} }
@ -57,9 +57,9 @@ public interface StoreApi {
@RequestMapping(value = "/store/order/{orderId}", @RequestMapping(value = "/store/order/{orderId}",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.GET) method = RequestMethod.GET)
default Callable<ResponseEntity<Order>> getOrderById(@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("orderId") Long orderId) { default CompletableFuture<ResponseEntity<Order>> getOrderById(@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("orderId") Long orderId) {
// do some magic! // do some magic!
return () -> new ResponseEntity<Order>(HttpStatus.OK); return CompletableFuture.completedFuture(new ResponseEntity<Order>(HttpStatus.OK));
} }
@ -70,9 +70,9 @@ public interface StoreApi {
@RequestMapping(value = "/store/order", @RequestMapping(value = "/store/order",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.POST) method = RequestMethod.POST)
default Callable<ResponseEntity<Order>> placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @RequestBody Order body) { default CompletableFuture<ResponseEntity<Order>> placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @RequestBody Order body) {
// do some magic! // do some magic!
return () -> new ResponseEntity<Order>(HttpStatus.OK); return CompletableFuture.completedFuture(new ResponseEntity<Order>(HttpStatus.OK));
} }
} }

View File

@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.CompletableFuture;
@Api(value = "user", description = "the user API") @Api(value = "user", description = "the user API")
@ -28,9 +28,9 @@ public interface UserApi {
@RequestMapping(value = "/user", @RequestMapping(value = "/user",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.POST) method = RequestMethod.POST)
default Callable<ResponseEntity<Void>> createUser(@ApiParam(value = "Created user object" ,required=true ) @RequestBody User body) { default CompletableFuture<ResponseEntity<Void>> createUser(@ApiParam(value = "Created user object" ,required=true ) @RequestBody User body) {
// do some magic! // do some magic!
return () -> new ResponseEntity<Void>(HttpStatus.OK); return CompletableFuture.completedFuture(new ResponseEntity<Void>(HttpStatus.OK));
} }
@ -40,9 +40,9 @@ public interface UserApi {
@RequestMapping(value = "/user/createWithArray", @RequestMapping(value = "/user/createWithArray",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.POST) method = RequestMethod.POST)
default Callable<ResponseEntity<Void>> createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List<User> body) { default CompletableFuture<ResponseEntity<Void>> createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List<User> body) {
// do some magic! // do some magic!
return () -> new ResponseEntity<Void>(HttpStatus.OK); return CompletableFuture.completedFuture(new ResponseEntity<Void>(HttpStatus.OK));
} }
@ -52,9 +52,9 @@ public interface UserApi {
@RequestMapping(value = "/user/createWithList", @RequestMapping(value = "/user/createWithList",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.POST) method = RequestMethod.POST)
default Callable<ResponseEntity<Void>> createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List<User> body) { default CompletableFuture<ResponseEntity<Void>> createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List<User> body) {
// do some magic! // do some magic!
return () -> new ResponseEntity<Void>(HttpStatus.OK); return CompletableFuture.completedFuture(new ResponseEntity<Void>(HttpStatus.OK));
} }
@ -65,9 +65,9 @@ public interface UserApi {
@RequestMapping(value = "/user/{username}", @RequestMapping(value = "/user/{username}",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.DELETE) method = RequestMethod.DELETE)
default Callable<ResponseEntity<Void>> deleteUser(@ApiParam(value = "The name that needs to be deleted",required=true ) @PathVariable("username") String username) { default CompletableFuture<ResponseEntity<Void>> deleteUser(@ApiParam(value = "The name that needs to be deleted",required=true ) @PathVariable("username") String username) {
// do some magic! // do some magic!
return () -> new ResponseEntity<Void>(HttpStatus.OK); return CompletableFuture.completedFuture(new ResponseEntity<Void>(HttpStatus.OK));
} }
@ -79,9 +79,9 @@ public interface UserApi {
@RequestMapping(value = "/user/{username}", @RequestMapping(value = "/user/{username}",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.GET) method = RequestMethod.GET)
default Callable<ResponseEntity<User>> getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing. ",required=true ) @PathVariable("username") String username) { default CompletableFuture<ResponseEntity<User>> getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing. ",required=true ) @PathVariable("username") String username) {
// do some magic! // do some magic!
return () -> new ResponseEntity<User>(HttpStatus.OK); return CompletableFuture.completedFuture(new ResponseEntity<User>(HttpStatus.OK));
} }
@ -92,10 +92,9 @@ public interface UserApi {
@RequestMapping(value = "/user/login", @RequestMapping(value = "/user/login",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.GET) method = RequestMethod.GET)
default Callable<ResponseEntity<String>> loginUser(@ApiParam(value = "The user name for login", required = true) @RequestParam(value = "username", required = true) String username, default CompletableFuture<ResponseEntity<String>> loginUser(@ApiParam(value = "The user name for login", required = true) @RequestParam(value = "username", required = true) String username,@ApiParam(value = "The password for login in clear text", required = true) @RequestParam(value = "password", required = true) String password) {
@ApiParam(value = "The password for login in clear text", required = true) @RequestParam(value = "password", required = true) String password) {
// do some magic! // do some magic!
return () -> new ResponseEntity<String>(HttpStatus.OK); return CompletableFuture.completedFuture(new ResponseEntity<String>(HttpStatus.OK));
} }
@ -105,9 +104,9 @@ public interface UserApi {
@RequestMapping(value = "/user/logout", @RequestMapping(value = "/user/logout",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.GET) method = RequestMethod.GET)
default Callable<ResponseEntity<Void>> logoutUser() { default CompletableFuture<ResponseEntity<Void>> logoutUser() {
// do some magic! // do some magic!
return () -> new ResponseEntity<Void>(HttpStatus.OK); return CompletableFuture.completedFuture(new ResponseEntity<Void>(HttpStatus.OK));
} }
@ -118,10 +117,9 @@ public interface UserApi {
@RequestMapping(value = "/user/{username}", @RequestMapping(value = "/user/{username}",
produces = { "application/xml", "application/json" }, produces = { "application/xml", "application/json" },
method = RequestMethod.PUT) method = RequestMethod.PUT)
default Callable<ResponseEntity<Void>> updateUser(@ApiParam(value = "name that need to be deleted",required=true ) @PathVariable("username") String username, default CompletableFuture<ResponseEntity<Void>> updateUser(@ApiParam(value = "name that need to be deleted",required=true ) @PathVariable("username") String username,@ApiParam(value = "Updated user object" ,required=true ) @RequestBody User body) {
@ApiParam(value = "Updated user object" ,required=true ) @RequestBody User body) {
// do some magic! // do some magic!
return () -> new ResponseEntity<Void>(HttpStatus.OK); return CompletableFuture.completedFuture(new ResponseEntity<Void>(HttpStatus.OK));
} }
} }