CREATING GENERIC REST INTERFACES FOR RESTEASY · PDF file• XText based DSL for interface...
Transcript of CREATING GENERIC REST INTERFACES FOR RESTEASY · PDF file• XText based DSL for interface...
C R E A T I N G G E N E R I C R E S T I N T E R F A C E S F O R R E S T E A S Y I N A M O D E L - D R I V E N W A Y
JUDCon 2013, India
January 18th 2013 1
Markus Gulden
Creating generic REST interfaces for RESTEasy in a model-driven way
Executive Summary
2
• Interfaces of composed systems might not fit for external clients: - Not web service-enabled - Technologically heterogeneous - Complex data model
Problem
• Use case-specific interface for each client type - Additional web service layer - Unified and RESTful interface - Simplified data model
Solution
• RESTEasy as JAX-RS implementation for REST-interface • JAXB for data model • Reflection based transformation between data models
Runtime
• XText based DSL for interface specification and code generator • Data model as XML schema by Eclipse XSD SDK Tooling
Creating generic REST interfaces for RESTEasy in a model-driven way January 18th 2013
Index
Zielpuls Introduction Trends and Motivation Approach Implementation Demonstration Summary
3 Creating generic REST interfaces for RESTEasy in a model-driven way January 18th 2013
Zielpuls Introduction
Zielpuls GmbH • Technology consulting in
automotive, aerospace, chemical and mechanical engineering industry
• Integration of technical and methodical expertise
• Interfaces (technical and organizational) are our bread and butter
Markus Gulden • Technology consultant at
Zielpuls • Focus on Connected Car/Car IT
and New Mobility • 5 years of experience in Java EE
and JBoss
4
Range of services Positioning
Creating generic REST interfaces for RESTEasy in a model-driven way January 18th 2013
Trends and Motivation
IT-systems become more and more the backbone of innovative enterprises
5
Approach for use case-
specific client interfaces
Implementation of internal processes and customer services
Composition of existing systems to reduce cost and risks
Existing approaches (SOA) and products (ESB, message broker)
Complex data model
Technologically heterogeneous and oversized interfaces
Not web service-enabled or even legacy interfaces
Trends Issues for external clients
Creating generic REST interfaces for RESTEasy in a model-driven way January 18th 2013
Solution
Approach
One interface per client-type is required:
6
REST-based interfaces • Unified • Only required services are provided
Heterogeneous and oversized interfaces
Use case-specific, simplified data model Complex data model
Additional web service-layer Not web service-enabled
One use case-specific interface for each
client-type
Creating generic REST interfaces for RESTEasy in a model-driven way January 18th 2013
App
licat
ion
laye
r
Approach in Detail (1)
Additional layer • Implementation as web service • REST-based [1]
Ø HTTP as application protocol Ø Data representation as XML
• Additional layer encapsulates existing interfaces
Ø Unified interface for several services
7
Service 1 Service 2 Service n
Pre
sent
a-tio
n la
yer
Interface 1 Interface n
DBMS 1 DBMS 2 DBMS n
- [1] R. T. Fielding. Architectural styles and the design of network-based software architectures. Phd thesis, University of California, Irvine, 2000.
Creating generic REST interfaces for RESTEasy in a model-driven way January 18th 2013
Reservation
Vehicle location
Customer smart phone
Another client
User data
Approach in Detail (2)
Simplified data model • Employment of the Data Transfer
Object (DTO) [2, 3] pattern • Encapsulation of multiple objects
into one DTO • Only required attributes are
mapped • Automatic transformation
between data models at runtime
• Example: Car sharing reservation list - Time - Station - License number
8
RentingStation - id : long - stationName: String - latitude : double - longitude : double
Reservation - id : long - begin : Date - end : Date - status : int
Vehicle - licenseNo : String - type: String - registration : Date
ReservationDTO - stationName: String - begin : Date - end : Date - licenseNo : String
- [2] M. Fowler. Patterns of Enterprise Application Architecture. Addison-Wesley Professional, 2002. - [3] Sun Microsystems, Inc. Core J2EE Patterns - Transfer Object. http://www.oracle.com/technetwork/java/transferobject-139757.html, 2002.
Creating generic REST interfaces for RESTEasy in a model-driven way January 18th 2013
Implementation - Runtime
9
• Reflection based implementation [3]
• JNDI • More technologies
possible
• JAXB • Marshalling as XML/
JSON
• JAX-RS • Part of Java EE 6 • RESTEasy by
JBoss
Interface Data model
Transfor-mation of
data models
Call of target
services
Creating generic REST interfaces for RESTEasy in a model-driven way January 18th 2013
Implementation - Runtime
JAX-RS @Path(„/reservations") public class ReservationService {
@GET @Produces(„application/xml") public List<ReservationDTO> getReservations() {
//Call business logic }
@PUT @Consumes(„application/xml") public void updateReservation(ReservationDTO state) { //Call business logic }
}
10 Creating generic REST interfaces for RESTEasy in a model-driven way January 18th 2013
Implementation - Runtime
JAXB @XmlType (name = „ReservationDTO") public class ReservationDTO {
protected String stationName; protected String licenseNumber; @XmlElement (required = true)
protected Date begin; @XmlElement (required = true)
protected Date end; //Getters
//Setters }
11 Creating generic REST interfaces for RESTEasy in a model-driven way January 18th 2013
Implementation - Tooling
12
Interface design & call
of target services • Tool is based on XText framework
• Simple DSL, which - Models the REST structure of the new interface - Maps REST resources on existing services
• Belonging generator creates - Creates JAX-RS code - JNDI calls for target services
Data model design
• XML Schema Definition SDK contained in Eclipse • Data model as XML schema • Out-of-the-box-generation of JAXB classes
Creating generic REST interfaces for RESTEasy in a model-driven way January 18th 2013
Implementation - Tooling
Interface DSL
13
Interface - name : String
RestUrl - relativeUrl : String
Service - identifier : String
Method - name: String
DataType - identifier: String
1…* subUrls
0…* subUrls
0…* services
1…* methods
0…1 inputType
0…1 returnType
Creating generic REST interfaces for RESTEasy in a model-driven way January 18th 2013
Interface structure
provided to client
Target services
DTOs for simplified data
model
Implementation - Development Process
14
Development/ Composition
Creation of method signatures
JAXB
Application creation
Interfaces
Deployment
Signatures
Design and generation
- REST classes - DTOs
Configuration
JAX-RS
Execution once
Ausführung n-mal
Execution n times
Creating generic REST interfaces for RESTEasy in a model-driven way January 18th 2013
Sequence
Demonstration
15
Data model and interface design
Deployment and demonstration
Re-design of data model
Initial situation
l Specification of DTOs as XML schema and interface structure
l Generation of JAXB JAX-RS classes
l Deployment and demonstration of system
l DTO modification: Additional attribute l Generation of JAXB classes
l One service with one method deployed as EJB l One global data model
Creating generic REST interfaces for RESTEasy in a model-driven way January 18th 2013
Deployment and demonstration
l Deployment and demonstration of system
Summary
Runtime
Tooling
16
• Less runtime resources required on client side
• Reduced effort at implementation on client side
Benefits
• Additional web service layer • Unified and RESTful interface • Simplified data model
Solution: Use case-specific interface for each client type
• Less implementation effort on server and client side
• Ability to reuse of existing systems
Benefits
Solution: Model-driven approach
Creating generic REST interfaces for RESTEasy in a model-driven way January 18th 2013
Zielpuls GmbH | Leopoldstraße 244 | 80807 Munich | Germany T +49 89 5404248-00 | Fax +49 89 5404248-10 [email protected] | www.zielpuls.com
W E H E L P Y O U T O S E T U P A N E F F E C T I V E I N T E R F A C E M A N A G E M E N T.
17
RESTEasy
§ Various frameworks to help you build RESTful Web Services and RESTful Java applications
§ Fully certified and portable implementation of the JAX-RS specification
§ RESTEasy can run in any Servlet container § Embeddedable server implementation for junit
testing § JAXB marshalling into XML, JSON, Jackson,
Fastinfoset, and Atom as well as wrappers for maps, arrays, lists, and sets of JAXB Objects
19 Creating generic REST interfaces for RESTEasy in a model-driven way January 18th 2013