Skip to content

Commit

Permalink
add service for java ee app server cheatsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
rieckpil committed Mar 19, 2019
1 parent 766e5d5 commit 2766a14
Show file tree
Hide file tree
Showing 16 changed files with 197 additions and 8 deletions.
22 changes: 22 additions & 0 deletions application-server-cheatsheet/.gitignore
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/
2 changes: 2 additions & 0 deletions application-server-cheatsheet/Dockerfile
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.
5 changes: 5 additions & 0 deletions application-server-cheatsheet/buildAndRun.bat
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
3 changes: 3 additions & 0 deletions application-server-cheatsheet/buildAndRun.sh
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
46 changes: 46 additions & 0 deletions application-server-cheatsheet/pom.xml
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>
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 {

}
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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
message=Hello World Java EE 8
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>
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>
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 application-server-cheatsheet/src/test/java/sample/SampleTest.java
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 added application-server-cheatsheet/wad.jar
Binary file not shown.
11 changes: 11 additions & 0 deletions graalvm-intro/.vscode/launch.json
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"
}
]
}
16 changes: 8 additions & 8 deletions graalvm-intro/README.md
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`

0 comments on commit 2766a14

Please sign in to comment.