ibeans = dead-simple integration for web app development

Download iBeans = Dead-simple integration for web app development

If you can't read please download the document

Upload: ken-yagen

Post on 16-Apr-2017

2.163 views

Category:

Technology


1 download

TRANSCRIPT

ESB or not to ESB: Hello iBeans

iBeans = dead-simple integration + web app development

Ken YagenSilicon Valley Code Camp, October, 2009

Agenda

Introduction to Mule iBeans

Demo

How it works

Using iBeans

The Future of iBeans

All contents Copyright 2009, MuleSoft Inc.

What is an iBean?

A way to access external services, Facebook, AWS, eBay

A well-defined interface to a hosted service

service can be public or internal to your company

A Java interface with annotated method

A really easy way to create a reusable component

All contents Copyright 2009, MuleSoft Inc.

Introduction to Mule iBeans

Dramatically simplified integration for web applications

Simple API using annotations

Works with JSP, JSF, Struts, Spring, JavaScript

Task-based integration, e.g.:

Send/receive email

Subscribe to JMS queue

Poll RSS or Twitter feed

Publish REST service

Open source

Based on Mule

All contents Copyright 2009, MuleSoft Inc.

Do we need another framework?

Plenty of ESB/integration frameworks out there

Mule, Open ESB, Camel, Spring Integration

All feel SOA-influenced

Not much for the WebApp developers who just wants grab data quickly

Focus on:

Dead simple API

Reuse

Task-based integration

All contents Copyright 2009, MuleSoft Inc.

Demo time

All contents Copyright 2009, MuleSoft Inc.

How it Works

Container-based approach

iBeans bundled with Tomcat, not WebApp

Auto discovery

Web Apps select services by adding servlet definitions

Full support for AJAX messaging and RPC

iBeans console used for updating and removing features

IBean and Application annotations

Modules for: Email, Scheduling, Atom, Jms, Rest, Ajax, Xml, Guice, Spring

Built with the cloud in mind

Tomcat/Tcat Server/MuleMule iBeansWeb App 1Web App 2Web App 3

Cloud and data servicesAll contents Copyright 2009, MuleSoft Inc.

iBeans Central

Update

Browse

The @Call and @UriParam Annotations

public interface TwitterIBean{ @Call(uri = "http://www.twitter.com/statuses/show/{id}.json") String statusesShow(@UriParam("id") String id) throws CallException;}

All contents Copyright 2009, MuleSoft Inc.

The @State Annotation

public interface TwitterIBean{ @State void init(@UriParam(format) String format);

@Call(uri = http://www.twitter.com/statuses/show/{id}.{format}) String statusesShow(@UriParam("id") String id) throws CallException;}

All contents Copyright 2009, MuleSoft Inc.

Static Defaults

public interface TwitterIBean{ @UriParam(format) static String DEFAULT_FORMAT = json;

@State void init(@UriParam(format) String format);

@Call(uri = "http://www.twitter.com/statuses/show/{id}.{format}") String statusesShow(@UriParam("id") String id) throws CallException;}

All contents Copyright 2009, MuleSoft Inc.

The @ReturnType Annotation and Generic Types

public interface TwitterIBean{ @UriParam(format) static String DEFAULT_FORMAT = json;

@State void init(@UriParam(format) String format, @ReturnType Class retType);

@Call(uri = "http://www.twitter.com/statuses/show/{id}.{format}") T statusesShow(@UriParam("id") String id) throws CallException;}

All contents Copyright 2009, MuleSoft Inc.

Always provide sensible defaults

public interface TwitterIBean { @UriParam(format) static String DEFAULT_FORMAT = json; @ReturnType static Class DEFAULT_RETURN_TYPE = String.class; @State void init(@UriParam(format) String format, @ReturnType Class retType);

@Call(uri = "http://www.twitter.com/statuses/show/{id}.{format}") T statusesShow(@UriParam("id") String id) throws CallException;}

All contents Copyright 2009, MuleSoft Inc.

Testing the iBean

public class TwitterIBeanTest extends AbstractIBeansTestCase{ @IntegrationBean private TwitterIBean twitter; public void testTwitter() throws Exception { twitter.init(xml, Document.class); Document doc = twitter.statusesShow(1234567890); }}

All contents Copyright 2009, MuleSoft Inc.

Other Annotations

AnnotationDescriptionType

@HeaderParamConfigures a header on the outgoing messageParam, Field

@PayloadParamUsed for Http, configures a POST parameterParam

@PayloadAttaches data to the body of the messageParam

@StateWill store values on the instance of the bean for later referenceMethod

@PropertyParam Adds a property to the message that can be used later i.e. user/pass for authenticationParam, Field

All contents Copyright 2009, MuleSoft Inc.

Transforming Response Data

public class TwitterTransformers{ @Transformer protected Status twitterXmlToStatus(Document doc) { String status = selectValue("/status/text", doc); String user = selectValue("/user/name", doc); return new Status(status, user); }}

All contents Copyright 2009, MuleSoft Inc.

public class TwitterIBeanTest extends AbstractIBeansTestCase{ @IntegrationBean private TwitterIBean twitter; public void testTwitter() throws Exception { registerBeans(new TwitterTransformers()); twitter.init(xml, Status.class); Status status = twitter.statusesShow(1234567890); }}

All contents Copyright 2009, MuleSoft Inc.

Testing iBeans

Application Annotations

AnnotationDescriptionType

@ScheduleCron scheduling for calling a method, can be used to poll channelsMethod

@ReceiveReceive Data on a channel URIMethod

@SendSend the return of the method on a channel URIMethod

@ReceiveAndReplyReceive Data on a channel URI and send the return back to the caller

Method

All contents Copyright 2009, MuleSoft Inc.

@Schedule, @Send Example

public class TwitterSchedule{ @IntegrationBean private TwitterIBean twitter; @Schedule(interval = 5000) @Send(uri = "ajax:///ibeans/ajax/twitter") public Document getTimeline() throws Exception { twitter.init(xml, Document.class) return twitter.getPublicTimeline(); }}

All contents Copyright 2009, MuleSoft Inc.

iBeans Console

All contents Copyright 2009, MuleSoft Inc.

iBeans Shell

Groovy-based iBeans shell

List, create iBeans

Get help for an iBean

Test an ibean really quickly

All contents Copyright 2009, MuleSoft Inc.

Topics we may not have covered

Error Handling

ParamFactory for creating complex headers and parameters

i.e. Amazon secure hash params for EC2

Using generic VariableType return types to allow users to set the data format

Authentication

All contents Copyright 2009, MuleSoft Inc.

The Future of iBeans

Web Services support (JAX-RS)

Support for scripting in the console

Combine with Tcat for cloud development and provisioning

Centralized configuration (Mule Registry)

Mule 3.0 will be able to host iBeans

Support for other languages: Scala, Ruby, Clojure, etc

Could become the WCF for the JVM

All contents Copyright 2009, MuleSoft Inc.

???

Links for Mule iBeans:

Homepage: http://www.mulesoft.org/display/IBEANS/Home

Links for Tcat:

Homepage: http://mulesoft.com/tcat

About me:

Blog: http://blog.mulesoft.org

Twitter: http://twitter.com/kenyagen

Company: http://mulesoft.com

All contents Copyright 2009, MuleSoft Inc.

All contents Copyright 2009, MuleSoft Inc.

All contents Copyright 2009, MuleSoft Inc.