Apache Camel Example Application - Earthquake Mashup

Similar documents
Implementing Enterprise Integration Patterns Using Open Source Frameworks

Methods and tools for data and software integration Enterprise Service Bus

Building the European Biodiversity. Observation Network (EU BON)

How to secure your Apache Camel deployment

Enterprise Service Bus

Spoilt for Choice Which Integration Framework to choose? Mule ESB. Integration. Kai Wähner

Building a Service Oriented Architecture with ServiceMix. Jeff Genender CTO Savoir Technologies, Inc

FUSE-ESB4 An open-source OSGi based platform for EAI and SOA

CERTIFIED MULESOFT DEVELOPER EXAM. Preparation Guide

Concrete uses of XML in software development and data analysis.

Systems Integration in the Cloud Era with Apache Camel. Kai Wähner, Principal Consultant

The future of middleware: enterprise application integration and Fuse

Enterprise Service Bus Evaluation as Integration Platform for Ocean Observatories

INTEGRATION BETWEEN WEB STORE AND WEB SERVICE USING APACHE CAMEL INTEGRATION FRAMEWORK

President and Director OeHF. Implementing IHE Actors using the Open ehealth Integration Platform (IPF)

Drupal CMS for marketing sites

Novell Identity Manager

Apache CXF Web Services

Beyond the SOA/BPM frontiers Towards a complete open cooperative environment

PHP Integration Kit. Version User Guide

Fuse ESB Enterprise Installation Guide

Developing Web Services with Apache CXF and Axis2

EVALUATION. WA1844 WebSphere Process Server 7.0 Programming Using WebSphere Integration COPY. Developer

Developers Integration Lab (DIL) System Architecture, Version 1.0

Magnus Larsson Callista Enterprise AB

Swordfish SOA Runtime Framework

Onset Computer Corporation

WELCOME TO Open Source Enterprise Architecture

REST and SOAP Services with Apache CXF

XML Processing and Web Services. Chapter 17

ATHABASCA UNIVERSITY. Enterprise Integration with Messaging

Christoph Emmersberger. Florian Springer. Senacor Technologies AG Wieseneckstraße Schwaig b. Nürnberg

RED HAT JBOSS FUSE. A lightweight, flexible integration platform

Enhanced Connector Applications SupportPac VP01 for IBM WebSphere Business Events 3.0.0

Redbook Overview Patterns: SOA Design with WebSphere Message Broker and WebSphere ESB

Java Web Services Training

Creating new university management software by methodologies of Service Oriented Architecture (SOA)

The WebShop E-Commerce Framework

Enterprise Integration Patterns

Automating Rich Internet Application Development for Enterprise Web 2.0 and SOA

IBM SPSS Collaboration and Deployment Services Version 6 Release 0. Single Sign-On Services Developer's Guide

New Features in Neuron ESB 2.6

Firewall Builder Architecture Overview

Smooks Dev Tools Reference Guide. Version: GA

Jobs Guide Identity Manager February 10, 2012

Copyright 2013 Consona Corporation. All rights reserved

Publish Acrolinx Terminology Changes via RSS

JobScheduler Web Services Executing JobScheduler commands

EAI and Spring Integration. Josh Long Architect, Software Engineer JoshLong.com

ESB pilot project at the FMI

Open ESB. Sang Shin Java Technology Evangelist Sun Microsystems, Inc. Raffaele Spazzoli Imola Informatica 1

JBoss Portlet Container. User Guide. Release 2.0

ActiveVOS Server Architecture. March 2009

Developing a Web Server Platform with SAPI Support for AJAX RPC using JSON

CST6445: Web Services Development with Java and XML Lesson 1 Introduction To Web Services Skilltop Technology Limited. All rights reserved.

rpafi/jl open source Apache Axis2 Web Services 2nd Edition using Apache Axis2 Deepal Jayasinghe Create secure, reliable, and easy-to-use web services

Salesforce integration with Enterprise Open Source. Mischa de Vries László van den Hoek SFDC Consultant OS Consultant

Improving performance for security enabled web services. - Dr. Colm Ó héigeartaigh

Elgg 1.8 Social Networking

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

JBOSS ESB. open source community experience distilled. Beginner's Guide. Enterprise. Magesh Kumar B

