FraSCAty Velocity

10 August, 2011 (10:56) | Technical | By Jérémie Guillemotte

What is Velocity :

Apache Velocity Engine is a free open-source templating engine. Velocity permits you to use a simple yet powerful template language to reference objects defined in Java code. It is written in 100% pure Java. You can find more information on the official Apache site :

Velocity and FraSCAti (or vice versa)

Velocity is embedded in FraSCAti. We will see in this article how to deploy a little FraSCAti Velocity application.

How it’s works :

So we have made a little test project to show how Velocity can work with FraSCAti.

The composite file =>

<pre name="code" class="xml">
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<composite xmlns="" xmlns:frascati="" name="test">
  <component name="c">
    <implementation.velocity xmlns="" default="index.html" location="contents"/>
    <!-- Velocity Binding -->
    <service name="Velocity">
      <binding.http xmlns="" uri="/pages"/>
    <!-- TEST Reference -->
    <reference name="xsltservice">
      < interface="com.openwide.easysoa.frascati.velocity.XSLTService"/>
      < uri=""/>

We declare here an sca component that use an implementation velocity tag. In this tag, it is possible to declare the default page to display and the directory where to get this page.
In addition, we declare a service where we define the endpoint where the http service will be published.
Finally, we add a reference to a well known internet service : Twitter. This reference needs a java interface and a REST Binding.

In the Maven pom file, don’t forget to include FraSCAti dependencies, especially the frascati-implementation-velocity dependency :

Maven pom file =>


XSLTService interface file =>

package com.openwide.easysoa.frascati.velocity;


public interface XSLTService {
    String getTrends();

In this interface, we declare the Twitter service to use. All the handling code will be generated by FraSCAti. The only thing to do here is to declare the method to call and some informations like the REST method to use and the path where the service can be accessed. The result of the Twitter service will be returned as a String.

Java test class =>

package com.openwide.easysoa.frascati.velocity;

import org.apache.log4j.Logger;
import org.ow2.frascati.FraSCAti;
import org.ow2.frascati.assembly.factory.processor.ProcessingContextImpl;
import org.ow2.frascati.util.FrascatiException;
import org.junit.Test;
import org.junit.Before;

* Unit test for simple App.
public class VelocityTest {

    * Logger
    private static Logger logger = Logger.getLogger(VelocityTest.class.getClass());

    /** The FraSCAti platform */
    private static FraSCAti frascati;

    // Set system properties for FraSCAti
    static {
        System.setProperty("org.ow2.frascati.bootstrap", "org.ow2.frascati.bootstrap.FraSCAti");

    * Init the remote systems for the test
    * Frascati and HTTP Proxy
    * Instantiate FraSCAti and retrieve services.
    * @throws InterruptedException
    public final void setUp() throws FrascatiException, InterruptedException {
        // Start fraSCAti
        // Start Velocity test

    * Wait for an user action to stop the test
    * @throws ClientException
    * @throws SOAPException
    * @throws IOException
    public final void testWaitUntilRead() throws Exception{"Velocity test started, wait for user action to stop !");
        // Just push a key in the console window to stop the test;"Velocity test stopped !");

    * Start FraSCAti
    * @throws FrascatiException
    private static void startFraSCAti() throws FrascatiException{
        frascati = FraSCAti.newFraSCAti();

    * Start Velocity Test
    * @throws FrascatiException
    private static void startTestComposite() throws FrascatiException{
        URL compositeUrl = ClassLoader.getSystemResource("frascati-velocity-test.composite") ;
        frascati.processComposite(compositeUrl.toString(), new ProcessingContextImpl());


In this class, the job is to create and launch a FraSCAti engine, load the composite file to start the velocity test application and wait for an user action to stop the test.

And to finish, the index.html file =>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Frascati Velocity Test</title>
    <p>Working !</p>
    <p>#set( $email = "moc.tsetnull@oof" ) Email : $email</p>
    <p>Test Parameter : $testParam</p>
      Requesting Twitter service :
      Twitter test response : <br /> $xsltservice.getTrends()

So in this html file, we can see three things :

  • First, it is possible to set a ‘$email’ velocity variable and display it.
  • Second, it is very simple to get a ‘testParam’ URL parameter.
  • Third, we have a direct access to the referenced object ‘xsltservice’ which has been declared in the sca composite file. FraSCAti does the job for us.

How to run :

Open a console and type the following Maven command : mvn install
This command will build the project and launch the test.

How to test :

Open your favorite Web Browser and go to the address : http://localhost:8090/pages/index.html?testParam=test

If all works well, you can see that the index.html page is displayed :

Working !

Email : moc.tsetnull@oof

Test Parameter : test

Requesting Twitter service :
Twitter test response :
{“trends”:[{"name":"#replacebandnameswithlesbian","url":"http:\/\/\/search\/%23replacebandnameswithlesbian"},{"name":"#WhyAreYou","url":"http:\/\/\/search\/%23WhyAreYou"},{"name":"#londonriots","url":"http:\/\/\/search\/%23londonriots"},{"name":"JUSTIN WON","url":"http:\/\/\/search\/%22JUSTIN%20WON%22"},{"name":"My Lesbian Romance","url":"http:\/\/\/search\/%22My%20Lesbian%20Romance%22"},{"name":"Who Gon Stop Me","url":"http:\/\/\/search\/%22Who%20Gon%20Stop%20Me%22"},{"name":"No Church In the Wild","url":"http:\/\/\/search\/%22No%20Church%20In%20the%20Wild%22"},{"name":"Gotta Have It","url":"http:\/\/\/search\/%22Gotta%20Have%20It%22"},{"name":"Lift Off","url":"http:\/\/\/search\/%22Lift%20Off%22"},{"name":"TCA","url":"http:\/\/\/search\/TCA"}],”as_of”:”Mon, 08 Aug 2011 09:51:34 +0000″}

Some informations are displayed, you can see the test parameter included in the test url and the result of the request made on the Twitter service.

Conclusion :

It is quite easy to use Velocity in FraSCAti. The complete sources of this little test project can be downloaded at : http://github/easysoa/samples/frascati-velocity-sample.

You can find more informations about FraSCATi at

Next step with FraSCAti and Velocity in EasySOA will be to make a generic UI Scaffolder proxy.

Write a comment

Couldn't connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0)