Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc. Building an Using Web Services and Apache Synapse v2

Paul Fremantle VP of Technology WSO2 [email protected]

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 1 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

About Me ƒ Co-founder and VP of Technology and Partnerships at WSO2 ¾ The leading Open Source Web services company ƒ Co-Chair of the OASIS WSRX Technical Committee ƒ Committer on Apache Synapse ƒ Member of the Apache Software Foundation ƒ Co-author of Building Web Services in Java 2nd Edition ƒ http://bloglines.com/blog/paulfremantle ƒ Ex IBM Senior Technical Staff Member ¾ developed the IBM Web Services Gateway ¾ Apache WSIF, C/C++, JWSDL/WSDL4J Apache Woden

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 2 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc. Apache Synapse The Small Print

Synapse is an effort undergoing incubation at the Apache Software Foundation (ASF), sponsored by the Web Services PMC. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects.

While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.

In other words… an incubator project for the moment

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 3 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Contents ƒ What is an ESB? ƒ A Web services based ESB ƒ Connect, Manage, Transform ƒ Apache Synapse ¾Structure and model ¾Deployment ¾Configuration ¾Programming model ƒ Examples and demo

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 4 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

What is an ESB?

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 5 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

A Common ESB Definition

“Any to any data connectivity and transformation (including Web Services) built on an advanced, proven, reliable middleware infrastructure”

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 6 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

ESB Definition

“Any to any data connectivity and transformation (including Web Services) built on an advanced, proven, reliable middleware infrastructure” which means ƒ Our existing middleware re-branded as an SOA platform, with some new web services adapters at the edges

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 7 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

So what is an Enterprise Service Bus?

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 8 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

A Bus Bus

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 9 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Busbar

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 10 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Bus

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 11 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

“The Original ESB”

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 12 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

What Is Good about ESBs? ƒ SOA based integration ¾More than just message passing ¾Metadata about the contracts involved • e.g. WSDL, Schema, Policy ƒ Bus model is very powerful ¾Every message goes into the “bus” and ends up in the right place

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 13 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

So Why Comments Like This: ƒ Anne Thomas Manes: ¾ “I do not believe that an ESB is an essential component of SOA. When it comes right down to it, you don't need any new products to do SOA. After all, SOA is about design, not technology.” ¾ “For the most part, ‘ESB’ is a marketing term.” ¾ “But by 2003, a bunch of other vendors hijacked the term and applied it to their own integration products.”

Are ESBs a new lock-in point?

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 14 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Service Oriented Architecture

Service Service Service

Contract Contract Contract

ESB

Process Portal Call Center Management

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 15 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

The Only Common Data Model

Service Service Service

Contract Contract Contract

XML, XML Schema

Process Portal Call Center Management

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 16 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc. The Only Common Interaction Models

Service Service Service

Contract Contract Contract

HTTP 1.1 200 OK

Process Portal Call Center Management

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 17 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc. What Do You Need for Enterprise Integration? ƒ Connectivity ƒ Data formats ƒ Security ƒ Reliability ƒ Routing ƒ Metadata ƒ Management

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 18 Colorado Software Summit:What October 22 – 27, 2006 Do You Need for © Copyright 2006, WSO2 Inc. Enterprise Integration? ƒ Connectivity ¾ Get data and messages from A to B ƒ Data formats ¾ Understand what shape the data is in ƒ Security ¾ Ensure end-to-end confidentiality, authentication, integrity ƒ Reliability ¾ Ensure message delivery ƒ Routing ¾ Decouple systems from the physical topology ƒ Metadata ¾ Understand what systems are there and what they offer and use

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 19 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc. What Do You Get from Web Services?

ƒ Connectivity ¾ Lightweight universal connectivity ¾ HTTP, REST, SOAP, XOP/MTOM (binary data) ƒ Data formats ¾ Common data model and data description language ¾ XML, XML Schema ƒ Security ¾ Encryption, Authentication, Single Signon ¾ WS-Security, WS-Trust, WS-SecureConversation ƒ Reliability ¾ Exactly once in-order delivery ¾ WS-ReliableMessaging ƒ Routing ¾ To/From/ReplyTo headers ¾ WS-Addressing ƒ Metadata ¾ Functional and non-functional description, capabilities and requirements ¾ WSDL, WS-Policy, XML Schema

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 20 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

