• Stars
    star
    200
  • Rank 195,325 (Top 4 %)
  • Language
    Java
  • Created almost 13 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Java Petstore using the Java EE 6

Application - Petstore Java EE 6

  • Author : Antonio Goncalves
  • Level : Intermediate
  • Technologies : Java EE 6 (JPA 2.0, CDI 1.0, Bean Validation 1.0, EJB Lite 3.1, JSF 2.0, JAX-RS 1.1)
  • Application Servers : GlassFish 3.x, JBoss 7.x, TomEE 1.x
  • Summary : A Petstore-like application using Java EE 6

Download the code from GitHub

Purpose of this application

Do you remember the good old Java Petstore ? It was a sample application created by Sun for its Java BluePrints program. The Java Petstore was designed to illustrate how J2EE (and then Java EE) could be used to develop an eCommerce web application. Yes, the point of the Petstore is to sell pets online.

The Petstore had a huge momentum and we started to see plenty of Petstore-like applications flourish. The idea was to build an application with a certain technology. Let's face it, the J2EE version was far too complex using plenty of (today outdated) design patterns. When I wrote my Java EE 5 book back in 2006, I decided to write a Petstore-like application but much simpler. But again, it's out-dated today.

So what you have here is another Petstore-like application but using Java EE 6 and all its goodies (CDI, EJB Lite, REST interface). It is based on the Petstore I developped for my Java EE 5 book (sorry, it's written in French). I've updated it to be more Java EE 6, ask some friends to contribute, and here we are. The goals of this sample is to :

  • use Java EE 6 and just Java EE 6 : no external framework or dependency, we even use the java.util.logging API ;o)
  • make it simple : no complex business algorithm, the point is to bring Java EE 6 technologies together to create an eCommerce website

If you want to use a different web interface, external frameworks, add some sexy alternative JVM language… feel free to fork the code. But we won't do it. We want this EE 6 Petstore to remain simple and to stick to Java EE 6.

The only external framework that we use is Arquillian. Arquillian is used for integration testing. Using Maven profile, you can test services, injection, persistence... against different application servers

Component diagram

Glassfish 3.1.2

Glassfish is the Java EE 6 reference implementation.

Compile and package

Being Maven centric, you can compile and package it with mvn clean compile, mvn clean package or mvn clean install. The package and install phase will automatically trigger the unit tests. Once you have your war file, you can deploy it.

GlassFish is the default deployment application server, so you don't need to use any Maven profile. But if you wanted you could do mvn -Pglassifh-embedded clean install.

Test with Glassfish embedded

Launching tests under Glassfish is straight forward. You only have to lauch :

mvn clean install -Pglassfish-embedded

Galssfish will launch during the build and tests will be executed in it.

Deploy in Glassfish

This sample has been tested with GlassFish 3.1.2 in several modes :

  • GlassFish runtime : download GlassFish, install it, start GlassFish (typing asadmin start-domain) and once the application is packaged deploy it (using the admin console or the command line asadmin deploy target/applicationPetstore.war)
  • GlassFish embedded : use the GlassFish Maven Plugin by running mvn clean package embedded-glassfish:run (you might have to increase Perm Gen space with MAVEN_OPTS set to -XX:MaxPermSize=128m)

JBoss 7.1.1

JBoss 7.x implements Java EE 6.

Test with JBoss managed

To launch tests under JBoss you first should install JBoss and set the environnment variable JBOSS_HOME to JBoss installation directory. Once this is done you'll launch the test with this command

mvn clean install -Pjbossas7-managed

During the build, Arquillian will launch JBoss and execute the tests in it.

Deploy with JBoss 7.1.1

Execute the sample

Once deployed go to the following URL and start buying some pets: http://localhost:8080/applicationPetstore. You can use these login/passwd : marc/marc bill/bill jobs/jobs

The admin REST interface allows you to create/update/remove items in the catalog, orders or customers. You can run the following curl commands :

  • curl -X GET http://localhost:8080/applicationPetstore/rs/catalog/categories
  • curl -X GET http://localhost:8080/applicationPetstore/rs/catalog/products
  • curl -X GET http://localhost:8080/applicationPetstore/rs/catalog/items

You can also get a JSON reprensetation as follow :

  • curl -X GET -H "accept: application/json" http://localhost:8080/applicationPetstore/rs/catalog/items

Third Party Tools & Frameworks

Twitter Bootstrap

When, like me, you have no web designer skills at all and your web pages look ugly, you use Twitter Bootstrap ;o)

Silk Icons

I use Silk Icons which are in Creative Commons

Arquillian

JRebel

JRebel is a JVM-plugin that makes it possible for Java developers to instantly see any code change made to an app without redeploying. It is very useful when you develop in a managed environment like application servers. If you need/want to use JRebel, just follow the manual. To generate a rebel.xml file just do mvn jrebel:generate