RED HAT JBOSS FUSE. An open source enterprise service bus

Oracle Service Bus Examples and Tutorials

SOA-14: Continuous Integration in SOA Projects Andreas Gies

Application. 1.1 About This Tutorial Tutorial Requirements Provided Files

JBoss ESB 4.3 GA. Content Based Routing JBESB CBR 5/20/08 JBESB-CBR-5/20/08

Rotorcraft Health Management System (RHMS)

Integrating NLTK with the Hadoop Map Reduce Framework Human Language Technology Project

FileMaker Server 9. Custom Web Publishing with PHP

JVA-561. Developing SOAP Web Services in Java

Web. Services. Web Technologies. Today. Web. Technologies. Internet WWW. Protocols TCP/IP HTTP. Apache. Next Time. Lecture # Apache.

Next-Generation ESB. Kevin Conner SOA Platform Architect, Red Hat Keith Babo JBoss ESB Project Lead, Red Hat. June 23rd, 2010

Example for Using the PrestaShop Web Service : CRUD

Building SOA Applications with JAX-WS, JAX- RS, JAXB, and Ajax

Introducing Apache Pivot. Greg Brown, Todd Volkert 6/10/2010

AquaLogic Service Bus

Runbook Activity Reference for System Center 2012 R2 Orchestrator

WebSphere Application Server security auditing

Talend ESB. Getting Started Guide 5.5.1

European Commission e-trustex Software Architecture Document

VALLIAMMAI ENGINEERING COLLEGE SRM NAGAR, KATTANKULATHUR DEPARTMENT OF COMPUTER APPLICATIONS SUBJECT : MC7502 SERVICE ORIENTED ARCHITECTURE

Event Logging - Introduction

IKAN ALM Architecture. Closing the Gap Enterprise-wide Application Lifecycle Management

The presentation explains how to create and access the web services using the user interface. WebServices.ppt. Page 1 of 14

Web Analytics Understand your web visitors without web logs or page tags and keep all your data inside your firewall.

SYSTEM DEVELOPMENT AND IMPLEMENTATION

ebay : How is it a hit

Open Source SOA with Service Component Architecture and Apache Tuscany. Jean-Sebastien Delfino Mario Antollini Raymond Feng

WEB SERVICES. Revised 9/29/2015

RED HAT JBOSS FUSE SERVICE WORKS 6 COMPARED WITH MULE ESB ENTERPRISE 3.4

Agents and Web Services

ITS. Java WebService. ITS Data-Solutions Pvt Ltd BENEFITS OF ATTENDANCE:

SOA Fundamentals For Java Developers. Alexander Ulanov, System Architect Odessa, 30 September 2008

Developing Java Web Services

Transcription:

University of Applied Sciences Department of Informatics and Media Apache Camel Example Application - Earthquake Mashup Systemintegration 1. Term Master Informatik Prof. Dr. Preuss Provided by: Robert Stümer, Nils Petersohn, Steffen Reinkensmeier 27.01.2011.

Contents 1 Introduction / Motivation / Project 1 2 Information Collection and Normalization 2 3 Aggregating Information Sources 4 4 Enrich Data with related Information 6 5 Email Notification 11 6 RESTful Service 13 7 XLink with jaxb Adapters 15 8 Deployment Steps 17 Bibliography 18 ii

1 Introduction / Motivation / Project System integration is the part of a software architecture. It helps to connect components or subsystems together. Certain patterns are used in the industry today. Using and learning EIP ( Enterprise Integration Patterns ) with Apache Camel is the goal of this Project. The Example for this project is all about earthquake data from around the world. The Application is able to read earthquake data from various RSS Feeds and processes it. During the processing the data will be in form of XML and Java Objects. The data will be enriched, spitted, sorted, aggregated, normalized, marshaled unmarshaled and finally provided again in form of a restful service. The specified task is as follows: 1. Read Earthquake Data continuously from those two RSS Streams http://geofon.gfz-potsdam.de/db/eqinfo.php?fmt=rss http://earthquake.usgs.gov/eqcenter/catalogs/eqs1day-m2.5.xml 2. enrich this data with other related information like the weather in this area at this time. Data can be from here: http://www.programmableweb.com. 3. sort the earthquakes by the earth parts where they appear 4. if the earthquake has a strength of more than M 5.5 than send an formatted warning email to an email address. 5. provide this data via a Restful interface in form of a list of the earth parts with an xlink to detailed information of the earthquakes. 1

