Dashboard > Documentation > ... > 2. Developer Guide > 2.8. Guice Services

View Info

2.8. Guice Services

 Documentation Summary
 Page Summary

Introduction

Granite Data Services brings support for Google Guice and Wideplay Warp services.

For a complete sample with Granite DS/Guice/Warp/Ejb3 entity beans working together, download graniteds-guice-1.0.0.zip and import it as a new Eclipse project.

Guice Services Configuration

In order to access your Guice services from your Flex application, you must configure your Flex services as follow:

services-config.xml
<services-config>
  <services>
    <service
      id="granite-service"
      class="flex.messaging.services.RemotingService"
      messageTypes="flex.messaging.messages.RemotingMessage">
      <destination id="cars">
        <channels>
          <channel ref="my-graniteamf"/>
        </channels>
        <properties>
          <factory>guiceFactory</factory>
          <source>test.granite.guice.services.Cars</source>
        </properties>
      </destination>
    </service>
  </services>

  <factories>
    <factory id="guiceFactory" class="org.granite.guice.GuiceServiceFactory" />
  </factories>

  <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>

The org.granite.guice.GuiceServiceFactory is declared in the <fatory> node and used in the "cars" destination (see <service> node). The <source> node then declares the test.granite.guice.services.Cars class as a Guice service (see this class in graniteds-guice-1.0.0.zip for @Inject and @Transactional annotations usage).

Additional Web Configuration (web.xml)

In order to initialize Guice and Warp persistence, you must also customize your web.xml as follow:

web.xml
<web-app version="2.4" ...>
    ...
    <!-- Guice specific context listener (initialize Guice
         injector and WARP persistence) -->
    <listener>
        <listener-class>test.granite.guice.listeners.InitNDestroy</listener-class>
    </listener>

    <!-- WARP persistence filter -->
    <filter>
        <filter-name>sessionPerRequestFilter</filter-name>
        <filter-class>com.wideplay.warp.jpa.SessionPerRequestFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>sessionPerRequestFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    ...
</web-app>

The InitNDestroy listener purpose is to initialize a Guice injector and Warp/Hibernate persistence (see details in graniteds-guice-1.0.0.zip).


Browse Space
- Pages
- Labels
- Attachments
- Mail
- Bookmarks
- News
- Activity
- Advanced

Explore Confluence
- Popular Labels
- Notation Guide

Your Account
Log In

Other Features

View a printable version of the current page.

Add Content
- Add Comment


Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.6.0 Build:#913 Sep 27, 2007)
Bug/feature request - Contact Administrators

SourceForge.net Logo
Copyright © 2007-2008 Adequate Systems. All Rights Reserved.