This document provides an overview of using Mule to integrate with web services. It discusses building a bookstore web service using JAX-WS, generating a client, and configuring Mule with a CXF connector. It also covers transforming CSV book data to objects and sending to the web service, and transforming order objects to emails and sending via SMTP. The key steps are building the web service, generating a client, developing message transformers, and configuring Mule endpoints and routing.
4. SOA Swiss Army Knife
Supports a variety of service topologies including ESB
Highly Scalable; using SEDA event model
Asynchronous, Synchronous and Request/Response Messaging
J2EE Support: JBI, JMS, EJB, JCA, JTA, Servlet
Powerful event routing capabilities (based on EIP book)
Breadth of connectivity; 60+ technologies
Transparent Distribution
Transactions; Local and Distributed (XA)
Fault tolerance; Exception management
Secure; Authentication/Authorization
5. Why do developers choose Mule?
No prescribed message format
XML, CSV, Binary, Streams, Record, Java Objects
Mix and match
Zero code intrusion
Mule does not impose an API on service objects
Objects are fully portable
Existing objects can be managed
POJOs, IoC Objects, EJB Session Beans, Remote Objects
REST / Web Services
Easy to test
Mule can be run easily from a JUnit test case
Framework provides a Test compatibility kit
Scales down as well as up
7. Mule Topologies
Mule can be configured to implement any topology:
Enterprise Service Bus
Client/Server and Hub n' Spoke
Peer Network
Pipeline
Enterprise Service Network
8. Core Concepts: UMO Service
UMO Services in Mule can be any object -
POJOs, EJBs, Remote Objects, WS/REST Services
A service will perform a business function and may rely on other
sources to obtain additional information
Configured in Xml, or programmatically
Mule Manages Threading, Pooling and resource management
Managed via JMX at runtime
9. Core Concepts: Endpoints
Used to connect components and external
systems together
Endpoints use a URI for Addressing
Can have transformer, transaction, filter, security
and meta-information associated
Two types of URI
scheme://[username][:password]@[host]
[:port]?[params]
smtp://ross:pass@localhost:25
scheme://[address]?[params]
jms://my.queue?persistent=true
10. Core Concepts: Routers
Control how events are sent and received
Can model all routing patterns defined in the EIP Book
Inbound Routers
Idempotency
Selective Consumers
Re-sequencing
Message aggregation
Outbound Routers
Message splitting / Chunking
Content-based Routing
Broadcasting
Rules-based routing
Load Balancing
11. Core Concepts: Transformers
Transformers
Converts data from one format to another
Can be chained together to form transformation pipelines
<jms:object-to-jms name="XmlToJms"/>
<custom-transformer name="CobolXmlToBusXml"
class="com.myco.trans.CobolXmlToBusXml"/>
<endpoint address="jms://trades"
transformers="CobolXmlToBusXml, XmlToJms"/>
15. How?
1. Build web service
2. Configure Mule server
3. Generate web service client
4. Build CSV->Book converter
5. Configure Mule with File inbound router and CXF
outbound router
6. Configure Mule with Email endpoint to confirm
orders
7. Send messages to email service from bookstore
16. Quick Intro to JAX-WS
The standard way to build SOAP web services
Supports code first web service building through
annotations
Supports WSDL first through ant/maven/command
line tools
17. Building the Web Service
public interface Bookstore {
long addBook(Book book);
Collection<Long> addBooks(Collection<Book> books);
Collection<Book> getBooks();
}
18. Annotating the service
@WebService
public interface Bookstore {
long addBook(@WebParam(name="book") Book book);
@WebResult(name="bookIds")
Collection<Long> addBooks(
@WebParam(name="books") Collection<Book> books);
@WebResult(name="books")
Collection<Book> getBooks();
void placeOrder(@WebParam(name=“bookId”) long bookId,
@WebParam(name=“address”)String address,
@WebParam(name=“email”)String email)
}
25. Some notes about web services
Be careful about your contracts!!!
Don’t couple your web service too tightly (like this
example), allow a degree of separation
This allows
Maitainability
Evolvability
Versioning
WSDL first helps this
26. The Publisher
Wants to read in CSV and publish to web service
Use a CXF generated client as the “outbound router”
CsvBookPublisher converts File to List<Book>
Books then get sent to outbound router
36. Sending the Message
public void orderBook(long bookId, String address, String email) {
// In the real world we'd want this hidden behind
// an OrderService interface
try {
Book book = books.get(bookId);
MuleMessage msg = new MuleMessage(
new Object[] { book, address, email} );
RequestContext.getEventContext().dispatchEvent(
msg, "orderEmailService");
System.out.println("Dispatched message to orderService.");
} catch (UMOException e) {
// If this was real, we'd want better error handling
throw new RuntimeException(e);
}
}
Notas del editor
Components, Endpoints, Lets look at the Xml for a component