2 Information Collection and Normalization The Normalizer [HW03] (Pic. 2.1) routes each message type through a custom Message Translator so that the resulting messages match a common format. The different message formats are collected in one channel ( direct : collectorchannel ) and than routed according to their xml format. The Routing is accomplished with a xpath condition which routes the messages to the specified Message Translators [HW03] (Pic. 2.2). Here The Translator is implemented with a XSLT formatter http://www.w3.org/tr/xslt. The relative source code is listed in 2.1 Figure 2.1: Normalizer Pattern [HW03] Figure 2.2: Translator Pattern [HW03] 2

2 Information Collection and Normalization Listing 2.1: Normalizer and Translator Source Code 1 from ( 2 " http :// geofon.gfz - potsdam.de/db/ eqinfo. php? fmt = rss & splitentries = false ") 3. log (" retrieve ") 4.to(" direct : collectorchannel "); 5 6 from ( 7 " http :// earthquake. usgs. gov / eqcenter / catalogs / eqs1day -M2.5. xml? fmt = rss & splitentries = false ") 8. log (" retrieve ") 9.to(" direct : collectorchannel "); 10 11 from (" direct : collectorchannel ") 12. choice () 13. when (). xpath ("/ rss / channel / item / pubdate ") 14.to(" xslt : data / xsl / transformation2. xsl ") 15. setheader (" visited ", constant ( true )) 16. log (" true : has / rss / channel / item / pubdate ") 17.to(" direct : normalizedmsg ") 18. otherwise () 19.to(" xslt : data / xsl / transformation. xsl ") 20. setheader (" visited ", constant ( true )) 21. log (" false : has not / rss / channel / item / pubdate ") 22.to(" direct : normalizedmsg "); 3

3 Aggregating Information Sources The Aggregator is a special filter that receives a stream of messages an identifies messages that are correlated. Once a complete set of messages has been received, the Aggregator collects information from each correlated message and publishes a single, aggregated message to the output channel for further processing. [HW03] Figure 3.1: Aggregator Pattern [HW03] Camel provides a method named aggregate with two parameters, first the identifier (the message header which was defined before in chapter 2) of the messages to aggregate and second the strategy (as a Object: SpecialAggregationStrategy which implements org.apache.camel.processor.aggregate.aggregationstrategy). Code listing 3.1 shows the implementation in this project for the normalized messages from Chapter 2. Code listing 3.2 shows the strategy which is fairly simple. Listing 3.1: Aggregator 1 from (" direct : normalizedmsg ") 2. aggregate ( header (" visited "), new XMLAggregationStrategy ()) 3. completionsize (2). delay ( 3000) 4.to(" direct : filterbiggestearthquakes ") 5.to(" direct : UnmarshallMergedSources "); Listing 3.2: Aggregation Strategy 1 import org. apache. camel. Exchange ; 4

3 Aggregating Information Sources 2 import org. apache. camel. processor. aggregate. AggregationStrategy ; 3 4 public class XMLAggregationStrategy implements AggregationStrategy { 5 6 public Exchange aggregate ( Exchange oldexchange, Exchange newexchange ) { 7 if ( oldexchange == null ) { 8 return newexchange ; 9 } 10 String oldbody = oldexchange. getin (). getbody ( String. class ); 11 String newbody = newexchange. getin (). getbody ( String. class ); 12 String body = oldbody + newbody ; 13 14 body = body 15. replaceall (" <\\? xml version =\"1\\.0\" encoding =\" UTF -8\"\\? > ", 16 "") 17. replaceall (" </ earthquakes >(.*) <earthquakes >", "") 18. replaceall ( 19 " </ earthquakes >< earthquakes xmlns : geo =\" http :// www \\. w3 \\. org /2003/01/ geo / wgs84_pos #\" >", 20 ""). replaceall (" </ earthquakes >< earthquakes >", ""); 21 22 oldexchange. getin (). setbody ( body ); 23 return oldexchange ; 24 } 25 } 5

