Skip to content

Commit c47d543

Browse files
committed
Solution of the workshop
1 parent 387b5f5 commit c47d543

File tree

64 files changed

+2608
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2608
-1
lines changed

Diff for: .gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@ crashlytics-build.properties
4343

4444
# Arquillian (warp)
4545
lib
46-
log.txt
46+
log.txt
47+
48+
# Snyk plugin
49+
.dcignore

Diff for: solution/readme.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# MicroProfile generated Applications
2+
3+
MicroProfile Starter has generated 2 MicroProfile applications for you.
4+
5+
There are 2 projects generated so that the examples for the Rest Client and/or JWT Auth specification are more realistic in the sense that they actually call an endpoint within another service.
6+
7+
. In the `service-a` directory, you can find an application with the major parts of the application. This can be seen as the 'client'.
8+
. In the `service-b` directory, you can find some endpoints which will be called by code within the client application. This can be seen as the 'backend'.
9+
10+
Have a look in the `readme.md` file in each directory which describes how each project can be built and run.
11+
12+
13+
Once both projects are built and started, open your browser at the following URL to launch the test page and execute both projects:
14+
15+
http://localhost:8080/index.html

Diff for: solution/service-a/pom.xml

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright 2019-2021 Rudy De Busscher (Payara Services)
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
21+
<modelVersion>4.0.0</modelVersion>
22+
<groupId>com.example</groupId>
23+
<artifactId>demo-service-a</artifactId>
24+
<version>1.0-SNAPSHOT</version>
25+
<packaging>war</packaging>
26+
<properties>
27+
<maven.compiler.target>11</maven.compiler.target>
28+
<failOnMissingWebXml>false</failOnMissingWebXml>
29+
<maven.compiler.source>11</maven.compiler.source>
30+
<payaraVersion>5.2021.1</payaraVersion>
31+
<final.name>demo</final.name>
32+
</properties>
33+
<inceptionYear>2019</inceptionYear>
34+
<dependencies>
35+
<dependency>
36+
<groupId>org.eclipse.microprofile</groupId>
37+
<artifactId>microprofile</artifactId>
38+
<version>4.0.1</version>
39+
<type>pom</type>
40+
<scope>provided</scope>
41+
</dependency>
42+
<dependency>
43+
<groupId>io.vertx</groupId>
44+
<artifactId>vertx-auth-jwt</artifactId>
45+
<version>3.9.5</version>
46+
</dependency>
47+
</dependencies>
48+
<build>
49+
<finalName>demo</finalName>
50+
<plugins>
51+
<plugin>
52+
<groupId>com.mycila</groupId>
53+
<artifactId>license-maven-plugin</artifactId>
54+
<version>3.0</version>
55+
<configuration>
56+
<header>src/etc/headerTemplate.txt</header>
57+
<properties>
58+
<owner>Rudy De Busscher (Payara Services)</owner>
59+
</properties>
60+
<excludes>
61+
<exclude>**/*.adoc</exclude>
62+
<exclude>**/*.pem</exclude>
63+
<exclude>**/README</exclude>
64+
<exclude>**/LICENSE.txt</exclude>
65+
<exclude>**/NOTICE.txt</exclude>
66+
<exclude>**/NOTICE</exclude>
67+
<exclude>**/converters/**</exclude>
68+
</excludes>
69+
<mapping>
70+
<java>SLASHSTAR_STYLE</java>
71+
</mapping>
72+
</configuration>
73+
<dependencies>
74+
<dependency>
75+
<groupId>com.mycila</groupId>
76+
<artifactId>license-maven-plugin-git</artifactId>
77+
<version>3.0</version>
78+
</dependency>
79+
</dependencies>
80+
<executions>
81+
<execution>
82+
<goals>
83+
<goal>check</goal>
84+
</goals>
85+
</execution>
86+
</executions>
87+
</plugin>
88+
</plugins>
89+
90+
</build>
91+
<profiles>
92+
<profile>
93+
<id>payara-micro</id>
94+
<activation>
95+
<activeByDefault>true</activeByDefault>
96+
</activation>
97+
<build>
98+
<plugins>
99+
<plugin>
100+
<groupId>fish.payara.maven.plugins</groupId>
101+
<artifactId>payara-micro-maven-plugin</artifactId>
102+
<version>1.0.5</version>
103+
<executions>
104+
<execution>
105+
<phase>package</phase>
106+
<goals>
107+
<goal>bundle</goal>
108+
</goals>
109+
</execution>
110+
</executions>
111+
<configuration>
112+
<payaraVersion>${payaraVersion}</payaraVersion>
113+
</configuration>
114+
</plugin>
115+
</plugins>
116+
</build>
117+
</profile>
118+
</profiles>
119+
</project>

Diff for: solution/service-a/readme.md

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# MicroProfile generated Application
2+
3+
## Introduction
4+
5+
MicroProfile Starter has generated this MicroProfile application for you.
6+
7+
The generation of the executable jar file can be performed by issuing the following command
8+
9+
10+
mvn clean package
11+
12+
This will create an executable jar file **demo-microbundle.jar** within the _target_ maven folder. This can be started by executing the following command
13+
14+
java -jar target/demo-microbundle.jar
15+
16+
17+
18+
19+
To launch the test page, open your browser at the following URL
20+
21+
http://localhost:8080/index.html
22+
23+
24+
## Next Step
25+
26+
Leave the server-a server running and proceed with the instructions contained in `demo/service-b/readme.md`.
27+
28+
29+
## Specification examples
30+
31+
By default, there is always the creation of a JAX-RS application class to define the path on which the JAX-RS endpoints are available.
32+
33+
Also, a simple Hello world endpoint is created, have a look at the class **HelloController**.
34+
35+
More information on MicroProfile can be found [here](https://microprofile.io/)
36+
37+
38+
### Config
39+
40+
Configuration of your application parameters. Specification [here](https://microprofile.io/project/eclipse/microprofile-config)
41+
42+
The example class **ConfigTestController** shows you how to inject a configuration parameter and how you can retrieve it programmatically.
43+
44+
### Fault tolerance
45+
46+
Add resilient features to your applications like TimeOut, RetryPolicy, Fallback, bulkhead and circuit breaker. Specification [here](https://microprofile.io/project/eclipse/microprofile-fault-tolerance)
47+
48+
The example class **ResilienceController** has an example of a FallBack mechanism where an fallback result is returned when the execution takes too long.
49+
50+
### Health
51+
52+
The health status can be used to determine if the 'computing node' needs to be discarded/restarted or not. Specification [here](https://microprofile.io/project/eclipse/microprofile-health)
53+
54+
The class **ServiceHealthCheck** contains an example of a custom check which can be integrated to health status checks of the instance. The index page contains a link to the status data.
55+
56+
### Metrics
57+
58+
The Metrics exports _Telemetric_ data in a uniform way of system and custom resources. Specification [here](https://microprofile.io/project/eclipse/microprofile-metrics)
59+
60+
The example class **MetricController** contains an example how you can measure the execution time of a request. The index page also contains a link to the metric page (with all metric info)
61+
62+
### JWT Auth
63+
64+
Using the OpenId Connect JWT token to pass authentication and authorization information to the JAX-RS endpoint. Specification [here](https://microprofile.io/project/eclipse/microprofile-rest-client)
65+
66+
Have a look at the **TestSecureController** class which calls the protected endpoint on the secondary application.
67+
The **ProtectedController** (secondary application) contains the protected endpoint since it contains the _@RolesAllowed_ annotation on the JAX-RS endpoint method.
68+
69+
The _TestSecureController_ code creates a JWT based on the private key found within the resource directory.
70+
However, any method to send a REST request with an appropriate header will work of course. Please feel free to change this code to your needs.
71+
72+
### Open API
73+
74+
Exposes the information about your endpoints in the format of the OpenAPI v3 specification. Specification [here](https://microprofile.io/project/eclipse/microprofile-open-api)
75+
76+
The index page contains a link to the OpenAPI information of your endpoints.
77+
78+
### Open Tracing
79+
80+
Allow the participation in distributed tracing of your requests through various micro services. Specification [here](https://microprofile.io/project/eclipse/microprofile-opentracing)
81+
82+
### Rest Client
83+
84+
A type safe invocation of HTTP rest endpoints. Specification [here](https://microprofile.io/project/eclipse/microprofile-rest-client)
85+
86+
The example calls one endpoint from another JAX-RS resource where generated Rest Client is injected as CDI bean.
87+

Diff for: solution/service-a/src/etc/headerTemplate.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright ${license.git.copyrightYears} ${owner}
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2019-2021 Rudy De Busscher (Payara Services)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.example.demo;
17+
18+
import javax.enterprise.context.ApplicationScoped;
19+
import javax.ws.rs.ApplicationPath;
20+
import javax.ws.rs.core.Application;
21+
22+
/**
23+
*
24+
*/
25+
@ApplicationPath("/data")
26+
@ApplicationScoped
27+
public class DemoRestApplication extends Application {
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2019-2021 Rudy De Busscher (Payara Services)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.example.demo;
17+
18+
import com.example.demo.cdi.GreetingHelper;
19+
import com.example.demo.cdi.SomeEvent;
20+
21+
import javax.enterprise.event.Event;
22+
import javax.inject.Inject;
23+
import javax.inject.Singleton;
24+
import javax.ws.rs.GET;
25+
import javax.ws.rs.Path;
26+
import javax.ws.rs.PathParam;
27+
28+
@Singleton
29+
@Path("/greet")
30+
public class GreetingResource {
31+
32+
// Added in the CDI example
33+
@Inject
34+
private GreetingHelper greetHelper;
35+
36+
// Added in the CDI events example
37+
@Inject
38+
private Event<SomeEvent> someEvent;
39+
40+
@GET
41+
@Path("{name}")
42+
public String sayHi(@PathParam("name") String name) {
43+
//return "Hello " + name; // Removed in CDI example
44+
someEvent.fire(new SomeEvent(name)); // Added in the CDI events example
45+
return greetHelper.defineGreeting(name); // Added in the CDI example
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2019-2021 Rudy De Busscher (Payara Services)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.example.demo;
17+
18+
import javax.inject.Singleton;
19+
import javax.ws.rs.GET;
20+
import javax.ws.rs.Path;
21+
22+
/**
23+
*
24+
*/
25+
@Path("/hello")
26+
@Singleton
27+
public class HelloController {
28+
29+
@GET
30+
public String sayHello() {
31+
return "Hello World";
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2019-2021 Rudy De Busscher (Payara Services)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.example.demo.cdi;
17+
18+
import javax.annotation.PostConstruct;
19+
20+
//@ApplicationScoped Commented to demonstrate the Producer
21+
public class GreetingHelper {
22+
23+
private String greetingMsg;
24+
25+
@PostConstruct
26+
public void init() {
27+
greetingMsg = "Hello From Helper %s";
28+
}
29+
30+
public String defineGreeting(String name) {
31+
return String.format(greetingMsg, name);
32+
}
33+
}

0 commit comments

Comments
 (0)