Revert "BAEL-4134"
This commit is contained in:
committed by
GitHub
parent
dffa1f64e6
commit
485b4e3e99
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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>com.baeldung.orderservice</groupId>
|
||||
<artifactId>order-client</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>order-client</name>
|
||||
<description>Order service client module</description>
|
||||
<url>http://projects.spring.io/spring-boot/</url>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung.orderservice</groupId>
|
||||
<artifactId>order-service</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.baeldung.orderservice.client;
|
||||
|
||||
public interface OrderClient {
|
||||
|
||||
OrderResponse order(OrderDTO orderDTO);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.baeldung.orderservice.client;
|
||||
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
|
||||
@Component
|
||||
public class OrderClientImpl implements OrderClient {
|
||||
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
public OrderClientImpl(RestTemplateBuilder builder) {
|
||||
|
||||
this.restTemplate = builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderResponse order(OrderDTO orderDTO) {
|
||||
|
||||
String serviceUrl = "http://localhost:8002/order-service";
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
HttpEntity<OrderDTO> request = new HttpEntity<>(orderDTO, headers);
|
||||
|
||||
OrderResponse orderResponse = restTemplate.postForObject(serviceUrl + "/create", request, OrderResponse.class);
|
||||
|
||||
return orderResponse;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.baeldung.orderservice.client;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class OrderDTO {
|
||||
|
||||
private int customerId;
|
||||
private String itemId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.orderservice.client;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class OrderResponse {
|
||||
|
||||
private int orderId;
|
||||
private String productId;
|
||||
private String status;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
server.port=8002
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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>com.baeldung.orderservice</groupId>
|
||||
<artifactId>order-server</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<parent>
|
||||
<artifactId>order-service</artifactId>
|
||||
<groupId>com.baeldung.orderservice</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.baeldung.orderservice</groupId>
|
||||
<artifactId>order-client</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.baeldung.orderservice;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Order {
|
||||
|
||||
private Integer id;
|
||||
private Integer customerId;
|
||||
private String itemId;
|
||||
private String date;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.orderservice;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* Spring Boot application starter class
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class OrderApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(OrderApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.baeldung.orderservice;
|
||||
|
||||
import com.baeldung.orderservice.client.OrderDTO;
|
||||
import com.baeldung.orderservice.client.OrderResponse;
|
||||
import org.apache.commons.lang.time.DateFormatUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
public class OrderService {
|
||||
|
||||
|
||||
private List<Order> orders = Arrays.asList(
|
||||
|
||||
new Order(1, 1, "A101", "2020/02/14"),
|
||||
new Order(2, 1, "A101", "2020/02/14"),
|
||||
new Order(3, 2, "A150", "2020/02/17"));
|
||||
|
||||
@GetMapping
|
||||
public List<Order> getAllOrders() {
|
||||
return orders;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public List<Order> getOrdersByCustomer(@PathVariable int id) {
|
||||
return orders.stream()
|
||||
.filter(order -> order.getCustomerId() == id).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public OrderResponse createOrder(@RequestBody OrderDTO request) {
|
||||
|
||||
int lastIndex = orders.size();
|
||||
Order order = new Order();
|
||||
order.setId(lastIndex + 1);
|
||||
order.setCustomerId(request.getCustomerId());
|
||||
order.setItemId(request.getItemId());
|
||||
String date = DateFormatUtils.format(new Date(), "yyyy/MM/dd");
|
||||
order.setDate(date);
|
||||
|
||||
return new OrderResponse(order.getId(), order.getItemId(), "CREATED");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
#Spring Boot server configuration
|
||||
server.servlet.context-path=/order-service
|
||||
server.port=8002
|
||||
|
||||
123
spring-cloud/spring-cloud-bootstrap/order-service/pom.xml
Normal file
123
spring-cloud/spring-cloud-bootstrap/order-service/pom.xml
Normal file
@@ -0,0 +1,123 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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>com.baeldung.orderservice</groupId>
|
||||
<artifactId>order-service</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>order-service</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>order-client</module>
|
||||
<module>order-server</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>${commons-lang.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.qunix</groupId>
|
||||
<artifactId>structure-maven-plugin</artifactId>
|
||||
<version>${structure-maven.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-json</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<mainClass>${orderservice.mainclass}</mainClass>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<classifier>exec</classifier>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>start-application</id>
|
||||
<configuration>
|
||||
<mainClass>com.baeldung.orderservice.OrderApplication</mainClass>
|
||||
<classesDirectory>../order-server/target/classes</classesDirectory>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>start</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.qunix</groupId>
|
||||
<artifactId>structure-maven-plugin</artifactId>
|
||||
<version>${structure-maven.version}</version>
|
||||
<inherited>false</inherited>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>modules</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<commons-lang.version>2.6</commons-lang.version>
|
||||
<structure-maven.version>0.0.2</structure-maven.version>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<orderservice.mainclass>com.baeldung.orderservice.OrderApplication</orderservice.mainclass>
|
||||
</properties>
|
||||
</project>
|
||||
Reference in New Issue
Block a user