-
Notifications
You must be signed in to change notification settings - Fork 757
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add service for java ee app server cheatsheet
- Loading branch information
Showing
16 changed files
with
197 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
|
||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
/nbproject/private/ | ||
/build/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM payara/server-full:latest | ||
COPY target/application-server-cheatsheet.war $DEPLOY_DIR |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@echo off | ||
call mvn clean package | ||
call docker build -t de.rieckpil.blog/application-server-cheatsheet . | ||
call docker rm -f application-server-cheatsheet | ||
call docker run -d -p 8080:8080 -p 4848:4848 --name application-server-cheatsheet de.rieckpil.blog/application-server-cheatsheet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
mvn clean package && docker build -t de.rieckpil.blog/application-server-cheatsheet . | ||
docker rm -f application-server-cheatsheet || true && docker run -d -p 8080:8080 -p 4848:4848 --name application-server-cheatsheet de.rieckpil.blog/application-server-cheatsheet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>de.rieckpil.blog</groupId> | ||
<artifactId>application-server-cheatsheet</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>war</packaging> | ||
<dependencies> | ||
<dependency> | ||
<groupId>javax</groupId> | ||
<artifactId>javaee-api</artifactId> | ||
<version>8.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.microprofile</groupId> | ||
<artifactId>microprofile</artifactId> | ||
<version>2.0.1</version> | ||
<type>pom</type> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<version>2.23.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<finalName>application-server-cheatsheet</finalName> | ||
</build> | ||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<failOnMissingWebXml>false</failOnMissingWebXml> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
</properties> | ||
</project> |
9 changes: 9 additions & 0 deletions
9
application-server-cheatsheet/src/main/java/sample/JAXRSConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package sample; | ||
|
||
import javax.ws.rs.ApplicationPath; | ||
import javax.ws.rs.core.Application; | ||
|
||
@ApplicationPath("resources") | ||
public class JAXRSConfiguration extends Application { | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
application-server-cheatsheet/src/main/java/sample/SampleResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package sample; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
|
||
import javax.annotation.Resource; | ||
import javax.inject.Inject; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.PersistenceContext; | ||
import javax.sql.DataSource; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
@Path("sample") | ||
public class SampleResource { | ||
|
||
@Inject | ||
@ConfigProperty(name = "message") | ||
private String message; | ||
|
||
@PersistenceContext | ||
private EntityManager em; | ||
|
||
@Resource(lookup = "jdbc/postgres") | ||
private DataSource dataSource; | ||
|
||
@GET | ||
public Response message() throws SQLException { | ||
String databaseName = ""; | ||
|
||
try (Connection con = dataSource.getConnection()) { | ||
databaseName = con.getMetaData().getDatabaseProductName(); | ||
} | ||
|
||
return Response.ok(message + " with database: " + databaseName).build(); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
application-server-cheatsheet/src/main/resources/META-INF/microprofile-config.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
message=Hello World Java EE 8 |
9 changes: 9 additions & 0 deletions
9
application-server-cheatsheet/src/main/resources/META-INF/persistence.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<persistence version="2.2" | ||
xmlns="http://xmlns.jcp.org/xml/ns/persistence" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"> | ||
<persistence-unit name="prod" transaction-type="JTA"> | ||
<jta-data-source>jdbc/postgres</jta-data-source> | ||
</persistence-unit> | ||
</persistence> |
6 changes: 6 additions & 0 deletions
6
application-server-cheatsheet/src/main/webapp/WEB-INF/beans.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" | ||
bean-discovery-mode="all"> | ||
</beans> |
4 changes: 4 additions & 0 deletions
4
application-server-cheatsheet/src/main/webapp/WEB-INF/payara-web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<!DOCTYPE payara-web-app PUBLIC "-//Payara.fish//DTD Payara Server 4 Servlet 3.0//EN" "https://raw.githubusercontent.com/payara/Payara-Server-Documentation/master/schemas/payara-web-app_4.dtd"> | ||
<payara-web-app> | ||
<context-root>/</context-root> | ||
</payara-web-app> |
31 changes: 31 additions & 0 deletions
31
application-server-cheatsheet/src/test/java/sample/SampleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package sample; | ||
|
||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.CoreMatchers.everyItem; | ||
import static org.hamcrest.CoreMatchers.hasItem; | ||
import static org.hamcrest.CoreMatchers.hasItems; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
|
||
public class SampleTest { | ||
|
||
@Test | ||
public void testLists() { | ||
List<String> stringList = Arrays.asList("java", "jdk", "jre"); | ||
assertThat(stringList, hasItem("java")); | ||
assertThat(stringList, hasItems("java", "jdk")); | ||
assertThat(stringList, everyItem(containsString("j"))); | ||
} | ||
|
||
@Test | ||
public void testWithHamcrest() { | ||
String result = "HelloWorld!"; | ||
assertThat(result, is("HelloWorld!")); | ||
} | ||
|
||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"type": "java", | ||
"name": "CodeLens (Launch) - HelloWorld", | ||
"request": "launch", | ||
"mainClass": "HelloWorld", | ||
"projectName": "graalvm-intro" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# Codebase for the blog post [#WHATIS? GraalVM](https://rieckpil.de/whatis-graalvm/) | ||
|
||
Steps to run this project: | ||
|
||
1. Clone this Git repository | ||
2. Navigate to the folder `graalvm-intro` | ||
3. Start your docker engine | ||
4. Build the image with `docker build -t graalvmintro .` and see the native image creation and execution during build | ||
# Codebase for the blog post [#WHATIS? GraalVM](https://rieckpil.de/whatis-graalvm/) | ||
|
||
Steps to run this project: | ||
|
||
1. Clone this Git repository | ||
2. Navigate to the folder `graalvm-intro` | ||
3. Start your docker engine | ||
4. Build the image with `docker build -t graalvmintro .` and see the native image creation and execution during build | ||
5. Optional update `src/main/java` for a new Java class of your choice and add it to the `Dockerfile` |