Accessibility

Table of Contents

The Flex, Spring and BlazeDS full stack – Part 3: Putting the application together

Creating a module to share configuration files

The goal of this section is to avoid duplicating configuration files. First, we need to create a new module under todolist, our sample application. The new module will contain the two configuration files. Later on, the module can be packaged in a resource zip that will be included in both the web and desktop modules.

Open a command line in todolist and run the following command:

mvn archetype:create -DgroupId=org.epseelon.samples -DartifactId=todolist-config

Then navigate to todolist-config and delete the src/main/java and src/test directories. After that, create an src/main/resources directory and create a services-config.xml document inside it that contains the following code:

<?xml version="1.0" encoding="UTF-8"?>
<services-config>
  <services>
    <service-include file-path="remoting-config.xml" />
  </services>
 
  <!-- Spring factory registration -->
  <factories>
    <factory id="spring"
     class="org.epseelon.samples.todolist.controller.SpringFactory" />
  </factories>
 
  <channels>
    <channel-definition id="channel-amf"
       class="mx.messaging.channels.AMFChannel">
    <endpoint
       url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf"
       class="flex.messaging.endpoints.AMFEndpoint" />
      <properties>
        <polling-enabled>false</polling-enabled>
      </properties>
    </channel-definition>
  </channels>
 
  <logging>
    <target class="flex.messaging.log.ConsoleTarget"
      level="Error">
      <properties>
        <prefix>[BlazeDS]</prefix>
        <includeDate>true</includeDate>
        <includeTime>false</includeTime>
        <includeLevel>true</includeLevel>
        <includeCategory>true</includeCategory>
      </properties>
      <filters>
        <pattern>Endpoint.*</pattern>
        <pattern>Service.*</pattern>
        <pattern>Message.*</pattern>
        <pattern>DataService.*</pattern>
        <pattern>Configuration</pattern>
       </filters>
    </target>
  </logging>
 
  <system>
    <redeploy>
      <enabled>true</enabled>
      <watch-interval>20</watch-interval>
      <watch-file>
        {context.root}/WEB-INF/flex/services-config.xml
      </watch-file>
      <watch-file>
        {context.root}/WEB-INF/flex/remoting-config.xml
      </watch-file>
      <touch-file>{context.root}/WEB-INF/web.xml</touch-file>
    </redeploy>
  </system>
</services-config>

While still in the same directory, create a file named remoting-config.xml that contains the following code:

<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service"
class="flex.messaging.services.RemotingService">
 
  <adapters>
    <adapter-definition id="java-object"
      class="flex.messaging.services.remoting.adapters.JavaAdapter"
      default="true" />
  </adapters>
 
  <default-channels>
    <channel ref="channel-amf" />
  </default-channels>
 
  <destination id="todoService">
    <properties>
      <factory>spring</factory>
      <source>todoService</source>
    </properties>
  </destination>
</service>

Edit the todolist-config/pom.xml file so that it looks like this:

<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <parent>
    <artifactId>todolist</artifactId>
    <groupId>org.epseelon.samples</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.epseelon.samples</groupId>
  <artifactId>todolist-config</artifactId>
  <name>todolist-config</name>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <id>make shared resources</id>
            <goals>
              <goal>single</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <descriptors>
                <descriptor>src/main/assembly/resources.xml</descriptor>
              </descriptors>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Notice the pom packaging and configuration of the maven assembly plug-in that references the assembly descriptor to package the shared configuration. Create the src/main/assembly/resources.xml file, as follows:

<assembly>
  <id>resources</id>
  <formats>
    <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <fileSets>
    <fileSet>
      <directory>src/main/resources</directory>
      <outputDirectory></outputDirectory>
    </fileSet>
  </fileSets>
</assembly>

Run 'mvn install' and you'll see a file called todolist-config-1.0-SNAPSHOT-resources.zip, containing the two configuration files. This is exactly what we wanted, because now we can include these configuration files in the various modules of the to do list sample application.

In the next part of this article, I'll describe the process required to allow BlazeDS to consume our to do list service.