4 Enrich Data with related Information Information can be added to the original Message with the Message Transformation Pattern Content Enricher. Figure 4.1: Content Enricher Pattern [HW03] The Content Enricher (Pic. 4.1) uses information inside the incoming message to retrieve data from an external source.[hw03] This is accomplished via the coordinates of the earthquake. which are used to retrieve area information http://api.wunderground.com/auto/wui/geo/geolookupxml and weather information from http://www.worldweatheronline.com/feed/weather.ashx. See Listing 4.1 for the source code. Listing 4.1: Enricher 1 from (" direct : UnmarshallMergedSources ") 2. unmarshal ( jaxb ) 3. process ( new EnrichmentProcessor ()) The EnrichmentP rocessor can now work with the java instances see Listing 4.2 Listing 4.2: EnrichmentProcessor 1 final class EnrichmentProcessor implements Processor { 6

4 Enrich Data with related Information 2 public void process ( Exchange exchange ) throws Exception { 3 EarthquakeCollection ec = exchange. getin (). getbody ( 4 EarthquakeCollection. class ); 5 ArrayList < Earthquake > listclone = new ArrayList < Earthquake >() ; 6 int i = 1; 7 for ( Earthquake e : ec. getentries ()) { 8 String additionalinfo = CommonUtils 9. findadditionalinfo (e. getlocation ()); 10 11 e. setcountry ( additionalinfo. contains (" not found ")? " undefined " 12 : additionalinfo ); 13 14 Weather findweatherinfo = CommonUtils. findweatherinfo ( e. getlocation ()); 15 16 e. setweather ( findweatherinfo ); 17 18 e. setid (i ++) ; 19 20 listclone. add (e); 21 } 22 ec. setentries ( listclone ); 23 System. out. println (" setting earthquakes now "); 24 exchange. getin () 25. setbody ( ec, EarthquakeCollection. class ); 26 } 27 } For the most flexibility the XML Message is automatically unmarshaled to the specified Java objects via the JAXB Unmarshaler. Earthpart EarthPartCollection EarthquakeCollection Earthquake Weather WeatherWrapper This is easily accomplished with jaxb Annotations in the data models. For more information on JAXB please visit: http://www.oracle.com/technetwork/articles/javase/index-140168.html In Camel, data formats are pluggable transformers that can transform messages from one form to another and vice versa. Each data format is represented in Camel as an interface in org.apache.camel.spi.dataformat containing two methods: 7

4 Enrich Data with related Information marshal For marshaling a message into another form, such as marshaling Java objects to XML, CSV, EDI, HL7, or other well-known data models. unmarshal The reverse operation which turns data from well known formats back into a message. You may already have realized that these two functions are opposites, meaning that one is capable of reversing what the other has done, as illustrated in figure 4.2. [IA10] Figure 4.2: Transforming with Data Formats [HW03] The Marshaled State is shown in the Class Diagram (Pic 4.3) for the package edu.f hb.sysint.camel.model The marshalled state is the XML Form (Pic. 4.4, 4.5) 8

4 Enrich Data with related Information Figure 4.3: edu.fhb.sysint.camel.model Package 9

4 Enrich Data with related Information Figure 4.4: marshalled Earthparts Figure 4.5: marshalled Earthquake 10

5 Email Notification If the strength of the Earthquakes are more than M 5.5 than an email notification must be delivered. This is implemented with Apache Camel through the splitter Pattern (Pic 5.1) Figure 5.1: Sequencer with Splitter Pattern The Source is spitted and aggregated. If The xpath evaluates to true the message is reformatted in a human readable format and sent to the provided email address. Listing 5.1: Splitting Pattern 1 from (" direct : filterbiggestearthquakes ") 2. split ( xpath ("/ earthquakes / earthquake [size >5.4] ")) 3. setheader (" splitted ", constant ( true )) 4. aggregate ( header (" splitted "), new SimpleAggregationStrategy ()) 5. completioninterval ( 2000) 6. process ( new Processor () { 7 public void process ( Exchange exchange ) throws Exception { 8 String body = exchange. getin (). getbody ( String. class ); 9 body = "<earthquakes >" + body + " </ earthquakes >"; 10 exchange. getin (). setbody (body, String. class ); 11 } 12 }) 13. unmarshal ( jaxb ) 14. process ( new EmailProcessor ()) 15.to(" smtps :// camelfhb@smtp. gmail. com? password = camelfhb31 &to= camelfhb@googlemail. com ") 16. delay (120000) ; The Resulting Email is shown in Pic 5.2 11

