Yet Another Petstore !


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 entire application with a certain technology). But let’s face it, the J2EE version was far too complex and was using plenty of (today outdated) design patterns. When I wrote my Java EE 5 book back in 2006 (sorry, it’s written in French), I decided to write a Petstore-like application in Java EE 5 but much simpler. But again, it’s out-dated today.

Later on I wrote a book about Java EE 6and felt there was a need to have an updated Petstore so we could discover new patterns and APIs. Unfortunately Sun/Oracle didn’t do it… so I’ve decided to do it myself (with some help from my friends Antoine Sabot-DurandBrice Leporini, Hervé Le Morvan). I’ve updated my YAPS Petstore to follow Java EE 6 and all its goodies (CDI, EJB Lite, REST interface, Bean Validation).

The goals of this sample is to :

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

If you want to use a different web interface (PrimeFaces, pure HTML, Android…), external frameworks, add some sexy alternative JVM language… feel free to fork the code and do so. But I won’t do it because I want this EE 6 Petstore to remain simple and to stick to Java EE 6.


The only external frameworks that I’ve used are Twitter Bootstrap (so my JSF pages don’t look too ugly) and Arquillian for integration testing. My goal is to be able to deploy this Yaps Petstore on different application servers. For now it’s mostly GlassFish, JBoss but some work is also happening on TomEE and I’ll try to port it later on Resin, Weblogic, Websphere…. and who knows, do some performance benchmark of the same application but on different servers.

My next task is to deploy this Yaps Petstore on CloudBees… stay tuned. In the meantime, give it a try and let me know what you think.

