7
Nov
45

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!

  • DZone
  • Digg
  • del.icio.us
  • Slashdot
  • email
  • Facebook
  • Google Bookmarks
  • blogmarks
  • StumbleUpon
  • Technorati
  • Twitter
  • Reddit
  • Tumblr
  • LinkedIn
No TweetBacks yet. (Be the first to Tweet this post)
Enjoyed reading this post?
Subscribe to the RSS feed and have all new posts delivered straight to you.
45 Comments:
  1. Pierre 9 Nov, 2009

    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 ?

  2. Sébastien 9 Nov, 2009

    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.

  3. Evgeny Naku 11 Nov, 2009

    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!

  4. Sébastien 11 Nov, 2009

    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.

  5. Evgeny Naku 11 Nov, 2009

    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.

  6. Sébastien 11 Nov, 2009

    You must have changed something in the POM somehow because it’s looking for a todolist-common-as.SWF whereas todolist-common-as is built as a SWC library.
    Can you please send me your project at sebastien.arbogast@gmail.com and I’ll have a look at it.

  7. Sébastien 11 Nov, 2009

    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.

  8. Isidro 12 Nov, 2009

    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.

  9. Sébastien 13 Nov, 2009

    No no, it’s not down. It’s right there. Check your network or something.

  10. TH 19 Nov, 2009

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

  11. TH 19 Nov, 2009

    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.

  12. Sébastien 19 Nov, 2009

    I agree that githib’s download interface is not the most intuitive in the world, but github is not down.
    Try watching the following video and if it still doesn’t work I’ll send you a package.

    http://screenjel.ly/fo3wHLg2s8Y

  13. Irshad Buchh 22 Nov, 2009

    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)

  14. Sébastien 22 Nov, 2009

    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

  15. Jahz 22 Nov, 2009

    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

  16. Sébastien 22 Nov, 2009

    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.

  17. Jahz 22 Nov, 2009

    Thx for you answer, all working fine now.

    Jahz

  18. mark 24 Nov, 2009

    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

  19. Sébastien 24 Nov, 2009

    I don’t see any error in your log. Are you sure that you set the privileges right for your database user?

  20. Mark 24 Nov, 2009

    I manually inserted a todo record and it is working fine via the ui now… Thanks, mark

  21. liangjieliu 24 Nov, 2009

    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?

  22. mark 25 Nov, 2009

    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

  23. Franz See 29 Nov, 2009

    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

  24. Franz See 1 Dec, 2009

    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

  25. kiran 8 Dec, 2009

    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

  26. Mihail Sergeev 14 Dec, 2009

    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

  27. uday 29 Dec, 2009

    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

  28. Sébastien 29 Dec, 2009

    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.

  29. Rade 8 Jan, 2010

    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

  30. admir 18 Jan, 2010

    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

  31. admir 18 Jan, 2010

    ….ok got it to work, used another browser.

  32. firas 17 Feb, 2010

    that’s what i am getting too, but your advice didn’t help i still get the same no matter what i do…

  33. cristi 9 Mar, 2010

    Thank you for this great example!

  34. Dionis 12 Mar, 2010

    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!

  35. Job 30 Mar, 2010

    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.

  36. Edde 21 Apr, 2010

    I have the exactly problem with Job. Can anyone explains this? Thanks.

  37. Sri 21 Apr, 2010

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

    Can you help, please

  38. Sébastien 21 Apr, 2010

    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.

  39. Rajesh V 1 Jul, 2010

    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

  40. Kin 6 Jul, 2010

    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

  41. Shyam 15 Jul, 2010

    Hi Sebastien,

    I want to do this with ant scripts . does that make any trouble .

    Shyam

  42. Jeremy 28 Jul, 2010

    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?

  43. Eran 4 Aug, 2010

    Great work !

    it will be nice if u can upgrade it to use the latest flex,
    version 4.1.

  44. hdave 5 Aug, 2010

    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?

  45. Sébastien 24 Aug, 2010

    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.

Post your comment



Celadon theme by the Themes Boutique