RIFE logo
This page last changed on May 01, 2007 by rife@klaus-meffert.de.

(See also: Out of container testing)

RIFE is a powerful framework for developing Java web applications. However, RIFE is also useful when developing non-web applications, like a standalone server and GUI applications. Let's take a look at what RIFE can offer in this area.

Using RIFE for non-web application development gives several benefits, for example RIFE's scheduler, the database connectivity layer, and the authentication layer.

It can also be of good help when developing the backend for a web application, since it makes it easy to test it without having to run it inside a full blown web application server. The next few sections will give an example of how to do this.

Writing a non-web application

To make an application work both inside an application server and as a standalone application, we need a custom participant that launches the actual application. This way the application can be launched either from the main method or when RIFE is initializing all the participants in the repository.

We'll write a very simple participant called TestParticipant to demonstrate this. First, we add it to the repository:

Participant file defining TestParticipant
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rep SYSTEM "/dtd/rep.dtd">

  <participant param="rep/test.xml">TestParticipant</participant>

The actual implementation of the participant must be implement the interface com.uwyn.rife.rep.Participant. For example, like in the TestParticipant.java below:

Implementation of a Participant
package com.imendio.test;

import com.uwyn.rife.rep.Participant;
import java.util.ArrayList;

public class TestParticipant implements Participant
  TestInstance instance;

  public TestParticipant()
    instance = new TestInstance();

  public Object getObject()
    return getObject(null);

  public Object getObject(Object o)
    return instance;

  public List getObjects()
    return getObjects(null);

  public List getObjects(Object o)
    ArrayList objectsList = new ArrayList();
    return objectsList;

As you can see we have a TestInstance object that is created in the constructor. This is the actual class that does all the work, and the participant is just a container class to launch the instance. To access the instance from the rest of the application, we just call (TestInstance)participant.getObject().

Now the application is running as a participant in an application server. How do we start it from a non-web application?

Starting a participant from the main method
public class TestApp
  TestInstance instance;

  public static void main (String args[])
    ResourceFinder resourceFinder = ResourceFinderClasspath.getInstance();
    Rep.initialize("rep/participants.xml", resourceFinder);

    TestInstance instance = (TestInstance) Rep.getParticipant("TestParticipant").getObject();

As you can see we use the same methods for accessing our application from the main method as we do from within a web application.

Document generated by Confluence on Oct 19, 2010 14:57