diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/pom.xml b/spring-boot-project/spring-boot-actuator-autoconfigure/pom.xml index 684b5f2307..2d793ae266 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/pom.xml +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/pom.xml @@ -321,6 +321,12 @@ spring-session-core true + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + runtime + org.springframework.boot diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/AuditEventsEndpointDocumentationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/AuditEventsEndpointDocumentationTests.java index 4e753f7e3d..1edc267296 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/AuditEventsEndpointDocumentationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/AuditEventsEndpointDocumentationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,10 @@ package org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation; -import java.time.ZonedDateTime; +import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.Collections; -import java.util.Date; import org.junit.Test; @@ -74,10 +73,9 @@ public class AuditEventsEndpointDocumentationTests @Test public void filteredAuditEvents() throws Exception { - ZonedDateTime now = ZonedDateTime.now(); + OffsetDateTime now = OffsetDateTime.now(); String queryTimestamp = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(now); - Date date = new Date(now.toEpochSecond() * 1000); - given(this.repository.find("alice", date, "logout")).willReturn( + given(this.repository.find("alice", now.toInstant(), "logout")).willReturn( Arrays.asList(new AuditEvent("alice", "logout", Collections.emptyMap()))); this.mockMvc .perform(get("/actuator/auditevents").param("principal", "alice") @@ -94,7 +92,7 @@ public class AuditEventsEndpointDocumentationTests parameterWithName("type").description( "Restricts the events to those with the given " + "type. Optional.")))); - verify(this.repository).find("alice", date, "logout"); + verify(this.repository).find("alice", now.toInstant(), "logout"); } @Configuration diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEvent.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEvent.java index a6e287919a..fcae7248c6 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEvent.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,12 +17,11 @@ package org.springframework.boot.actuate.audit; import java.io.Serializable; +import java.time.Instant; import java.util.Collections; -import java.util.Date; import java.util.HashMap; import java.util.Map; -import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -46,7 +45,7 @@ import org.springframework.util.Assert; @JsonInclude(Include.NON_EMPTY) public class AuditEvent implements Serializable { - private final Date timestamp; + private final Instant timestamp; private final String principal; @@ -61,7 +60,7 @@ public class AuditEvent implements Serializable { * @param data The event data */ public AuditEvent(String principal, String type, Map data) { - this(new Date(), principal, type, data); + this(Instant.now(), principal, type, data); } /** @@ -72,7 +71,7 @@ public class AuditEvent implements Serializable { * @param data The event data in the form 'key=value' or simply 'key' */ public AuditEvent(String principal, String type, String... data) { - this(new Date(), principal, type, convert(data)); + this(Instant.now(), principal, type, convert(data)); } /** @@ -82,7 +81,7 @@ public class AuditEvent implements Serializable { * @param type the event type * @param data The event data */ - public AuditEvent(Date timestamp, String principal, String type, + public AuditEvent(Instant timestamp, String principal, String type, Map data) { Assert.notNull(timestamp, "Timestamp must not be null"); Assert.notNull(type, "Type must not be null"); @@ -107,11 +106,10 @@ public class AuditEvent implements Serializable { } /** - * Returns the date/time that the even was logged. - * @return the time stamp + * Returns the date/time that the event was logged. + * @return the timestamp */ - @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssZ") - public Date getTimestamp() { + public Instant getTimestamp() { return this.timestamp; } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventRepository.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventRepository.java index e1f8592f40..b06a6c9dff 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventRepository.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventRepository.java @@ -16,7 +16,7 @@ package org.springframework.boot.actuate.audit; -import java.util.Date; +import java.time.Instant; import java.util.List; /** @@ -43,6 +43,6 @@ public interface AuditEventRepository { * @return audit events of specified type relating to the principal * @since 1.4.0 */ - List find(String principal, Date after, String type); + List find(String principal, Instant after, String type); } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventsEndpoint.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventsEndpoint.java index ba9eaafa0e..930a528728 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventsEndpoint.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventsEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package org.springframework.boot.actuate.audit; -import java.util.Date; +import java.time.OffsetDateTime; import java.util.List; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; @@ -40,10 +40,10 @@ public class AuditEventsEndpoint { } @ReadOperation - public AuditEventsDescriptor eventsWithPrincipalDateAfterAndType(String principal, - Date after, String type) { - return new AuditEventsDescriptor( - this.auditEventRepository.find(principal, after, type)); + public AuditEventsDescriptor events(String principal, OffsetDateTime after, + String type) { + return new AuditEventsDescriptor(this.auditEventRepository.find(principal, + after == null ? null : after.toInstant(), type)); } /** diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventsEndpointWebExtension.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventsEndpointWebExtension.java index f20e9c80d0..c9b7b63bd6 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventsEndpointWebExtension.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventsEndpointWebExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package org.springframework.boot.actuate.audit; -import java.util.Date; +import java.time.OffsetDateTime; import org.springframework.boot.actuate.audit.AuditEventsEndpoint.AuditEventsDescriptor; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; @@ -40,10 +40,9 @@ public class AuditEventsEndpointWebExtension { } @ReadOperation - public WebEndpointResponse eventsWithPrincipalDateAfterAndType( - @Nullable String principal, Date after, @Nullable String type) { - AuditEventsDescriptor auditEvents = this.delegate - .eventsWithPrincipalDateAfterAndType(principal, after, type); + public WebEndpointResponse events(@Nullable String principal, + OffsetDateTime after, @Nullable String type) { + AuditEventsDescriptor auditEvents = this.delegate.events(principal, after, type); return new WebEndpointResponse<>(auditEvents); } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventsJmxEndpointExtension.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventsJmxEndpointExtension.java index ee529b9434..69f53068ea 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventsJmxEndpointExtension.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEventsJmxEndpointExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package org.springframework.boot.actuate.audit; -import java.util.Date; +import java.time.OffsetDateTime; import org.springframework.boot.actuate.audit.AuditEventsEndpoint.AuditEventsDescriptor; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; @@ -39,15 +39,14 @@ public class AuditEventsJmxEndpointExtension { } @ReadOperation - public AuditEventsDescriptor eventsWithDateAfter(Date dateAfter) { - return this.delegate.eventsWithPrincipalDateAfterAndType(null, dateAfter, null); + public AuditEventsDescriptor eventsAfter(OffsetDateTime after) { + return this.delegate.events(null, after, null); } @ReadOperation - public AuditEventsDescriptor eventsWithPrincipalAndDateAfter(String principal, - Date dateAfter) { - return this.delegate.eventsWithPrincipalDateAfterAndType(principal, dateAfter, - null); + public AuditEventsDescriptor eventsWithPrincipalAndAfter(String principal, + OffsetDateTime after) { + return this.delegate.events(principal, after, null); } } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/InMemoryAuditEventRepository.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/InMemoryAuditEventRepository.java index 914cf85616..e4ac680400 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/InMemoryAuditEventRepository.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/InMemoryAuditEventRepository.java @@ -16,7 +16,7 @@ package org.springframework.boot.actuate.audit; -import java.util.Date; +import java.time.Instant; import java.util.LinkedList; import java.util.List; @@ -70,7 +70,7 @@ public class InMemoryAuditEventRepository implements AuditEventRepository { } @Override - public List find(String principal, Date after, String type) { + public List find(String principal, Instant after, String type) { LinkedList events = new LinkedList<>(); synchronized (this.monitor) { for (int i = 0; i < this.events.length; i++) { @@ -83,10 +83,11 @@ public class InMemoryAuditEventRepository implements AuditEventRepository { return events; } - private boolean isMatch(String principal, Date after, String type, AuditEvent event) { + private boolean isMatch(String principal, Instant after, String type, + AuditEvent event) { boolean match = true; match = match && (principal == null || event.getPrincipal().equals(principal)); - match = match && (after == null || event.getTimestamp().compareTo(after) >= 0); + match = match && (after == null || event.getTimestamp().isAfter(after)); match = match && (type == null || event.getType().equals(type)); return match; } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/listener/AuditApplicationEvent.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/listener/AuditApplicationEvent.java index 9d77acf1c7..e205da9349 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/listener/AuditApplicationEvent.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/listener/AuditApplicationEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package org.springframework.boot.actuate.audit.listener; -import java.util.Date; +import java.time.Instant; import java.util.Map; import org.springframework.boot.actuate.audit.AuditEvent; @@ -60,13 +60,13 @@ public class AuditApplicationEvent extends ApplicationEvent { /** * Create a new {@link AuditApplicationEvent} that wraps a newly created * {@link AuditEvent}. - * @param timestamp the time stamp + * @param timestamp the timestamp * @param principal the principal * @param type the event type * @param data the event data - * @see AuditEvent#AuditEvent(Date, String, String, Map) + * @see AuditEvent#AuditEvent(Instant, String, String, Map) */ - public AuditApplicationEvent(Date timestamp, String principal, String type, + public AuditApplicationEvent(Instant timestamp, String principal, String type, Map data) { this(new AuditEvent(timestamp, principal, type, data)); } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/convert/IsoOffsetDateTimeConverter.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/convert/IsoOffsetDateTimeConverter.java index a4f1bf7e7c..8babd7cd2c 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/convert/IsoOffsetDateTimeConverter.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/convert/IsoOffsetDateTimeConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,29 +18,25 @@ package org.springframework.boot.actuate.endpoint.convert; import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; -import java.util.Date; -import java.util.concurrent.TimeUnit; import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.ConverterRegistry; import org.springframework.util.StringUtils; /** - * A {@link String} to {@link Date} {@link Converter} that uses + * A {@link String} to {@link OffsetDateTime} {@link Converter} that uses * {@link DateTimeFormatter#ISO_OFFSET_DATE_TIME ISO offset} parsing. * * @author Andy Wilkinson * @author Stephane Nicoll * @since 2.0.0 */ -public class IsoOffsetDateTimeConverter implements Converter { +public class IsoOffsetDateTimeConverter implements Converter { @Override - public Date convert(String source) { + public OffsetDateTime convert(String source) { if (StringUtils.hasLength(source)) { - OffsetDateTime offsetDateTime = OffsetDateTime.parse(source, - DateTimeFormatter.ISO_OFFSET_DATE_TIME); - return new Date(TimeUnit.SECONDS.toMillis(offsetDateTime.toEpochSecond())); + return OffsetDateTime.parse(source, DateTimeFormatter.ISO_OFFSET_DATE_TIME); } return null; } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/annotation/JmxEndpointOperationFactory.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/annotation/JmxEndpointOperationFactory.java index 81e625914a..8070f999f8 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/annotation/JmxEndpointOperationFactory.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/annotation/JmxEndpointOperationFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,9 @@ package org.springframework.boot.actuate.endpoint.jmx.annotation; import java.lang.reflect.Method; import java.lang.reflect.Parameter; +import java.time.Instant; import java.util.ArrayList; import java.util.Collections; -import java.util.Date; import java.util.List; import java.util.Map; import java.util.function.Supplier; @@ -113,7 +113,7 @@ class JmxEndpointOperationFactory implements OperationFactory { if (type.isEnum()) { return String.class; } - if (Date.class.isAssignableFrom(type)) { + if (Instant.class.isAssignableFrom(type)) { return String.class; } if (type.getName().startsWith("java.")) { diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/flyway/FlywayEndpoint.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/flyway/FlywayEndpoint.java index a66d227f35..37c7d4ae85 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/flyway/FlywayEndpoint.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/flyway/FlywayEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package org.springframework.boot.actuate.flyway; -import java.util.Date; +import java.time.Instant; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -99,7 +99,7 @@ public class FlywayEndpoint { private final String installedBy; - private final Date installedOn; + private final Instant installedOn; private final Integer installedRank; @@ -113,7 +113,7 @@ public class FlywayEndpoint { this.script = info.getScript(); this.state = info.getState(); this.installedBy = info.getInstalledBy(); - this.installedOn = info.getInstalledOn(); + this.installedOn = Instant.ofEpochMilli(info.getInstalledOn().getTime()); this.installedRank = info.getInstalledRank(); this.executionTime = info.getExecutionTime(); } @@ -150,7 +150,7 @@ public class FlywayEndpoint { return this.installedBy; } - public Date getInstalledOn() { + public Instant getInstalledOn() { return this.installedOn; } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/GitInfoContributor.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/GitInfoContributor.java index 32d2e0dccb..96733462d1 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/GitInfoContributor.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/GitInfoContributor.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package org.springframework.boot.actuate.info; -import java.util.Date; +import java.time.Instant; import java.util.Map; import java.util.Properties; @@ -59,7 +59,7 @@ public class GitInfoContributor extends InfoPropertiesInfoContributor contexts; - private final Date dateExecuted; + private final Instant dateExecuted; private final String deploymentId; @@ -142,7 +142,8 @@ public class LiquibaseEndpoint { this.changeLog = ranChangeSet.getChangeLog(); this.comments = ranChangeSet.getComments(); this.contexts = ranChangeSet.getContextExpression().getContexts(); - this.dateExecuted = ranChangeSet.getDateExecuted(); + this.dateExecuted = Instant + .ofEpochMilli(ranChangeSet.getDateExecuted().getTime()); this.deploymentId = ranChangeSet.getDeploymentId(); this.description = ranChangeSet.getDescription(); this.execType = ranChangeSet.getExecType(); @@ -170,7 +171,7 @@ public class LiquibaseEndpoint { return this.contexts; } - public Date getDateExecuted() { + public Instant getDateExecuted() { return this.dateExecuted; } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/InMemoryTraceRepository.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/InMemoryTraceRepository.java index 1d585ef9bb..cb457053e0 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/InMemoryTraceRepository.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/InMemoryTraceRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ package org.springframework.boot.actuate.trace; +import java.time.Instant; import java.util.ArrayList; import java.util.Collections; -import java.util.Date; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -66,7 +66,7 @@ public class InMemoryTraceRepository implements TraceRepository { @Override public void add(Map map) { - Trace trace = new Trace(new Date(), map); + Trace trace = new Trace(Instant.now(), map); synchronized (this.traces) { while (this.traces.size() >= this.capacity) { this.traces.remove(this.reverse ? this.capacity - 1 : 0); diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/Trace.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/Trace.java index ba49e689a4..d3ab58201b 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/Trace.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/Trace.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package org.springframework.boot.actuate.trace; -import java.util.Date; +import java.time.Instant; import java.util.Map; import org.springframework.util.Assert; @@ -29,18 +29,18 @@ import org.springframework.util.Assert; */ public final class Trace { - private final Date timestamp; + private final Instant timestamp; private final Map info; - public Trace(Date timestamp, Map info) { + public Trace(Instant timestamp, Map info) { Assert.notNull(timestamp, "Timestamp must not be null"); Assert.notNull(info, "Info must not be null"); this.timestamp = timestamp; this.info = info; } - public Date getTimestamp() { + public Instant getTimestamp() { return this.timestamp; } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventsEndpointTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventsEndpointTests.java index 852c16aad7..66bfb7b727 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventsEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventsEndpointTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ package org.springframework.boot.actuate.audit; +import java.time.OffsetDateTime; import java.util.Collections; -import java.util.Date; import java.util.List; import org.junit.Test; @@ -44,18 +44,16 @@ public class AuditEventsEndpointTests { public void eventsWithType() { given(this.repository.find(null, null, "type")) .willReturn(Collections.singletonList(this.event)); - List result = this.endpoint - .eventsWithPrincipalDateAfterAndType(null, null, "type").getEvents(); + List result = this.endpoint.events(null, null, "type").getEvents(); assertThat(result).isEqualTo(Collections.singletonList(this.event)); } @Test - public void eventsWithDateAfter() { - Date date = new Date(); - given(this.repository.find(null, date, null)) + public void eventsCreatedAfter() { + OffsetDateTime now = OffsetDateTime.now(); + given(this.repository.find(null, now.toInstant(), null)) .willReturn(Collections.singletonList(this.event)); - List result = this.endpoint - .eventsWithPrincipalDateAfterAndType(null, date, null).getEvents(); + List result = this.endpoint.events(null, now, null).getEvents(); assertThat(result).isEqualTo(Collections.singletonList(this.event)); } @@ -63,8 +61,7 @@ public class AuditEventsEndpointTests { public void eventsWithPrincipal() { given(this.repository.find("Joan", null, null)) .willReturn(Collections.singletonList(this.event)); - List result = this.endpoint - .eventsWithPrincipalDateAfterAndType("Joan", null, null).getEvents(); + List result = this.endpoint.events("Joan", null, null).getEvents(); assertThat(result).isEqualTo(Collections.singletonList(this.event)); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventsEndpointWebIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventsEndpointWebIntegrationTests.java index c11b404abd..9cc1233d56 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventsEndpointWebIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventsEndpointWebIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ package org.springframework.boot.actuate.audit; import java.time.Instant; import java.util.Collections; -import java.util.Date; import net.minidev.json.JSONArray; import org.junit.Test; @@ -105,7 +104,7 @@ public class AuditEventsEndpointWebIntegrationTests { } private AuditEvent createEvent(String instant, String principal, String type) { - return new AuditEvent(Date.from(Instant.parse(instant)), principal, type, + return new AuditEvent(Instant.parse(instant), principal, type, Collections.emptyMap()); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventsJmxEndpointExtensionTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventsJmxEndpointExtensionTests.java index 33c9b3f583..1a5bbd46fc 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventsJmxEndpointExtensionTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventsJmxEndpointExtensionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ package org.springframework.boot.actuate.audit; +import java.time.OffsetDateTime; import java.util.Collections; -import java.util.Date; import java.util.List; import org.junit.Test; @@ -42,21 +42,21 @@ public class AuditEventsJmxEndpointExtensionTests { Collections.singletonMap("a", "alpha")); @Test - public void eventsWithDateAfter() { - Date date = new Date(); - given(this.repository.find(null, date, null)) + public void eventsCreatedAfter() { + OffsetDateTime now = OffsetDateTime.now(); + given(this.repository.find(null, now.toInstant(), null)) .willReturn(Collections.singletonList(this.event)); - List result = this.extension.eventsWithDateAfter(date).getEvents(); + List result = this.extension.eventsAfter(now).getEvents(); assertThat(result).isEqualTo(Collections.singletonList(this.event)); } @Test public void eventsWithPrincipalAndDateAfter() { - Date date = new Date(); - given(this.repository.find("Joan", date, null)) + OffsetDateTime now = OffsetDateTime.now(); + given(this.repository.find("Joan", now.toInstant(), null)) .willReturn(Collections.singletonList(this.event)); - List result = this.extension - .eventsWithPrincipalAndDateAfter("Joan", date).getEvents(); + List result = this.extension.eventsWithPrincipalAndAfter("Joan", now) + .getEvents(); assertThat(result).isEqualTo(Collections.singletonList(this.event)); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/InMemoryAuditEventRepositoryTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/InMemoryAuditEventRepositoryTests.java index 93365ed929..c926213584 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/InMemoryAuditEventRepositoryTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/InMemoryAuditEventRepositoryTests.java @@ -16,8 +16,8 @@ package org.springframework.boot.actuate.audit; -import java.util.Calendar; -import java.util.Date; +import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -99,20 +99,17 @@ public class InMemoryAuditEventRepositoryTests { @Test public void findByDate() { - Calendar calendar = Calendar.getInstance(); - calendar.set(2000, 1, 1, 0, 0, 0); - calendar.set(Calendar.MILLISECOND, 0); + Instant instant = Instant.now(); Map data = new HashMap<>(); InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository(); - repository.add(new AuditEvent(calendar.getTime(), "dave", "a", data)); - calendar.add(Calendar.DAY_OF_YEAR, 1); - repository.add(new AuditEvent(calendar.getTime(), "phil", "b", data)); - calendar.add(Calendar.DAY_OF_YEAR, 1); - Date after = calendar.getTime(); - repository.add(new AuditEvent(calendar.getTime(), "dave", "c", data)); - calendar.add(Calendar.DAY_OF_YEAR, 1); - repository.add(new AuditEvent(calendar.getTime(), "phil", "d", data)); - calendar.add(Calendar.DAY_OF_YEAR, 1); + repository.add(new AuditEvent(instant, "dave", "a", data)); + repository + .add(new AuditEvent(instant.plus(1, ChronoUnit.DAYS), "phil", "b", data)); + repository + .add(new AuditEvent(instant.plus(2, ChronoUnit.DAYS), "dave", "c", data)); + repository + .add(new AuditEvent(instant.plus(3, ChronoUnit.DAYS), "phil", "d", data)); + Instant after = instant.plus(1, ChronoUnit.DAYS); List events = repository.find(null, after, null); assertThat(events.size()).isEqualTo(2); assertThat(events.get(0).getType()).isEqualTo("c"); diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/convert/ConversionServiceParameterMapperTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/convert/ConversionServiceParameterMapperTests.java index 1d0dbb958b..d5c4c99db4 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/convert/ConversionServiceParameterMapperTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/convert/ConversionServiceParameterMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package org.springframework.boot.actuate.endpoint.convert; -import java.util.Date; +import java.time.OffsetDateTime; import org.junit.Rule; import org.junit.Test; @@ -77,7 +77,8 @@ public class ConversionServiceParameterMapperTests { @Test public void createShouldRegisterIsoOffsetDateTimeConverter() { ConversionServiceParameterMapper mapper = new ConversionServiceParameterMapper(); - Date mapped = mapper.mapParameter("2011-12-03T10:15:30+01:00", Date.class); + OffsetDateTime mapped = mapper.mapParameter("2011-12-03T10:15:30+01:00", + OffsetDateTime.class); assertThat(mapped).isNotNull(); } @@ -87,7 +88,7 @@ public class ConversionServiceParameterMapperTests { ConversionServiceParameterMapper mapper = new ConversionServiceParameterMapper( conversionService); this.thrown.expect(ParameterMappingException.class); - mapper.mapParameter("2011-12-03T10:15:30+01:00", Date.class); + mapper.mapParameter("2011-12-03T10:15:30+01:00", OffsetDateTime.class); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/convert/IsoOffsetDateTimeConverterTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/convert/IsoOffsetDateTimeConverterTests.java index 248c26c0e3..f2dd860f32 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/convert/IsoOffsetDateTimeConverterTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/convert/IsoOffsetDateTimeConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package org.springframework.boot.actuate.endpoint.convert; -import java.util.Date; +import java.time.OffsetDateTime; import org.junit.Test; @@ -34,16 +34,17 @@ public class IsoOffsetDateTimeConverterTests { @Test public void convertShouldConvertIsoDate() { IsoOffsetDateTimeConverter converter = new IsoOffsetDateTimeConverter(); - Date date = converter.convert("2011-12-03T10:15:30+01:00"); - assertThat(date).isNotNull(); + OffsetDateTime time = converter.convert("2011-12-03T10:15:30+01:00"); + assertThat(time).isNotNull(); } @Test public void registerConverterShouldRegister() { DefaultConversionService service = new DefaultConversionService(); IsoOffsetDateTimeConverter.registerConverter(service); - Date date = service.convert("2011-12-03T10:15:30+01:00", Date.class); - assertThat(date).isNotNull(); + OffsetDateTime time = service.convert("2011-12-03T10:15:30+01:00", + OffsetDateTime.class); + assertThat(time).isNotNull(); } } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/GitInfoContributorTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/GitInfoContributorTests.java index d1a6074bab..861269d5a3 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/GitInfoContributorTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/info/GitInfoContributorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package org.springframework.boot.actuate.info; -import java.util.Date; +import java.time.Instant; import java.util.Map; import java.util.Properties; @@ -45,8 +45,8 @@ public class GitInfoContributorTests { assertThat(content.get("commit")).isInstanceOf(Map.class); Map commit = (Map) content.get("commit"); Object commitTime = commit.get("time"); - assertThat(commitTime).isInstanceOf(Date.class); - assertThat(((Date) commitTime).getTime()).isEqualTo(1457098593000L); + assertThat(commitTime).isInstanceOf(Instant.class); + assertThat(((Instant) commitTime).toEpochMilli()).isEqualTo(1457098593000L); } @SuppressWarnings("unchecked") diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfigurationTests.java index 10e1406bec..5fd0c3f543 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -79,7 +79,7 @@ public class ProjectInfoAutoConfigurationTests { assertThat(buildProperties.getArtifact()).isEqualTo("demo"); assertThat(buildProperties.getName()).isEqualTo("Demo Project"); assertThat(buildProperties.getVersion()).isEqualTo("0.0.1-SNAPSHOT"); - assertThat(buildProperties.getTime().getTime()).isEqualTo(1457100965000L); + assertThat(buildProperties.getTime().toEpochMilli()).isEqualTo(1457100965000L); } @Test @@ -90,7 +90,7 @@ public class ProjectInfoAutoConfigurationTests { assertThat(buildProperties.getArtifact()).isEqualTo("acme"); assertThat(buildProperties.getName()).isEqualTo("acme"); assertThat(buildProperties.getVersion()).isEqualTo("1.0.1-SNAPSHOT"); - assertThat(buildProperties.getTime().getTime()).isEqualTo(1457088120000L); + assertThat(buildProperties.getTime().toEpochMilli()).isEqualTo(1457088120000L); } @Test diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/BuildProperties.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/BuildProperties.java index d599419e2f..5ace972c91 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/BuildProperties.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/BuildProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ package org.springframework.boot.info; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Date; +import java.time.Instant; import java.util.Properties; /** @@ -77,8 +77,8 @@ public class BuildProperties extends InfoProperties { * @return the build time * @see #get(String) */ - public Date getTime() { - return getDate("time"); + public Instant getTime() { + return getInstant("time"); } private static Properties processEntries(Properties properties) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/GitProperties.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/GitProperties.java index 64b7f73e49..066f8241ae 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/GitProperties.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/GitProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ package org.springframework.boot.info; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Date; +import java.time.Instant; import java.util.Properties; /** @@ -73,8 +73,8 @@ public class GitProperties extends InfoProperties { * @return the commit time * @see #get(String) */ - public Date getCommitTime() { - return getDate("commit.time"); + public Instant getCommitTime() { + return getInstant("commit.time"); } private static Properties processEntries(Properties properties) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/InfoProperties.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/InfoProperties.java index 483f338056..e70c9233ac 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/InfoProperties.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/info/InfoProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package org.springframework.boot.info; -import java.util.Date; +import java.time.Instant; import java.util.Iterator; import java.util.Map; import java.util.Properties; @@ -55,16 +55,16 @@ public class InfoProperties implements Iterable { } /** - * Return the value of the specified property as a {@link Date} or {@code null} if the - * value is not a valid {@link Long} representation of an epoch time. + * Return the value of the specified property as an {@link Instant} or {@code null} if + * the value is not a valid {@link Long} representation of an epoch time. * @param key the key of the property * @return the property value */ - public Date getDate(String key) { + public Instant getInstant(String key) { String s = get(key); if (s != null) { try { - return new Date(Long.parseLong(s)); + return Instant.ofEpochMilli(Long.parseLong(s)); } catch (NumberFormatException ex) { // Not valid epoch time diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/info/BuildPropertiesTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/info/BuildPropertiesTests.java index 0d69c862d1..234be8be4d 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/info/BuildPropertiesTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/info/BuildPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ public class BuildPropertiesTests { assertThat(properties.getVersion()).isEqualTo("0.0.1"); assertThat(properties.getTime()).isNotNull(); assertThat(properties.get("time")).isEqualTo("1457098593000"); - assertThat(properties.getTime().getTime()).isEqualTo(1457098593000L); + assertThat(properties.getTime().toEpochMilli()).isEqualTo(1457098593000L); } @Test diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/info/GitPropertiesTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/info/GitPropertiesTests.java index 0b7a8f7cde..bd3e6222b1 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/info/GitPropertiesTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/info/GitPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,7 +53,7 @@ public class GitPropertiesTests { createProperties("master", "abcdefg", null, "1457527123")); assertThat(properties.getCommitTime()).isNotNull(); assertThat(properties.get("commit.time")).isEqualTo("1457527123000"); - assertThat(properties.getCommitTime().getTime()).isEqualTo(1457527123000L); + assertThat(properties.getCommitTime().toEpochMilli()).isEqualTo(1457527123000L); } @Test @@ -62,7 +62,7 @@ public class GitPropertiesTests { createProperties("master", "abcdefg", null, "2016-03-04T14:36:33+0100")); assertThat(properties.getCommitTime()).isNotNull(); assertThat(properties.get("commit.time")).isEqualTo("1457098593000"); - assertThat(properties.getCommitTime().getTime()).isEqualTo(1457098593000L); + assertThat(properties.getCommitTime().toEpochMilli()).isEqualTo(1457098593000L); } @Test