diff --git a/petclinic-api-gateway/.gitignore b/petclinic-api-gateway/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..b06a9e2c14dc1b71b697f1de6b4704e535d6efbb --- /dev/null +++ b/petclinic-api-gateway/.gitignore @@ -0,0 +1,14 @@ +# Maven +target/ + +# Eclipse +.settings/ +.classpath +.project + +# IntelliJ IDEA +.idea +*.iml + +# Branch switching +generated/ diff --git a/petclinic-api-gateway/pom.xml b/petclinic-api-gateway/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..b28dd9c8ce15fe7d392c983abb9198792117cdc3 --- /dev/null +++ b/petclinic-api-gateway/pom.xml @@ -0,0 +1,73 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.springframework.samples.petclinic.api</groupId> + <artifactId>petclinic-api-gateway</artifactId> + <version>1.4.1</version> + <packaging>jar</packaging> + + <name>petclinic-api-gateway</name> + <description>PetClinic API Gateway</description> + + <parent> + <groupId>org.springframework.samples</groupId> + <artifactId>springboot-petclinic</artifactId> + <version>1.4.1</version> + </parent> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + <java.version>1.8</java.version> + </properties> + + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-actuator</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-starter-config</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-starter-eureka</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-starter-zuul</artifactId> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.springframework.cloud</groupId> + <artifactId>spring-cloud-dependencies</artifactId> + <version>Camden.SR1</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + + +</project> diff --git a/petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/ApiGatewayApplication.java b/petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/ApiGatewayApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..ed03d9940fff8c76544c08ba7a42c81383a41e2d --- /dev/null +++ b/petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/ApiGatewayApplication.java @@ -0,0 +1,16 @@ +package org.springframework.samples.petclinic.api; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.netflix.zuul.EnableZuulProxy; + +@EnableZuulProxy +@EnableDiscoveryClient +@SpringBootApplication +public class ApiGatewayApplication { + + public static void main(String[] args) { + SpringApplication.run(ApiGatewayApplication.class, args); + } +} diff --git a/petclinic-api-gateway/src/main/resources/bootstrap.yml b/petclinic-api-gateway/src/main/resources/bootstrap.yml new file mode 100644 index 0000000000000000000000000000000000000000..42caccbdb34d36257aecf55d51892b35db957d34 --- /dev/null +++ b/petclinic-api-gateway/src/main/resources/bootstrap.yml @@ -0,0 +1,6 @@ +spring: + cloud: + config: + uri: http://localhost:8888 + application: + name: api-gateway diff --git a/petclinic-api-gateway/src/test/java/org/springframework/samples/petclinic/api/ApiGatewayApplicationTests.java b/petclinic-api-gateway/src/test/java/org/springframework/samples/petclinic/api/ApiGatewayApplicationTests.java new file mode 100644 index 0000000000000000000000000000000000000000..3ea1424c95121bdfa23af859446149d5966929b3 --- /dev/null +++ b/petclinic-api-gateway/src/test/java/org/springframework/samples/petclinic/api/ApiGatewayApplicationTests.java @@ -0,0 +1,16 @@ +package org.springframework.samples.petclinic.api; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ApiGatewayApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/boundary/web/owner/OwnerResource.java b/petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/boundary/web/owner/OwnerResource.java index f27f2eb6227a6a9cca05e14c612d9bb104f7ac1e..aa045e866cc272ce0d7688c79ccd01a602db2184 100644 --- a/petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/boundary/web/owner/OwnerResource.java +++ b/petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/boundary/web/owner/OwnerResource.java @@ -17,8 +17,8 @@ package org.springframework.samples.petclinic.clients.boundary.web.owner; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; -import org.springframework.samples.petclinic.clients.domain.model.owner.Owner; import org.springframework.samples.petclinic.clients.application.OwnerService; +import org.springframework.samples.petclinic.clients.domain.model.owner.Owner; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.*; @@ -31,6 +31,7 @@ import java.util.Collection; * @author Arjen Poutsma * @author Michael Isvy */ +@RequestMapping("/owners") @RestController public class OwnerResource { @@ -53,7 +54,7 @@ public class OwnerResource { /** * Create Owner */ - @RequestMapping(value = "/owner", method = RequestMethod.POST) + @PostMapping @ResponseStatus(HttpStatus.CREATED) public void createOwner(@Valid @RequestBody Owner owner) { this.ownerService.saveOwner(owner); @@ -62,7 +63,7 @@ public class OwnerResource { /** * Read single Owner */ - @RequestMapping(value = "/owner/{ownerId}", method = RequestMethod.GET) + @GetMapping(value = "/{ownerId}") public Owner findOwner(@PathVariable("ownerId") int ownerId) { return retrieveOwner(ownerId); } @@ -70,7 +71,7 @@ public class OwnerResource { /** * Read List of Owners */ - @GetMapping("/owner/list") + @GetMapping public Collection<Owner> findAll() { return ownerService.findAll(); } @@ -78,7 +79,7 @@ public class OwnerResource { /** * Update Owner */ - @RequestMapping(value = "/owner/{ownerId}", method = RequestMethod.PUT) + @PutMapping(value = "/{ownerId}") public Owner updateOwner(@PathVariable("ownerId") int ownerId, @Valid @RequestBody Owner ownerRequest) { Owner ownerModel = retrieveOwner(ownerId); // This is done by hand for simplicity purpose. In a real life use-case we should consider using MapStruct. diff --git a/petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/boundary/web/pet/PetResource.java b/petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/boundary/web/pet/PetResource.java index 07c15f85830dc34a3182004b13b199b43e46415d..2ebc2d797b134e768923d14d2e114f8ca590a468 100644 --- a/petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/boundary/web/pet/PetResource.java +++ b/petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/boundary/web/pet/PetResource.java @@ -19,16 +19,16 @@ import com.fasterxml.jackson.annotation.JsonFormat; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.http.HttpStatus; -import org.springframework.samples.petclinic.clients.domain.model.owner.Owner; import org.springframework.samples.petclinic.clients.application.OwnerService; -import org.springframework.samples.petclinic.clients.domain.model.pet.Pet; import org.springframework.samples.petclinic.clients.application.PetService; +import org.springframework.samples.petclinic.clients.domain.model.owner.Owner; +import org.springframework.samples.petclinic.clients.domain.model.pet.Pet; import org.springframework.samples.petclinic.clients.domain.model.pet.PetType; import org.springframework.web.bind.annotation.*; import javax.validation.constraints.Size; +import java.util.Collection; import java.util.Date; -import java.util.Map; /** * @author Juergen Hoeller @@ -49,18 +49,19 @@ public class PetResource { } @GetMapping("/petTypes") - Object getPetTypes() { + public Collection<PetType> getPetTypes() { return petService.findPetTypes(); } - @GetMapping("/owners/{ownerId}/pets/new") - public String initCreationForm(@PathVariable("ownerId") int ownerId, Map<String, Object> model) { - Owner owner = ownerService.findOwnerById(ownerId); - Pet pet = new Pet(); - owner.addPet(pet); - model.put("pet", pet); - return "pets/createOrUpdatePetForm"; - } + //TODO: unused? +// @GetMapping("/owners/{ownerId}/pets/new") +// public String initCreationForm(@PathVariable("ownerId") int ownerId, Map<String, Object> model) { +// Owner owner = ownerService.findOwnerById(ownerId); +// Pet pet = new Pet(); +// owner.addPet(pet); +// model.put("pet", pet); +// return "pets/createOrUpdatePetForm"; +// } @PostMapping("/owners/{ownerId}/pets") @ResponseStatus(HttpStatus.NO_CONTENT) @@ -92,7 +93,7 @@ public class PetResource { petService.savePet(pet); } - @GetMapping("/owner/*/pet/{petId}") + @GetMapping("/pets/{petId}") public PetDetails findPet(@PathVariable("petId") int petId) { return new PetDetails(petService.findPetById(petId)); } diff --git a/petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/boundary/web/pet/PetValidator.java b/petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/boundary/web/pet/PetValidator.java index 9484bbb59b61c8dbf59808c5f4faf7b8a60657d0..9f888d21bcbf6ae0db0a64408db319f6a794991a 100644 --- a/petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/boundary/web/pet/PetValidator.java +++ b/petclinic-clients-service/src/main/java/org/springframework/samples/petclinic/clients/boundary/web/pet/PetValidator.java @@ -25,6 +25,7 @@ import org.springframework.validation.Errors; * @author Ken Krebs * @author Juergen Hoeller */ +//TODO: unused? public class PetValidator { public void validate(Pet pet, Errors errors) { diff --git a/petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/web/boundary/VetResource.java b/petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/web/boundary/VetResource.java index 76f75e5f2c3902061c150b4589f146abfe4cbef4..c05c7d0f695a3cd4f69c123507cf7169a9b45cd3 100644 --- a/petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/web/boundary/VetResource.java +++ b/petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/web/boundary/VetResource.java @@ -16,9 +16,10 @@ package org.springframework.samples.petclinic.vets.web.boundary; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.samples.petclinic.vets.domain.model.vet.Vet; import org.springframework.samples.petclinic.vets.application.VetService; +import org.springframework.samples.petclinic.vets.domain.model.vet.Vet; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.Collection; @@ -29,6 +30,7 @@ import java.util.Collection; * @author Ken Krebs * @author Arjen Poutsma */ +@RequestMapping("/vets") @RestController public class VetResource { @@ -39,7 +41,7 @@ public class VetResource { this.vetService = vetService; } - @GetMapping("/vets") + @GetMapping public Collection<Vet> showResourcesVetList() { return vetService.findVets(); } diff --git a/petclinic-visits-service/src/main/java/org/springframework/samples/petclinic/visits/boundary/web/visit/VisitResource.java b/petclinic-visits-service/src/main/java/org/springframework/samples/petclinic/visits/boundary/web/visit/VisitResource.java index 68b7922887505cbef6e1aad0df675d0ad4648f25..8f528d1bb041786db5522eea9361a93cff561541 100644 --- a/petclinic-visits-service/src/main/java/org/springframework/samples/petclinic/visits/boundary/web/visit/VisitResource.java +++ b/petclinic-visits-service/src/main/java/org/springframework/samples/petclinic/visits/boundary/web/visit/VisitResource.java @@ -15,14 +15,14 @@ */ package org.springframework.samples.petclinic.visits.boundary.web.visit; - import org.springframework.beans.factory.annotation.Autowired; - import org.springframework.http.HttpStatus; - import org.springframework.samples.petclinic.visits.domain.model.visit.Visit; - import org.springframework.samples.petclinic.visits.application.VisitService; - import org.springframework.web.bind.annotation.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.samples.petclinic.visits.application.VisitService; +import org.springframework.samples.petclinic.visits.domain.model.visit.Visit; +import org.springframework.web.bind.annotation.*; - import javax.validation.Valid; - import java.util.List; +import javax.validation.Valid; +import java.util.List; /** * @author Juergen Hoeller @@ -40,7 +40,7 @@ public class VisitResource { this.visitService = visitService; } - @PostMapping("/owners/{ownerId}/pets/{petId}/visits") + @PostMapping("/pets/{petId}/visits") @ResponseStatus(HttpStatus.NO_CONTENT) public void create( @Valid @RequestBody Visit visit, @@ -50,7 +50,7 @@ public class VisitResource { visitService.saveVisit(visit); } - @GetMapping("/owners/{ownerId}/pets/{petId}/visits") + @GetMapping("/pets/{petId}/visits") public List<Visit> visits(@PathVariable("petId") int petId) { return visitService.findVisitsByPetId(petId); } diff --git a/pom.xml b/pom.xml index fecfcb2a7825fe1108572bb95e28c7d1bb2593a3..008eab2ceaa3a92511bdc4b8092ef1a33f8e9155 100644 --- a/pom.xml +++ b/pom.xml @@ -22,6 +22,7 @@ <module>petclinic-visits-service</module> <module>petclinic-config-server</module> <module>petclinic-discovery-server</module> + <module>petclinic-api-gateway</module> </modules> <properties>