Skip to content

Commit 58ebe20

Browse files
author
Psilo
committed
add version fetching
1 parent e5dce5b commit 58ebe20

File tree

6 files changed

+56
-1
lines changed

6 files changed

+56
-1
lines changed

Diff for: Information.template

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package @package@;
2+
3+
public class Information {
4+
public static final String BuildTime = "@buildTime@";
5+
public static final String PomVersion = "@pomVersion@";
6+
}

Diff for: pom.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
<parent>
66
<groupId>info.unterrainer.commons</groupId>
77
<artifactId>parent-pom</artifactId>
8-
<version>0.0.20</version>
8+
<version>0.0.21</version>
99
</parent>
1010

1111
<properties>
1212
<mainclass>info.unterrainer.commons.httpserver.HttpServer</mainclass>
13+
<package-path>info/unterrainer/commons/httpserver</package-path>
14+
<packg-string>info.unterrainer.commons.httpserver</packg-string>
1315
</properties>
1416

1517
<modelVersion>4.0.0</modelVersion>

Diff for: src/main/java/info/unterrainer/commons/httpserver/HttpServer.java

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import info.unterrainer.commons.httpserver.exceptions.HttpException;
1818
import info.unterrainer.commons.httpserver.exceptions.NotFoundException;
1919
import info.unterrainer.commons.httpserver.handlers.AppNameHandler;
20+
import info.unterrainer.commons.httpserver.handlers.AppVersionHandler;
2021
import info.unterrainer.commons.httpserver.handlers.DateTimeHandler;
2122
import info.unterrainer.commons.httpserver.handlers.HealthHandler;
2223
import info.unterrainer.commons.httpserver.jsons.MessageJson;
@@ -108,6 +109,7 @@ private void create() {
108109
});
109110

110111
get("/", new AppNameHandler(applicationName));
112+
get("/version", new AppVersionHandler());
111113
get("/datetime", new DateTimeHandler());
112114
get("/health", new HealthHandler());
113115

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package info.unterrainer.commons.httpserver;
2+
3+
public class Information {
4+
public static final String BuildTime = "2020-07-06T13:16:01Z";
5+
public static final String PomVersion = "0.0.19";
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package info.unterrainer.commons.httpserver.handlers;
2+
3+
import info.unterrainer.commons.httpserver.Information;
4+
import info.unterrainer.commons.httpserver.enums.Attribute;
5+
import info.unterrainer.commons.httpserver.jsons.AppVersionJson;
6+
import io.javalin.http.Context;
7+
import io.javalin.http.Handler;
8+
import lombok.RequiredArgsConstructor;
9+
10+
@RequiredArgsConstructor
11+
public class AppVersionHandler implements Handler {
12+
13+
private AppVersionJson message;
14+
15+
@Override
16+
public void handle(final Context ctx) throws Exception {
17+
if (message == null)
18+
message = AppVersionJson.builder()
19+
.PomVersion(Information.PomVersion)
20+
.BuildTime(Information.BuildTime)
21+
.build();
22+
ctx.attribute(Attribute.RESPONSE_OBJECT, message);
23+
ctx.attribute(Attribute.RESPONSE_STATUS, 200);
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package info.unterrainer.commons.httpserver.jsons;
2+
3+
import lombok.Data;
4+
import lombok.NoArgsConstructor;
5+
import lombok.experimental.SuperBuilder;
6+
7+
@Data
8+
@NoArgsConstructor
9+
@SuperBuilder(toBuilder = true)
10+
public class AppVersionJson {
11+
12+
private String BuildTime;
13+
private String PomVersion;
14+
}

0 commit comments

Comments
 (0)