Skip to content

Commit 0518a11

Browse files
Initial commit
0 parents  commit 0518a11

File tree

5 files changed

+131
-0
lines changed

5 files changed

+131
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target/

Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM openjdk:12
2+
3+
ADD target/simple-java-rest-docker-0.0.1-jar-with-dependencies.jar /opt/application.jar
4+
5+
EXPOSE 1337
6+
7+
ENTRYPOINT exec java -jar /opt/application.jar

pom.xml

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright (c) 2018 envimate GmbH - https://envimate.com/.
4+
~
5+
~ Licensed to the Apache Software Foundation (ASF) under one
6+
~ or more contributor license agreements. See the NOTICE file
7+
~ distributed with this work for additional information
8+
~ regarding copyright ownership. The ASF licenses this file
9+
~ to you under the Apache License, Version 2.0 (the
10+
~ "License"); you may not use this file except in compliance
11+
~ with the License. You may obtain a copy of the License at
12+
~
13+
~ http://www.apache.org/licenses/LICENSE-2.0
14+
~
15+
~ Unless required by applicable law or agreed to in writing,
16+
~ software distributed under the License is distributed on an
17+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18+
~ KIND, either express or implied. See the License for the
19+
~ specific language governing permissions and limitations
20+
~ under the License.
21+
-->
22+
23+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
24+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
25+
<modelVersion>4.0.0</modelVersion>
26+
27+
<groupId>com.envimate.examples</groupId>
28+
<artifactId>simple-java-rest-docker</artifactId>
29+
<version>0.0.1</version>
30+
31+
<dependencies>
32+
<dependency>
33+
<groupId>com.envimate.httpmate</groupId>
34+
<artifactId>core</artifactId>
35+
<version>1.0.22</version>
36+
</dependency>
37+
</dependencies>
38+
39+
<build>
40+
<plugins>
41+
<plugin>
42+
<groupId>org.apache.maven.plugins</groupId>
43+
<artifactId>maven-compiler-plugin</artifactId>
44+
<version>3.8.1</version>
45+
<configuration>
46+
<release>${java.version}</release>
47+
<source>${java.version}</source>
48+
<target>${java.version}</target>
49+
</configuration>
50+
</plugin>
51+
<plugin>
52+
<groupId>org.apache.maven.plugins</groupId>
53+
<artifactId>maven-assembly-plugin</artifactId>
54+
<executions>
55+
<execution>
56+
<phase>package</phase>
57+
<goals>
58+
<goal>single</goal>
59+
</goals>
60+
<configuration>
61+
<archive>
62+
<manifest>
63+
<mainClass>
64+
com.envimate.examples.http.Application
65+
</mainClass>
66+
</manifest>
67+
</archive>
68+
<descriptorRefs>
69+
<descriptorRef>jar-with-dependencies</descriptorRef>
70+
</descriptorRefs>
71+
</configuration>
72+
</execution>
73+
</executions>
74+
</plugin>
75+
</plugins>
76+
</build>
77+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.envimate.examples.http;
2+
3+
import com.envimate.httpmate.HttpMate;
4+
import com.envimate.httpmate.convenience.endpoints.PureJavaEndpoint;
5+
import com.envimate.httpmate.convenience.handler.HttpHandler;
6+
7+
import java.time.LocalDateTime;
8+
import java.time.format.DateTimeFormatter;
9+
10+
import static com.envimate.httpmate.HttpMate.anHttpMateConfiguredAs;
11+
import static com.envimate.httpmate.LowLevelBuilder.LOW_LEVEL;
12+
13+
public final class Application {
14+
public static void main(String[] args) {
15+
final HttpHandler httpHandler = (request, response) -> {
16+
final LocalDateTime time = LocalDateTime.now();
17+
final String dateFormatted = time.format(DateTimeFormatter.ISO_TIME);
18+
19+
response.setStatus(200);
20+
response.setBody("time now is " + dateFormatted);
21+
};
22+
23+
final HttpMate httpMate = anHttpMateConfiguredAs(LOW_LEVEL)
24+
.get("/time", httpHandler)
25+
.build();
26+
PureJavaEndpoint.pureJavaEndpointFor(httpMate)
27+
.listeningOnThePort(1337);
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.envimate.examples.http;
2+
3+
import com.envimate.httpmate.HttpMate;
4+
import com.envimate.httpmate.convenience.endpoints.PureJavaEndpoint;
5+
6+
import static com.envimate.httpmate.http.HttpRequestMethod.*;
7+
8+
public final class FakeTwitter {
9+
public static void main(String[] args) {
10+
final HttpMate httpMate = HttpMate.aLowLevelHttpMate()
11+
.callingTheHandler(System.out::println)
12+
.forRequestPath("/*").andRequestMethods(GET, POST, PUT)
13+
.build();
14+
15+
PureJavaEndpoint.pureJavaEndpointFor(httpMate).listeningOnThePort(1337);
16+
}
17+
}

0 commit comments

Comments
 (0)