From 8e031f194e1c7d8ea37added79503893c597bde4 Mon Sep 17 00:00:00 2001 From: Pete Stevenson Date: Mon, 16 May 2022 15:11:19 -0700 Subject: [PATCH] Upgrade to Java 18. Signed-off-by: Pete Stevenson --- pom.xml | 57 ++++++++++++++++--- scripts/build.sh | 2 +- .../config/PrometheusAutoConfiguration.java | 21 ------- .../orders/controllers/OrdersController.java | 25 ++++---- .../orders/services/AsyncGetService.java | 17 +++--- 5 files changed, 75 insertions(+), 47 deletions(-) diff --git a/pom.xml b/pom.xml index d2bc6312..8b97debf 100644 --- a/pom.xml +++ b/pom.xml @@ -14,28 +14,69 @@ org.springframework.boot spring-boot-starter-parent - 1.4.4.RELEASE + 2.4.0 + UTF-8 - 1.8 + 18 0.0.21 + + com.h2database + h2 + org.springframework.boot - spring-boot-starter-data-rest + spring-boot-starter-data-jpa + 2.6.7 + + + junit + junit + 4.13.2 + test + + + org.hibernate.validator + hibernate-validator + + + org.springframework + spring-core + 5.3.20 + + + org.springframework + spring-web + 5.3.20 + + + javax.validation + validation-api + 2.0.1.Final + + + org.springframework.hateoas + spring-hateoas org.springframework.boot - spring-boot-starter-data-mongodb + spring-boot-starter-data-rest + 2.6.6 + + + org.mongodb + mongo-java-driver + 3.12.10 - org.springframework.cloud - spring-cloud-starter-zipkin - 1.1.0.RELEASE + org.springframework.boot + spring-boot-starter-data-mongodb + 2.6.6 io.prometheus @@ -55,6 +96,7 @@ org.springframework.data spring-data-rest-hal-browser + 3.3.9.RELEASE org.springframework.boot @@ -83,6 +125,7 @@ org.springframework.boot spring-boot-maven-plugin + 1.5.22.RELEASE org.apache.maven.plugins diff --git a/scripts/build.sh b/scripts/build.sh index adbac566..5782053f 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -23,7 +23,7 @@ else fi CODE_DIR=$(cd $SCRIPT_DIR/..; pwd) echo $CODE_DIR -$DOCKER_CMD run --rm -v $HOME/.m2:/root/.m2 -v $CODE_DIR:/usr/src/mymaven -w /usr/src/mymaven maven:3.2-jdk-8 mvn -DskipTests package +$DOCKER_CMD run --rm -v $HOME/.m2:/root/.m2 -v $CODE_DIR:/usr/src/mymaven -w /usr/src/mymaven maven:3.8.5-openjdk-18 mvn -q -DskipTests package cp -r $CODE_DIR/docker $CODE_DIR/target/docker/ cp -r $CODE_DIR/target/*.jar $CODE_DIR/target/docker/${IMAGE} diff --git a/src/main/java/works/weave/socks/orders/config/PrometheusAutoConfiguration.java b/src/main/java/works/weave/socks/orders/config/PrometheusAutoConfiguration.java index bdbdc37d..95a4c1de 100644 --- a/src/main/java/works/weave/socks/orders/config/PrometheusAutoConfiguration.java +++ b/src/main/java/works/weave/socks/orders/config/PrometheusAutoConfiguration.java @@ -1,10 +1,6 @@ package works.weave.socks.orders.config; -import io.prometheus.client.exporter.MetricsServlet; -import io.prometheus.client.hotspot.DefaultExports; -import io.prometheus.client.spring.boot.SpringBootMetricsCollector; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.actuate.endpoint.PublicMetrics; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.web.servlet.ServletRegistrationBean; @@ -14,22 +10,5 @@ import java.util.Collection; @Configuration -@ConditionalOnClass(SpringBootMetricsCollector.class) class PrometheusAutoConfiguration { - @Bean - @ConditionalOnMissingBean(SpringBootMetricsCollector.class) - SpringBootMetricsCollector springBootMetricsCollector(Collection publicMetrics) { - SpringBootMetricsCollector springBootMetricsCollector = new SpringBootMetricsCollector - (publicMetrics); - springBootMetricsCollector.register(); - return springBootMetricsCollector; - } - - @Bean - @ConditionalOnMissingBean(name = "prometheusMetricsServletRegistrationBean") - ServletRegistrationBean prometheusMetricsServletRegistrationBean(@Value("${prometheus.metrics" + - ".path:/metrics}") String metricsPath) { - DefaultExports.initialize(); - return new ServletRegistrationBean(new MetricsServlet(), metricsPath); - } } diff --git a/src/main/java/works/weave/socks/orders/controllers/OrdersController.java b/src/main/java/works/weave/socks/orders/controllers/OrdersController.java index 1b9a1748..a442f4ea 100644 --- a/src/main/java/works/weave/socks/orders/controllers/OrdersController.java +++ b/src/main/java/works/weave/socks/orders/controllers/OrdersController.java @@ -2,12 +2,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Optional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.ParameterizedTypeReference; import org.springframework.data.rest.webmvc.RepositoryRestController; -import org.springframework.hateoas.Resource; -import org.springframework.hateoas.mvc.TypeReferences; +import org.springframework.hateoas.EntityModel; +import org.springframework.hateoas.server.EntityLinks; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; @@ -18,6 +19,7 @@ import works.weave.socks.orders.services.AsyncGetService; import works.weave.socks.orders.values.PaymentRequest; import works.weave.socks.orders.values.PaymentResponse; +import org.springframework.hateoas.server.core.TypeReferences.EntityModelType; import java.io.IOException; import java.util.Calendar; @@ -28,12 +30,15 @@ import java.util.concurrent.TimeoutException; import java.util.regex.Matcher; import java.util.regex.Pattern; - +import org.springframework.hateoas.config.EnableHypermediaSupport; @RepositoryRestController public class OrdersController { private final Logger LOG = LoggerFactory.getLogger(getClass()); + @Autowired + private EntityLinks entityLinks; + @Autowired private OrdersConfigurationProperties config; @@ -59,14 +64,11 @@ CustomerOrder newOrder(@RequestBody NewOrderResource item) { LOG.debug("Starting calls"); - Future> addressFuture = asyncGetService.getResource(item.address, new TypeReferences - .ResourceType
() { + Future> addressFuture = asyncGetService.getResource(item.address, new EntityModelType
() { }); - Future> customerFuture = asyncGetService.getResource(item.customer, new TypeReferences - .ResourceType() { + Future> customerFuture = asyncGetService.getResource(item.customer, new EntityModelType() { }); - Future> cardFuture = asyncGetService.getResource(item.card, new TypeReferences - .ResourceType() { + Future> cardFuture = asyncGetService.getResource(item.card, new EntityModelType() { }); Future> itemsFuture = asyncGetService.getDataList(item.items, new ParameterizedTypeReference>() { @@ -97,7 +99,10 @@ CustomerOrder newOrder(@RequestBody NewOrderResource item) { } // Ship - String customerId = parseId(customerFuture.get(timeout, TimeUnit.SECONDS).getId().getHref()); + EntityModel customer = customerFuture.get(timeout, TimeUnit.SECONDS); + String customerId = parseId(customer.getRequiredLink("self").getHref()); + // Optional id = customer.Id; + // String customerId = "abc";//parseId(entityLinks.linkToItemResource(customer, customer.getId())); Future shipmentFuture = asyncGetService.postResource(config.getShippingUri(), new Shipment (customerId), new ParameterizedTypeReference() { }); diff --git a/src/main/java/works/weave/socks/orders/services/AsyncGetService.java b/src/main/java/works/weave/socks/orders/services/AsyncGetService.java index 901c6213..a38aa039 100644 --- a/src/main/java/works/weave/socks/orders/services/AsyncGetService.java +++ b/src/main/java/works/weave/socks/orders/services/AsyncGetService.java @@ -7,10 +7,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.ParameterizedTypeReference; import org.springframework.hateoas.MediaTypes; -import org.springframework.hateoas.Resource; -import org.springframework.hateoas.Resources; -import org.springframework.hateoas.hal.Jackson2HalModule; -import org.springframework.hateoas.mvc.TypeReferences; +import org.springframework.hateoas.EntityModel; +import org.springframework.hateoas.CollectionModel; +import org.springframework.hateoas.mediatype.hal.Jackson2HalModule; import org.springframework.http.MediaType; import org.springframework.http.RequestEntity; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; @@ -19,6 +18,8 @@ import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import works.weave.socks.orders.config.RestProxyTemplate; +import org.springframework.hateoas.server.core.TypeReferences.EntityModelType; +import org.springframework.hateoas.server.core.TypeReferences.CollectionModelType; import java.io.IOException; import java.net.URI; @@ -52,21 +53,21 @@ public AsyncGetService(RestProxyTemplate restProxyTemplate) { } @Async - public Future> getResource(URI url, TypeReferences.ResourceType type) throws + public Future> getResource(URI url, EntityModelType type) throws InterruptedException, IOException { RequestEntity request = RequestEntity.get(url).accept(HAL_JSON).build(); LOG.debug("Requesting: " + request.toString()); - Resource body = restProxyTemplate.getRestTemplate().exchange(request, type).getBody(); + EntityModel body = restProxyTemplate.getRestTemplate().exchange(request, type).getBody(); LOG.debug("Received: " + body.toString()); return new AsyncResult<>(body); } @Async - public Future> getDataList(URI url, TypeReferences.ResourcesType type) throws + public Future> getDataList(URI url, CollectionModelType type) throws InterruptedException, IOException { RequestEntity request = RequestEntity.get(url).accept(HAL_JSON).build(); LOG.debug("Requesting: " + request.toString()); - Resources body = restProxyTemplate.getRestTemplate().exchange(request, type).getBody(); + CollectionModel body = restProxyTemplate.getRestTemplate().exchange(request, type).getBody(); LOG.debug("Received: " + body.toString()); return new AsyncResult<>(body); }