flexlogo.pngspringlogo.pngI have written some posts about using flex and the project Spring BlazeDS Integration. If you haven’t read that post I suggest you start there first : Flex remoting without configuring the client. That said, what is this post about? As the title already says, we are going to upgrade the example from the previous blog post to use the new features of the M2 release of spring Blazeds integration.


Maven

I do not think the spring blazeds artifacts are available in maven yet. Therefor you have to download them and install them in your local maven repo, or deploy them in your Artifactory if you use it.


mvn install:install-file -DgroupId=org.springframework.flex -DartifactId=org.springframework.flex -Dversion=1.0.0.M2 -Dpackaging=jar -Dfile=/path/to/jar

Change the used version of the jar in the books-web projects pom.xml. If you haven’t downloaded the sources yet, you can find them here.

Doing a mvn clean install and everything should be fine. If you are having problems with out of memory exceptions, give maven a bit of extra memory


export MAVEN_OPTS=-Xmx256m

Namespace support in spring configuration

Message broker

Next up is changing the spring configuration to use the new namespace support. Before you can use the new namespace, you have to specify it in the xml header. The next code block shows you the configuration as I use it. The suggestion comes from the reference manual.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:flex="http://www.springframework.org/schema/flex"
       xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/flex http://www.springframework.org/schema/flex/spring-flex-1.0.xsd">
...
</beans>

The first element configures the message broker, the handler mapping and a message broker handler adapter. If you read my previous post, remember that we add our own handler adapter as well for the config files. By default spring looks up a handler adapter. If one is already available and you need a second, you have to configure one yourself. In our case we add the simple controller handler adapter.

The new namespace configuration also adds a SimpleUrlHandlermapping. We need to add our mapping for the config.properties file. Therefore we cannot use the default mapping. The default mapping routes all requests to the MessageBroker. Check the following code for the additional configuration as I would have liked it. To bad this is not possible. On the other hand, Jeremy Grelle gives a good explanation why this cannot be done this way in this forum thread.

    <flex:message-broker>
        <flex:mapping pattern="/config.properties=configPropertyController"/>
        <flex:mapping pattern="/*=_messageBroker"/>
    </flex:message-broker>

This code block shows how it really must be. Which is good as well.

    <flex:message-broker>
        <flex:secured />
    </flex:message-broker>

    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="order" value="0"/>
        <property name="mappings">
            <value>
                /config.properties=configPropertyController
            </value>
        </property>
    </bean>

Remote services

Methods of beans can be exposed at remote services. There is namespace support for this as well. Again the namespace provides a lot of default behavior. One of the things is the name of the service that comes from the references bean. I need to change this since the used name is already used. This can easily be done using the service-id property. There is another feature that I like. You can explicitly configure the methods to expose or the methods to prevent from being exposed. You can use the exclude-methods and the include-methods. I use this to prevent the internal use method from being exposed. The following code block shows the configuration.

    <flex:remote-service service-id="remoteBookManager" ref="bookManager" 
                         exclude-methods="internalUseStoreBook"/>

Remote services configuration

If your application is only using spring managed remote services you can remove the remoting configuration completely. Default channels are provided by the spring integration. We do have a problem with our current security implementation. This makes use of a non spring managed remote service for authentication. If we want to remove this we need to use the new spring security integration. That is the next step.

Integrating spring security

The new M2 milestone comes with spring security integration. To be honest, there is not much use for me here. I did add it because there must be some exception handling and mapping being done. I still have some questions on this area that I will try to get answered the coming weeks. So stay tuned for an improved security version as well.

Summary

The following two code blocks show the old config file and the new style. I just love these more clean configuration files that make use of namespaces. To bad I have to provide my own SimpleUrlMappingHandler, but as mentioned it is probably better to make the separation.

