Monday, December 17, 2012

PhotoDB, TomEE and httpd in the cloud

This post will show how you could install our PhotoDB application and the TomEE server in the cloud with a T1 Micro box. Go to the http://aws.amazon.com/ec2/ website and open the "Management Console".


Click on "EC2".


Click on "Launch Instance".


Click "Continue".


Select "Ubuntu 12.04.1 LTS".


Click "Continue".


Click "Continue" again.


And again...


Give a name to your box and click "Continue".


Select "Create a new Key Pair", give a name to it and click "Create & Download your Key Pair".


Select "Create a new Security Group", give a name to your new group and add the "ssh" and the "http" rules to your firewall. Click "Continue".


Click "Launch".


Click "Close".


Open a terminal and execute the following command...


Click on "Instances".


"Right-Click" your running instance and click "Connect".


Click "Connect with a standalone SSH Client" and copy the example they give.


Go to your terminal and paste this command. Change the path to your key and the user name from "root" to "ubuntu".


Hit "Enter" and say "yes".


Now it is time to install our software and start TomEE. I am going to use a TomEE server with a pre-installed photodb application. Execute the following lines in order to download it to your Amazon box.

sudo apt-get update && \
sudo apt-get install -y openjdk-7-jdk make apache2 libapache2-mod-proxy-html && \
wget https://dl.dropbox.com/u/1459144/posts/tomee-cloud/Makefile && \
make start-tomee && \
sudo a2enmod proxy_http && \
sudo vi /etc/apache2/mods-enabled/proxy.conf


The last command will open the "proxy.conf" file. Paste the following code to this file.

<VirtualHost *:80>
  ProxyRequests   Off
  ProxyPass  "/" http://localhost:8080/photodb/
  ProxyPassReverse "/" http://localhost:8080/photodb/
</VirtualHost>

Save and close the file.


Restart the Apache (httpd) server.

sudo service apache2 restart


Type "exit" to logout and copy the address of your server.


Open a browser and paste this address.


The "user name" is "michael" and the "password" is "bad".


Done. Now you have a TomEE server running in the cloud! Time to play around. Drag some pictures to your browser...


Don't forget to "terminate" our server instance once you are done playing with it, otherwise you will keep paying for the server.

FIM!

Friday, December 14, 2012

Building a Java EE application with Intellij (and Windows)

We are going to use Intellij to build our photodb project (Check Getting started with Apache TomEE by Jonathan Gallimore to see an example with Eclipse). By using an IDE to build and run the application, we make this a multi-platform task, meaning that the Windows users can follow the same steps as Ubuntu ones. In fact, I will use a Windows box for this demo. I won't install the tools. I will assume that you have a computer with the following software already installed.
Open the IDE and select "Check out from Version Control" and then "Git".



Set the Git parameters, click "Clone" and then "No".
  • https://github.com/tveronezi/photodb.git
  • C:\Users\tveronezi\dev\ws
  • photodb


We hit "No" because we want to hack the way Intellij imports Maven projects, otherwise we will see an extra generated folder (Intellij stuff) under the photodb root directory.

Now hit "Import Project", navigate to the photodb directory and click "Ok".



Select "Import project from external model", "Maven" and click "Next".


Select "Keep project files in", point it to another directory and click "Next".



Click "Next" again.



Select the JDK that you want to use in the project (Add one if necessary).


Click "Next" and then "Finish".



Now lets prepare the Application Server. We will use the bleeding edge version of TomEE. You can either build your server locally or download it here [I've already built it for you ;O)]. Now extract it to a directory of your choice.

Click on "Edit Configurations..."



Add a new configuration.



Select "TomEE Server" and "Local"



Click "Configure" and set the path of your TomEE installation.



Select the "Deployment" tab, click "Add" and "Artifact".



Select "photodb-gui:exploded".


Change the "Application Context" to "/photodb".



We are almost there. We still need to configure the JAAS. Copy "photodb/src/main/config/localLoginScript.js" to the config folder of your TomEE installation. Now add an environment variable to TomEE.


The variable is "CATALINA_OPTS" and the value is...

Djava.security.auth.login.config=C:\Users\tveronezi\dev\ws\photodb\src\main\config\login.config


Now start your server...


In a few seconds you should see an opened browser. The user is "michael" and the password is "test".


Add some photos...


That's it! 10 minutes to prepare our development environment. :O)