Skip to content

Commit 52a9aaa

Browse files
committed
helidon plus CDI plus DeltaSpike
1 parent 24736e7 commit 52a9aaa

File tree

14 files changed

+496
-0
lines changed

14 files changed

+496
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"opc": "bc84982facad2db59af9af88bef0f205a95b36df75ac3c8497a60d2f6ade816c",
3+
"oraclepaas": "cd0f7b9ccde0549075838a5b4d6f1b258062407062ad6896341a836dc981f514"
4+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# configure the Oracle infrastructure classic
2+
provider "opc" {
3+
user = "SEU E-MAIL DA CONTA ORACLE CLOUD"
4+
password = "SEU PASSWORD DA CONTA ORACLE CLOUD"
5+
identity_domain = "ID DO ORACLE IDENTiTY DOMAIN"
6+
storage_endpoint = "https://SEUIDENTITYDOMAIN.SUAREGION.storage.oraclecloud.com"
7+
storage_service_id = "NOME IDENTITY DOMANIN USADO PARA ENTRA NA ORACLE CLOUD"
8+
}
9+
10+
#Configure the Oracle Cloud Platform provider
11+
provider "oraclepaas" {
12+
user = "SEU E-MAIL DA CONTA ORACLE CLOUD"
13+
password = "SEU PASSWORD DA CONTA ORACLE CLOUD"
14+
identity_domain = "ID DO ORACLE IDENTiTY DOMAIN"
15+
application_endpoint = "https://apaas.us.oraclecloud.com"
16+
}
17+
18+
# Passo para criar um Storage Container
19+
20+
# cria um container
21+
resource "opc_storage_container" "my-apps" {
22+
name = "my-apps"
23+
}
24+
25+
# cria um objeto dentro do container
26+
# aqui ele copia o helidon-sample.zip e armazena no container chamado my-apps
27+
resource "opc_storage_object" "helidon-java-app" {
28+
name = "helidon-sample.zip"
29+
container = "${opc_storage_container.my-apps.name}"
30+
file = "helidon-sample.zip"
31+
etag = "${md5(file("helidon-sample.zip"))}"
32+
content_type = "application/zip;charset=UTF-8"
33+
}
34+
35+
# Passo para criar um Application Container
36+
resource "oraclepaas_application_container" "helidon-java-app" {
37+
name = "EventApp" # nome do app
38+
runtime = "java"
39+
archive_url = "${opc_storage_container.my-apps.name}/${opc_storage_object.helidon-java-app.name}" #localizaçaõ do objeto do Storage
40+
subscription_type = "HOURLY"
41+
42+
deployment {
43+
memory = "1G"
44+
instances = 1
45+
}
46+
}
47+
48+
output "web_url" {
49+
value = "${oraclepaas_application_container.helidon-java-app.web_url}/event"
50+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"runtime":{"majorVersion":"10"},
3+
"command":"java -jar helidon-sample.jar"
4+
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>br.org.soujava.rio</groupId>
6+
<artifactId>helidon.se.demo</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<name>helidon-se-demo</name>
9+
<description>demo of helidon se </description>
10+
11+
<properties>
12+
<helidon.version>0.11.0</helidon.version>
13+
<maven.compiler.source>11</maven.compiler.source>
14+
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
15+
<mainClass>org.jboss.weld.environment.se.StartMain</mainClass>
16+
<libs.classpath.prefix>libs</libs.classpath.prefix>
17+
<copied.libs.dir>${project.build.directory}/${libs.classpath.prefix}</copied.libs.dir>
18+
<weld.version>3.0.5.Final</weld.version>
19+
<deltaspike.version>1.9.0</deltaspike.version>
20+
</properties>
21+
22+
<!-- Dependencias para Helidon e deltaspike-->
23+
<dependencyManagement>
24+
<dependencies>
25+
<dependency>
26+
<groupId>io.helidon</groupId>
27+
<artifactId>helidon-bom</artifactId>
28+
<version>${helidon.version}</version>
29+
<type>pom</type>
30+
<scope>import</scope>
31+
</dependency>
32+
33+
<dependency>
34+
<groupId>org.apache.deltaspike.distribution</groupId>
35+
<artifactId>distributions-bom</artifactId>
36+
<version>${deltaspike.version}</version>
37+
<type>pom</type>
38+
<scope>import</scope>
39+
</dependency>
40+
</dependencies>
41+
</dependencyManagement>
42+
43+
<!-- Dependencias para Helidon-->
44+
<dependencies>
45+
<dependency>
46+
<groupId>io.helidon.bundles</groupId>
47+
<artifactId>helidon-bundles-webserver</artifactId>
48+
</dependency>
49+
<dependency>
50+
<groupId>io.helidon.config</groupId>
51+
<artifactId>helidon-config-yaml</artifactId>
52+
</dependency>
53+
54+
<!-- CDI-->
55+
<dependency>
56+
<groupId>org.jboss.weld.se</groupId>
57+
<artifactId>weld-se-shaded</artifactId>
58+
<version>${weld.version}</version>
59+
<type>jar</type>
60+
</dependency>
61+
62+
<!-- H2 DataBase-->
63+
<dependency>
64+
<groupId>com.h2database</groupId>
65+
<artifactId>h2</artifactId>
66+
<version>1.4.187</version>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>org.hibernate</groupId>
71+
<artifactId>hibernate-entitymanager</artifactId>
72+
<version>5.2.8.Final</version>
73+
</dependency>
74+
<dependency>
75+
<groupId>org.apache.deltaspike.modules</groupId>
76+
<artifactId>deltaspike-data-module-api</artifactId>
77+
<scope>compile</scope>
78+
</dependency>
79+
<dependency>
80+
<groupId>org.apache.deltaspike.modules</groupId>
81+
<artifactId>deltaspike-data-module-impl</artifactId>
82+
<scope>runtime</scope>
83+
</dependency>
84+
<dependency>
85+
<groupId>org.apache.deltaspike.cdictrl</groupId>
86+
<artifactId>deltaspike-cdictrl-api</artifactId>
87+
<scope>compile</scope>
88+
</dependency>
89+
90+
<!-- Necessario para o Java 10-->
91+
<dependency>
92+
<groupId>javax.xml.bind</groupId>
93+
<artifactId>jaxb-api</artifactId>
94+
<version>2.2.11</version>
95+
</dependency>
96+
<dependency>
97+
<groupId>com.sun.xml.bind</groupId>
98+
<artifactId>jaxb-core</artifactId>
99+
<version>2.2.11</version>
100+
</dependency>
101+
<dependency>
102+
<groupId>com.sun.xml.bind</groupId>
103+
<artifactId>jaxb-impl</artifactId>
104+
<version>2.2.11</version>
105+
</dependency>
106+
107+
</dependencies>
108+
109+
<build>
110+
<finalName>helidon-sample</finalName>
111+
<pluginManagement>
112+
<plugins>
113+
<plugin>
114+
<groupId>org.apache.maven.plugins</groupId>
115+
<artifactId>maven-jar-plugin</artifactId>
116+
<version>2.5</version>
117+
<configuration>
118+
<archive>
119+
<manifest>
120+
<addClasspath>true</addClasspath>
121+
<classpathPrefix>${libs.classpath.prefix}</classpathPrefix>
122+
<mainClass>${mainClass}</mainClass>
123+
</manifest>
124+
</archive>
125+
</configuration>
126+
</plugin>
127+
</plugins>
128+
</pluginManagement>
129+
<plugins>
130+
<plugin>
131+
<groupId>org.apache.maven.plugins</groupId>
132+
<artifactId>maven-dependency-plugin</artifactId>
133+
<executions>
134+
<execution>
135+
<id>copy-dependencies</id>
136+
<phase>prepare-package</phase>
137+
<goals>
138+
<goal>copy-dependencies</goal>
139+
</goals>
140+
<configuration>
141+
<outputDirectory>${copied.libs.dir}</outputDirectory>
142+
<overWriteReleases>false</overWriteReleases>
143+
<overWriteSnapshots>false</overWriteSnapshots>
144+
<overWriteIfNewer>true</overWriteIfNewer>
145+
<overWriteIfNewer>true</overWriteIfNewer>
146+
<includeScope>runtime</includeScope>
147+
<excludeScope>test</excludeScope>
148+
</configuration>
149+
</execution>
150+
</executions>
151+
</plugin>
152+
</plugins>
153+
</build>
154+
</project>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package br.org.soujava.rio.helidon.main;
2+
3+
import java.io.IOException;
4+
import java.util.Optional;
5+
6+
import javax.enterprise.event.Observes;
7+
import javax.inject.Inject;
8+
import javax.json.Json;
9+
import javax.json.JsonObject;
10+
11+
import org.jboss.weld.environment.se.events.ContainerInitialized;
12+
13+
import br.org.soujava.rio.helidon.model.Event;
14+
import br.org.soujava.rio.helidon.model.ResponseModel;
15+
import br.org.soujava.rio.helidon.repository.EventRepository;
16+
import io.helidon.webserver.Handler;
17+
import io.helidon.webserver.Routing;
18+
import io.helidon.webserver.ServerConfiguration;
19+
import io.helidon.webserver.ServerRequest;
20+
import io.helidon.webserver.ServerResponse;
21+
import io.helidon.webserver.WebServer;
22+
import io.helidon.webserver.json.JsonSupport;
23+
24+
public class App {
25+
26+
public static Optional<String> port = Optional.ofNullable(System.getenv("PORT"));
27+
28+
@Inject
29+
private EventRepository eventRepository;
30+
31+
public void main(@Observes ContainerInitialized event) throws IOException {
32+
33+
var configuration = ServerConfiguration.builder().port(Integer.parseInt(port.orElse("8080"))).build();
34+
35+
WebServer.create(configuration,Routing.builder().register(JsonSupport.create())
36+
.post("/event", Handler.create(JsonObject.class, this::addEvent))
37+
.get("/event", this::getEventsAll ))
38+
.start();
39+
}
40+
41+
private void addEvent(ServerRequest req, ServerResponse res, JsonObject json) {
42+
43+
var event = new Event(json.getString("name"), json.getString("description"), json.getString("speaker"));
44+
45+
this.eventRepository.save(event);
46+
47+
var builder = Json.createArrayBuilder();
48+
builder.add(new ResponseModel(res.status().code(), "Event Added Successfully!").forRest());
49+
50+
res.send(builder.build());
51+
}
52+
53+
private void getEventsAll(ServerRequest req, ServerResponse res) {
54+
55+
var builder = Json.createArrayBuilder();
56+
eventRepository.findAll().forEach(data -> builder.add(data.forRest()));
57+
58+
res.send(builder.build());
59+
}
60+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package br.org.soujava.rio.helidon.model;
2+
3+
import javax.json.Json;
4+
import javax.json.JsonObject;
5+
import javax.persistence.Entity;
6+
import javax.persistence.GeneratedValue;
7+
import javax.persistence.GenerationType;
8+
import javax.persistence.Id;
9+
10+
@Entity
11+
public class Event {
12+
13+
@Id
14+
@GeneratedValue(strategy = GenerationType.AUTO)
15+
private Long id;
16+
17+
private String name;
18+
19+
private String description;
20+
21+
private String speaker;
22+
23+
public Event() { }
24+
25+
public Event(String name, String description, String speaker) {
26+
super();
27+
this.name = name;
28+
this.description = description;
29+
this.speaker = speaker;
30+
}
31+
32+
public Long getId() {
33+
return id;
34+
}
35+
36+
public void setId(Long id) {
37+
this.id = id;
38+
}
39+
40+
public String getName() {
41+
return name;
42+
}
43+
44+
public void setName(String name) {
45+
this.name = name;
46+
}
47+
48+
public String getDescription() {
49+
return description;
50+
}
51+
52+
public void setDescription(String description) {
53+
this.description = description;
54+
}
55+
56+
public String getSpeaker() {
57+
return speaker;
58+
}
59+
60+
public void setSpeaker(String speaker) {
61+
this.speaker = speaker;
62+
}
63+
64+
@Override
65+
public String toString() {
66+
return "name:" + name + ", description:" + description + ", speaker:" + speaker;
67+
}
68+
69+
public JsonObject forRest() {
70+
71+
var builder = Json.createObjectBuilder();
72+
return builder.add("id", id)
73+
.add("name", name)
74+
.add("description", description)
75+
.add("speaker", speaker)
76+
.build();
77+
}
78+
}

0 commit comments

Comments
 (0)