Spring, Flex, BlazeDS Full Stack is Back!


After trying for weeks to integrate Flex and BlazeDS into Grails, in vain, I’ve decided to come back to vanilla Spring/Hibernate for Conference Guide server. And I took the opportunity to upgrade my todolist sample application, the one featured in the article published both on this blog and on the Adobe Developer Connection.

Here are the improvements compared to the original version:

  • I replaced the old SpringFactory by Spring BlazeDS Integration (spring-flex) library
  • I’ve added basic security using Spring Security, based on Cristophe Coenraets’ article on DZone
  • The domain now has 2 entities with a one-to-many relationship: you can manage several todolists, each having several items
  • I’m now using proper DTO’s for data transfer between the client and the server, which is for me the cleaner way to do things
  • Flexmojos Maven plugin has been upgraded to 3.4.2 (the latest stable version today).

I won’t go into detail about every aspect of this project because I think it can be much more useful to use it as a basis rather than try to reproduce it from scratch. Here is what you need to do to make it work:

  • Download the project source code on GitHub
  • Install Maven 2.2.0 if not already done
  • Run “mvn install” at the root of your project until you get a BUILD SUCCESSFUL message
  • Copy server/target/todolist.war to the webapps directory of your Tomcat server, or startup Tomcat and run “mvn org.codehaus.mojo:tomcat-maven-plugin:1.0-beta-1:redeploy” from within the server module
  • Open your browser on http://localhost:8080/todolist and login as john/john
  • Enjoy!

Capture d’écran 2009-11-07 à 19.12.52

If you have any suggestion for improvements, of if you have any question, feel free to leave a comment here. Cheers!

, ,