5 Email Notification Figure 5.2: Email Result 12

6 RESTful Service The Mashup is provided via a REST Web Service (http://localhost:9000/earthquakeservice/) The provided Data is sorted by Earth parts which were determined via the enrichment Phase. Camel has the availability to establish a REST Service with the Help of the Apache CXF Project which works closely JAXB (marshaling/unmarshaling). The Rest Router (Listing 6.1 ) determines the requested URL and requests the DAO Layer [Fow02] to send the correct response Data. Listing 6.1: Rest Router 1 String name = RestServiceImpl. class. getname (); 2 from (" cxfrs :// http :// localhost :9000? resourceclasses =" + name ). process ( 3... The CXF Endpoint is configured with the Definition class (Listing 6.2) Listing 6.2: CXF Service Definition 1 import javax.ws.rs.get ; 2 import javax.ws.rs. Path ; 3 import javax.ws.rs. PathParam ; 4 import javax.ws.rs. Produces ; 5 6 import edu. fhb. sysint. camel. dao. EarthpartDao ; 7 import edu. fhb. sysint. camel. dao. EarthquakeDao ; 8 import edu. fhb. sysint. camel. model. EarthPartCollection ; 9 import edu. fhb. sysint. camel. model. Earthpart ; 10 import edu. fhb. sysint. camel. model. Earthquake ; 11 12 @Path ("/ earthquakeservice /") 13 @Produces (" application / xml ") 14 public class RestServiceImpl { 15 16 public RestServiceImpl () { 17 } 18 19 @GET 20 @Path ("/ Earthparts ") 21 public EarthPartCollection getallearthparts () { 22 return EarthpartDao. all (); 13

6 RESTful Service 23 } 24 25 @GET 26 @Path ("/ Earthquake / findbyid /{ id}") 27 public Earthquake getearthquake ( @ PathParam (" id") Integer id) { 28 return EarthquakeDao. findbyid ( id); 29 } 30 31 } 14

