Christophe has posted 2 posts at DZone. View Full User Profile

An Introduction to Spring BlazeDS Integration

04.02.2009
| 154861 views |
  • submit to reddit

Last December, SpringSource and Adobe announced a partnership aimed at streamlining the integration between Spring and BlazeDS. This partnership has led to the new Spring BlazeDS Integration project, which allows you to seamlessly integrate the two technologies and build state-of-the-art Internet applications that feature a Flex front end and a Spring back end.

Whether you are a Flex developer just learning Spring or a Spring developer learning Flex, you can benefit from the powerful integration of these technologies.

Spring has emerged as the de facto standard for building the Java back end of Internet applications. Flex is rapidly becoming the preferred technology for building innovative Internet applications delivered in the browser and on the desktop (using the Adobe AIR runtime).

This article provides an introduction to the Spring BlazeDS Integration, and includes a simple example application to illustrate key concepts.

What is Spring?

The foundation of the Spring framework is a lightweight component container that implements the Inversion of Control (IoC) pattern. Using an IoC container, components don't instantiate or even look up their dependencies (the objects they work with). The container is responsible for injecting those dependencies when it creates the components (hence the term "Dependency Injection", which is also used to describe this pattern).

By enabling looser coupling between components, the Spring IoC container has proven to be a solid foundation for building robust enterprise applications.

The components managed by the Spring IoC container are called Spring beans. In addition to its core IoC container, The Spring framework includes several other modules, including support for transaction management, JDBC Data Access, and ORM Data Access. While these modules are beyond the scope of this article, it is important to note that an additional benefit of using BlazeDS with Spring is the ability to leverage these modules to facilitate the development of your remote objects. More information on the Spring framework can be found here.

What is Flex?

Flex is an environment for building Rich Internet Applications. The Flex programming model includes:

  • ActionScript - an ECMAScript-compliant, object-oriented programming language. With some syntactical  differences, ActionScript looks and feels similar to Java, and supports the same object-oriented constructs: packages, classes, inheritance, interfaces, strong (but also dynamic) typing, and so on.
  • MXML - an XML-based language that provides an abstraction on top of ActionScript, and allows parts of an application (typically the View) to be built declaratively.
  • An extensive set of class libraries. The documentation is available here in Javadoc-like format.

The Flex source code (.mxml and .as files) is compiled into Flash bytecode (.swf) that is executed at the client side by the ActionScriptVirtual Machine in Flash Player using a Just-In-Time compiler.

The Flex SDK is an open-source project. It includes the Flex component library, the compiler, the debugger, and the documentation. A complete discussion of Flex is beyond the scope of this article, but you can find more information and download the Flex SDK here.

What is BlazeDS?

BlazeDS is a set of data services that give your Flex applications additional options for data connectivity. Without BlazeDS (or, without deploying any Flex-specific component on the server side), Flex applications can access back-end data using either the HTTPService or WebService components:

  • You use the HTTPService component to send HTTP requests to a server and consume the response. Although the HTTPService is often used to consume XML, it can be used to consume responses in other formats, including JSON. The Flex HTTPService is similar to the XMLHttpRequest component available in Ajax.
  • You use the WebService component to invoke SOAP-based web services.

       BlazeDS adds the following services:

  • The Remoting Service allows your Flex application to directly invoke methods of Java objects deployed in your application server.
  • The Message Service provides a publish/subscribe infrastructure that enables your Flex application to publish messages and subscribe to a messaging destination, enabling the development of real-time data push and collaborative applications. 
  • The Proxy Service allows your Flex application to make cross-domain service requests in a secure and controlled manner. In other words, it allows your Flex application to access a service available on a different domain than the domain from where the application was downloaded (without having to deploy a crossdomain.xml policy file on the target domain).

BlazeDS is deployed as a set of JAR files as part of your web application. Like the Flex SDK, BlazeDS is an open-source project. More information is available here.

Published at DZone with permission of its author, Christophe Coenraets.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Roger Marin replied on Thu, 2009/04/02 - 9:56am

Awesome tutorial, any chance we can get the source code?

