5. POJO Services

 Documentation Summary
 Page Summary

Introduction

Besides EJB 3, Spring, Seam, and Guice services, Granite DS supports Plain Old Java Object (POJO) services with three different scopes: request (the default), session, and application. When a RemoteObject is configured to use this kind of destination, Granite DS instantiates or retrieves an object, depending on the scope, on which it calls the desired method.

This may be the best option for small Flex applications deployed on a simple servlet container such as Tomcat or Jetty. While it is of course possible to use a database with this kind of setup, advanced features and clean transaction isolation would require more sophisticated technologies like those available in EJB 3.

For a basic sample with POJO and Granite DS, download graniteds-***.zip and import the examples/graniteds_pojo directory as a new Eclipse project.

For another POJO sample, also see the "Hello, world" tutorial.

A Sample POJO Service

For example, you may implement a POJO service as follows:

package test.pojo;

public class PojoService {

    private int counter = 0;

    public int getCounter() {
        return ++counter;
    }
}

 

Configuration

You must also provide a services-config.xml file like this one:

services-config.xml
<?xml version="1.0" encoding="UTF-8"?>

<services-config>

    <services>
        <service
            id="granite-service"
            class="flex.messaging.services.RemotingService"
            messageTypes="flex.messaging.messages.RemotingMessage">
            <destination id="pojo">
                <channels>
                    <channel ref="my-graniteamf"/>
                </channels>
                <properties>
                    <scope>session</scope>
                    <source>test.pojo.PojoService</source>
                </properties>
            </destination>
        </service>
    </services>

    <channels>
        <channel-definition id="my-graniteamf" class="mx.messaging.channels.AMFChannel">
            <endpoint
                uri="http://{server.name}:{server.port}/{context.root}/graniteamf/amf"
                class="flex.messaging.endpoints.AMFEndpoint"/>
        </channel-definition>
    </channels>

</services-config>

Then, a RemoteObject in your MXML file may call the getCounter() method on the POJO destination. Since the scope is configured as session, the counter will increment each time you call the method. There is no need to configure a factory for this to work; POJO factory is the default.

You may alternatively specify a "*" wildcard source instead of a fully qualified class name. In this case you will specify the source property at runtime on the RemotingMessage's source property. See Flex documentation here.


Browse Space

- Pages
- Blog
- Labels
- Attachments
- Bookmarks
- Mail
- Advanced

Explore Confluence

- Popular Labels
- Notation Guide

Your Account

Log In

Other Features

Add Content


Copyright © 2011 Granite Data Services S.A.S. All Rights Reserved.