Sunday, January 13, 2013

RESTful WS use case with TomEE and ExtJS 4 MVC (full app)

Attention: This is old stuff. New build instructions here

You feel that JAX-RS is really nice but you still don't know how you could use it in a real application. This quick post shows an ExtJS app that interacts with TomEE to manage its data. There is no servlets. The interaction is via restful webservices only.

This is a full webapplication, but It will eventually be the authentication layer of our photodb project. We will use it to manage the photodb users.

Feel free to use this application as starting point for your own apps, but be aware of the ExtJS licensing structure. The code that I implemented is distributed under the Apache 2 license, but Ext JS uses GPL with some exceptions (more information here). Basically, you can use the code I did for whatever you want. But, if you plan to create non-opensource application, you will need to buy an ExtJS license.

Ok, no more boring licensing issues. Let's grab our source code.

mkdir -p ~/dev/ws/faceid-ws
cd ~/dev/ws/faceid-ws
git clone
cd faceid
mvn clean install -DskipTests=true

Done. You have just built the application in your computer. Go ahead and download the latest TomEE+ server. Extract the server, put the faceid-gui.war file under the webapps directory and start it. Your application will start at http://localhost:8080/faceid-gui.

Are you lazy? If you are using a linux box, you are also lucky. :O) Just copy and paste the lines below to a terminal and execute it. These lines will:

  1. checkout the faceid source code;
  2. build the application;
  3. download Apache TomEE+;
  4. unzip the server;
  5. copy faceid-gui.war to the "tomee/webapps" directory;
  6. start the server;
  7. tail the catalina.out log file 

mkdir -p ~/dev/ws/faceid-ws &&\
cd ~/dev/ws/faceid-ws &&\
git clone &&\
cd faceid &&\
mvn clean install -DskipTests=true &&\
cd .. &&\
wget  &&\
tar -xvzf apache-tomee-1.5.1-plus.tar.gz  &&\
mv apache-tomee-plus-1.5.1 tomee &&\
cp faceid/faceid-gui/target/faceid-gui.war tomee/webapps/ &&\
./tomee/bin/ &&\
tail -f ./tomee/logs/catalina.out

What does this application give to you?

  1. Real example of an ExtJS application with the mvc architecture.
  2. An use case for rest webservices (GET, POST, PUT, DELETE).
  3. Placeholder for your junit tests.
  4. Placeholder for your Jamine tests (see Makefile. Run "make run-jasmine").
  5. Lint integration with jslint4java (see Makefile. Run "make run-lint").
  6. Groovy integration.
  7. Yet another example of how easy is to use our beloved TomEE :O)

Read the Makefile code to see how to run jasmine

Have fun!