So What Is Synapse? ƒ A intermediary

Synapse.xml Ethernet Ethernet User Synapse mediators Extensions

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 21 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

The Synapse Pattern of an ESB

Java J2EE JMS Axis2/Java S JAXWS Axis2/J CICS Legacy management DB2 Axis/C routing transformation PHP Web validation SAP security policy IMS S S Partner .net Gateway XML REST SOAP MTOM JSON

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 22 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

A Web Services Mediation Engine

TP MT manage HT OM ST/ RE route S OAP/W /JMS SS transform XML auth XSLT, E4X SOAP/H HTTP x POJO validate TTP SOAP/ p x S a ge th e p r e g r java o S MS f l O /J AP AP JMX /W SO SS

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 23 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

What Does Synapse Do? ƒ Connect

ƒ Manage

ƒ Transform

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 24 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Connect ƒ Route messages ¾ Based on XPath, Regex, etc. ƒ Deal with mismatch ¾ Initiate/Terminate RM, WS-Sec ƒ Switch ¾ POX or REST to SOAP to JSON ¾ JMS to HTTP to SMTP ƒ Virtualisation ¾ Virtual URI to real URI mapping

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 25 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Connect Example

Synapse Real Client Service

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 26 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Manage ƒ Logging ƒ Tracking – adding headers ƒ Authentication and Authorisation ƒ Schema validation ƒ Failover, retry and load-balancing

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 27 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Manage Examples Logs the whole message

Adds a SOAP header Logged

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 28 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Transform ƒ XSL Transforms ¾Apply an XSLT to the SOAP message or Body ƒ JavaScript/E4X ¾E4X is a simple mapping of XML directly into JavaScript ƒ POJO ¾Write Java logic that manipulates the message ƒ JSON ÅÆ XML ¾Take in JSON/HTTP and send out XML or SOAP

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 29 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Transform Example

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 30 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Synapse’s Two Approaches Rules

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 31 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Deployment Models

Synapse

HTTP Proxy

req prov Gateway

SOAP SOAP SOAP Intermediary Intermediary Intermediary

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 32 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Deployment

ƒ Transparent proxy ¾ Configure the client to use Synapse as a proxy • Works with or without WS-Addressing headers ¾ Or use a “smart client” and set ¾ Pure rule based model ƒ Gateway ¾ New “Proxy Services” • Hosting virtual endpoints in Synapse • Either simply direct to an endpoint or via a sequence • Simple config of WSRM, WSSec ¾ Endpoint based model

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 33 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc. First Rule of the Synapse Programming Model ƒ “Don’t use the Synapse Programming Model”

ƒ The aim of Synapse is to build in the common functions: ¾ Log, route, modify headers, etc. ¾ Engage QoS: WSS, WSRM, WSA, etc. ƒ And use XML models: ¾ XPath, XSLT, etc. ƒ Configure the routing and transformation using a simple XML file

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 34 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Synapse Config Language

mediators

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 35 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Sequences ƒ A chain of actions to take on a given message ¾The actions may be conditional ¾Each sequence can have a name and be re-used

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 36 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc. Example

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 37 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Endpoints A simple local representation of a remote endpoint

Allows characteristics such as policy, RM, Security to be configured

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 38 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Useful Mediators

ƒ send ƒ header ¾ Set a header in the ¾ Send on message ƒ drop ƒ filter ¾ Ditch the message ¾ Do this if the XPath or Regex matches ƒ log ƒ class ¾ log message ¾ Call a user mediator ƒ makefault ƒ validate ¾ Send a fault on or back ¾ XSD validation ƒ transform ƒ switch ¾ Conditional processing ¾ XSLT

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 39 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Synapse Extensions ƒ Packaged as a JAR ƒ Uses dynamic discovery to register new XML elements into the configuration model ƒ e.g. ¾ • Allows users to use Spring to wire up a mediator ¾ • Allows user to use JavaScript and E4X to implement transforms ƒ Extensions use the same programming model as User mediators ¾ Enhanced with an XML-based factory

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 40 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

