Java 11 migration: patterns starting with a (#1084)

* Moves abstract-factory pattern to java 11

* Moves abstract-document pattern to java 11

* Moves acyclic-visitor pattern to java 11

* Moves adapter pattern to java 11

* Moves aggregator-microservices pattern to java 11

* Moves api-gateway pattern to java 11
This commit is contained in:
Anurag Agarwal
2019-11-13 21:34:51 +05:30
committed by Ilkka Seppälä
parent 3c57bf7078
commit f04fc3c0dc
26 changed files with 151 additions and 172 deletions

View File

@ -47,7 +47,7 @@ public class ApiGateway {
*/
@RequestMapping(path = "/desktop", method = RequestMethod.GET)
public DesktopProduct getProductDesktop() {
DesktopProduct desktopProduct = new DesktopProduct();
var desktopProduct = new DesktopProduct();
desktopProduct.setImagePath(imageClient.getImagePath());
desktopProduct.setPrice(priceClient.getPrice());
return desktopProduct;
@ -60,7 +60,7 @@ public class ApiGateway {
*/
@RequestMapping(path = "/mobile", method = RequestMethod.GET)
public MobileProduct getProductMobile() {
MobileProduct mobileProduct = new MobileProduct();
var mobileProduct = new MobileProduct();
mobileProduct.setPrice(priceClient.getPrice());
return mobileProduct;
}

View File

@ -27,7 +27,6 @@ import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import org.springframework.stereotype.Component;
@ -43,21 +42,19 @@ public class ImageClientImpl implements ImageClient {
*/
@Override
public String getImagePath() {
String response = null;
HttpClient httpClient = HttpClient.newHttpClient();
HttpRequest httpGet =
HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:50005/image-path")).build();
var httpClient = HttpClient.newHttpClient();
var httpGet = HttpRequest.newBuilder()
.GET()
.uri(URI.create("http://localhost:50005/image-path"))
.build();
try {
HttpResponse<String> httpResponse = httpClient.send(httpGet, BodyHandlers.ofString());
response = httpResponse.body();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
var httpResponse = httpClient.send(httpGet, BodyHandlers.ofString());
return httpResponse.body();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
return response;
return null;
}
}

View File

@ -27,7 +27,6 @@ import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import org.springframework.stereotype.Component;
@ -43,22 +42,19 @@ public class PriceClientImpl implements PriceClient {
*/
@Override
public String getPrice() {
String response = null;
HttpClient httpClient = HttpClient.newHttpClient();
HttpRequest httpGet =
HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:50006/price")).build();
var httpClient = HttpClient.newHttpClient();
var httpGet = HttpRequest.newBuilder()
.GET()
.uri(URI.create("http://localhost:50006/price"))
.build();
try {
HttpResponse<String> httpResponse = httpClient.send(httpGet, BodyHandlers.ofString());
response = httpResponse.body();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
var httpResponse = httpClient.send(httpGet, BodyHandlers.ofString());
return httpResponse.body();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
return response;
return null;
}
}