7 XLink with jaxb Adapters Jaxb allows the use of the Adapter Pattern [GHJV95]. This allows to define special Marshaling for Objects. When the jaxb unmarshaler gets to the Earth part Object than the data field Earthquakes is not umarshaled normally. The Annotation @XmlJavaTypeAdapter (Listing 7.1) Redirects that action to special marshalling/umarshalling methods. Listing 7.1: Earthpart Class 1 import java. util. List ; 2 3 import javax. xml. bind. annotation. XmlAccessType ; 4 import javax. xml. bind. annotation. XmlAccessorType ; 5 import javax. xml. bind. annotation. XmlAttribute ; 6 import javax. xml. bind. annotation. XmlElement ; 7 import javax. xml. bind. annotation. XmlElementWrapper ; 8 import javax. xml. bind. annotation. XmlRootElement ; 9 import javax. xml. bind. annotation. adapters. XmlJavaTypeAdapter ; 10 11 import edu. fhb. sysint. camel. model. Earthquake ; 12 import edu. fhb. sysint. camel. model. adapter. XLinkAdapterEarthquake ; 13 14 @ XmlRootElement ( name = " earthpart ") 15 @ XmlAccessorType ( XmlAccessType. FIELD ) 16 public class Earthpart { 17 18 @XmlAttribute ( name = " name ") 19 private String name = ""; 20 21 @ XmlElementWrapper ( name = " erathquakes ") 22 @ XmlElement ( name = " erathquake ") 23 @XmlJavaTypeAdapter ( XLinkAdapterEarthquake. class ) 24 private List < Earthquake > earthquakes ; 25 26... Since the Classes for marshaling this special requirement are located in an extra package edu.f hb.sysint.camel.model.adapter it was possible to use the namespace mechanism at package level. Annotations that can be applied to the package element are referred to as package-level annotations. An annotation with ElementType.PACKAGE as one of its targets is a package- 15

7 XLink with jaxb Adapters level annotation. Package-level annotations are placed in a package-info.java 7.2 file. This file should contain only the package statement, preceded by annotations. When the compiler encounters package-info.java file, it will create a synthetic interface, package-name.packageinfo. The interface is called synthetic because it is introduced by the compiler and does not have a corresponding construct in the source code. This synthetic interface makes it possible to access package-level annotations at runtime.[jay] Listing 7.2: package-info.java for the Adapter Package 1 @javax. xml. bind. annotation. XmlSchema ( namespace = " http :// www.w3. org /1999/ xlink ", xmlns = { @javax. xml. bind. annotation. XmlNs ( prefix = " xlink ", namespaceuri = " http :// www.w3.org /1999/ xlink ") }, elementformdefault = javax. xml. bind. annotation. XmlNsForm. QUALIFIED ) 2 package edu. fhb. sysint. camel. model. adapter ; 16

8 Deployment Steps The System is deployed via the Apache Servicemix OSGI Runtime Container. Apache ServiceMix is an open source ESB (Enterprise Service Bus) that combines the functionality of a Service Oriented Architecture (SOA) and an Event Driven Architecture (EDA) to create an agile, enterprise ESB.[sm] The Camel Version used is 2.4.0-fuse-02-00 from the repository http://repo.fusesource. com/maven2/. 1. download fuse 4-3-0 file and unpack to /downloadedfuse http://fusesource.com/ product_download/fuse-esb-apache-servicemix/4-3-0-fuse-03-00/unix 2. replace /downloadedfuse/etc/org.apache.karaf.features.cfg key value pair "features- Boot=..." with featuresboot=config,activemq-broker,camel,camel-http,camel-jaxb,jbi-cluster,war, servicemix-cxf-bc,servicemix-file,servicemix-ftp,servicemix-http,servicemix-jms, servicemix-mail,servicemix-bean,servicemix-camel,servicemix-cxf-se,servicemix-drools, servicemix-eip,servicemix-osworkflow,servicemix-quartz,servicemix-scripting, servicemix-validation,servicemix-saxon,servicemix-wsn2005,camel,camel-spring-osgi, cxf,camel-cxf,camel-jetty,web,cxf-jaxrs,camel-rss,activemq-camel,rome-osgi,camel-mail 3. please modify the Constants in GlobalConstants.java for path settings. 4. in the project root do mvn install 5. start fuse with /downloadedfuse/bin/servicemix 6. on the karaf shell type: install -s mvn:edu.fhb.sysint.camel/apachecamelearthquakeservice 7. browse to http://localhost:9000/earthquakeservice/earthparts 17

Bibliography [Fow02] Fowler, M.: Patterns of enterprise application architecture. Addison-Wesley Longman Publishing Co., Inc. Boston, MA, USA, 2002. ISBN 0321127420 [GHJV95] Gamma, E. ; Helm, R. ; Johnson, R. ; Vlissides, J.: Design patterns: elements of reusable object-oriented software. Bd. 206. Addison-wesley Reading, MA, 1995 [HW03] Hohpe, G. ; Woolf, B.: Enterprise integration patterns: Designing, building, and deploying messaging solutions. Addison-Wesley Longman Publishing Co., Inc. Boston, MA, USA, 2003. ISBN 0321200683 [IA10] Ibsen, C. ; Anstey, J.: Camel in Action. Manning Publications, 2010 [Jay] Jayaratchagan, Narayanan: Declarative Programming in Java. http:// onjava.com/pub/a/onjava/2004/04/21/declarative.html?page=3 [sm] Apache ServiceMix. http://servicemix.apache.org/home.html 18

List of Figures 2.1 Normalizer Pattern [HW03]........................... 2 2.2 Translator Pattern [HW03]........................... 2 3.1 Aggregator Pattern [HW03]............................ 4 4.1 Content Enricher Pattern [HW03]....................... 6 4.2 Transforming with Data Formats [HW03]................... 8 4.3 edu.fhb.sysint.camel.model Package....................... 9 4.4 marshalled Earthparts.............................. 10 4.5 marshalled Earthquake.............................. 10 5.1 Sequencer with Splitter Pattern.......................... 11 5.2 Email Result................................... 12 19