User Mediators ƒ Simple Java class that implements the Mediator interface: boolean mediate(MessageContext mc);

true= continue processing false= halt processing

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 41 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Programming Model (Continued) ƒ o.a.synapse.MessageContext ƒ A representation of a SOAP infoset ¾Routing model • get/setTo, From, ReplyTo, FaultTo, MessageId, etc. ¾get/setEnvelope() • AXIOM representation ¾isResponse(), isMTOM(), isRest() ¾get/setProperties()

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 42 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Asynchronous Internals ƒ We are just working on a non-blocking IO model for Synapse ¾If full WS-Addressing in place then already asynchronous • Updating Synapse to have same behaviour even the client or server block on HTTP ¾Requires a NIO transport for Axis2 • Since Axis2 does all the IO for Synapse ¾More important for an intermediary than an endpoint • Endpoints are usually doing something with the thread while the socket is open

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 43 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Async IO Diagram

Incoming req Synapse

Request Thread1 processing Outgoing req Socket open Socket open

Incoming resp

Response Thread2 processing Outgoing resp

This model means: 1. Synapse threads never blocked during normal processing 2. Number of sockets open >> number of threads Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 44 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc. Scalable Event Driven Architecture ƒ Simple model of stages and queues for handling load ƒ Matt Welsh’s PhD thesis

http://www.eecs.harvard.edu/~mdw/proj/seda/

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 45 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

NIO Model Is Effectively SEDA

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 46 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

“Registry” Support ƒ So far everything has been stored in a single XML file ¾Synapse.xml ƒ Hard to manage ƒ Also ¾Requirement to update the directives without restarting Synapse

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 47 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Registry Model ƒ A registry is just a remote (or local) source of XML files ¾No special APIs or models from the Synapse perspective ƒ A pluggable model for reading from a registry ¾Synapse ships with a URL based implementation

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 48 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc. Properties and Dynamic Properties ƒ Properties are just local configuration items ƒ Can be used to set up global configuration ƒ Dynamic properties are properties backed by a registry ƒ The values are cached and read from the registry ¾Allows sequences, endpoints and other config to be loaded dynamically

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 49 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Dynamic Property example XML file stored at http://mystore.wso2.com/endpoint.xml

synapse.xml

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 50 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

So What Do You Need? Anne Thomas Manes again: ƒ One or more service platforms (endpoints) ƒ A SOA management solution (mediation) ƒ A registry (metadata) ƒ An XML gateway if services will be exposed outside the firewall

Synapse can be both the XML Gateway and the SOA management solution

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 51 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Demo

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 52 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Web Publisher JMS Synapse Services ActiveMQ Tungsten

TCPMON

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 53 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc.

Status

ƒ Incubator in Apache since August 2005 ¾ All Apache Contributed code, core committer team ƒ M1 release – January 2006 ¾ Core function, HTTP Proxy support, XSLT, XPath ƒ M2 release – June 2006 ¾ Clean up of config language ƒ 0.90 release – soon! (we always say that) ¾ Proxy services ¾ Repackage as a MAR ¾ JavaScript/E4X support Looking to Graduate from incubation when Apache gives us the go-ahead

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 54 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc. Getting involved

HomeWiki / Home site ƒ http://wiki.apache.org/ws/Synapse ƒ http://incubator.apache.org/synapse/ SVN ƒ https://svn.apache.org/repos/asf/incubator/synapse/trunk/java Try it out ¾ http://incubator.apache.org/synapse/download/M2/download.cgi ƒ Submit bug reports ¾ http://issues.apache.org/jira/browse/SYNAPSE Join us [email protected] Submit use cases, bugs, ideas, or even code (but actually we’d prefer the former) Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 55 Colorado Software Summit: October 22 – 27, 2006 © Copyright 2006, WSO2 Inc. Questions

Paul Fremantle — Building an Enterprise Service Bus Using Web Services and Apache Synapse v2 Page 56