old

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:flex="http://www.springframework.org/schema/flex"
       xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/flex http://www.springframework.org/schema/flex/spring-flex-1.0.xsd">

    <!-- Bootstraps and exposes the BlazeDS MessageBroker -->
    <bean id="mySpringManagedMessageBroker" class="org.springframework.flex.messaging.MessageBrokerFactoryBean"/>

    <!-- Maps request paths at /* to the BlazeDS MessageBroker -->
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <value>
                /config.properties=configPropertyController
                /*=mySpringManagedMessageBroker
            </value>
        </property>
    </bean>

    <!-- Dispatches requests mapped to a MessageBroker -->
    <bean class="org.springframework.flex.messaging.servlet.MessageBrokerHandlerAdapter"/>

    <!-- Dispatches request mapped to a Controller -->
    <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>

    <!-- remote proxies -->    
    <bean id="remoteBookManager" class="org.springframework.flex.messaging.remoting.FlexRemotingServiceExporter">
        <property name="messageBroker" ref="mySpringManagedMessageBroker"/>
        <property name="service" ref="bookManager"/>
    </bean>

    <!-- Controllers for property configuration files -->
    <bean id="configPropertyController" class="nl.gridshore.samples.books.web.controller.ConfigPropertyController"/>

    <!-- View resolver used connect the views returned by controllers to view implementation classes -->
    <bean id="defaultViewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
        <property name="basename" value="views"/>
        <property name="order" value="1"/>
    </bean>
</beans>

new

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:flex="http://www.springframework.org/schema/flex"
       xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/flex http://www.springframework.org/schema/flex/spring-flex-1.0.xsd">

    <!-- Bootstraps and exposes the BlazeDS MessageBroker -->
    <flex:message-broker>
        <flex:secured />
    </flex:message-broker>

    <!-- remote proxies -->
    <flex:remote-service service-id="remoteBookManager" ref="bookManager"
                         exclude-methods="internalUseStoreBook"/>

    <!-- Non default url handler mapping needed for the property file -->
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="order" value="0"/>
        <property name="mappings">
            <value>
                /config.properties=configPropertyController
            </value>
        </property>
    </bean>

    <!-- Dispatches request mapped to a Controller -->
    <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>

    <!-- Controllers for property configuration files -->
    <bean id="configPropertyController" class="nl.gridshore.samples.books.web.controller.ConfigPropertyController"/>

    <!-- View resolver used connect the views returned by controllers to view implementation classes -->
    <bean id="defaultViewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
        <property name="basename" value="views"/>
        <property name="order" value="1"/>
    </bean>
</beans>
Tagged on:             

8 thoughts on “Upgrading to Spring BlazeDS Integration M2

  • April 20, 2009 at 9:25 am
    Permalink

    Hi,

    Thanks for this post! I am trying to get this running, but …

    1. starting the server causes an exception:
    org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document ‘http://www.springframework.org/schema/flex/spring-flex-1.0.xsd’, because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not .
    Any idea? The document does not seem to be available…

    2. Additionally I want to ask how to integrate the BlazeDS libs into the project. Is this handle by a pom file (which one?) or are the libs part of the books-web?
    http://code.google.com/p/gridshore/source/browse/trunk/books-overview/books-web/pom.xml does not seem to use spring-blazeds-integration since your dependencies look like com.adobe.blazeds instead of org.springframework.flex?

    Thanks for your help!

    Reply
    • April 20, 2009 at 9:33 am
      Permalink

      I have checkedin a new version of the super pom. Now there are an additional numbers of repositories included that should help in getting the demo to run. I have other people complaining about a not running demo. I do not seem to have the problem you mention in step 1. I do know that some of these problems have to do with xalan. By adding this to your pom, the problem might be resolved.

      Hope that helps

      Reply
  • April 17, 2009 at 7:17 pm
    Permalink

    I am confused about the config.properties file. Where is it located in your books-overview tutorial and what is in this file exactly?

    Reply
    • April 17, 2009 at 7:36 pm
      Permalink

      The config.properties is on the server and is used to load some config properties. The nice part is that spring-actionscript takes care of the problems of loading this file.

      Hope that helps

      Reply
  • March 12, 2009 at 11:26 am
    Permalink

    Hi,
    i have a one question ,how to implement the Producer and Consumer methodology in the ‘Spring BlazeDS Integration’ in DataBase value insert.

    if its possible or not???

    any code??

    Reply
    • March 12, 2009 at 11:32 am
      Permalink

      Not sure if I understand what you mean. Do you mean notification of the clients?

      Reply
  • March 10, 2009 at 3:26 pm
    Permalink

    Dependencies
    ————

    http://s3browse.com/getObject/repository.springsource.com/maven/bundles/external/

    http://s3browse.com/getObject/repository.springsource.com/maven/bundles/release/

    The dependent artifacts seems to be named as com.springsource.edu.emory.mathcs.backport-2.2.0.jar
    will the final version have the artifact id as in other public repositories (not starting with com.springsource.)

    To get started I have used this as repo. Looks like we should be using this repository

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>