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!
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!”
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.
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.
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.
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.
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.
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.
No no, it’s not down. It’s right there. Check your network or something.
I too am having problems downloading this. Can someone post it somewhere else? let me know where to get it from?
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.
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
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
that’s what i am getting too, but your advice didn’t help i still get the same no matter what i do…
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.
Thx for you answer, all working fine now.
Jahz
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
I don’t see any error in your log. Are you sure that you set the privileges right for your database user?
I manually inserted a todo record and it is working fine via the ui now… Thanks, mark
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?
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
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
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
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
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
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.
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
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
….ok got it to work, used another browser.
Thank you for this great example!
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!
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.
I have the exactly problem with Job. Can anyone explains this? Thanks.
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.
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
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
Hi Sebastien,
I want to do this with ant scripts . does that make any trouble .
Shyam
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?
Great work !
it will be nice if u can upgrade it to use the latest flex,
version 4.1.
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.
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)
Hi,
ignore the previous post, i just realised the tomcat plugin config…
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.
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.
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.
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????
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
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
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!
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.
[…] The prototype of the project I used can be found here: http://sebastien-arbogast.com/2009/11/07/spring-flex-blazeds-full-stack-is-back. […]
Salut,
Le content assist fonctionne nickel avec la 4.5 de FB.
As-tu essayé graniteDS plutot que blazeDS? Bien mieux à mon goût (j’ai testé plein de conf entre blazeds, Mate, Caingorn, Gds…
Un exemple complet ici: https://github.com/Tcharl/Osgiliath-ref-example/tree/master/newArchetypeTest
Ce qui m’a fait tripper, c’est qu’on a à peu près les même sites avec les mêmes références^^.
Enjoy! Charlie