Skip to content

componentMiddleware

Sebastian Schlicht edited this page Mar 12, 2014 · 7 revisions

Getting started

Install tomcat.

Open your tomcat-users.xml (on my system it lives under /etc/tomcat/tomcat-users.xml. Make sure you define the role manager-script and that you have a user that has it:

<role rolename="manager-script"/>
<user username="tomcat" password="tomcat" roles="manager-script"/>

This user must not have the role manager-gui as well.
Open your maven settings file settings.xml (on my system it lives under ~/.m2/settings.xml. Under the <servers> tag define the following:

<server>
  <id>tomcat-server</id>
  <username>your tomcat user</username>
  <password>your tomcat password</password>
</server>

Get the middleware code:

git clone https://github.com/renepickhardt/metalcon.git
git checkout feature/middleware
cd middleware

You can deploy the middleware to tomcat (make sure its running!) like this:

mvn tomcat7:deploy

The middleware is now accessible under http://localhost:8080/middleware/.

Note: this only works if the middleware is not deployed already. If it already is use mvn tomcat7:redeploy.

You can also start the middleware in a separate jetty instance using:

mvn jetty:run

The middleware is now accessible under http://localhost:8000/.

Jetty automatically detects changes in the java code and reloads recompiled java classes (current autodetect cycle is every 5 seconds). Jetty also instantly has all changed template code available. So for developing you will most likely only use jetty instead of tomcat. Sometimes autodetecting doesn't work correctly, if you are getting weird results kill jetty with Ctrl-C and restart.

Templates / Views

The middleware views are written in FreeMarker templates.

Documentation is available in the FreeMarker Manual. If you only want to program views you need to read the Template Authors Guide. If you want to develop middleware logic you should probably read the whole thing.

There exists a FreeMarker Eclipse plugin to get syntax highlighting in Eclipse, see FreeMarker plugins.

Middleware logic / Controller

The middleware is written in java with Spring.

We are using ØMQ to talk to our backend components.

Model View Controller

In the middleware MVC takes place. Thus there are three packages for Java classes that are related to the particular component area.

  • model: middleware.domain
  • view: middleware.view
  • controller: middleware.controller

View

Views are used to display the data available for a site. Each tab contains the same sort of data regardless of which page is including it. Thus view classes do only contain getters and setters, there is no data gathering.

Tab content

To create getters and setters for tab content use view.entity.tab.content.impl.<TabType>TabContent.

Tab preview

To create getters and setters for tab previews use view.entity.tab.preview.impl.<TabType>TabPreview.

Controller

Controllers are used to fill the view with data from the model. They react to a specific URL. While the view is equal for each tab, the data displayed may be not. Thus there are different controller classes that call the setters of the view to inject their data.

In controller.entity.generator.<TabType>TabGenerator there are two methods:

  • generateTabContent
  • generateTabPreview

This methods should call the setters of the view classes and inject their data this way.

While this class is used for all tabs of this type, there are classes derived from it, that are used for one specific page: controller.entity.impl.<PageType>.<PageType><TabType>TabGenerator. Besides the super-call you can inject page specific data here.

Templates

Templates are located in /src/main/webapp/WEB-INF/views/.

There are various types of template files:

  • __*.ftl: templates only providing macros (library)
  • _*.ftl: templates that do not contain content but include other template files (include)
  • *.ftl: templates that actually contain content elements (content)

The entry point for Spring is site. It includes metalcon providing several macros.
If the requested page is an entity it will include entity in entity/.
Depending on view.entityType of the current entity this template includes impl/<entity>.

Tab preview

impl/<entity> assigns entity_tabPreviews and therefore decides which tab previews will be available.
Via tab/preview/tab_preview tab/preview/impl/<tab>_tab gets included, depending on tab.entityTabType.

Tab content

entity does also include tab/content/impl/<tab>_tab via tab/content/tab_content depending on tab.entityTabType.

Clone this wiki locally