Skip to content

cyrille-leclerc/agoncal-application-petstore-ee7

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Application - Petstore Java EE 7

  • Author : Antonio Goncalves
  • Level : Intermediate
  • Technologies : Java EE 7 (JPA 2.1, CDI 1.1, Bean Validation 1.1, EJB Lite 3.2, JSF 2.2, JAX-RS 2.0), Twitter Bootstrap (Bootstrap 2.3.1, JQuery 1.9.1)
  • Application Servers : GlassFish 4.x
  • Summary : A Petstore-like application using Java EE 7

Download the code from GitHub

Test this application on CloudBees

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 7 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 based on my Java EE 6 book, and now I'm updating it again so it uses some new features of Java EE 7. The goals of this sample is to :

  • use Java EE 7 and just Java EE 7 : no external framework or dependency, it even use the java.util.logging API ;o)
  • make it simple : no complex business algorithm, the point is to bring Java EE 7 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 the goal of this EE 7 Petstore is to remain simple and to stick to Java EE 7.

The only external framework used are Arquillian and Twitter Bootstrap. Arquillian is used for integration testing. Using Maven profile, you can test services, injection, persistence... against different application servers. Twitter Bootstrap brings a bit of beauty to the web interface.

Component diagram

Glassfish 4.x

Glassfish 4.x is the Java EE 7 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 -Pglassfish4-embedded

Glassfish will launch during the build and tests will be executed in it. Other profiles will run the integration tests using other application servers or management modes :

mvn clean install -Pglassfish4-embedded
mvn clean install -Pglassfish4-managed
mvn clean install -Pwildfly-embedded

Deploy in Glassfish

This sample has been tested with GlassFish 4.x 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)

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 integartion tests, make sure you add the "Integration test coverage" widget to your Sonar dashboard (you need admin priviliges).

Developpers

Some people who worked on this project :

Bugs & Workaround

Licensing

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

antonio goncalves

About

A Java Petstore using the Java EE 7

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • CSS 44.0%
  • Java 38.0%
  • JavaScript 18.0%