57 responses to “Spring, Flex, BlazeDS Full Stack is Back!”

  1. Have you tried to exchange data using JSON through asynchronous XHR using the same technology stack ? The backend exposes REST like web services. The frontend is completely decoupled from the backend implemention. It looks cleaner but it might not worth the trouble. What do you think ?

    • Whenever possible, I always prefer remoting protocols (hessian, burlap, AMF) to message-based protocols (REST, SOAP). Plus, AMF is highly optimized and supports native serialization/deserialization with Java.

  2. Hi! Thank you for your post!
    Everything works fine, but project couldn’t compile.
    I commented 1 line in client/pom.xml.
    and now dependency section for common part of actionscript is:

    ${project.groupId}
    todolist-common-as
    ${project.version}
    swc
    <!–rsl–>

    what is “rsl” scope for ?
    And one more question:

    After I login, sometimes (almost every request to todoListService) i get an error: An Authentication object was not found in the SecurityContext. Why is that? Do you get the same error?

    Thank you!

    • You should leave it as RSL. RSL is a special scope. I think it means “remote shared library” or something like that. The idea is to make it possible for users of the app to cache this library in their Flash player and thus reduce the size of the SWF they have to download. What error did you have exactly?

      Concerning the authentication error, yes, I get that too from time to time but it’s very inconsistent. I’m still looking into it, but if someone knows where this comes from, feel free to raise your hand.

  3. I recompiled the project and the error is:

    Error resolving artifacts org.epseelon:todolist-common-as:swf:2.0-SNAPSHOT
    Embedded error: Unable to download the artifact from any repository …

    I’ll try to find the answer to the question about security error.

  4. OK, so thanks a lot to Velo, the lead developer of Flexmojos: if you have the same problem as Evgeny, just run “mvn clean install” and it should do the trick.

    Now concerning authentication, it’s true that it behaves strangely. I’ve created an issue (http://github.com/sarbogast/todolist-spring/issues/#issue/1) for that and I’ll let you guys know when I find where this comes from.

    In the meantime, if another BlazeDS fan wants to check out the project and help me figure out what’s wrong, you’re more than welcome.

  5. Hello, I’m try download the project source code on GitHub and it´s down.

    Can you give me another link to try download the code.

    Thanks for all.

  6. I too am having problems downloading this. Can someone post it somewhere else? let me know where to get it from?

  7. I was able to sole this by creating an account on GitHub, along with branching this code and then downloading that and deleting my branch.

  8. Hi,
    I tried it but I get the stack trace as:

    -verify-digests=true -static-link-runtime-shared-libraries=false -load-config=
    -metadata.language+=en_US
    [INFO] ————————————————————————
    [ERROR] FATAL ERROR
    [INFO] ————————————————————————
    [INFO] Java heap space
    [INFO] ————————————————————————
    [INFO] Trace
    java.lang.OutOfMemoryError: Java heap space
    at macromedia.abc.AbcParser.getQNameFromCPool(AbcParser.java:1322)
    at macromedia.abc.AbcParser.methodTrait(AbcParser.java:649)
    at macromedia.abc.AbcParser.classTrait(AbcParser.java:1071)
    at macromedia.abc.AbcParser.parseTraits(AbcParser.java:1144)
    at macromedia.abc.AbcParser.parseScript(AbcParser.java:1197)
    at macromedia.abc.AbcParser.parseAbc(AbcParser.java:108)
    at flex2.compiler.abc.Compiler.parse1(Compiler.java:179)
    at flex2.compiler.API.parse1(API.java:2315)
    at flex2.compiler.API.parse1(API.java:2268)
    at flex2.compiler.API.batch2(API.java:369)
    at flex2.compiler.API.batch(API.java:1117)
    at flex2.compiler.API.compile(API.java:1290)
    at flex2.tools.oem.Application.compile(Application.java:1077)
    at flex2.tools.oem.Application.recompile(Application.java:1029)
    at flex2.tools.oem.Application.compile(Application.java:681)
    at flex2.tools.oem.Application.build(Application.java:428)
    at org.sonatype.flexmojos.compiler.AbstractFlexCompilerMojo.build(AbstractFlexCompilerMojo.java:2437)

    • You have to increase the memory limit allocated to Maven. Try creating an environment vairable called MAVEN_OPTS and set its value to -XX:MaxPermSize=128m -Xmx512m

  9. Hello, thx for the updated tutorial, compilation is fine, deployment fine as well, login OK, but when i try to do anything with todos, i have issues with mysql.
    Could you please remind how to configure mysql or point the proper link ?
    I think compared to first tutorial, we now have on more table for todolist, but i’ve no idea how to configure it.

    Thx,

    Jahz

    • Normally, you shouldn’t have to configure anything. Database tables are created automatically the first time when the application starts, thanks to JPA and Hibernate. If you started with the database from the previous version, I suggest you create another database for this version and put the right connection data in the profile at the end of the root pom.xml.

  10. Sebastien,
    Thanks for the sample app! I built it and got it going in tomcat, but whenever I try to load a todolist it gives me the ‘Could not create Todo List’. The tables are getting created in my database, but something is wrong… Here is my tomcat log:

    DEBUG JDBCTransaction – begin
    DEBUG ConnectionManager – opening JDBC connection
    DEBUG DriverManagerDataSource – Creating new JDBC DriverManager Connection to [jdbc:mysql://localhost:3306/bandaid]
    DEBUG JDBCTransaction – current autocommit status: true
    DEBUG JDBCTransaction – disabling autocommit
    DEBUG JpaTransactionManager – Exposing JPA transaction as JDBC transaction [SimpleConnectionHandle: com.mysql.jdbc.ConnectionImpl@6d9e6c]
    DEBUG AbstractSecurityInterceptor – Secure object: ReflectiveMethodInvocation: public abstract java.util.List org.epseelon.todolist.business.TodoListService.getAllLists(); target is of class [org.epseelon.todolist.business.impl.TodoListServiceImpl]; ConfigAttributes: [ROLE_USER]
    DEBUG JpaTransactionManager – Initiating transaction rollback
    DEBUG JpaTransactionManager – Rolling back JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@97a607]
    DEBUG JDBCTransaction – rollback
    DEBUG JDBCTransaction – re-enabling autocommit
    DEBUG JDBCTransaction – rolled back JDBC Connection
    DEBUG ConnectionManager – aggressively releasing JDBC connection
    DEBUG ConnectionManager – releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
    DEBUG JpaTransactionManager – Closing JPA EntityManager [org.hibernate.ejb.EntityManagerImpl@97a607] after transaction
    DEBUG EntityManagerFactoryUtils – Closing JPA EntityManager
    DEBUG ThrowsAdviceInterceptor – Found handler for exception of type [java.lang.Throwable]: public void org.springframework.flex.core.ExceptionTranslationAdvice.afterThrowing(java.lang.Throwable) throws java.lang.Throwable
    DEBUG DispatcherServlet – Null ModelAndView returned to DispatcherServlet with name ‘spring-flex’: assuming HandlerAdapter completed request handling
    DEBUG DispatcherServlet – Successfully completed request
    DEBUG RequestContextListener – Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@df9cf4

  11. I want to use command “mvn eclipse:eclipse” to turn it to a eclipse project (in the root directory),but it cannot work.Can someone tell me how do it?

  12. sebastien,
    I am digging into your code… I am assuming that you used Granite to generate the .as files from your java objects?
    I have created a new getter/setter on an object and am not seeing it generated in the .as file.
    I deleted the file, assuming that it would be recreated but I get a compilation error now from the other .as files.

    I’m sure this is a simple thing, but I can’t figure it out…
    Thanks!
    mark

  13. Hi,

    I tried converting the application that you created to run against HSQLD (instead of mysql) and then I tried running it via tomcat:run-war.

    However, I think it sometimes fails to communicate with the server (I’ve placed breakpoints all over the place and they don’t seem to get hit). But several restarts, and it will start to work properly. But after that, another restart would most probably bring it back to its unusable state…Any ideas?

    (Btw, I tried it with your version 01 – I migrated it to use HSQLDB and to use jetty:run-war and it worked properly).

    Thanks,
    Franz

  14. I figured out what my problem is. I simply forgot to comment out the mysql dependency and that was enough to cause the erratic behaviour (even if hibernate was configured to use hsqldb).

    Thanks,
    Franz

  15. Hi,

    I opened it in eclipse, but could not figure it out how to run it.

    I have installed tomcat also, how to run it in eclipse on tomcat.

    Thanks.
    Kiran

  16. Hi Sebastien,

    I thought you’d be glad to know this (great!) sample performs pretty well – I’m running it on a poor machine (Pentium 4 2GHz, 2 GB RAM) but still ~400k todolists are loaded in 30secs. from localhost. I just had to change log4j level from ‘debug’ to ‘info’ as console output is a big bad performance eater. Another interesting point is that I ran it in Jetty, but I guess this doesn’t matter that much.

    Once again, great job!

    Kudos,
    Misho

  17. Hi Sebastien,

    Im had seen a couple of sample projects at your blog and im very much impressed with your demos.I’m new bee to flex+spring+blazeds.Can you please send me tutorials on integrating flex+spring in flex builder. It will help me a lot for my career improvement.

    Thanks & Regards
    Uday

    • Thanks for the pleasant feedback. Unfortunately, I won’t be of much help concerning Flex Builder as I’m not a big Eclipse fan myself so I don’t use Flex Builder a lot.

  18. Hi Sebastien,

    first of all, great work! However, I am having problems with optimization and metadata in the RSL module. I am using Parsley (http://www.spicefactory.org/parsley/), which requires that metadata be kept in the artifacts, which the keepAs3Metadatas configuration option takes care of when compiling swfs or swcs, but seemingly not when optimizing! The flexmojos plugin documentation mentions nothing on this matter, so I’m wondering whether this is an issue, desired behavior, or whether I am doing something wrong (should I post code here?)

    Thanks,
    Rade

  19. I loved your first version and would really like to try the upgraded one but I just can’t get it to download…when I click on download source nothing happens…Am I doing something wrong?

    Thanks

    Admir

  20. Hello Sébastien,

    Thanks for the great example!
    One question – what is by you the best way to build/redeploy application during the development – during code changes? The one that reduces time to the possible minimum.

    Thanks at advance!

  21. I need a little help.. after running “mnv install” it says I am missing two required artifacts:

    1) net.sf.saxon:saxon-dom:jar:9.0

    and

    2) com.adobe.flex:compiler:pom:3.4.0.9271

    I have to admit I am a n00b to maven but I just can’t seem to get it to work 🙁 Thanks in advance.

  22. I have the same issue as well.2 artefacts missing. The flex mojo plugins are not loacted by maven.

    Can you help, please

    • It seems that Sonatype changed their repository for Flex artifacts. In the root pom.xml, simply change the url of flex-mojos-repository from “http://repository.sonatype.org/content/groups/public” into “http://repository.sonatype.org/content/groups/flexgroup”. Do the same for pluginRepository. And it should work.

      Thanks a lot for pointing that out.

  23. Hi,

    I am getting this error:
    [DEBUG] File: http://repo1.maven.org/maven2/com/adobe/flex/framework/framework/4.0.0.14159/framework-4.0.0.14159.rb.swc does not exist
    org.apache.maven.wagon.ResourceDoesNotExistException: File: http://repo1.maven.org/maven2/com/adobe/flex/framework/framework/4.0.0.14159/framework-4.0.0.14159.rb.swc does not exist
    at org.apache.maven.wagon.shared.http.AbstractHttpClientWagon.fillInputData(AbstractHttpClientWagon.java:603)

    It;s apparently looking for a *.swc file. Did any one of you face the same issues? Any pointers on that? I replaced (updated) the flex-mojos rep information in the root pom. I believe that’s all the change I have made.

    -Rajesh

  24. Hi Sebastien,

    First off, thanks for this very helpful startup tutorial. I would please like to ask for help on the same problem that Mr Irshad Buchh has encountered. I have already tried the suggestion that you made by creating an environment vairable called MAVEN_OPTS and setting its value to -XX:MaxPermSize=128m -Xmx512m. I did this but the “mvn clean install” command still shows the java heap space Fatal Error.

    I have also tried to set MAVEN_OPTS on the bin/mvn file and JAVA_OPTS catalina.bat file to the same value that you suggested but I still get the same error.
    Could you please suggest any other approaches to the solution? If it could help, here are the details of the version of the software that I have been using:
    Apache Maven 2.2.1
    Java version: 1.5.0_09

    Best regards,
    Kin

  25. Hey Sebastian. I have tried downloading the source both in firefox and IE and neither work for me. I watched the video you included and I dont even have the same buttons on the screen you seem to have, so perhaps the site has changed since you posted the vid.

    Any possibility the source is somewhere else?

  26. Sebastien — Awesome app, worked perfectly for me once I set up mysql security. Also — since you are not a fan of Eclipse and Flex Builder, can I ask what IDE you do use with what Flex development tooling and why?

    • I’m using IntelliJ for all my Grails and Java work, and for some of the Flex work. And when I need to prototype Flex UI’s quickly and visually, I fire up Flash Builder just for that.

  27. Hi,

    I have Jetty as a plugin in my todolist-server pom.xml project….

    org.mortbay.jetty
    maven-jetty-plugin
    6.1.19

    /myContext

    MAVEN_OPTS
    “-Xms512m -Xmx1024m -XX:MaxPermSize=384m”

    JVM-ARG
    “-XX:MaxPermSize=386m”

    JAVA_OPTS
    “-Xms512m -Xmx1024m”

    <!– -XX:MaxPermSize=256m –>

    4

    8080
    60000

    src/main/webapp/WEB-INF

    **/*.jsp

    **/*.properties
    **/*.xml

    0

    when i start the run jetty:run

    i get the following error…

    Caused by: java.lang.IllegalArgumentException: Flex configuration file does not exist at path: /WEB-INF/flex/services-config.xml
    at org.springframework.util.Assert.isTrue(Assert.java:65)
    at org.springframework.flex.config.FlexConfigurationManager$ResourceResolverAdapter.getConfigurationFile(FlexConfigurationManager.java:181)
    at flex.messaging.config.AbstractConfigurationParser.parse(AbstractConfigurationParser.java:67)
    at org.springframework.flex.config.FlexConfigurationManager.getMessagingConfiguration(FlexConfigurationManager.java:108)
    at org.springframework.flex.core.MessageBrokerFactoryBean.afterPropertiesSet(MessageBrokerFactoryBean.java:128)
    … 78 more
    2010-10-13 14:23:28.364:/todolist:WARN: unavailable
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘_messageBrokerDefaultHandlerMapping’: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘_messageBroker’: Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanInitializationException: MessageBroker initialization failed; nested exception is java.lang.IllegalArgumentException: Flex configuration file does not exist at path: /WEB-INF/flex/services-config.xml
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)

  28. Hi Sebastien,

    Great example. I have one issue. My client maven project has no Flex nature, therefore cant use no flex code assist. Please can someone help.

  29. Hi, maybe i have not been clear. I am using the example as described on Flash Builder 4. I have noticed I have no flex code assist on my client maven project. i am unable to add a Flex nature aslo.

    Please could someone advise.

  30. After making these changes “It seems that Sonatype changed their repository for Flex artifacts. In the root pom.xml, simply change the url of flex-mojos-repository from “http://repository.sonatype.org/content/groups/public” into “http://repository.sonatype.org/content/groups/flexgroup”. Do the same for pluginRepository.”

    at least the build is happening.
    thanks for the info.

  31. Not able to see the deployed application on tomcat 7.
    Want to understand what these steps are for:
    I have successfully completed till this:
    # Download the project source code on GitHub
    # Install Maven 2.2.0 if not already done
    # Run “mvn install” at the root of your project until you get a BUILD SUCCESSFUL message
    # Copy server/target/todolist.war to the webapps directory of your Tomcat server, or startup Tomcat

    But from this step and onwards, it’s giving me the issues:
    and run “mvn org.codehaus.mojo:tomcat-maven-plugin:1.0-beta-1:redeploy” from within the server module
    # Open your browser on http://localhost:8080/todolist and login as john/john

    Once i was able to login successfully using john/john also but at the time of saving the todolist-got creation error.

    I couldn’t create the user todolist in MySQL. But i am able to create the schema and the table.
    I have the root user which should be able to have access to this table also-right????

  32. Getting this error:
    [INFO]
    [INFO] <<< tomcat-maven-plugin:1.0-beta-1:redeploy (default-cli) @ todolist-server << [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

    at the time of executing this command:
    run “mvn org.codehaus.mojo:tomcat-maven-plugin:1.0-beta-1:redeploy” from within the server module

  33. I keep getting this error??? I blew my local repository away also..but still gets this error.. i don’t understand why? any help is greatly appreciated.

    The project org.epseelon:todolist-client:2.0-SNAPSHOT (C:UsersJeryl Cooktodolist-springclientpom.xml) has 2 errors
    Unresolveable build extension: Plugin org.sonatype.flexmojos:flexmojos-maven-plugin:3.4.2 or one of its dependencies could not be resolved: The following artifacts could not be resolved: com.adobe.flex:compiler:pom:3.4.0.9271, net.sf.saxon:saxon-dom:jar:9.0: Failure to find com.adobe.flex:compiler:pom:3.4.0.9271 in http://repository.sonatype.org/content/groups/public was cached in the local repository, resolution will not be reattempted until the update interval of flex-mojos-repository has elapsed or updates are forced -> [Help 2]
    Unknown packaging: swf @ line 10, column 16

    The project org.epseelon:todolist-server:2.0-SNAPSHOT (C:UsersJeryl Cooktodolist-springserverpom.xml) has 1 error
    Unresolveable build extension: Plugin org.sonatype.flexmojos:flexmojos-maven-plugin:3.1.0 or one of its dependencies could not be resolved: Failure to find com.adobe.flex:compiler:pom:3.4.0.9271 in http://repository.sonatype.org/content/groups/public was cached in the local repository, resolution will not be reattempted until the update interval of flex-mojos-repository has elapsed or updates are forced -> [Help 2]

    The project org.epseelon:todolist-common-as:2.0-SNAPSHOT (C:UsersJeryl Cooktodolist-springcommon-aspom.xml) has 2 errors
    Unresolveable build extension: Plugin org.sonatype.flexmojos:flexmojos-maven-plugin:3.4.2 or one of its dependencies could not be resolved: The following artifacts could not be resolved: com.adobe.flex:compiler:pom:3.4.0.9271, net.sf.saxon:saxon-dom:jar:9.0: Failure to find com.adobe.flex:compiler:pom:3.4.0.9271 in http://repository.sonatype.org/content/groups/public was cached in the local repository, resolution will not be reattempted until the update interval of flex-mojos-repository has elapsed or updates are forced -> [Help 2]
    Unknown packaging: swc @ line 11, column 16

  34. sorry for repost:

    “http://repository.sonatype.org/content/groups/public” into “http://repository.sonatype.org/content/groups/flexgroup”

    would be great to update git! :)..thanks for the ‘jump start’ Sebastien!

  35. Is it me or is this really confusing for a beginner ? 🙂

    Couple of questions…

    1. I’ve got the app to compile… the .WAR seems to work fine, but the database is not populated. (pom.xml changed for mysql details). Where abouts in the code does it do the database generation?

    2. Can anyone recommend any books ok the Java bits? I don’t really want to learn a lot of Java, but I’m finding navigating around a little confusing.

    Thanks for the demo… once I get it running I can probe a little more. Also thanks for not using Eclipse…. it’s good to see how it hangs together without all the GUI behind scenes bits.

Leave a Reply

%d bloggers like this: