SlideShare a Scribd company logo
1 of 62
Download to read offline
Christian Kaltepoth | ingenit GmbH & Co. KG
Beyond PrettyFaces
Einführung in Rewrite
URL-Rewriting
Wikipedia
A rewrite engine is software located in a
Web application framework running on a
Web server that modifies a web URL's
appearance.
This modification is called URL rewriting.
http://en.wikipedia.org/wiki/Rewrite_engine
Beispiel
http://www.onlineshop.de/b/ref=sa_m
enu_desk3?ie=UTF8&node=2193272340
http://www.onlineshop.de/elektronik
Sprechende RESTful URLs
http://www.javaserverfaces.org/news
http://jax.de/2013/sessions/
https://github.com/ocpsoft/rewrite/issues/87
http://stackoverflow.com/questions/tagged/jsf
Wozu das Ganze?
Vorteile
• Adressierbare Informationen
– Wo bin ich hier?
– "Vertrauen"
• Reload und Bookmarks
• Einfache HTML Links
– Lose Kopplung
• Technologieneutralität
SEO
• Keywords in URL
• Optimierung des Rankings
http://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
• Integration mit JSF Navigation
Warum Rewrite?
API Abhängigkeiten
Servlet-spezifisch
JSF-spezifisch
PrettyFaces
Einschränkungen
• Mapping nur via Request Path
• Eingeschränkte Konfiguration via XML
• Annotation API „verbesserungswürdig“
• Konvertierung nur eingeschränkt
möglich
• Nicht besonders erweiterbar
Der Neuanfang
Was ist Rewrite?
Key Features
• Servlet basiertes Rewriting auf Basis
einer Rule-Engine
• Framework Integration
– JSF, CDI, Spring, Shiro, etc.
• Konfiguration: Java DSL + Annotations
• Fokus auf Erweiterbarkeit
• Open Source (Apache 2.0)
Begriffe
• Configuration:
– Sortierte Liste
von Rules
• Rule:
– Conditions
– Operations
– Priority
Rewriting Types
Inbound
Outbound
Inbound
GET /faces/home.xhtml HTTP/1.1
Host: www.acme.com
Connection: 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 DSL
public class RewriteConfig extends HttpConfigurationProvider {
@Override
public Configuration getConfiguration(ServletContext ctx) {
// Konfiguration
}
@Override
public int priority() {
return 10;
}
}
ConfigurationBuilder
return ConfigurationBuilder.begin()
// Variante 1
.addRule()
.when( /* condition */ )
.perform( /* operation */ )
// Variante 2
.addRule( /* rule */ )
;
Initial Redirect
http://www.acme.com/
http://www.acme.com/faces/home.xhtml
Redirect
Beispiel: Initial Redirect
.addRule()
.when(
Direction.isInbound().and(Path.matches("/"))
)
.perform(
Redirect.permanent("/faces/home.xhtml")
)
Der erste Rewrite
http://www.acme.com/faces/home.xhtml
http://www.acme.com/home
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"))
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
@RequestScoped
public class ProductListPage {
private String category;
}
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 ProductListPage {
// <f:viewParam name=“category“ ...>
private String category;
/* ... */
}
Ohne View-Parameter
@Named
@RequestScoped
@Join(path = "/products/{category}",
to = "/faces/products.xhtml")
public class ProductListPage {
@Parameter
private String category;
/* ... */
}
Validierung
@Named
@RequestScoped
@Join(path = "/products/{category}",
to = "/faces/products.xhtml")
public class ProductListPage {
@Parameter
@Matches("[a-zA-Z-]+")
private String category;
/* ... */
}
JSF Validators
@Named
@RequestScoped
@Join(path = "/products/{category}",
to = "/faces/products.xhtml")
public class ProductListPage {
@Parameter
@Validate(with = CategoryValidator.class)
private String category;
/* ... */
}
Request Actions
Request Actions
@Named
@RequestScoped
@Join(path = "/home",
to = "/faces/home.xhtml")
public class HomePage {
@RequestAction
public void init() {
/* your code */
}
}
Ignore Postbacks
@Named
@ViewScoped
@Join(path = "/home",
to = "/faces/home.xhtml")
public class HomePage {
@RequestAction
@IgnorePostback
public void init() {
/* your code */
}
}
Deferral
@Named
@ViewScoped
@Join(path = "/home",
to = "/faces/home.xhtml")
public class HomePage {
@RequestAction
@Deferred(before = Phase.RENDER_RESPONSE)
public void prepareRender() {
/* your code */
}
}
Navigation
Navigation
<h:link outcome="/products.xhtml">
<f:param name="category" value="books"/>
Bücher
</h:link>
<a href="/products/books">
Bücher
</a>
Navigation
public class SomePage {
public String actionMethod() {
/* do something */
return "/products.xhtml?category=books" +
"&faces-redirect=true";
}
}
Navigation
public class SomePage {
public Navigate actionMethod() {
/* do something */
return Navigate.to(ProductListPage.class)
.with("category", "books");
}
}
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" />
<script type="text/javascript"
src="http://dh8sm43.cloudfront.net/jquery.js" />
Erzeugt
Gewünscht
CDN URL Relocation
.addRule(
CDN.relocate("/faces/javax.faces.resource/jquery.js")
.to("http://dh8sm43.cloudfront.net/jquery.js")
)
Resource
Transformation
HTTP Response
Rewrite
Transformation
Pipeline
Usecases
• Minification
– JavaScript, CSS
• Compression
– GZIP, Deflate
• Rendering
– SASS, SCSS, Markdown, Textile, ...
• Custom Processing
JavaScript Minify
.addRule()
.when(
Direction.isInbound().and(Path.matches(
"/faces/javax.faces.resource/{*}.js"))
)
.perform(
Transform.with(Minify.js())
)
Rendering
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;
}
Beispiel: Sass
.addRule()
.when(
Direction.isInbound().and(
Path.matches("/styles/{*}.sass"))
)
.perform(
Response.setContentType("text/css").and(
Transform.with(Sass.compiler()))
);
Wie migriere ich meine
PrettyFaces Anwendung?
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
Thank you!
http://ocpsoft.org/rewrite/
Christian Kaltepoth
christian@kaltepoth.de
@chkal

