Amalegeni-WS setup

Java 7 / Go

You need to have Java on your system, as well as Ant. Since Amalegeni-WS is using the latest Jetty libraries (well, what was considered the latest in Aug 2013), you need Java 7 The jdk that was used to write these examples was jdk1.7.0_25.

And of course: if you want to run the generated Go code, then you better have Go installed too!

Setup Amalegeni

See the amalegeni ../download page. Getting the latest version is always the best advice. The version used for writing these examples was 1.1.4.

Sample installation run :

cd /opt
wget -q -O - http://www.accumulator.be/amalegeni/dist/amalegeni-1.1.4.tgz | sudo tar xvfz -
sudo ln -s amalegeni-1.1.4 amalegeni11

Download the Amalegeni-WS tar-ball

Grab this tarball: amalegeniws-0.9.tgz and unpack it somewhere on your system. Your ~/tmp directory would be a good location!

wget -q -O - http://www.accumulator.be/amalegeni/amalegeniws/amalegeniws-0.9.tgz | tar xfz - 

Configure your database

Create a user in your oracle database: connect with sql-plus as an administrator, and run these commands:

create user amalegeni identified by amalegeni 
    default tablespace users 
    temporary tablespace temp 
    quota unlimited on users;

grant connect, resource to amalegeni;

grant create view to amalegeni;

Change the database connection parameters of amalegeni-ws

Edit the OracleBaseService java file, to define the hostname for your database server, and the database instance name.

cd amalegeniws-0.9
vi src/amalegeniws/common/OracleBaseService.java

Goto line 18, and swap 'YOUR_DB_SERVER' for the hostname of your db server (which may be localhost), and replace 'YOUR_DB_INSTANCE' with the Oracle instance name of your database.

String database = "jdbc:oracle:thin:@[YOUR_DB_SERVER]:1521:[YOUR_DB_INSTANCE]";

Let's see if it compiles and runs!

As stated earlier, you need Java 7, so ensure that it's installed and your PATH and CLASSPATH variables are pointing to the right JDK!

Now enter 'ant run' (assuming you are still in the amalegeniws-0.9 subdir) :

ant run

.. 
..

run:
     [java] 2013-09-03 02:19:26.051:INFO:oejs.Server:main: jetty-9.0.4.v20130625
     [java] 2013-09-03 02:19:26.203:INFO:oejs.ServerConnector:main: Started ServerConnector@1ceb49a5{HTTP/1.1}{0.0.0.0:8181}

No errors? Perfect!

Your webserver is now up and running, ready to serve! (Keep it running, don't kill it yet)

Let's see if we can talk to the db

Following commands can be executed on the command line or enter the URL's into a browser.

wget -q -O - "http://localhost:8181/CountrySetup.check()"
ORA-00942: table or view does not exist

The country table has not been created yet, so it's normal to get the table-doesn-t-exist error.

Interludium: in case you are wondering where to find the source code of what gets executed, it's defined in the file: src/amalegeniws/proc/CountrySetup-csae.mlg

Let's move ahead now, and create the table, insert data, then check again.

wget -q -O - "http://localhost:8181/CountrySetup.createCountryTable()"

wget -q -O - "http://localhost:8181/CountrySetup.insertCountryData()"

wget -q -O - "http://localhost:8181/CountrySetup.check()"
252

That's better! The country table exists now, with 252 entries. By the way: thanks to Geonames for the data!

Hint: if you leave out the method-name, you get a list of the methods in that package:

wget -q -O - "http://localhost:8181/CountrySetup"

String check()
void createCountryTable()
void insertCountryData()
int countCountryData()
String getNow()

.. and if you leave out the package name, then you get a list of packages:

wget -q -O - "http://localhost:8181"

CountryService
CountrySetup
CountryTeardown

Alternative setup

As an alternative way to create and populate the table, you can also run the following ant target:

ant countrysetup

And in the end, when you are done experimenting and want to get rid of the table, run this (but don't do it now) :

ant countryteardown

Try go

Try to run the generated go code:

 go run ./src/amalegeniws/proc/generated/CountryService.go
CountryService aka countryservice
--- Executing getCountry() -----------------------------------------------------
{AQ 14000000 Antarctica}
{AU 7686850 Australia}
{AR 2766890 Argentina}
{AO 1246700 Angola}
{AF 647500 Afghanistan}
{AZ 86600 Azerbaijan}
{AT 83858 Austria}
{AE 82880 United Arab Emirates}
{AM 29800 Armenia}
{AL 28748 Albania}
{AN 960 Netherlands Antilles}
{AD 468 Andorra}
{AG 443 Antigua and Barbuda}
{AS 199 American Samoa}
{AW 193 Aruba}
{AI 102 Anguilla}

Done

Okay, you've completed the setup: congrats! Now you can continue with creating your own service classes, see the examples in directory src/amalegeniws/proc/

© Willem Moors, 2009 - 2013