Skip to content

Commit f9c5d85

Browse files
authored
Merge pull request #2 from lvivJavaClub/storage-client-added
Storage service client added
2 parents 36efd16 + ddabb56 commit f9c5d85

29 files changed

+524
-84
lines changed

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<module>rating-service</module>
1818
<module>hackster-service</module>
1919
<module>realtor-service</module>
20-
<module>storage-service</module>>
20+
<module>storage-service</module>
21+
<module>storage-service-client</module>
2122
</modules>
2223
</project>

realtor-service/pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55

6-
<groupId>com.lohika.jclub</groupId>
6+
<groupId>com.lohika.jclub.realtor</groupId>
77
<artifactId>realtor-service</artifactId>
88
<version>0.0.1-SNAPSHOT</version>
99
<packaging>jar</packaging>
@@ -22,7 +22,7 @@
2222
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2323
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2424
<java.version>1.8</java.version>
25-
<spring-cloud.version>Dalston.SR1</spring-cloud.version>
25+
<spring-cloud.version>Dalston.RELEASE</spring-cloud.version>
2626
</properties>
2727

2828
<dependencies>
@@ -49,6 +49,11 @@
4949
<groupId>org.springframework.cloud</groupId>
5050
<artifactId>spring-cloud-starter-feign</artifactId>
5151
</dependency>
52+
<dependency>
53+
<groupId>com.lohika.jclub.storage</groupId>
54+
<artifactId>storage-service-client</artifactId>
55+
<version>0.0.1-SNAPSHOT</version>
56+
</dependency>
5257
</dependencies>
5358

5459
<dependencyManagement>

realtor-service/src/main/java/com/lohika/jclub/RealtorServiceApplication.java

Lines changed: 0 additions & 50 deletions
This file was deleted.

realtor-service/src/main/java/com/lohika/jclub/ApartmentRecord.java renamed to realtor-service/src/main/java/com/lohika/jclub/realtor/ApartmentRecord.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.lohika.jclub;
1+
package com.lohika.jclub.realtor;
22

33
import lombok.*;
44

realtor-service/src/main/java/com/lohika/jclub/ApartmentRecordClient.java renamed to realtor-service/src/main/java/com/lohika/jclub/realtor/ApartmentRecordClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.lohika.jclub;
1+
package com.lohika.jclub.realtor;
22

33
import feign.Headers;
44
import feign.RequestLine;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.lohika.jclub.realtor;
2+
3+
import feign.Feign;
4+
5+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
6+
import org.springframework.boot.autoconfigure.web.WebMvcRegistrations;
7+
import org.springframework.boot.autoconfigure.web.WebMvcRegistrationsAdapter;
8+
import org.springframework.cloud.netflix.feign.FeignClient;
9+
import org.springframework.context.annotation.Bean;
10+
import org.springframework.context.annotation.Configuration;
11+
import org.springframework.core.annotation.AnnotationUtils;
12+
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
13+
14+
/**
15+
* https://github.com/spring-cloud/spring-cloud-netflix/issues/466
16+
*/
17+
@Configuration
18+
@ConditionalOnClass({Feign.class})
19+
public class FeignMappingDefaultConfiguration {
20+
@Bean
21+
public WebMvcRegistrations feignWebRegistrations() {
22+
return new WebMvcRegistrationsAdapter() {
23+
@Override
24+
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
25+
return new FeignFilterRequestMappingHandlerMapping();
26+
}
27+
};
28+
}
29+
30+
private static class FeignFilterRequestMappingHandlerMapping extends RequestMappingHandlerMapping {
31+
@Override
32+
protected boolean isHandler(Class<?> beanType) {
33+
return super.isHandler(beanType) && (AnnotationUtils.findAnnotation(beanType, FeignClient.class) == null);
34+
}
35+
}
36+
}

realtor-service/src/main/java/com/lohika/jclub/RealtorController.java renamed to realtor-service/src/main/java/com/lohika/jclub/realtor/RealtorController.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
package com.lohika.jclub;
1+
package com.lohika.jclub.realtor;
22

33
import lombok.extern.slf4j.Slf4j;
4+
5+
import com.lohika.jclub.storage.Apartment;
6+
import com.lohika.jclub.storage.StorageServiceClient;
7+
48
import org.springframework.beans.factory.annotation.Autowired;
59
import org.springframework.cloud.client.ServiceInstance;
610
import org.springframework.cloud.client.discovery.DiscoveryClient;
@@ -22,7 +26,7 @@ public class RealtorController {
2226
private RestTemplate restTemplate;
2327

2428
@Autowired
25-
private RealtorService realtorService;
29+
private StorageServiceClient storageServiceClient;
2630

2731
@PostMapping("/apartments")
2832
public void addApartment(@RequestBody ApartmentRecord apartmentRecord) {
@@ -34,11 +38,21 @@ public void addApartment(@RequestBody ApartmentRecord apartmentRecord) {
3438

3539
@PostMapping("/storeApartments")
3640
public void storeApartment(@RequestBody ApartmentRecord apartmentRecord) {
37-
realtorService.storeApartment(apartmentRecord);
41+
42+
Apartment newApartment = Apartment.builder()
43+
.location(apartmentRecord.getLocation())
44+
.mail(apartmentRecord.getMail())
45+
.phone(apartmentRecord.getPhone())
46+
.price(apartmentRecord.getPrice())
47+
.realtorName(apartmentRecord.getRealtorName())
48+
.sqft(apartmentRecord.getSqft())
49+
.build();
50+
51+
Apartment apartment = storageServiceClient.create(newApartment);
3852
/*ApartmentRecordClient apartmentRecordClient = Feign.builder().encoder(new JacksonEncoder())
3953
.decoder(new JacksonDecoder()).target(ApartmentRecordClient.class, "http://storage-service");
4054
apartmentRecordClient.storeApartment(apartmentRecord);*/
41-
log.info("Stored");
55+
log.info("Stored, {}", apartment);
4256
}
4357

4458
@RequestMapping("/service-instances/{applicationName}")
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.lohika.jclub.realtor;
2+
3+
4+
import com.lohika.jclub.storage.EnableStorageServiceClient;
5+
6+
import org.springframework.boot.SpringApplication;
7+
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
9+
import org.springframework.context.annotation.Bean;
10+
import org.springframework.web.client.RestTemplate;
11+
12+
@EnableStorageServiceClient
13+
@SpringBootApplication
14+
public class RealtorServiceApplication {
15+
16+
public static void main(String[] args) {
17+
SpringApplication.run(RealtorServiceApplication.class, args);
18+
}
19+
20+
@Bean
21+
@LoadBalanced
22+
public RestTemplate restTemplate() {
23+
return new RestTemplate();
24+
}
25+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
____ ____ _
2+
/ __ \___ ____ _/ / /_____ _____ ________ ______ __(_)_______
3+
/ /_/ / _ \/ __ `/ / __/ __ \/ ___/ / ___/ _ \/ ___/ | / / / ___/ _ \
4+
/ _, _/ __/ /_/ / / /_/ /_/ / / (__ ) __/ / | |/ / / /__/ __/
5+
/_/ |_|\___/\__,_/_/\__/\____/_/ /____/\___/_/ |___/_/\___/\___/
6+
7+
v.${application.version}

0 commit comments

Comments
 (0)