More Related Content

What's hot

Single Page WebApp Architecture
Single Page WebApp ArchitectureSingle Page WebApp Architecture
Single Page WebApp Architecture
Morgan Cheng
 

What's hot (20)

Mule esb
Mule esbMule esb
Mule esb
 
Building and Managing Projects with Maven
Building and Managing Projects with MavenBuilding and Managing Projects with Maven
Building and Managing Projects with Maven
 
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
 
Building and managing java projects with maven part-III
Building and managing java projects with maven part-IIIBuilding and managing java projects with maven part-III
Building and managing java projects with maven part-III
 
Karlsruher Entwicklertag 2013 - Webanwendungen mit AngularJS
Karlsruher Entwicklertag 2013 - Webanwendungen mit AngularJSKarlsruher Entwicklertag 2013 - Webanwendungen mit AngularJS
Karlsruher Entwicklertag 2013 - Webanwendungen mit AngularJS
 
Single Page WebApp Architecture
Single Page WebApp ArchitectureSingle Page WebApp Architecture
Single Page WebApp Architecture
 
Managing JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJSManaging JavaScript Dependencies With RequireJS
Managing JavaScript Dependencies With RequireJS
 
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
ZZ BC#7.5 asp.net mvc practice  and guideline refresh! ZZ BC#7.5 asp.net mvc practice  and guideline refresh!
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
 
MVC Frameworks for building PHP Web Applications
MVC Frameworks for building PHP Web ApplicationsMVC Frameworks for building PHP Web Applications
MVC Frameworks for building PHP Web Applications
 
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Get...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Get...Uniface Lectures Webinar - Building Responsive Applications with Uniface: Get...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Get...
 
Two scoops of django 1.6 - Ch7, Ch8
Two scoops of django 1.6  - Ch7, Ch8Two scoops of django 1.6  - Ch7, Ch8
Two scoops of django 1.6 - Ch7, Ch8
 
Angularjs architecture
Angularjs architectureAngularjs architecture
Angularjs architecture
 
Building single page applications
Building single page applicationsBuilding single page applications
Building single page applications
 
