Expand my Community achievements bar.

FlexFactory Example

Avatar

Level 2
I'm wanting to use Spring for my backend for Flex Data
Services. I

found the docs on using a class that implements the
FlexFactory

interface, but the really is not enough detail in the docs to
fully

understand how to fill out the FlexFactory implementation
class.



Has anyone successfully used this class? Do I create a single

FlexFactory class for all of my destinations that I want to
use Spring

with? Or do I create a FlexFactory impl for each destination?



Thanks

Bill
29 Replies

Avatar

Level 3
If you reference your POJO in a remoting service destination
directly, FDS will create the bean instance and Spring isn't
involved. By using the SpringFactory, you're allowing FDS to get
the bean instance from the Spring framework which will perform any
necessary dependecy injection, etc.



Hope that helps,

Seth

Avatar

Level 1
Seth,

Thanks, that makes sense. I want to pass data from my Spring
bean (which I registered inside remoting file as a source) to the
Flex app to eventually display it on my flash file (whatever gets
created after compiling .mxml file). Do I invoke SpringFactory
directly from .mxml file passing the Spring bean name and
properties (i.e. createFactoryInstance(beanName, properties)), or
there's a third piece to it?

Thanks,



/Roman

Avatar

Level 3
Hi Roman,



You don't need to invoke SpringFactory directly. Take a look
at Jeff's comment earlier in this thread. He uses the following
example:



<factories>

<factory id="spring"
class="flex.samples.factories.SpringFactory" />

</factories>

...

<destination id="WeatherService">

<properties>

<factory>spring</factory>

<source>weatherBean</source>

</properties>

</destination>



In your MXML app, you'd create a RemoteObject with its
destination set to "WeatherService" and then invoke the methods
defined by the 'weatherBean' class.



This all works exactly the same as a regular remote object as
far as you're concerned. The only difference is that the
destination gets its internal weatherBean instance from Spring
rather than creating a bean instance directly using reflection.



Best,

Seth

Avatar

Level 1
Seth,

Thanks again for your post. I think I got the idea of how it
all works. I've finally managed to put all the pieces together. I
set the FDS Logger level to debug, so that I can see the output. I
now get pretty nasty FDS error message when trying to access my
SpringBean from mx:RemoteObject tag. It looks like it cannot
resolve my SpringBean destination resulting in a
NullPointerException. I'll go back to check all the config files.
Maybe, my SpringFactory didn't initialize bean properly.

Thanks,



/Roman

Avatar

Level 1
Seth,

Thanks for your previous post. I think I now got all the
pieces together. I know my SpringFactory works because I after I've
defined it inside services-config, I see my debug statements inside
SpringFactory.createFactoryInstance() when app server starts up
kicking the FDS service. However, when I invoke my SpringBean from
inside the flex app, I get an error saying that it cannot find my
Spring service declared inside remoting-config. Inside the app
server console it says:

"Spring service named 'bus.ProductManager' does not exist"
with the root cause "rootCause =
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
bean named 'bus.ProductManager' is defined".

The ProductManager class is in fact my Spring bean declared
as a source inside remoting-config.



I've kept all my configuration very similar to the one in the
article about SpringFactory. I guess I'll go thru it one more time.
In a meantime, if you have any suggestions as of why FDS cannot
locate my spring bean, please let me know. Thanks,



/Roman



Avatar

Level 1
Seth,

Thanks for all your help. I finally got it working. My
problem was that inside remoting-config file I was using class name
for "source" instead of the bean name declared inside
applicationContext.xml.



One thing though: the whole FDS to Spring enchilada only
works if I declare my SpringBean inside applicationContext.xml with
id attribute (<beans><bean id="SpringBean"
class="pachage.class" etc). If I change the id attribute of my bean
into "name" like it says in the article (<bean name="SpringBean"
etc), the whole app doesn't even get loaded.

Thanks again,



/Roman

Avatar

Level 3
That's great news Roman :)



And you're correct. The readme file's applicationContext.xml
section has:



<bean name="..." ... />



rather than



<bean id="..." .../>



We'll correct this and update the extension.



Best,

Seth

Avatar

Level 1
Hey,



First of all good job on the FlexFactory!. I have all working
fine.. Loading the flex servlets with spring's
ServletWrappingController gives me an advantage to bind
interceptors (like a loginInterceptor) with the flex servlets.



Now i have the following question: Springs 2.0 Session scope
proxy beans.



I have a session scoped proxy bean representing a login
object for every (http) session on the website. This is injected in
several managers, and thus the managers can check wether the user
is logged in and if he has enough rights to call the method etc.



This still works fine when using Flex RPC calls to my Spring
managers with the Spring Factory.



But it aint working with Flex FDMS. Probebly because the FDMS
keeps state (and session) internal to flex. And new call go
straight to the server instead of going through some HTTP call
which gets catched by the Spring context.



So how is this Flex FDMS working internally? I thought it
should go through the messagebroker or something (which is a flex
servlet, so should have a http session?).

Avatar

Level 1
Hi All

This Flex factory works fine If I use default fill and sync
methods .

The moment i try to use mu custom fill and sync methods by
using the foll tags in data-management-config.xml

<properties>

<use-transactions>false</use-transactions>

<source>transAssembler</source>

<factory>spring</factory>

<scope>request</scope>



<metadata>

<identity property="transKey"/>

</metadata>



<network>

<session-timeout>20</session-timeout>

<paging enabled="false" pageSize="10" />

<throttle-inbound policy="ERROR" max-frequency="500"/>

<throttle-outbound policy="REPLACE"
max-frequency="500"/>

</network>



<server>

<fill-method>

<name>searchTransactions</name>

<params>com.citi.vo.TransMaintenanceVO</params>

</fill-method>

<sync-method>

<name>syncTransactions</name>

</sync-method>

</server>

</properties>



I get the foll error



flex.messaging.config.ConfigurationException: Unused tags in
<properties> found. Please fix them before continuing:

'/scope' in destination with id: 'transService' from file:
data-management-config.xml

'/server/sync-method' in destination with id: 'transService'
from file: data-management-config.xml

'/server/fill-method' in destination with id: 'transService'
from file: data-management-config.xml

at
flex.messaging.config.MessagingConfiguration.reportUnusedProperties(MessagingConfiguration.java:432)

at
flex.messaging.MessageBrokerServlet.init(MessageBrokerServlet.java:110)

at
org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1139)

at
org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:791)

at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:127)

at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)

at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)

at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)

at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)

at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)

at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)

at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)

at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)

at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)

at java.lang.Thread.run(Thread.java:595)

Apr 18, 2007 3:04:59 PM
org.apache.catalina.core.StandardWrapperValve invoke



But if I do not use spring factory and use the fully
qualified name of the assembler in the source tag everything works
fine.



Please suggest how to use spring factory with this
configuration