AW Talk is the official development team blog for AribaWeb, the Open Source component-based web application development framework for creating rich, AJAX-enabled applications with the absolute minimum of code (and no hand-coded Javascript).

AribaWeb 101: The Setup (Part 1)

When you start with some new framework like this you need to spend some time trying to really understand it. First you try to rely on high level tools which makes the development little bit easier but at the end you need to make sure you control the application and not other way around. And in this article and the next one I will try to show you two ways how you can setup your application in order to get maximum out of it.

AW ant building tools

When you look into the AribaWeb distribution or one of the first screencast you can see how easily you create new project where everything will be created for you, even the IntelliJ IDEA or Eclipse project.

As you know already there is a command called aw under the $AW_HOME/bin folder that let’s you create different types of application:


This is a helper tool based on the ant, which simplifies the creation of the project. It can be really useful if you do some initial setup or prototyping where you need to create quickly several projects. Since it’s only the ant script you can modify the type of the project anytime during your development process. 


Ant script structure

When you check out the $AW_HOME/tools/ directory for the ant file the first thing you notice there is not a one ant script which you can use but there are five. Yes five ant build scripts and each used for different type of the application (there is a common but it counts too ;-) ).

build-common.xml

This ant script is the main one because it contains all necessary properties and targets used by other scripts in order to build, deploy and even run your AribaWeb application.

Properties: 
You can override existing ant properties using well known .properties files which should be located in one of the following locations or directly inside your project’s build.xml script:

  • ${user.home}/aribaweb.build.properties
  • ${user.home}/build.properties
  • ${basedir}/build.properties
There many properties but those in this stage that you probably care about are:

Name
Description
servlet.port
Port on which your servlet container is listening
jpda.address
Debugging port on which your application listening
aw.search.path
If you try to run your AribaWeb application in debug mode and you want to have Rapid Turnaround enabled this property must be set and point to your src directory.
This can be also set by env. Variable called:
ARIBA_AW_SEARCH_PATH



build-widgets-app.xml




This ant script is usually included inside your generated AW Widget application. This script imports the common one from above. As you can see on the picture each generated ant script, which is part of your application, contains only import tag which points to this ant script.



Let’s pretend that we have created our first widgets application and inside of this build.xml you will only see these 4 tags.
What you probably might want to do is to change your debugging port on which your Tomcat is listening. In my case some other process occupied this port so I had to changed it (I think it was Skype)

In this case my tomcat will listen on this debugging port 5678. 

Properties:
In this stage you can also override some ant properties because by default this ant will generate a file called aribaweb.properties that is used by AribaWeb to correctly load and initialize your application.

Name
Description
aw.namespaceIdentifier
Since this is widget app you can also define your own widgets and if you are going to use them you will need to prefix them with some namespace. This is defined by this property. By default AW put "x"
aw.packagedResourceExtensions
Each application has many files that needs to be included for the deployment and in this property you specify what all file extensions to select.

So the project’s aribaweb.properties might look like this:




build-metaui-app.xml 

The same what we said earlier applies also for this type of application. The only difference you will find is this type of application includes some extra jar files related to meta-ui

Properties: 

Here you can also override some ant properties besides the ones we have described earlier: 

Name
Description
dependsOn.jar
Jar dependency declaration for your application. You specify the list of jars this application depends on. For this type of app it can be ariba.metaui
aw.packagedResourceExtensions
The same as in the widgets app but in this case you need to include also oss files.
Inlined-jars
You can also embed some file libraries as part of this jar
Pre-initializer
Name of the of the class file along with the method name you want to call during initialization process



build-jpa-app.xml

This type of build file you usually include in database-like applications or it is already included if you use the aw command and metaui-jpa.

Besides common tasks to build, package or deploy your application this one also contains necessary targets to initialize the configuration for your DB or O/R Mapping tool as well as starting build-in InMemory database.

Properties:

The most important properties in this type of application you care about are the ones that let you connect to the underling database through your O/R Mapping tool.

  •  hibernate.connection.driver_class
  •  hibernate.dialect
  •  hibernate.connection.username
  •  hibernate.connection.password
  •  hibernate.connection.url
  •  hibernate.hbm2ddl.auto
For the full list of properties please check the session configuration.

Application structure

When your project is generated it does not contains much but for simple prototype it’s probably ok. 


In real world you usually need to have everything under the control. So what else is there you need to be aware of in order to include other files into the project?

By default AW expects certain directory structure so it can properly register all the resources. This structure is important for the initialization process as well as for the build scripts, which expect names and specific folder layout.

Let’s start with the aribaweb.properties :

Example of aribaweb.properties
The first thing you want to do is to include aribaweb.properties file and not let the ant task to   generate it for you. Because when you are building real application these properties does not change much and became more or less static. Of course you might prefer to declare all this properties in your ant script.

The resource directories

As already mentioned for your development you need to layout your resources into structure that AW understands specifically the AWConcreteServerApplication.

In your source directory you need to create layout like this:



When AW is registering your resources directories the first thing it tries to lookup if you are in debugging mode and you want to utilize all the RapidTurnaround features:



In this branding folder (resource/webserver/branding) you store your own look and feel. Meaning that you can change each component’s style as well as images. Everything is brandable.

As you can see I put it in the source directory also aribaweb.properties, which will be taken by ant task.

There is something else you can see and it is your resource bundle files. The (resource/<locale>/strings) directory let you store your string translations. You might ask why there is another directory level or why the resource csv files are not directly under the locale?
Well the answer is simple. Not only resource files (the actually text) you want to have locale specific. There are other things like:

  • You can have images per locale
  • Maybe some other files used for templating that needs to be layout per locale. For example image that you have your Signup page and you need to send out confirmation email. Of course you do not want to use one template you want to use as many templates as many locales you will support in your application.

In this case your application can ask give me localized template so I can include it in my multipart email message, which I want to send out to user. And the only thing you do in your application is to ask for this localized file:


Code Example:
ResourceService.getService().findResourceURL("email/ConfirmationEmail.html",<user’s locale>);

And once you deploy your application the final result might look like this:



docroot:
  • This is your directory where you have your web server static resource. You can see that what we had under resource/webserver is now under docroot/config/.
  • You can also configure AW in the way so these web resources are on different server and mapped for example by your apache server.

                                                                     
Other areas to investigate:

To finish this part for you it is also worth to check how AW application is initialized. Therefore I recommend check out following:

  • Here everything starts. Once your application is created this method is called in order setup everything. 
AWConcreteServerApplication. registerResourceDirectories():
  • This one is responsible for scanning and all your directories and jar files and registering all your resources.

  • I think you can already guess from its name. This method that is executed inside registerResourceDirectories() will scan all your jar files and register all your images, oss  and everything what is in its way.


  • You want to call this method and set your own session validator if you want to have your custom authentization and authorization logic.

This is pretty much it and the next time in the part 2 I will show you different way how you can manage your build and application. If you are intellij Idea user you might be interested in this one. .



4 comments: