Christian Kaltepoth | ingenit GmbH & Co. KGBeyond PrettyFacesEinführung in Rewrite
URL-Rewriting
WikipediaA rewrite engine is software located in aWeb application framework running on aWeb server that modifies a web URL...
Beispielhttp://www.onlineshop.de/b/ref=sa_menu_desk3?ie=UTF8&node=2193272340http://www.onlineshop.de/elektronik
Sprechende RESTful URLshttp://www.javaserverfaces.org/newshttp://jax.de/2013/sessions/https://github.com/ocpsoft/rewrite/i...
Wozu das Ganze?
Vorteile• Adressierbare Informationen– Wo bin ich hier?– "Vertrauen"• Reload und Bookmarks• Einfache HTML Links– Lose Kopp...
SEO• Keywords in URL• Optimierung des Rankingshttp://www.amazon.com/JavaServer-Faces-2-0-Complete-Reference/dp/0071625097
PrettyFaces• JSF URL-Rewriting De-facto-Standard• RESTful URLs• Page Actions• Einfache Rewrite Engine• Dynamic Views• Inte...
Warum Rewrite?
API AbhängigkeitenServlet-spezifischJSF-spezifischPrettyFaces
Einschränkungen• Mapping nur via Request Path• Eingeschränkte Konfiguration via XML• Annotation API „verbesserungswürdig“•...
Der Neuanfang
Was ist Rewrite?
Key Features• Servlet basiertes Rewriting auf Basiseiner Rule-Engine• Framework Integration– JSF, CDI, Spring, Shiro, etc....
Begriffe• Configuration:– Sortierte Listevon Rules• Rule:– Conditions– Operations– Priority
Rewriting TypesInboundOutbound
InboundGET /faces/home.xhtml HTTP/1.1Host: www.acme.comConnection: keep-alive[....]
Outbound<a href="/faces/home.xhtml">Getting started</a>
Java DSL
Warum?• Typensichere Konfiguration• Code Assist durch IDE• Erweiterbar• Geführte Konfiguration• „Plain Java“
Java DSLpublic class RewriteConfig extends HttpConfigurationProvider {@Overridepublic Configuration getConfiguration(Servl...
ConfigurationBuilderreturn ConfigurationBuilder.begin()// Variante 1.addRule().when( /* condition */ ).perform( /* operati...
Initial Redirecthttp://www.acme.com/http://www.acme.com/faces/home.xhtmlRedirect
Beispiel: Initial Redirect.addRule().when(Direction.isInbound().and(Path.matches("/"))).perform(Redirect.permanent("/faces...
Der erste Rewritehttp://www.acme.com/faces/home.xhtmlhttp://www.acme.com/home
Der erste Rewrite.addRule().when(Direction.isInbound().and(Path.matches("/home"))).perform(Forward.to("/faces/home.xhtml")...
Einfacher: Joins.addRule(Join.path("/home").to("/faces/home.xhtml"))
Parameter/faces/products.xhtml?category=books/products/books
JSF 2.0 View Parameter<f:metadata><f:viewParam name="category"value="#{productListPage.category}" /></f:metadata>@Named@Re...
Join mit Parametern.addRule(Join.path("/products/{category}").to("/faces/products.xhtml"))
Demo
Annotations?
Einfacher Join@Named@RequestScoped@Join(path = "/home",to = "/faces/home.xhtml")public class HomePage {/* your code */}
Parameter/faces/products.xhtml?category=books/products/books
Mit View-Parametern@Named@RequestScoped@Join(path = "/products/{category}",to = "/faces/products.xhtml")public class Produ...
Ohne View-Parameter@Named@RequestScoped@Join(path = "/products/{category}",to = "/faces/products.xhtml")public class Produ...
Validierung@Named@RequestScoped@Join(path = "/products/{category}",to = "/faces/products.xhtml")public class ProductListPa...
JSF Validators@Named@RequestScoped@Join(path = "/products/{category}",to = "/faces/products.xhtml")public class ProductLis...
Request Actions
Request Actions@Named@RequestScoped@Join(path = "/home",to = "/faces/home.xhtml")public class HomePage {@RequestActionpubl...
Ignore Postbacks@Named@ViewScoped@Join(path = "/home",to = "/faces/home.xhtml")public class HomePage {@RequestAction@Ignor...
Deferral@Named@ViewScoped@Join(path = "/home",to = "/faces/home.xhtml")public class HomePage {@RequestAction@Deferred(befo...
Navigation
Navigation<h:link outcome="/products.xhtml"><f:param name="category" value="books"/>Bücher</h:link><a href="/products/book...
Navigationpublic class SomePage {public String actionMethod() {/* do something */return "/products.xhtml?category=books" +...
Navigationpublic class SomePage {public Navigate actionMethod() {/* do something */return Navigate.to(ProductListPage.clas...
Was kann Rewrite noch?
Content Delivery Networks(CDN)
JSF Resources<h:outputScript name="jquery.js" /><script type="text/javascript"src="/faces/javax.faces.resource/jquery.js" ...
CDN URL Relocation.addRule(CDN.relocate("/faces/javax.faces.resource/jquery.js").to("http://dh8sm43.cloudfront.net/jquery....
ResourceTransformation
HTTP ResponseRewriteTransformationPipeline
Usecases• Minification– JavaScript, CSS• Compression– GZIP, Deflate• Rendering– SASS, SCSS, Markdown, Textile, ...• Custom...
JavaScript Minify.addRule().when(Direction.isInbound().and(Path.matches("/faces/javax.faces.resource/{*}.js"))).perform(Tr...
Rendering
Beispiel: Sass$blue: #3bbfce;$margin: 16px;.content-navigation {border-color: $blue;color:darken($blue, 9%);}.border {padd...
Beispiel: Sass.addRule().when(Direction.isInbound().and(Path.matches("/styles/{*}.sass"))).perform(Response.setContentType...
Wie migriere ich meinePrettyFaces Anwendung?
Rewrite PrettyFaces Module<dependency><groupId>org.ocpsoft.rewrite</groupId><artifactId>rewrite-config-prettyfaces</artifa...
Thank you!http://ocpsoft.org/rewrite/Christian Kaltepothchristian@kaltepoth.de@chkal
Beyond PrettyFaces - Einführung in Rewrite
Nächste SlideShare
Wird geladen in …5
×

Beyond PrettyFaces - Einführung in Rewrite

1.534 Aufrufe

Veröffentlicht am

My Rewrite talk on JAX 2013

Veröffentlicht in: Technologie, News & Politik
0 Kommentare
1 Gefällt mir
Statistik
Notizen
  • Als Erste(r) kommentieren

Keine Downloads
Aufrufe
Aufrufe insgesamt
1.534
Auf SlideShare
0
Aus Einbettungen
0
Anzahl an Einbettungen
22
Aktionen
Geteilt
0
Downloads
10
Kommentare
0
Gefällt mir
1
Einbettungen 0
Keine Einbettungen

Keine Notizen für die Folie

Beyond PrettyFaces - Einführung in Rewrite

  1. 1. Christian Kaltepoth | ingenit GmbH & Co. KGBeyond PrettyFacesEinführung in Rewrite
  2. 2. URL-Rewriting
  3. 3. WikipediaA rewrite engine is software located in aWeb application framework running on aWeb server that modifies a web URLsappearance.This modification is called URL rewriting.http://en.wikipedia.org/wiki/Rewrite_engine
  4. 4. Beispielhttp://www.onlineshop.de/b/ref=sa_menu_desk3?ie=UTF8&node=2193272340http://www.onlineshop.de/elektronik
  5. 5. Sprechende RESTful URLshttp://www.javaserverfaces.org/newshttp://jax.de/2013/sessions/https://github.com/ocpsoft/rewrite/issues/87http://stackoverflow.com/questions/tagged/jsf
  6. 6. Wozu das Ganze?
  7. 7. Vorteile• Adressierbare Informationen– Wo bin ich hier?– "Vertrauen"• Reload und Bookmarks• Einfache HTML Links– Lose Kopplung• Technologieneutralität
  8. 8. SEO• Keywords in URL• Optimierung des Rankingshttp://www.amazon.com/JavaServer-Faces-2-0-Complete-Reference/dp/0071625097
  9. 9. PrettyFaces• JSF URL-Rewriting De-facto-Standard• RESTful URLs• Page Actions• Einfache Rewrite Engine• Dynamic Views• Integration mit JSF Navigation
  10. 10. Warum Rewrite?
  11. 11. API AbhängigkeitenServlet-spezifischJSF-spezifischPrettyFaces
  12. 12. Einschränkungen• Mapping nur via Request Path• Eingeschränkte Konfiguration via XML• Annotation API „verbesserungswürdig“• Konvertierung nur eingeschränktmöglich• Nicht besonders erweiterbar
  13. 13. Der Neuanfang
  14. 14. Was ist Rewrite?
  15. 15. Key Features• Servlet basiertes Rewriting auf Basiseiner Rule-Engine• Framework Integration– JSF, CDI, Spring, Shiro, etc.• Konfiguration: Java DSL + Annotations• Fokus auf Erweiterbarkeit• Open Source (Apache 2.0)
  16. 16. Begriffe• Configuration:– Sortierte Listevon Rules• Rule:– Conditions– Operations– Priority
  17. 17. Rewriting TypesInboundOutbound
  18. 18. InboundGET /faces/home.xhtml HTTP/1.1Host: www.acme.comConnection: keep-alive[....]
  19. 19. Outbound<a href="/faces/home.xhtml">Getting started</a>
  20. 20. Java DSL
  21. 21. Warum?• Typensichere Konfiguration• Code Assist durch IDE• Erweiterbar• Geführte Konfiguration• „Plain Java“
  22. 22. Java DSLpublic class RewriteConfig extends HttpConfigurationProvider {@Overridepublic Configuration getConfiguration(ServletContext ctx) {// Konfiguration}@Overridepublic int priority() {return 10;}}
  23. 23. ConfigurationBuilderreturn ConfigurationBuilder.begin()// Variante 1.addRule().when( /* condition */ ).perform( /* operation */ )// Variante 2.addRule( /* rule */ );
  24. 24. Initial Redirecthttp://www.acme.com/http://www.acme.com/faces/home.xhtmlRedirect
  25. 25. Beispiel: Initial Redirect.addRule().when(Direction.isInbound().and(Path.matches("/"))).perform(Redirect.permanent("/faces/home.xhtml"))
  26. 26. Der erste Rewritehttp://www.acme.com/faces/home.xhtmlhttp://www.acme.com/home
  27. 27. Der erste Rewrite.addRule().when(Direction.isInbound().and(Path.matches("/home"))).perform(Forward.to("/faces/home.xhtml")).addRule().when(Direction.isOutbound().and(Path.matches("/faces/home.xhtml"))).perform(Substitute.with("/home"))
  28. 28. Einfacher: Joins.addRule(Join.path("/home").to("/faces/home.xhtml"))
  29. 29. Parameter/faces/products.xhtml?category=books/products/books
  30. 30. JSF 2.0 View Parameter<f:metadata><f:viewParam name="category"value="#{productListPage.category}" /></f:metadata>@Named@RequestScopedpublic class ProductListPage {private String category;}
  31. 31. Join mit Parametern.addRule(Join.path("/products/{category}").to("/faces/products.xhtml"))
  32. 32. Demo
  33. 33. Annotations?
  34. 34. Einfacher Join@Named@RequestScoped@Join(path = "/home",to = "/faces/home.xhtml")public class HomePage {/* your code */}
  35. 35. Parameter/faces/products.xhtml?category=books/products/books
  36. 36. Mit View-Parametern@Named@RequestScoped@Join(path = "/products/{category}",to = "/faces/products.xhtml")public class ProductListPage {// <f:viewParam name=“category“ ...>private String category;/* ... */}
  37. 37. Ohne View-Parameter@Named@RequestScoped@Join(path = "/products/{category}",to = "/faces/products.xhtml")public class ProductListPage {@Parameterprivate String category;/* ... */}
  38. 38. Validierung@Named@RequestScoped@Join(path = "/products/{category}",to = "/faces/products.xhtml")public class ProductListPage {@Parameter@Matches("[a-zA-Z-]+")private String category;/* ... */}
  39. 39. JSF Validators@Named@RequestScoped@Join(path = "/products/{category}",to = "/faces/products.xhtml")public class ProductListPage {@Parameter@Validate(with = CategoryValidator.class)private String category;/* ... */}
  40. 40. Request Actions
  41. 41. Request Actions@Named@RequestScoped@Join(path = "/home",to = "/faces/home.xhtml")public class HomePage {@RequestActionpublic void init() {/* your code */}}
  42. 42. Ignore Postbacks@Named@ViewScoped@Join(path = "/home",to = "/faces/home.xhtml")public class HomePage {@RequestAction@IgnorePostbackpublic void init() {/* your code */}}
  43. 43. Deferral@Named@ViewScoped@Join(path = "/home",to = "/faces/home.xhtml")public class HomePage {@RequestAction@Deferred(before = Phase.RENDER_RESPONSE)public void prepareRender() {/* your code */}}
  44. 44. Navigation
  45. 45. Navigation<h:link outcome="/products.xhtml"><f:param name="category" value="books"/>Bücher</h:link><a href="/products/books">Bücher</a>
  46. 46. Navigationpublic class SomePage {public String actionMethod() {/* do something */return "/products.xhtml?category=books" +"&faces-redirect=true";}}
  47. 47. Navigationpublic class SomePage {public Navigate actionMethod() {/* do something */return Navigate.to(ProductListPage.class).with("category", "books");}}
  48. 48. Was kann Rewrite noch?
  49. 49. Content Delivery Networks(CDN)
  50. 50. JSF Resources<h:outputScript name="jquery.js" /><script type="text/javascript"src="/faces/javax.faces.resource/jquery.js" /><script type="text/javascript"src="http://dh8sm43.cloudfront.net/jquery.js" />ErzeugtGewünscht
  51. 51. CDN URL Relocation.addRule(CDN.relocate("/faces/javax.faces.resource/jquery.js").to("http://dh8sm43.cloudfront.net/jquery.js"))
  52. 52. ResourceTransformation
  53. 53. HTTP ResponseRewriteTransformationPipeline
  54. 54. Usecases• Minification– JavaScript, CSS• Compression– GZIP, Deflate• Rendering– SASS, SCSS, Markdown, Textile, ...• Custom Processing
  55. 55. JavaScript Minify.addRule().when(Direction.isInbound().and(Path.matches("/faces/javax.faces.resource/{*}.js"))).perform(Transform.with(Minify.js()))
  56. 56. Rendering
  57. 57. Beispiel: Sass$blue: #3bbfce;$margin: 16px;.content-navigation {border-color: $blue;color:darken($blue, 9%);}.border {padding: $margin / 2;margin: $margin / 2;border-color: $blue;}.content-navigation {border-color: #3bbfce;color: #2b9eab;}.border {padding: 8px;margin: 8px;border-color: #3bbfce;}
  58. 58. Beispiel: Sass.addRule().when(Direction.isInbound().and(Path.matches("/styles/{*}.sass"))).perform(Response.setContentType("text/css").and(Transform.with(Sass.compiler())));
  59. 59. Wie migriere ich meinePrettyFaces Anwendung?
  60. 60. Rewrite PrettyFaces Module<dependency><groupId>org.ocpsoft.rewrite</groupId><artifactId>rewrite-config-prettyfaces</artifactId><version>2.0.0.Final</version></dependency>• Drop-In Replacement für PrettyFaces• „Sanfte“ Migration
  61. 61. Thank you!http://ocpsoft.org/rewrite/Christian Kaltepothchristian@kaltepoth.de@chkal

×