Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Upgrade to Java 18. #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 50 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,69 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.4.RELEASE</version>
<version>2.4.0</version>
<relativePath/>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<java.version>18</java.version>
<prometheus.version>0.0.21</prometheus.version>
</properties>

<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.6.7</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.20</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.3.20</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<artifactId>spring-boot-starter-data-rest</artifactId>
<version>2.6.6</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.10</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
<version>1.1.0.RELEASE</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>2.6.6</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
Expand All @@ -55,6 +96,7 @@
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-browser</artifactId>
<version>3.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -83,6 +125,7 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.22.RELEASE</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,22 +10,5 @@
import java.util.Collection;

@Configuration
@ConditionalOnClass(SpringBootMetricsCollector.class)
class PrometheusAutoConfiguration {
@Bean
@ConditionalOnMissingBean(SpringBootMetricsCollector.class)
SpringBootMetricsCollector springBootMetricsCollector(Collection<PublicMetrics> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -59,14 +64,11 @@ CustomerOrder newOrder(@RequestBody NewOrderResource item) {


LOG.debug("Starting calls");
Future<Resource<Address>> addressFuture = asyncGetService.getResource(item.address, new TypeReferences
.ResourceType<Address>() {
Future<EntityModel<Address>> addressFuture = asyncGetService.getResource(item.address, new EntityModelType<Address>() {
});
Future<Resource<Customer>> customerFuture = asyncGetService.getResource(item.customer, new TypeReferences
.ResourceType<Customer>() {
Future<EntityModel<Customer>> customerFuture = asyncGetService.getResource(item.customer, new EntityModelType<Customer>() {
});
Future<Resource<Card>> cardFuture = asyncGetService.getResource(item.card, new TypeReferences
.ResourceType<Card>() {
Future<EntityModel<Card>> cardFuture = asyncGetService.getResource(item.card, new EntityModelType<Card>() {
});
Future<List<Item>> itemsFuture = asyncGetService.getDataList(item.items, new
ParameterizedTypeReference<List<Item>>() {
Expand Down Expand Up @@ -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<Long> id = customer.Id;
// String customerId = "abc";//parseId(entityLinks.linkToItemResource(customer, customer.getId()));
Future<Shipment> shipmentFuture = asyncGetService.postResource(config.getShippingUri(), new Shipment
(customerId), new ParameterizedTypeReference<Shipment>() {
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -52,21 +53,21 @@ public AsyncGetService(RestProxyTemplate restProxyTemplate) {
}

@Async
public <T> Future<Resource<T>> getResource(URI url, TypeReferences.ResourceType<T> type) throws
public <T> Future<EntityModel<T>> getResource(URI url, EntityModelType<T> type) throws
InterruptedException, IOException {
RequestEntity<Void> request = RequestEntity.get(url).accept(HAL_JSON).build();
LOG.debug("Requesting: " + request.toString());
Resource<T> body = restProxyTemplate.getRestTemplate().exchange(request, type).getBody();
EntityModel<T> body = restProxyTemplate.getRestTemplate().exchange(request, type).getBody();
LOG.debug("Received: " + body.toString());
return new AsyncResult<>(body);
}

@Async
public <T> Future<Resources<T>> getDataList(URI url, TypeReferences.ResourcesType<T> type) throws
public <T> Future<CollectionModel<T>> getDataList(URI url, CollectionModelType<T> type) throws
InterruptedException, IOException {
RequestEntity<Void> request = RequestEntity.get(url).accept(HAL_JSON).build();
LOG.debug("Requesting: " + request.toString());
Resources<T> body = restProxyTemplate.getRestTemplate().exchange(request, type).getBody();
CollectionModel<T> body = restProxyTemplate.getRestTemplate().exchange(request, type).getBody();
LOG.debug("Received: " + body.toString());
return new AsyncResult<>(body);
}
Expand Down