MONTREAL JUNE 30, JULY 1ST AND 2ND 2012ERRest : The Next StepsPascal RobertMacTI.ca
Our agenda•   HTML views•   Alias, non-EO and fake primary keys•   Handling redirections•   Handling headers•   Other stuff
HTML views
Automatic HTML routing•   In your controller:    protected boolean isAutomaticHtmlRoutingEnabled() {      return true;    ...
Automatic HTML handling•   /blogEntries.html -> BlogEntryIndexPage•   /blogEntries/show.html -> BlogEntryShowPage•   /blog...
Non automatic•   Same as with direct actions•   You use pageWithName/return nextPage
Statefullness•   Have HTML components and want statefulness? Use Ajax    components    •   D2W components wont work•   For...
HTML views demo
Security•   We need to protect creation of users and blog posts•   checkAccess() is not what we need•   We need to modify ...
Security Demo
Alias•   Can remap entity names to something else    ERXRestNameRegistry.registry().setExternalNameForInternalName("Pos   ...
Alias demo
Faking primary keys•   Might need more useful value for primary key, or hidding it    •   Example: blog title instead of p...
Fake ids demo
Date formats•   Default patterns:    •   NSTimestamp: %Y-%m-%dT%H:%M:%SZ    •   Java Date and JodaTime LocalDate: yyyy-MM-...
Date formatting•   Differents formatters for NSTimestamp, Java dates and Joda Time    •   er.rest.(timestamp|date|joda)For...
Date formatting•   Cascade:    •   er.rest.(timestamp|date|joda)Formatter (from context)    •   er.rest. (timestamp|date|j...
Date formats demo
Advanced stuff
Transactions
Transactions    •   Was built to support Dojo    •   Allow queuing transactions, commit later    •   Client send transacti...
Transactions demo
Redirections•   Title of blog is different? Need to send old URLs to new one•   Must keep track of older title...•   EOF a...
Adding caching•   Why send the same data if it doesnt change?•   Browsers have cache•   Client APIs could cache too•   Aga...
What we need•   Unique ID    •   title() + "_" + primaryKey()•   Entity to keep track of current state    •   Etag value  ...
The model
Redirections and caching demo
Adding non-EO support•   Needs delegate for non-EO•   Can use strings instead of ERXKey•   Extends from ERXAbstractRestDel...
JSON Schema •   Was added for Dojo JsonRestStore •   But also useful for documenting your REST services •   Add this to th...
JSON Schema exampleGET http://127.0.0.1/cgi-bin/WebObjects/Movies.woa/-6100/ra/movies?schema=true{    "name":"Movie",    "...
MONTREAL JUNE 30, JULY 1ST AND 2ND 2012Q&A
Upcoming SlideShare
Loading in …5
×

ERRest - The Next Steps

2,512 views

Published on

Covered topics:

- HTML views
- Non-enterprise objects
- Using caching and redirections
- Security
- Alias
- Date formatting
- Transactions

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

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

No notes for slide

ERRest - The Next Steps

  1. 1. MONTREAL JUNE 30, JULY 1ST AND 2ND 2012ERRest : The Next StepsPascal RobertMacTI.ca
  2. 2. Our agenda• HTML views• Alias, non-EO and fake primary keys• Handling redirections• Handling headers• Other stuff
  3. 3. HTML views
  4. 4. Automatic HTML routing• In your controller: protected boolean isAutomaticHtmlRoutingEnabled() { return true; }• Component name: <EntityName><Action>Page.wo• Component must implement IERXRouteComponent
  5. 5. Automatic HTML handling• /blogEntries.html -> BlogEntryIndexPage• /blogEntries/show.html -> BlogEntryShowPage• /blogEntries/update.html -> BlogEntryUpdatePage• ...
  6. 6. Non automatic• Same as with direct actions• You use pageWithName/return nextPage
  7. 7. Statefullness• Have HTML components and want statefulness? Use Ajax components • D2W components wont work• For other formats, can use sessions • Store session ID in cookies
  8. 8. HTML views demo
  9. 9. Security• We need to protect creation of users and blog posts• checkAccess() is not what we need• We need to modify the login method
  10. 10. Security Demo
  11. 11. Alias• Can remap entity names to something else ERXRestNameRegistry.registry().setExternalNameForInternalName("Pos t", BlogEntry.ENTITY_NAME);• For attributes, use cover methods and ERXKey
  12. 12. Alias demo
  13. 13. Faking primary keys• Might need more useful value for primary key, or hidding it • Example: blog title instead of primary key• Can redefine "id" for REST context• Need a delegate • Need to override default routes if id not numeric
  14. 14. Fake ids demo
  15. 15. Date formats• Default patterns: • NSTimestamp: %Y-%m-%dT%H:%M:%SZ • Java Date and JodaTime LocalDate: yyyy-MM-ddTHH:mm:ssZ• Can change the pattern for all controllers, by controller or action• Wont apply to WO components (HTML views)
  16. 16. Date formatting• Differents formatters for NSTimestamp, Java dates and Joda Time • er.rest.(timestamp|date|joda)Formatter (java.text.Format object) • er.rest.(timestamp|date|joda)Format (String) • er.rest.(timestamp|date|joda)Format.primary (String) • er.rest.(timestamp|date|joda)Format.secondary (String)
  17. 17. Date formatting• Cascade: • er.rest.(timestamp|date|joda)Formatter (from context) • er.rest. (timestamp|date|joda) Format (from context) • er.rest. (timestamp|date|joda) Format (from properties) • If value contains a space: • er.rest. (timestamp|date|joda) Format.secondary • If value dont contains a space: • er.rest.(timestamp|date|joda) Format.primary
  18. 18. Date formats demo
  19. 19. Advanced stuff
  20. 20. Transactions
  21. 21. Transactions • Was built to support Dojo • Allow queuing transactions, commit later • Client send transaction state, client id and sequence id • Set ERXRest.transactionsEnabled to true • Need to store session ID in cookies public Session() { setStoresIDsInCookies(true); }
  22. 22. Transactions demo
  23. 23. Redirections• Title of blog is different? Need to send old URLs to new one• Must keep track of older title...• EOF and changes notifications to the rescue!
  24. 24. Adding caching• Why send the same data if it doesnt change?• Browsers have cache• Client APIs could cache too• Again, changes notifications to the rescue!
  25. 25. What we need• Unique ID • title() + "_" + primaryKey()• Entity to keep track of current state • Etag value • Last modified timestamp • Primary key value • State (inserted, updated, deleted)• Entity to keep track of history• Using change notifications to populate state and history
  26. 26. The model
  27. 27. Redirections and caching demo
  28. 28. Adding non-EO support• Needs delegate for non-EO• Can use strings instead of ERXKey• Extends from ERXAbstractRestDelegate• Implements logic that finds objects and “primary keys”
  29. 29. JSON Schema • Was added for Dojo JsonRestStore • But also useful for documenting your REST services • Add this to the URL: ?schema=true • Add this to your action: if (isSchemaRequest()) { return schemaResponse(showFilter()); }
  30. 30. JSON Schema exampleGET http://127.0.0.1/cgi-bin/WebObjects/Movies.woa/-6100/ra/movies?schema=true{ "name":"Movie", "properties":{ "title":{ "optional":false, "type":"string", "minLength":1, "maxLength":255 }, "dateReleased":{ "optional":true, "type":"string", "format":"date-time" }, "category":{ "optional":true, "type":"string", "maxLength":20 } }}
  31. 31. MONTREAL JUNE 30, JULY 1ST AND 2ND 2012Q&A

×