Sonar

Sonar provides services for continuous inspection of code quality. I use it to have some metrics on the Yaps Petstore (and produce, hopefully, not too ugly code with good code coverage). You can also use it to get some metrics. Download, install and run Sonar with mvn -Pjacoco,glassfish3 install sonar:sonar (or mvn -Pjacoco,jboss7 install sonar:sonar to run on JBoss 7). For integration testing we need to use JaCoCo. To view the code coverage of integration tests, make sure you add the "Integration test coverage" widget to your Sonar dashboard (you need admin privileges).

Developpers

Some people who worked on this project :

Bugs & Workaround

  • [If you can't deploy with Intellij IDEAand JDK 7 on JBoss](http://youtrack.jetbrains.com/issue/IDEA-826) : -Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.KQueueSelectorProvider

Licensing

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

antonio goncalves

More Repositories

1

agoncal-book-javaee7

Code of my Java EE 7 Book
Java
279
star
2

agoncal-application-petstore-ee7

A Java Petstore using the Java EE 7
Java
193
star
3

agoncal-sample-jaxrs

Samples about JAX-RS
Java
90
star
4

agoncal-application-conference

Angular 2 application with micro services
Java
46
star
5

agoncal-sample-javaee

Samples about Java EE
Java
38
star
6

agoncal-sample-cdi

Samples about CDI
Java
38
star
7

baking-microservice-pie

This is the code of the demos for the "Baking a Microservice Pie" talk given by @radcortez and @agoncal
Java
37
star
8

agoncal-application-cdbookstore

An e-commerce web app that sells CDs and Books
Java
32
star
9

agoncal-fascicle-quarkus

Code of my fascicle "Understanding Quarkus"
Java
31
star
10

agoncal-fascicle-quarkus-pract

Code of my fascicle "Practicing Quarkus"
Java
26
star
11

agoncal-fascicle-jpa

Code of my JPA Fascicle
Java
24
star
12

agoncal-course-quarkus-microservices

Code for of course "Building Microservices with Quarkus"
Java
23
star
13

agoncal-course-quarkus-starting

Code of my course "Starting with Quarkus"
HTML
23
star
14

agoncal-sample-angular

Angular samples
TypeScript
23
star
15

agoncal-training-javaee6

The labs I use for my Beginning Java EE 6 Training
Java
20
star
16

swagger-ui-angular6

Angular6 + Swagger-UI example app
TypeScript
16
star
17

agoncal-training-javaee7

The labs I use for my Beginning Java EE 7 Training http://www.antoniogoncalves.org
Java
11
star
18

agoncal-sample-quarkus

Quarkus samples
Java
11
star
19

agoncal-course-quarkus-jpa-panache

Code of my course "Building a Quarkus Application with JPA & Panache"
Java
10
star
20

agoncal-book-javaee6

Code of my Java EE 6 Book
Java
9
star
21

agoncal-talks

Material of the talks I did
HTML
9
star
22

agoncal-sample-arquilian

Samples about Arquillian
Java
6
star
23

agoncal-sample-jpa

Java
6
star
24

agoncal-book-javaee5

Code for the book "Cahier du Programmeur - Java EE 5"
Java
5
star
25

agoncal-training-javaee6-advanced

The labs I use for my Advanced Java EE 6 Training
Java
4
star
26

agoncal-other

HTML
4
star
27

agoncal-sample-jhipster

JHipster samples
Java
4
star
28

agoncal-articles

Material of the articles I wrote
Java
4
star
29

agoncal-sample-forge

Samples about JBoss Forge
Java
4
star
30

agoncal-application-cdbookstore-ms

An e-commerce web app that sells CDs and Books using Micro Services
Java
3
star
31

agoncal-formation-microservices

Code pour la formation Microservices
Java
3
star
32

agoncal-fascicle-bean-validation

Code of my Bean Validation Fascicle
Java
2
star
33

agoncal-sample-jsf

Samples about JSF
HTML
2
star
34

agoncal-training-microservices

Code for the Microservices training
Java
2
star
35

agoncal-sample-bean-validation

Samples about Bean Validation
Java
1
star
36

agoncal-fascicle-microprofile

Code of my future MicroProfile Fascicle
Java
1
star
37

agoncal-sample-ejb

Samples about EJBs
Java
1
star
38

agoncal-sample-microservices

Samples about Micro Services
Java
1
star
39

agoncal-sample-jaxws

Samples about SOAP Web Services
Java
1
star
40

agoncal-mslearn-java-petclinic-simplified

Java
1
star
41

agoncal-sample-azure

Samples about Azure
Java
1
star
42

agoncal-sample-github-actions

Samples using GitHub actions
Shell
1
star
43

agoncal-sample-mapstruct

Mapstructu Samples
Java
1
star