About these ads
Comments
20 Responses to “Yet Another Petstore !”
  1. Jaime Martinez says:

    Antonio una pregunta, veo que utilizas JSF y REST, pero existe realmente una interacción entre ellos o REST es únicamente para dejar expuestos los métodos para un posible uso.

    Disculpa por escribir en español.

    Saludos,

  2. markito says:

    Hi Antonio, what do you think about Duke’s Forest ? http://docs.oracle.com/javaee/6/tutorial/doc/glnrj.html We’re trying to create a kind of “new Pet Store” but a little bit simpler. And it’s pure Java EE 6, of course! ;)

    Please let me know your thoughts.

  3. Yes, Petstore had a huge momentum, Its nice, I will also try the I will get it properly, thanks

  4. frustrates coz java ee experts dont care for beginners says:

    OMG! this is downloading 100s of jars n poms for last 28 mins…even when I have glassfish and arquillion in local repo..will this ever stop…what the hell I need those spring jars for…this example is supposed to demo java ee….Sir I have to work hard to buy bandwidth….I can’t understand when everyone trying to learn java ee6 is having glassfish(ee reference implementation) installed on local systems,why the most of examples come with pom n bom instead of build.xml…..aargh….huh..

  5. Martin says:

    hola Antonio, soy nuevo con maven cuando corro mvn clean install -Pglassfish-embedded muestra el siguiente error:

    [INFO] Scanning for projects…
    [WARNING]
    Profile with id: ‘glassfish-embedded’ has not been activated.

    [INFO] ————————————————————————
    [INFO] Building Petstore application using Java EE 6
    [INFO] task-segment: [clean, install]
    [INFO] ————————————————————————
    [INFO] [clean:clean {execution: default-clean}]
    [INFO] Deleting file set: /home/martin/maven-pruebas/target (included: [**], excluded: [])
    [INFO] [resources:resources {execution: default-resources}]
    [INFO] Using ‘UTF-8′ encoding to copy filtered resources.
    [INFO] Copying 7 resources
    [INFO] [jrebel:generate {execution: generate-rebel-xml}]
    [INFO] Processing org.agoncal.application:petstoreee6 with packaging war
    [INFO] ————————————————————————
    [ERROR] BUILD ERROR
    [INFO] ————————————————————————
    [INFO] Error building POM (may not be this project’s POM).

    Project ID: org.glassfish.main:glassfish-parent:pom:3.1.2-b20

    Reason: Cannot find parent: net.java:jvnet-parent for project: org.glassfish.main:glassfish-parent:pom:3.1.2-b20 for project org.glassfish.main:glassfish-parent:pom:3.1.2-b20

    [INFO] ————————————————————————
    [INFO] For more information, run Maven with the -e switch
    [INFO] ————————————————————————
    [INFO] Total time: 4 seconds
    [INFO] Finished at: Fri Jul 13 23:13:16 ART 2012
    [INFO] Final Memory: 28M/165M
    [INFO] ————————————————————————

    Can you help me, thank you very much!!!

  6. pascal says:

    Merci pour cette application modèle et aussi pour le très bon livre Beginning Java™ EE 6 Platform with GlassFish™ 3.

    Je travaille avec java depuis 2 ans mais ai encore des difficultés avec CDI, interfaces et tout simplement la réalisation complète d’application web.
    Cette application vient à point dans mon étude quotidienne de java.
    Pourtant un tutorial, ou un livre, pour créer ce Petstore ne serait pas superflu. Qu’en pensez-vous ?

    Il y a quelque temps déjà j’ai suivi le très bon tutorial de Andreas Manessinger

    http://programming.manessinger.com/tutorials/an-eclipse-glassfish-java-ee-6-tutorial/

    mais ce tutorial etait sans maven.

    Pour tester le Petstore vous avez utilisé Mockito.
    Sur ohloh j’ai comparé mockito et jmockit https://www.ohloh.net/p/compare?project_0=Mockito&project_1=JMockit
    J’ai l’impression que mockito n’est plus développé. Est-ce que vous avez une préférence particulière pour mockito ?

  7. Juan Pablo says:

    Hi

    It would be possible to add security roles and make them work along with subject principals in a vendor independent way in the current state of the application ?

    I am a little confused about the pluggability of the LoginModules and how make them work without the vendor specific implementations

    Can anyone give me some guidelines?

    Sorry for my poor English.

    • agoncal says:

      Adding other security roles in my todo list. I really need to write a bit more about security : it’s a very important topic but poorly documented in EE. Stay tune

      • gbougeard says:

        Hi Antonio,
        I did authentication with SSL certs in Glassfish, so I extended AppservCertificateLoginModule instead of LoginModule as you did.
        As it’s not possible to inject EJB in this class, I did it a vintage way :
        ic = new InitialContext();
        userEJB = (UserEJB) ic.lookup(“java:global/specify-it/UserEJB”);

        I noticed you did the trick another way (maybe more CDI oriented?) with BeanManager . Could you explain the difference in the two solutions (my simple lookup and your BeanManager stuff)?

  8. laurent says:

    Bonjour Antonio,

    Très beau travail. Etant novice sur javaEE j’ai trouvé cet exemple passionnant (en plus du bouquin).

    J’aurai juste une question sur une annotation (@produces) que je ne comprends pas trop.
    dans la class : AccountController
    @Produces
    @LoggedIn
    private Customer loggedinCustomer;
    Qui appriori dit : Attention prêt pour l’injection (ou un truc du style)

    dans la class : ShoppingCartController
    @Inject
    @LoggedIn
    private Instance loggedInCustomer;
    Qui dit : inject l’instance de Customer.

    Faut-il obligatoirement un qualifier pour ce genre d’opération ? ou si ce n’est pas le cas, comment il se débrouille pour retrouver ses petits ?

    Encore merci pour ce sympathique exemple.
    PS : Tu penses essayer de le déployer sur openShift ?

  9. Franco says:

    Thank you!

  10. Nel says:

    Hi Antonio,

    Very nice post as I am looking for tutorials about JavaEE.

    I bought your book overseas and I am about halfway thru and I certainly learned a lot from it as a javaee beginner. :)
    The book does not use any maven so its easy to follow along which is good for non-maven user like me.. :)

    Just a thought though, can you somehow create a tutorial for this discussing some of the important modules?
    I know that my request is hard and that you are busy and the task may take majority of your time.

    As a ‘newbie’ I find it hard to decipher everything here so I thought that ‘what if’ there is a documentation for this sample tutorial? I think that it would be too great since everything covered here is javaee-centered.
    I think everyone would link in at this site and make this their ‘official’ javaee tutorial site..

    But its just my thought though..I will try hard to understand everything.

    Thanks.

    Regards,
    Nel

  11. Sherif says:

    Just came across the PetStore application and was wondering if there is any option to run it using a database like mySQL.

  12. sam says:

    I recently downloaded src form Github

    using the mvn clean install -PJbossas7 managed i also get following error

    INFO] Scanning for projects…
    [WARNING]
    Profile with id: ‘glassfish-embedded’ has not been activated.

    [INFO] ————————————————————————
    [INFO] Building Petstore application using Java EE 6
    [INFO] task-segment: [clean, install]
    [INFO] ————————————————————————
    [INFO] [clean:clean {execution: default-clean}]
    [INFO] Deleting file set: /home/martin/maven-pruebas/target (included: [**], excluded: [])
    [INFO] [resources:resources {execution: default-resources}]
    [INFO] Using ‘UTF-8′ encoding to copy filtered resources.
    [INFO] Copying 7 resources
    [INFO] [jrebel:generate {execution: generate-rebel-xml}]
    [INFO] Processing org.agoncal.application:petstoreee6 with packaging war
    [INFO] ————————————————————————
    [ERROR] BUILD ERROR
    [INFO] ————————————————————————
    [INFO] Error building POM (may not be this project’s POM).

    Has this been resolved? it was reported above but reply is in French?

  13. Ben Friedman says:

    Still works well. Today I cloned the github repo, ran mvn package, deployed to glassfish 4, and started the app. Thank you.

  14. Anand says:

    Hi Antonio, it’s good to hear that updated java petstore is created, could you please release a book or provide step by step instructions pdf for the setup of this application?

    • agoncal says:

      I’ll update the README and make sure everything works fine with the latest JBoss and GlassFish release.

Trackbacks
Check out what others are saying...
  1. [...] a réalisé une version actualisée de Java Pet Store en JEE pour Java 6, comme c’est expliqué ici. Cette version de la Java Pet Store est accessible publiquement sur [...]

  2. [...] no longer supported by Oracle. For this article we are using a new implementation of Petstore named Yet Another Petstore (YAP) from Antonio [...]



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 7,493 other followers

%d bloggers like this: