Getting Started with Wonder

1,517 views
1,449 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,517
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
17
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Getting Started with Wonder

  1. 1. Getting Started with Wonder Kieran Kelleher WOWODC 2010 Montreal Green Island Consulting LLC SmartleadsUSA LLC SmartMix Technologies LLCFriday, September 3, 2010
  2. 2. Getting Started with Wonder • Get you started using Wonder • Wonder installation and upgrade - Binaries and Source • Create a Wonder Application • Convert existing non-Wonder to a Wonder Application • Review a few useful features of Wonder • ERXProperties, Properties files usage, ERXEC usage • ERPrototypes and Overriding prototypesFriday, September 3, 2010
  3. 3. What Is It? • World’s largest Open Source WebObjects project • Umbrella Project for • Patches and Bug Fixes to WebObjects • Very Useful Extensions to Standard WebObjects Functionality • Reusable WOComponents • Powerful Reusable Frameworks • Example Applications * Some verbiage reproduced from Jonathon “Wolf” Rentzsch’s 2002 CAWUG PresentationFriday, September 3, 2010
  4. 4. Brief History Snippet • A long long time ago in a galaxy far far away... • dotcom: “eResource” (“ER*”), then became NetStruxr • WOnder is acronym for • WebObjects Nodes for Distributing E-Resources • NetStruxr closed • SourceForge project named WONDER was created (~2002)Friday, September 3, 2010
  5. 5. What’s in It GoogleChart ERChronic ... and much more! (db *)PlugIn ERModernLook ERTaggable ERCaptcha ERProfiling ERIndexing ERModernDefaultSkin ERAttachment ExcelGenerator ERPDFGeneration ERRest ERModernD.T.W. Ajax JavaWOExtensions WOOgnl WOJRebel ERNeutralLook ERExtensions ERJars ERPrototypes ERJavaMail ERDirectToWebFriday, September 3, 2010
  6. 6. Why Should You Use It? • Bug fixes to standard WebObjects frameworks • Even Apple uses Wonder (Branch 2_0_0?) • Improved and Replaced Functionality • Extended and Additional Functionality • The source code has an educational benefit • Why reinvent and debug the wheel?Friday, September 3, 2010
  7. 7. How Do You Get It? “Semi-Pro” Way* “Pro” Way* Binaries Source * Terms coined by David Holt on wonder-disc mailing list on May 12, 2010Friday, September 3, 2010
  8. 8. Binary Frameworks Initial Installation $ mkdir WonderBinaries54 $ cd WonderBinaries54 $ curl -O http://webobjects.mdimension.com/hudson/job/Wonder54/lastSuccessfulBuild/artifact/dist/Wonder-Frameworks.tar.gz $ tar -xzvf Wonder-Frameworks.tar.gz $ sudo cp -Rvf *.framework /Library/Frameworks For WebObjects 5.3, replace “54” above with “53”Friday, September 3, 2010
  9. 9. Binary Frameworks Upgrade Installation $ cd WonderBinaries54 $ for FRAMEWORK in `echo *.framework`; do sudo rm -r /Library/Frameworks/${FRAMEWORK}; done $ rm -r * $ curl -O http://webobjects.mdimension.com/hudson/job/Wonder54/lastSuccessfulBuild/artifact/dist/Wonder-Frameworks.tar.gz $ tar -xzvf Wonder-Frameworks.tar.gz $ sudo cp -Rvf *.framework /Library/Frameworks For WebObjects 5.3, replace “54” above with “53”Friday, September 3, 2010
  10. 10. Source Frameworks Initial Installation $ svn co http://wonder.svn.sourceforge.net/svnroot/wonder/trunk/Wonder --revision <ARG> WonderSource $ cd WonderSource $ ant -Dwonder.patch=54 frameworks; sudo ant -Dwonder.patch=54 frameworks.install [WO 5.4] OR $ ant frameworks; sudo ant frameworks.install [WO 5.3] <ARG> = HEAD to get latest version. Type svn --help checkout for more.Friday, September 3, 2010
  11. 11. Source Frameworks Upgrade Installation $ cd ~/Roots/ $ for FRAMEWORK in `echo *.framework`; do sudo rm -r /Library/Frameworks/${FRAMEWORK}; done $ cd /path/to/WonderSource $ svn update --force --accept theirs-full --revision <ARG> $ ant -Dwonder.patch=54 clean; ant -Dwonder.patch=54 frameworks; sudo ant -Dwonder.patch=54 frameworks.install [WO 5.4] OR $ ant clean; ant frameworks; sudo ant frameworks.install [WO 5.3]Friday, September 3, 2010
  12. 12. Working with Wonder Source • Some Advantages of working with Source over Binaries: • Learn much about WebObjects and EOF (and java dev styles?) • Easily browse and search the source • Work with a specific svn version (teams, quality control) • Discover the Hidden Treasures (Don’t miss Chuck Hill later) • Note ERXExtensions classpath file contents for 5.3 vs 5.4 .....Friday, September 3, 2010
  13. 13. Demo • Linking Wonder Source projects to your Workspace • Creating a Wonder app • What is different between a Wonder app and a Standard appFriday, September 3, 2010
  14. 14. Integrating Wonder into Your Existing Application • Add Frameworks • Adjust Application, Session and DirectAction superclasses • Use ERXGenericRecord instead of EOGenericRecord • Configure Wonder-specific Properties • copy/paste from a new temp Wonder app as a starting pointFriday, September 3, 2010
  15. 15. Integrating Wonder into an Existing Application • DEMOFriday, September 3, 2010
  16. 16. Configuring Wonder’s Features • Wonder is configured, more or less, using Properties files. • Check comments and contents of each framework’s Properties file • Where to find Documentation • Java API • Framework “Documentation” directory • http://wiki.objectstyle.org/confluence/display/WONDER/Home • Examine Source codeFriday, September 3, 2010
  17. 17. Select Features • ERXProperties • EOModel Connection Dictionary using Properties • ERXEC usage • ERPrototypes • Over-riding Prototypes via ERXModel and ERXModelGroupFriday, September 3, 2010
  18. 18. ERXProperties • A variety of ways to organize Properties • ERXProperties replaces and extends deprecated NSProperties • many convenient utility methods including property coercion • log4j configured via Properties • Understanding how ERXProperties works can facilitate better team organization, app administration and general happiness :-)Friday, September 3, 2010
  19. 19. The Standard WebObjects Way Override Properties Framework Resources Properties Properties Properties Application Resources WebObjects.properties [user.home] dir -DpropertyName=propertyValue Command Line arguments -DpropertyName=”property Value”Friday, September 3, 2010
  20. 20. Properties: The Wonder Way Properties Properties Properties Properties.<username> Framework Resources Override Properties.<username> Properties.<username> Properties Application Resources WebObjects.properties [user.home] dir ( file1, file2, file3 ) [er.extensions.ERXProperties.OptionalConfigurationFiles] (absolute filepaths AND/OR application Resource filenames) Properties OR [er.extensions.ERXProperties.machinePropertiesPath] /<appName>/Properties (absolute filepath, default “/etc/WebObjects”) Properties.dev [er.extensions.ERXProperties.devPropertiesName] (file extension, App Resource, default “dev”) Properties.<username> Application Resources -DpropertyName=propertyValue Command Line arguments -DpropertyName=”property Value” @see er.extensions.foundation.ERXProperties.pathsForUserAndBundleProperties(boolean) Note: [propertyname] denotes a system property (so properties are determining the loading of more properties!)Friday, September 3, 2010
  21. 21. Examples of Properties fiddling... ## We always want to use @@ as the delimiter and NOT a single @ er.extensions.ERXSimpleTemplateParser.useOldDelimiter=false app.directActionPassword=passw0rd er.extensions.ERXJUnitPassword = @@app.directActionPassword@@ er.extensions.ERXLog4JPassword = @@app.directActionPassword@@ er.extensions.ERXGCPassword = @@app.directActionPassword@@ er.extensions.ERXDirectAction.ChangeSystemPropertyPassword = @@app.directActionPassword@@ app.smtpserver=192.168.3.142 WOSMTPHost=@@app.smtpserver@@ log4j.appender.myMail.SMTPHost=@@app.smtpserver@@ Automatically generated into Resources by build ## Optional properties to load er.extensions.ERXProperties.OptionalConfigurationFiles=deploy.properties log4j.appender.A2.file=/var/log/webobjects_apps/@@build.app.bundle.name@@-@@WOPort@@.log log4j.appender.myMail.Subject=Log4jError (@@build.app.bundle.name@@ @@host@@ @@WOPort@@)Friday, September 3, 2010
  22. 22. Common Dev/Deploy Properties StrategyFriday, September 3, 2010
  23. 23. EOModel Connection Dictionary WebObjects WayFriday, September 3, 2010
  24. 24. EOModel Connection Dictionary Wonder Way - Properties File: # For individual eomodels model.URL = jdbc:mysql://hostname/firstdatabase model.DBUser = firstuser model.DBPassword = firstpassword model.DBDriver = model.DBPlugin = # Global, or default where model entry not specified dbConnectURLGLOBAL = jdbc:mysql://hostname/nextdatabase dbConnectUserGLOBAL = nextuser dbConnectPasswordGLOBAL = nextpassword dbConnectDriverGLOBAL = dbConnectPluginGLOBAL = Wonder Way - WOMonitor Launch Arguments: -Dmodel.URL=”jdbc:mysql://localhost/database?useUnicode=true&characterEncoding=UTF-8” -Dmodel.DBUser=firstuser -Dmodel.DBPassword=firstpasswordFriday, September 3, 2010
  25. 25. ERXEC • EOEditingContext subclass • EOEditingContext ec = ERXEC.newEditingContext(); • supports automatic lock/unlock in R-R cycle • er.extensions.ERXEC.safeLocking=true • enabled by default for new Wonder projects • Calls ERXEnterpriseObject state transition will*/did* methods • Implemented by ERXGenericRecordFriday, September 3, 2010
  26. 26. ERXEC Auto Lock/Unlock • Implicitly supported in Request-Response threads • ERXApplication._endRequest() ... which calls ... • ERXEC.unlockAllContextsForCurrentThread(); • Background threads are your responsibility! • Here is how to do it ...Friday, September 3, 2010
  27. 27. Runnable lock handling public class MyTask implements Runnable { public void run() { ERXApplication._startRequest(); try { performTask(); } finally { ERXApplication._endRequest(); } } private void performTask() { EOEditingContext ec = ERXEC.newEditingContext(); ec.lock(); try { // Do some EOF stuff with the ec. } catch (Exception e) { // handle exception } finally { ec.unlock(); } } }Friday, September 3, 2010
  28. 28. Callable lock handling public class MyTask implements Callable<MyResultClass> { public MyResultClass call() { ERXApplication._startRequest(); try { return performTask(); } finally { ERXApplication._endRequest(); } } private MyResultClass performTask() { EOEditingContext ec = ERXEC.newEditingContext(); ec.lock(); try { // Do some EOF stuff with the ec. } catch (Exception e) { // handle exception } finally { ec.unlock(); } return myResult; } }Friday, September 3, 2010
  29. 29. Passing Objects to a Thread public WOActionResults shuffleStudioAction() { Studio studio = selectedStudio(); EOGlobalID studioGid = (EOGlobalID) ERXEOControlUtilities.convertEOtoGID(studio); ProcessStudioTask task = new ProcessStudioTask(studioGid); MyExecutorServices.executorService().execute(task); return null; }Friday, September 3, 2010
  30. 30. Thread Hydrates EO public class ProcessStudioTask extends ERXRunnable { private final EOGlobalID _studioGlobalID; public ProcessStudioTask(EOGlobalID studioGlobalID) { _studioGlobalID = studioGlobalID; } @Override public void _run() { EOEditingContext ec = ERXEC.newEditingContext(); ec.lock(); try { Studio studio = (Studio) ERXEOControlUtilities.convertGIDtoEO(ec, _studioGlobalID); } catch (Exception e) { // Handle error } finally { ec.unlock(); } } }Friday, September 3, 2010
  31. 31. ERPrototypes • DEMOFriday, September 3, 2010
  32. 32. Overriding Prototypes • ERXModel and ERXModelGroup • Allow “over-riding” of prototypes based on prototype entity naming conventions • Feature configured in system Properties: er.extensions.ERXModelGroup.modelClassName = com.webobjects.eoaccess.ERXModel er.extensions.ERXModel.useExtendedPrototypes = true er.extensions.ERXModelGroup.flattenPrototypes = falseFriday, September 3, 2010
  33. 33. Prototypes Over-ride Order • From lowest to highest priority: • EOPrototypes • EO<adaptorName>Prototypes (Wonder has ‘Memory’ and ‘REST’ adaptor protypes) • EOJDBC<pluginName>Prototypes (Wonder database prototype names) • EOCustomPrototypes • EO<adaptorName>CustomPrototypes • EOJDBC<pluginName>CustomPrototypes • EO<modelName>Prototypes • EO<adaptorName><modelName>Prototypes • EOJDBC<pluginName><modelName>PrototypesFriday, September 3, 2010
  34. 34. Override Prototypes • DEMOFriday, September 3, 2010
  35. 35. Resources • http://wiki.objectstyle.org/confluence/display/WONDER/Home • http://projectwonder.blogspot.com/ • http://webobjects.mdimension.com/hudson/ • JavaDoc and Binaries • “Wonder53” = Wonder for WebObjects 5.3.3 • “Wonder54” = Wonder for WebObjects 5.4.3 • Mailing Lists • https://lists.sourceforge.net/lists/listinfo/wonder-disc • https://lists.sourceforge.net/lists/listinfo/wonder-cvsFriday, September 3, 2010
  36. 36. Q&A Getting Start with Wonder WOWODC 2010Friday, September 3, 2010

×