Jan Vissers (ak... replied on Thu, 2009/04/02 - 12:28pm

Sorry but I don't quite get what this Spring integration offers more that the old SpringFactory way. We used that about half a year ago without any shortcomings. Basically we had one (Spring security enabled) security service exposed via BlazeDS that took care of psuedo single sign-on for us. Every other top-level business module was fronted by a facade, which was exposed via a simple BlazeDS RO Service entry - much like a stateless session bean.


Ryan Heaton replied on Thu, 2009/04/02 - 8:02pm in response to: Jan Vissers (aka Pojo)

Agreed. What's the news here? We've had full Spring+BlazeDS support in Enunciate now for almost a year using the plain-ol' SpringFactory.

ismav ikathry replied on Mon, 2009/04/06 - 11:58pm

Hi christophe,

                        I am a new bee to the spring and flex, I had seen many tutorials and i understood how they work but my doubt is how do i start my own project from scratch. Like is there any basic file so that I can import into Myeclipse and start building my app?Hope you understood my problem.

 by the way thanks for your tutorials which give gave a good overall idea. 

 

Vamsi

Tom Celis replied on Fri, 2009/04/24 - 3:20am

Nice tutorial! But I got stuck on a problem... When I call a remote object from flex (for example: product) I get the following errormessage:

[RPC Fault faultString="[MessagingError message='Destination 'product' either does not exist or the destination has no channels defined (and the application does not define any default channels.)']" faultCode="InvokeFailed" faultDetail="Couldn't establish a connection to 'product'"]

 I've configured it exactly the way you did:

...
  <flex:message-broker />
    <bean id="product" class="product.ProductDaoImpl">
        <flex:remote-service />
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
        scope="singleton">
        <property name="configLocation" value="WEB-INF/hibernate.cfg.xml" />
    </bean>
...

Do you have any clue?

 

thx!

Jonny Langford replied on Fri, 2009/05/08 - 5:32am

I got this error when making my remote call:

[RPC Fault faultString="Destination 'mortgageService' not accessible over channel 'my-amf'." faultCode="Server.Processing" faultDetail="null"]

 A bit of digging and turns out you need a default channel defined in the services-config.xml (and you don't need an include for remoting-config.xml). So services-config.xml should start like :

    <services>
        <service-include file-path="proxy-config.xml" />
        <service-include file-path="messaging-config.xml" />
        <default-channels>
            <channel ref="my-amf" />
        </default-channels>
    </services>

Hope this helps..

Dima Ponomarev replied on Fri, 2009/05/29 - 11:49am in response to: Tom Celis

May be you need to define a channel in tag <flex:remote-service />.

See a working example at  http://dima-vp.livejournal.com/573.html.

Note that I'm using a newer version of Spring-Flex library so the tag looks like <flex:remoting-destination channels="my-amf"/>.

Chetan Minajagi replied on Mon, 2009/08/10 - 10:39am

Hi,

I have been to follow the steps outlined here.I have accordingly created a new webapp in the turnkey blazeds tomcat and come up with the required configurations as outlined in this tutorial.However when i startup tomcat and try to access this link like http://localhost:<port>/<my-webapp> .I get a Requested resource is not available.

 

I don't see any errors on the tomcat logs also to help me figure out where i am going wrong.

can  you please put up a downloadable of this tutorial that we can drop into the webapps folder and then follow with the instructions in this tutorial.

 

I have spent more than a day in getting this right but i have no clue abt where/what needs to be done.

 

Regards,

Chetan

Chetan Minajagi replied on Tue, 2009/08/11 - 9:29am in response to: Chetan Minajagi

Hi,

 

I have made some progress now but not entirely met with success though.

I have created a bean id by name 'greetingService' in a spring-config file and referring that file from web-application-context.xml

 

I am now facing this error

 

Error creating bean with name 'org.springframework.flex.remoting.RemotingDestinationExporter#0': Cannot resolve reference to bean 'greetingService' while setting bean property 'service'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'greetingService' is defined

 

Can somebody help me resolve this.

 

Regards,

Chetan

 

 

 

Damaraju Vittal replied on Mon, 2009/08/24 - 6:34am

Hi ,

Create a Default channel in service-configt.xml . Add following code in 

  <default-channels>
            <channel ref="my-amf" />
        </default-channels>   

 

Vittal.

Christopher Grant replied on Mon, 2009/10/19 - 8:39am in response to: Chetan Minajagi

Hey Chetan, I had the same problem for awhile. It's because flash isn't loading the config. I don't know why some people have the issue and some don't be heres how I fixed it. The first way is to simply add an endpoint parameter to your remoteobject tag. The more correct way is to utilize the config file. To tell flash where and which config file to use, make sure your flex compiler has the -compiler.services option added for the value, point it to the physical lcoation of your service-config.xml file. This will tell flex where to lad the service config from and allow your app to locate the server/service Cheers -Christopher http://cgrant.wordpress.com

Martijn Bruinenberg replied on Fri, 2009/10/23 - 2:14am

See my Paddle generator http://paddle.devoorkant.nl.

I implemented a client-server example and a messaging service example as well.

-- Martijn

Logon Smith replied on Fri, 2010/03/05 - 11:47pm

I think the core features of the Spring Framework can be used by any Java application, but there are extensions for building web applications on top of the Java Enterprise platform.I learned these things during my exam preparation. Although the Spring Framework does not impose any specific programming model, it has become popular in the Java community as an alternative to, replacement for, or even addition to the Enterprise JavaBean (EJB) model.

Carla Brian replied on Wed, 2012/07/18 - 8:16am

I haven't heard about this one yet. I need more resources on this. I want to learn how to do this one. - Mercy Ministries

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.