AngularJS Deep Dives (NYC GDG Apr 2013)
AngularJS Deep Dives (NYC GDG Apr 2013)AngularJS Deep Dives (NYC GDG Apr 2013)
AngularJS Deep Dives (NYC GDG Apr 2013)
 
ZK framework
ZK frameworkZK framework
ZK framework
 
PHP & MVC
PHP & MVCPHP & MVC
PHP & MVC
 
Put a little Backbone in your WordPress
Put a little Backbone in your WordPressPut a little Backbone in your WordPress
Put a little Backbone in your WordPress
 
Building Web Applications with Zend Framework
Building Web Applications with Zend FrameworkBuilding Web Applications with Zend Framework
Building Web Applications with Zend Framework
 
Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014
 

Similar to Beyond PrettyFaces - Einführung in Rewrite

Microdata semantic-extend
Microdata semantic-extendMicrodata semantic-extend
Microdata semantic-extend
Seek Tan
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
funkatron
 
Advanced SEO for Web Developers
Advanced SEO for Web DevelopersAdvanced SEO for Web Developers
Advanced SEO for Web Developers
Nathan Buggia
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
Gavin Roy
 

Similar to Beyond PrettyFaces - Einführung in Rewrite (20)

Web Scraping In Ruby Utosc 2009.Key
Web Scraping In Ruby Utosc 2009.KeyWeb Scraping In Ruby Utosc 2009.Key
Web Scraping In Ruby Utosc 2009.Key
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
Spring Surf 101
Spring Surf 101Spring Surf 101
Spring Surf 101
 
Microdata semantic-extend
Microdata semantic-extendMicrodata semantic-extend
Microdata semantic-extend
 
Getting More Traffic From Search Advanced Seo For Developers Presentation
Getting More Traffic From Search  Advanced Seo For Developers PresentationGetting More Traffic From Search  Advanced Seo For Developers Presentation
Getting More Traffic From Search Advanced Seo For Developers Presentation
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
 
Great APIs - Future of Your Progress App
Great APIs - Future of Your Progress AppGreat APIs - Future of Your Progress App
Great APIs - Future of Your Progress App
 
Advanced SEO for Web Developers
Advanced SEO for Web DevelopersAdvanced SEO for Web Developers
Advanced SEO for Web Developers
 
Code Generation in Magento 2
Code Generation in Magento 2Code Generation in Magento 2
Code Generation in Magento 2
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep Dive
 
Supercharging your Organic CTR
Supercharging your Organic CTRSupercharging your Organic CTR
Supercharging your Organic CTR
 
Diagnosing Technical Issues With Search Engine Optimization
Diagnosing Technical Issues With Search Engine OptimizationDiagnosing Technical Issues With Search Engine Optimization
Diagnosing Technical Issues With Search Engine Optimization
 
URL Design
URL DesignURL Design
URL Design
 
WordPress Accessibility: WordCamp Chicago
WordPress Accessibility: WordCamp ChicagoWordPress Accessibility: WordCamp Chicago
WordPress Accessibility: WordCamp Chicago
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
 
Pyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsPyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web apps
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 

More from Christian Kaltepoth

More from Christian Kaltepoth (6)

TypeScript - das bessere JavaScript!?
TypeScript - das bessere JavaScript!?TypeScript - das bessere JavaScript!?
TypeScript - das bessere JavaScript!?
 
JavaScript im Jahr 2016
JavaScript im Jahr 2016JavaScript im Jahr 2016
JavaScript im Jahr 2016
 
MVC 1.0 - Das neue Webframework in Java EE 8
MVC 1.0 - Das neue Webframework in Java EE 8MVC 1.0 - Das neue Webframework in Java EE 8
MVC 1.0 - Das neue Webframework in Java EE 8
 
JSF vs. GWT? JSF und GWT!
JSF vs. GWT? JSF und GWT!JSF vs. GWT? JSF und GWT!
JSF vs. GWT? JSF und GWT!
 
Feature Flags mit Togglz
Feature Flags mit TogglzFeature Flags mit Togglz
Feature Flags mit Togglz
 
PrettyFaces: RESTful URLs für JSF
PrettyFaces: RESTful URLs für JSFPrettyFaces: RESTful URLs für JSF
PrettyFaces: RESTful URLs für JSF
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

Beyond PrettyFaces - Einführung in Rewrite