Last active
January 29, 2020 04:51
-
-
Save JohnyzHub/cf8e9560b8640dbfd27dc4bb98d5991c to your computer and use it in GitHub Desktop.
docker-compose for jakartaee restful jpa web application
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
FROM payara/server-full | |
LABEL Description This is a basic web application | |
COPY target/petstoreapplication.war $DEPLOY_DIR |
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
version: "3" | |
services: | |
pgres-db-service: | |
container_name: "pgres-db-service" | |
image: postgres | |
environment: | |
- POSTGRES_USER=postgres | |
- POSTGRES_PASSWORD=postgres | |
- POSTGRES_DB=postgres | |
volumes: | |
- pgres-volume:/var/lib/postgresql/data | |
restart: always | |
petstoreweb: | |
image: local:petstoreapp | |
container_name: "petstoreweb" | |
depends_on: | |
- pgres-db-service | |
ports: | |
- "8080:8080" | |
- "4848:4848" | |
restart: always | |
volumes: | |
pgres-volume: |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd"> | |
<resources> | |
<!-- Creates a connection pool in Payara to connect to a Postgresql database called "postgresql" --> | |
<jdbc-connection-pool datasource-classname="org.postgresql.ds.PGSimpleDataSource" name="java:app/jdbc/pgpetstorepool" res-type="javax.sql.DataSource"> | |
<property name="TargetServerType" value="any"></property> | |
<property name="BinaryTransfer" value="true"></property> | |
<property name="UnknownLength" value="2147483647"></property> | |
<property name="DisableColumnSanitiser" value="false"></property> | |
<property name="UseSpNego" value="false"></property> | |
<property name="SspiServiceClass" value="POSTGRES"></property> | |
<property name="ProtocolVersion" value="0"></property> | |
<property name="SendBufferSize" value="-1"></property> | |
<property name="ReceiveBufferSize" value="-1"></property> | |
<property name="LoadBalanceHosts" value="false"></property> | |
<property name="ReadOnly" value="false"></property> | |
<property name="LogUnclosedConnections" value="false"></property> | |
<property name="DatabaseName" value="postgres"></property> | |
<property name="CleanupSavepoints" value="false"></property> | |
<property name="GssLib" value="auto"></property> | |
<property name="EscapeSyntaxCallMode" value="select"></property> | |
<property name="LogServerErrorDetail" value="true"></property> | |
<property name="CancelSignalTimeout" value="10"></property> | |
<property name="PortNumber" value="0"></property> | |
<property name="DefaultRowFetchSize" value="0"></property> | |
<property name="User" value="postgres"></property> | |
<property name="DatabaseMetadataCacheFieldsMiB" value="5"></property> | |
<property name="RecvBufferSize" value="-1"></property> | |
<property name="URL" value="jdbc:postgresql://192.168.99.100/"></property> | |
<property name="Url" value="jdbc:postgresql://192.168.99.100/"></property> | |
<property name="AllowEncodingChanges" value="false"></property> | |
<property name="JaasLogin" value="true"></property> | |
<property name="PrepareThreshold" value="5"></property> | |
<property name="ReWriteBatchedInserts" value="false"></property> | |
<property name="HideUnprivilegedObjects" value="false"></property> | |
<property name="SocketTimeout" value="0"></property> | |
<property name="HostRecheckSeconds" value="10"></property> | |
<property name="Password" value="postgres"></property> | |
<property name="ConnectTimeout" value="10"></property> | |
<property name="ApplicationName" value="PostgreSQL JDBC Driver"></property> | |
<property name="PreparedStatementCacheQueries" value="256"></property> | |
<property name="Ssl" value="false"></property> | |
<property name="PreparedStatementCacheSizeMiB" value="5"></property> | |
<property name="ReadOnlyMode" value="transaction"></property> | |
<property name="LoginTimeout" value="0"></property> | |
<property name="ServerName" value="192.168.99.100"></property> | |
<property name="DatabaseMetadataCacheFields" value="65536"></property> | |
<property name="TcpKeepAlive" value="false"></property> | |
</jdbc-connection-pool> | |
<jdbc-resource jndi-name="java:app/jdbc/_petstoreDS" pool-name="java:app/jdbc/pgpetstorepool" ></jdbc-resource> | |
</resources> |
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
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1" | |
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence | |
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> | |
<persistence-unit name="petstorePU" | |
transaction-type="JTA"> | |
<description>Persistence Unit</description> | |
<jta-data-source>java:app/jdbc/_petstoreDS</jta-data-source> | |
<properties> | |
<property name="eclipselink.target-database" value="PostgreSQL" /> | |
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> | |
<property name="eclipselink.logging.level" value="INFO" /> | |
</properties> | |
</persistence-unit> | |
</persistence> |
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
<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/maven-v4_0_0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.docker.java.webapp.petstore</groupId> | |
<artifactId>petstoreapplication</artifactId> | |
<packaging>war</packaging> | |
<version>1.0</version> | |
<name>petstoreapplication Maven Webapp</name> | |
<url>http://maven.apache.org</url> | |
<properties> | |
<maven.compiler.source>11</maven.compiler.source> | |
<maven.compiler.target>11</maven.compiler.target> | |
<version.maven.compiler.plugin>3.8.1</version.maven.compiler.plugin> | |
<version.maven.war.plugin>3.2.3</version.maven.war.plugin> | |
<failOnMissingWebXml>false</failOnMissingWebXml> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | |
</properties> | |
<dependencies> | |
<!-- https://mvnrepository.com/artifact/jakarta.platform/jakarta.jakartaee-api --> | |
<dependency> | |
<groupId>jakarta.platform</groupId> | |
<artifactId>jakarta.jakartaee-api</artifactId> | |
<version>8.0.0</version> | |
</dependency> | |
<!-- maps the json to the pojo --> | |
<dependency> | |
<groupId>org.glassfish.jersey.media</groupId> | |
<artifactId>jersey-media-moxy</artifactId> | |
<version>2.29</version> | |
</dependency> | |
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql --> | |
<dependency> | |
<groupId>org.postgresql</groupId> | |
<artifactId>postgresql</artifactId> | |
<version>42.2.9</version> | |
</dependency> | |
<!-- https://mvnrepository.com/artifact/org.eclipse.persistence/eclipselink --> | |
<dependency> | |
<groupId>org.eclipse.persistence</groupId> | |
<artifactId>eclipselink</artifactId> | |
<version>2.7.5</version> | |
</dependency> | |
</dependencies> | |
<build> | |
<finalName>petstoreapplication</finalName> | |
</build> | |
</project> |
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
package com.docker.java.webapp.petstore.service; | |
import java.util.List; | |
import javax.annotation.PostConstruct; | |
import javax.ejb.Singleton; | |
import javax.inject.Inject; | |
import javax.persistence.EntityManager; | |
import javax.persistence.PersistenceContext; | |
import javax.persistence.TypedQuery; | |
import javax.ws.rs.Consumes; | |
import javax.ws.rs.GET; | |
import javax.ws.rs.Path; | |
import javax.ws.rs.Produces; | |
import javax.ws.rs.core.MediaType; | |
import javax.ws.rs.core.Response; | |
import com.docker.java.webapp.petstore.entity.Item; | |
@Path("catalog") | |
@Produces(MediaType.APPLICATION_JSON) | |
@Consumes(MediaType.APPLICATION_JSON) | |
@Singleton | |
public class PetstoreService { | |
@Inject | |
private EntityManager em; | |
@PostConstruct | |
private void init() { | |
Item item1 = new Item("Item1", "This is item1."); | |
Item item2 = new Item("Item2", "This is item2."); | |
em.persist(item1); | |
em.persist(item2); | |
} | |
@GET | |
public Response getList() { | |
TypedQuery<Item> findItems = em.createNamedQuery(Item.FIND_ALL_ITEMS, Item.class); | |
List<Item> items = findItems.getResultList(); | |
return Response.ok(items).build(); | |
} | |
} |
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
package com.docker.java.webapp.petstore.db; | |
import javax.enterprise.inject.Produces; | |
import javax.persistence.EntityManager; | |
import javax.persistence.PersistenceContext; | |
public class DatabaseProducer { | |
@Produces | |
@PersistenceContext(unitName = "petstorePU") | |
private EntityManager em; | |
} |
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
package com.docker.java.webapp.petstore.entity; | |
import java.io.Serializable; | |
import javax.persistence.Column; | |
import javax.persistence.Entity; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.GenerationType; | |
import javax.persistence.Id; | |
import javax.persistence.NamedQuery; | |
import javax.persistence.Table; | |
@Entity | |
@NamedQuery(name = Item.FIND_ALL_ITEMS, query = "SELECT i FROM Item i") | |
@Table(name = Item.TABLE_NAME) | |
public class Item implements Serializable { | |
private static final long serialVersionUID = 1L; | |
public static final String TABLE_NAME = "ITEM"; | |
public static final String FIND_ALL_ITEMS = "Item.findAllItems"; | |
@Id | |
@GeneratedValue(strategy = GenerationType.AUTO) | |
private int id; | |
@Column(name = "NAME") | |
private String name; | |
@Column(name = "DESCRIPTION") | |
private String description; | |
public Item() {} | |
public Item(String name, String description) { | |
super(); | |
this.name = name; | |
this.description = description; | |
} | |
public int getId() { | |
return id; | |
} | |
public void setId(int id) { | |
this.id = id; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public String getDescription() { | |
return description; | |
} | |
public void setDescription(String description) { | |
this.description = description; | |
} | |
@Override | |
public int hashCode() { | |
final int prime = 31; | |
int result = 1; | |
result = prime * result + ((description == null) ? 0 : description.hashCode()); | |
result = prime * result + id; | |
result = prime * result + ((name == null) ? 0 : name.hashCode()); | |
return result; | |
} | |
@Override | |
public boolean equals(Object obj) { | |
if (this == obj) | |
return true; | |
if (obj == null) | |
return false; | |
if (getClass() != obj.getClass()) | |
return false; | |
Item other = (Item) obj; | |
if (description == null) { | |
if (other.description != null) | |
return false; | |
} else if (!description.equals(other.description)) | |
return false; | |
if (id != other.id) | |
return false; | |
if (name == null) { | |
if (other.name != null) | |
return false; | |
} else if (!name.equals(other.name)) | |
return false; | |
return true; | |
} | |
@Override | |
public String toString() { | |
return "Item [id=" + id + ", name=" + name + ", description=" + description + "]"; | |
} | |
} |
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
package com.docker.java.petstore.configuration; | |
import javax.ws.rs.ApplicationPath; | |
import javax.ws.rs.core.Application; | |
@ApplicationPath("rest") | |
public class ApplicationConfiguration extends Application { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment