SlideShare a Scribd company logo
A	
  Progress	
  So*ware	
  Company
OSGi for real in enterprise integration
with Apache Karaf
Dr. Adrian Trenaman, Sr. Principal Solution Architect,
FuseSource
trenaman@fusesource.com
twitter: adrian_trenaman | linked-in adrian.trenaman
http://trenaman.blogspot.com http://slideshare.net/trenaman
A	
  Progress	
  So*ware	
  Company
Adrian Trenaman - credentials
•15 years IT consulting experience
- IONA Technologies, Progress
Software Corp, FuseSource
- SOA, ESB, Open Source, BPM,
Web Services, CORBA, …
- Solution focused: architecting,
mentoring, speaking, engineering,
doing…
• Committer, Apache Karaf
• PhD Artificial Intelligence, Dip.
Business Development
Ade’s consultancy map
A	
  Progress	
  So*ware	
  Company
Why are people adopting OSGi for
enterprise integration?
• Lead to the stream by ServiceMix, Karaf and other OSGi-based runtimes.
• ‘Green’ programming - reduce, reuse, recycle
– Reduce - the amount of code you write and deploy
– Reuse (modularity) -
• Separation of interface from implementation
• Versioning and multi-generational cohabitation
• Explicit dependency resolution - fail early, fail loud.
– Recycle - use existing legacy code if possible
• Agile deployment
– Dynamic deployment and hot redeploy
– Smaller artifacts
A	
  Progress	
  So*ware	
  Company
Motivating example
<<karaf>>
:ServiceMix
<<cxf-bundle>>
customer-rest
<<cxf-bundle>>
customer-soap-ws
<<camel-bundle>>
customer-batch-eip
<<blueprint-bundle>>
customer-logic
<<pojo>>
CustomerService
<<bundle>>
customer-jaxb
HTTP
SOAP/
HTTP
FILE
• Modular design
• Dynamic wiring
• POJO-driven
• Dependency Injection
• Standards based
class reuse
A	
  Progress	
  So*ware	
  Company
Aside: parsimonious, trim bundles…
• It’s so modular; no fat deployment artifacts!
• customer-batch-eip-1.0.0.jar - 5.5k
• customer-jaxb-1.0.0.jar - 4.4k
• customer-rest-1.0.0.jar - 4.9k
• customer-soap-ws-1.0.0.jar - 9.6k
• customer-logic-1.0.0.jar - 4.6k
A	
  Progress	
  So*ware	
  Company
Roadmap for this presentation
• Overview of Apache Karaf
• Discussion: Spring DM vs. Blueprint
• Implementing ‘motivating’ use-case
– OSGi POJO service
– RESTful, SOAP and EIP-based reuse of service
• Apache CXF JAX-RS
• Apache CXF JAX-WS
• Apache Camel
– Dynamic update of components
• Concluding thoughts
A	
  Progress	
  So*ware	
  Company
Apache Karaf - an overview
A	
  Progress	
  So*ware	
  Company
Apache Karaf
• A powerful OSGi-based container, originally ‘ServiceMix
Kernel’
– Supports Equinox and Felix OSGi runtimes
– Supports any component that can be wrapped as a jar file
(POJOs, HTTP servlets, Camel routes, JBI endpoints &
services, etc.)
• http://karaf.apache.org
Karaf
OSGI
Logging Deployment Provisioning Admin ConfigAdmin
Console
A	
  Progress	
  So*ware	
  Company
Apache Karaf - deployment
• Karaf hot-deploys any artifacts found in the deploy directory
– OSGi bundles (incl. Spring DM and OSGi Blueprint)
– Raw Spring/Blueprint files
– Karaf Archives (coming soon!)
• It provides additional deployment capabilities through different
URL handlers
– mvn: | file: | http: | wrap: | jbi: | etc...
• Extensible architecture means Karaf can support deployment
of different kinds of artifacts
– Used by ServiceMix 4 to deploy JBI artifacts
A	
  Progress	
  So*ware	
  Company
Apache Karaf - Deployment
• OSGi bundles
• JBI artifacts
• WARs
• Spring / Blueprint
XML configs
• Exploded archives
• Monitor
configuration files
A	
  Progress	
  So*ware	
  Company
Apache Karaf - logging
• The logging subsystem combines output from various loggers
to provide a standard OSGi Log service
– Based on OPS4j Pax Logging
(http://www.ops4j.org/projects/pax/logging)
– Supports API for Apache Commons Logging, SLF4J, Log4j, Java
Util Logging
– Combines all output into one synchronized log
– Uses Log4j configuration for easy management
• Karaf also provides a set of console commands to display,
view and change the log levels at runtime
A	
  Progress	
  So*ware	
  Company
Apache Karaf - Console
• The console provides a command line interface, with which
users can perform administrative tasks
• Commands take the form
{subshell}:{command} [options]
– A sub-shell is a group of related commands
– e.g. commands related to the OSGi framework begin with “osgi:”
• The console provides an SSH port for connecting to and
issuing commands in a remote instance of the kernel
– The ssh connection can be made secure
A	
  Progress	
  So*ware	
  Company
Apache Karaf - Configuration
• Configure bundles from multiple sources - properties files in
the /etc directory, JDBC, …
• Edit configuration values via the console
– These changes are propagated immediately to all bundles
• Can design bundles to dynamically detect configuration
changes and auto-reconfigure
• … all done through the OSGi ConfigAdmin service.
A	
  Progress	
  So*ware	
  Company
Modular deployment with
‘features’
• You can deploy almost anything into
Karaf
– War, Jar, bundle, spring, …
• Prefer OSGi bundles for your routing
/ integration / business logic
– More modular design, explicit
versioning, classpath control.
– Can share classes or objects
(OSGi services)
– Dynamic wiring of OSGi services
allows live hot deployment of
patches without impacting your
production deployment.
• Use the ‘feature’ mechanism to group
and co-deploy bundles.
<<jvm>>
:ServiceMix4
a:bundle
b:bundle
c:bundle
f1 f2
x:bundle
y:bundle
common
smx:> features:addUrl file:my-features.xml
smx:> features:install f1
my-features.xml
A	
  Progress	
  So*ware	
  Company
Spring DM vs. OSGi Blueprint
A	
  Progress	
  So*ware	
  Company
Spring DM and OSGi Blueprints
• Spring-DM is an OSGi extension to Spring
– First attempt at creating an easy dependency injection
programming model for OSGi.
– Now contributed to Eclipse (2009) as Gemini Blueprint project.
• ‘OSGi Blueprint’ is the standardized version of Spring-DM
– Implemented by Spring DM 2.x
– Apache Aries Blueprint used within Karaf
• Better support for namespace resolution and lifecycle
• Lightweight - smaller than Spring DM
A	
  Progress	
  So*ware	
  Company
Spring DM - Concept
<<karaf>>
META-INF/MANIFEST.MF
META-INF/spring/foo.xml
META-INF/spring/bar.xml
...
...
my-bundle.jar
All XML files in the META-
INF/spring directory are
interpreted as the same ‘Spring
Context’, and all beans are initiated
on bundle start and destroyed on
bundle stop.
A	
  Progress	
  So*ware	
  Company
OSGi Blueprint - concept
<<karaf>>
META-INF/MANIFEST.MF
OSGI-INF/blueprint/foo.xml
OSGI-INF/blueprint/bar.xml
...
...
my-bundle.jar
All XML files in the OSGI-
INF/blueprint directory are
interpreted as the same ‘Context’,
and all beans are initiated on bundle
start and destroyed on bundle stop.
A	
  Progress	
  So*ware	
  Company
Deploying POJO OSGi services
A	
  Progress	
  So*ware	
  Company
POJO OSGi Service
public interface CustomerService {
Customer lookupCustomer(String customerId);
}
public class CustomerServiceImpl implements CustomerService {
public Customer lookupCustomer(String customerId) {
Customer c = new Customer();
c.setFirstName("Ade");
c.setLastName("Trenaman");
c.setPhoneNumber("+1234567890");
c.setId(customerId);
return c;
}
}
Blah.xml
A	
  Progress	
  So*ware	
  Company
POJO OSGi Service
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="customerServiceImpl"
class="com.fusesource.customer.impl.CustomerServiceImpl"
init-method="init" destroy-method="destroy">
<property name="dbUrl" value="somedb://" />
</bean>
<service ref="customerServiceImpl"
interface="com.fusesource.customer.CustomerService" />
</blueprint>
OSGI-INF/blueprint/customer-service.xml
A	
  Progress	
  So*ware	
  Company
‘bnd’ magic within Maven handles the
OSGi packaging…
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${maven-bundle-plugin.version}</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>
com.fusesource.customer
</Export-Package>
<Private-Package>
com.fusesource.customer.impl
</Private-Package>
<Include-Resource>src/main/resources</Include-Resource>
</instructions>
</configuration>
</plugin>
pom.xml
A	
  Progress	
  So*ware	
  Company
Using a Karaf ‘features’ file to deploy
A	
  Progress	
  So*ware	
  Company
Using a Karaf features file
<?xml version="1.0" encoding="UTF-8"?>
<features>
<!-- import other features files -->
<repository>mvn:org.apache.servicemix/apache-
servicemix/${servicemix.version}/xml/features</repository>
<feature name="customer-jaxb" version="1.0.0">
<bundle>mvn:${pom.groupId}/customer-jaxb/1.0.0</bundle>
</feature>
<feature name="customer-logic" version="1.0.0">
<feature version="1.0.0">customer-jaxb</feature>
<bundle>mvn:${pom.groupId}/customer-logic/1.0.0</bundle>
</feature>
. . .
</features>
src/main/filtere-resources/features.xml
A	
  Progress	
  So*ware	
  Company
• Use the features:addUrl command to register the features
file.
• Use the features:install / features:uninstall
commands to start and stop each feature.
A	
  Progress	
  So*ware	
  Company
Deploying REST and Web Services with
Apache CXF
A	
  Progress	
  So*ware	
  Company
REST Service
private static Logger logger
= LoggerFactory.getLogger(RESTfulCustomerService.class);
private CustomerService customerServiceLogic;
@GET
@Path("/customers/{id}/")
@Produces("application/xml")
public Customer getCustomer(@PathParam("id") String id) {
logger.info("Invoking getCustomer, Customer id is: " + id);
// Make use of the backend customer service logic!
//
return customerServiceLogic.lookupCustomer(id);
}
RESTfulCustomerService.java
A	
  Progress	
  So*ware	
  Company
REST Service
<jaxrs:server id="customerService"
address="http://0.0.0.0:8182/crm">
<jaxrs:serviceBeans>
<ref bean="customerSvc"/>
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="customerSvc"
class="com.fusesource.customer.rest.RESTfulCustomerService"
init-method="init" destroy-method="destroy">
<property name="customerServiceLogic" ref="customerLogic"/>
</bean>
<osgi:reference id="customerLogic"
interface="com.fusesource.customer.CustomerService"/>
META-INF/spring/customer-rest.xml
A	
  Progress	
  So*ware	
  Company
SOAP Service
@WebService(
targetNamespace =
"http://demo.fusesource.com/wsdl/CustomerService/",
portName = "SOAPOverHTTP",
serviceName = "CustomerService", name = "CustomerService"
)
public class CustomerServiceImpl implements CustomerService {
public LookupCustomerResponse lookupCustomer(LookupCustomer
parameters) {
// Invoke on the OSGi POJO
Customer customer =
customerServiceLogic.lookupCustomer(parameters.getCustomerId());
...
return response;
}
}
CustomerServiceImpl.java
A	
  Progress	
  So*ware	
  Company
SOAP Service
<jaxws:endpoint id="customerServiceJaxWSEndpoint"
implementor="#customerServiceImpl"
address="http://localhost:8083/soap/CustomerService"
/>
<bean id="customerServiceImpl"
class="com.fusesource.demo.soap.customer.CustomerServiceImpl">
<property name="customerServiceLogic" ref="customerLogic"/>
</bean>
<osgi:reference id="customerLogic”
interface="com.fusesource.customer.CustomerService"/>
META-INF/spring/customer-soap.xml
A	
  Progress	
  So*ware	
  Company
Deploying EIP flows with Apache Camel
A	
  Progress	
  So*ware	
  Company
Camel Route
from("file:/tmp/customerIds")
.routeId("batchCustomerProcessor")
.split(body(String.class).tokenize("n"))
.to("bean:customerServiceLogic?method=lookupCustomer")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
Customer c = exchange.getIn().getBody(Customer.class);
logger.info("Processed customer " + c.getId() + ", name is "
+ c.getFirstName() + " " + c.getLastName());
}
});
CustomerBatchProcessor.java
A	
  Progress	
  So*ware	
  Company
Camel Route
<camelContext xmlns="http://camel.apache.org/schema/spring">
<routeBuilder ref="batchProcessor" />
</camelContext>
<bean name="batchProcessor"
class="com.fusesource.demo.batch.customer.CustomerBatchProcessor"/>
<osgi:reference id="customerServiceLogic"
interface="com.fusesource.customer.CustomerService"/>
META-INF/spring/camel-route.xml
A	
  Progress	
  So*ware	
  Company
Summing up
• OSGi provides goodness in terms of modularity.
• Versioning, dependency management, classpath isolation, dynamic
wiring
• Apache Karaf augments core OSGi runtime with cross-
functional-concerns
• Logging, shell, configuration, security, …
• Karaf is a good home for Camel EIPs, CXF services…
• Apache ServiceMix pulls it all together.
• All the code from this presentation is available from the author!
A	
  Progress	
  So*ware	
  Company
OSGi for real in enterprise integration with
Apache Karaf
Dr. Adrian Trenaman, Sr. Principal Solution Architect,
FuseSource
trenaman@fusesource.com
twitter: adrian_trenaman | linked-in adrian.trenaman
http://trenaman.blogspot.com http://slideshare.net/trenaman

More Related Content

PDF
ApacheCon EU 2014: Enterprise Development with Apache Karaf
PDF
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
PPT
OSGi & Blueprint
PDF
OSGi ecosystems compared on Apache Karaf - Christian Schneider
PDF
Microservices OSGi-running-with-apache-karaf
PDF
Modular Architectures using Micro Services
PDF
Jahia DX 7.2 : Bye bye felix, hello karaf
KEY
Jug Poitou Charentes - Apache, OSGi and Karaf
ApacheCon EU 2014: Enterprise Development with Apache Karaf
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
OSGi & Blueprint
OSGi ecosystems compared on Apache Karaf - Christian Schneider
Microservices OSGi-running-with-apache-karaf
Modular Architectures using Micro Services
Jahia DX 7.2 : Bye bye felix, hello karaf
Jug Poitou Charentes - Apache, OSGi and Karaf

What's hot (20)

PDF
Build bundles in the cloud - How Cloudyle PaaS+ helps creating OSGi applicati...
PDF
Cloud Foundry Open Tour India 2012 , Keynote
KEY
How Flipkart scales PHP
PDF
Java EE 7 Soup to Nuts at JavaOne 2014
PDF
What's New in WildFly 9?
PDF
MySQL Replication
PDF
PDF
Best Practices - PHP and the Oracle Database
PDF
Camel Desing Patterns Learned Through Blood, Sweat, and Tears
PPTX
Moving From Actions & Behaviors to Microservices
PDF
Connecting Apache Kafka With Mule ESB
PDF
ActiveMQ Performance Tuning
PPTX
Alfresco DevCon 2018: SDK 3 Multi Module project using Nexus 3 for releases a...
PPTX
Javaeeconf 2016 how to cook apache kafka with camel and spring boot
PDF
Serverless Java Challenges & Triumphs
PPTX
201511 - Alfresco Day - Platform Update and Roadmap - Gabriele Columbro - Bo...
PDF
Configuration Management Tools on NX-OS
PPTX
Moving Gigantic Files Into and Out of the Alfresco Repository
PDF
컨테이너 기술 소개 - Warden, Garden, Docker
PPTX
So I Wrote a Manifest
Build bundles in the cloud - How Cloudyle PaaS+ helps creating OSGi applicati...
Cloud Foundry Open Tour India 2012 , Keynote
How Flipkart scales PHP
Java EE 7 Soup to Nuts at JavaOne 2014
What's New in WildFly 9?
MySQL Replication
Best Practices - PHP and the Oracle Database
Camel Desing Patterns Learned Through Blood, Sweat, and Tears
Moving From Actions & Behaviors to Microservices
Connecting Apache Kafka With Mule ESB
ActiveMQ Performance Tuning
Alfresco DevCon 2018: SDK 3 Multi Module project using Nexus 3 for releases a...
Javaeeconf 2016 how to cook apache kafka with camel and spring boot
Serverless Java Challenges & Triumphs
201511 - Alfresco Day - Platform Update and Roadmap - Gabriele Columbro - Bo...
Configuration Management Tools on NX-OS
Moving Gigantic Files Into and Out of the Alfresco Repository
컨테이너 기술 소개 - Warden, Garden, Docker
So I Wrote a Manifest
Ad

Viewers also liked (8)

PDF
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
PDF
OSGi & Java EE in GlassFish
PDF
Karaf ee-apachecon eu-2012
PDF
Distributed Services - OSGi 4.2 and possible future enhancements
PPT
It's beautiful enRoute - Paul Fraser
PDF
Avoid the chaos - Handling 100+ OSGi Components - Balázs Zsoldos
KEY
OSGi in the Enterprise: Agility, Modularity, and Architecture's Paradox
PDF
Building LinkedIn's Next Generation Architecture with OSGi
OSGi and Java EE: A Hybrid Approach to Enterprise Java Application Development
OSGi & Java EE in GlassFish
Karaf ee-apachecon eu-2012
Distributed Services - OSGi 4.2 and possible future enhancements
It's beautiful enRoute - Paul Fraser
Avoid the chaos - Handling 100+ OSGi Components - Balázs Zsoldos
OSGi in the Enterprise: Agility, Modularity, and Architecture's Paradox
Building LinkedIn's Next Generation Architecture with OSGi
Ad

Similar to OSGi for real in the enterprise: Apache Karaf - NLJUG J-FALL 2010 (20)

KEY
Apache, osgi and karaf par Guillaume Nodet
PPTX
Introduction to-osgi
PDF
OSGi as Enterprise Integration Platform
ODP
W-JAX 2011: OSGi with Apache Karaf
PDF
Develop apps with Camel and GWT on OSGi
PDF
Aceu2009 Osgi Productline
PPT
OSGi For Java Infrastructures [5th IndicThreads Conference On Java 2010, Pune...
PDF
Be jug 090611_apacheservicemix
PPT
Os gi l
KEY
Introduction to EclipseRT (JAX 2010)
PPTX
Zero Downtime with OSGi - Chicago Coder Conference 05-15-2015
PDF
Osgi In Depth 1st Edition Alexandre De Castro Alves
PDF
Modular Java applications with OSGi on Apache Karaf
PDF
OSGi In Anger - Tara Simpson
PDF
Benefits of OSGi in Practise
PPTX
Introduction to OSGGi
PDF
OSGi and Java EE in GlassFish - Tech Days 2010 India
PPTX
Enterprise Spring Building Scalable Applications
PDF
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
PDF
Jee conf 2015
Apache, osgi and karaf par Guillaume Nodet
Introduction to-osgi
OSGi as Enterprise Integration Platform
W-JAX 2011: OSGi with Apache Karaf
Develop apps with Camel and GWT on OSGi
Aceu2009 Osgi Productline
OSGi For Java Infrastructures [5th IndicThreads Conference On Java 2010, Pune...
Be jug 090611_apacheservicemix
Os gi l
Introduction to EclipseRT (JAX 2010)
Zero Downtime with OSGi - Chicago Coder Conference 05-15-2015
Osgi In Depth 1st Edition Alexandre De Castro Alves
Modular Java applications with OSGi on Apache Karaf
OSGi In Anger - Tara Simpson
Benefits of OSGi in Practise
Introduction to OSGGi
OSGi and Java EE in GlassFish - Tech Days 2010 India
Enterprise Spring Building Scalable Applications
OSGi & Java EE: A hybrid approach to Enterprise Java Application Development,...
Jee conf 2015

More from Adrian Trenaman (14)

PDF
Why i love computer science
PDF
JavaOne 2015: Scaling micro services at Gilt
PDF
GeeCON Microservices 2015 scaling micro services at gilt
PDF
Solr nyc meetup - May 14 2015 - Adrian Trenaman
PDF
Scaling micro services at gilt
PDF
Lucene revolution 2013 adrian trenaman
PDF
Personalized Search on the Largest Flash Sale Site in America
PPT
Implementing WebServices with Camel and CXF in ServiceMix
PPT
WebServices in ServiceMix with CXF
PDF
Oop2008 RESTful services with GWT and Apache CXF
PDF
ApacheCon EU 2009 Tales from the front line - ActiveMQ ServiceMix and CXF
PDF
Apache coneu 2009-adrian-trenaman-adopting-open-source-in-the-enterprise
PDF
20100907 fuse-community-evening-adrian-trenaman-no-logo
PPT
An Introduction to Apache ServiceMix 4 - FUSE ESB
Why i love computer science
JavaOne 2015: Scaling micro services at Gilt
GeeCON Microservices 2015 scaling micro services at gilt
Solr nyc meetup - May 14 2015 - Adrian Trenaman
Scaling micro services at gilt
Lucene revolution 2013 adrian trenaman
Personalized Search on the Largest Flash Sale Site in America
Implementing WebServices with Camel and CXF in ServiceMix
WebServices in ServiceMix with CXF
Oop2008 RESTful services with GWT and Apache CXF
ApacheCon EU 2009 Tales from the front line - ActiveMQ ServiceMix and CXF
Apache coneu 2009-adrian-trenaman-adopting-open-source-in-the-enterprise
20100907 fuse-community-evening-adrian-trenaman-no-logo
An Introduction to Apache ServiceMix 4 - FUSE ESB

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
MYSQL Presentation for SQL database connectivity
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Cloud computing and distributed systems.
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
cuic standard and advanced reporting.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Encapsulation_ Review paper, used for researhc scholars
Diabetes mellitus diagnosis method based random forest with bat algorithm
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
NewMind AI Monthly Chronicles - July 2025
MYSQL Presentation for SQL database connectivity
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Cloud computing and distributed systems.
Per capita expenditure prediction using model stacking based on satellite ima...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Network Security Unit 5.pdf for BCA BBA.
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Big Data Technologies - Introduction.pptx
Review of recent advances in non-invasive hemoglobin estimation
cuic standard and advanced reporting.pdf

OSGi for real in the enterprise: Apache Karaf - NLJUG J-FALL 2010

  • 1. A  Progress  So*ware  Company OSGi for real in enterprise integration with Apache Karaf Dr. Adrian Trenaman, Sr. Principal Solution Architect, FuseSource trenaman@fusesource.com twitter: adrian_trenaman | linked-in adrian.trenaman http://trenaman.blogspot.com http://slideshare.net/trenaman
  • 2. A  Progress  So*ware  Company Adrian Trenaman - credentials •15 years IT consulting experience - IONA Technologies, Progress Software Corp, FuseSource - SOA, ESB, Open Source, BPM, Web Services, CORBA, … - Solution focused: architecting, mentoring, speaking, engineering, doing… • Committer, Apache Karaf • PhD Artificial Intelligence, Dip. Business Development Ade’s consultancy map
  • 3. A  Progress  So*ware  Company Why are people adopting OSGi for enterprise integration? • Lead to the stream by ServiceMix, Karaf and other OSGi-based runtimes. • ‘Green’ programming - reduce, reuse, recycle – Reduce - the amount of code you write and deploy – Reuse (modularity) - • Separation of interface from implementation • Versioning and multi-generational cohabitation • Explicit dependency resolution - fail early, fail loud. – Recycle - use existing legacy code if possible • Agile deployment – Dynamic deployment and hot redeploy – Smaller artifacts
  • 4. A  Progress  So*ware  Company Motivating example <<karaf>> :ServiceMix <<cxf-bundle>> customer-rest <<cxf-bundle>> customer-soap-ws <<camel-bundle>> customer-batch-eip <<blueprint-bundle>> customer-logic <<pojo>> CustomerService <<bundle>> customer-jaxb HTTP SOAP/ HTTP FILE • Modular design • Dynamic wiring • POJO-driven • Dependency Injection • Standards based class reuse
  • 5. A  Progress  So*ware  Company Aside: parsimonious, trim bundles… • It’s so modular; no fat deployment artifacts! • customer-batch-eip-1.0.0.jar - 5.5k • customer-jaxb-1.0.0.jar - 4.4k • customer-rest-1.0.0.jar - 4.9k • customer-soap-ws-1.0.0.jar - 9.6k • customer-logic-1.0.0.jar - 4.6k
  • 6. A  Progress  So*ware  Company Roadmap for this presentation • Overview of Apache Karaf • Discussion: Spring DM vs. Blueprint • Implementing ‘motivating’ use-case – OSGi POJO service – RESTful, SOAP and EIP-based reuse of service • Apache CXF JAX-RS • Apache CXF JAX-WS • Apache Camel – Dynamic update of components • Concluding thoughts
  • 7. A  Progress  So*ware  Company Apache Karaf - an overview
  • 8. A  Progress  So*ware  Company Apache Karaf • A powerful OSGi-based container, originally ‘ServiceMix Kernel’ – Supports Equinox and Felix OSGi runtimes – Supports any component that can be wrapped as a jar file (POJOs, HTTP servlets, Camel routes, JBI endpoints & services, etc.) • http://karaf.apache.org Karaf OSGI Logging Deployment Provisioning Admin ConfigAdmin Console
  • 9. A  Progress  So*ware  Company Apache Karaf - deployment • Karaf hot-deploys any artifacts found in the deploy directory – OSGi bundles (incl. Spring DM and OSGi Blueprint) – Raw Spring/Blueprint files – Karaf Archives (coming soon!) • It provides additional deployment capabilities through different URL handlers – mvn: | file: | http: | wrap: | jbi: | etc... • Extensible architecture means Karaf can support deployment of different kinds of artifacts – Used by ServiceMix 4 to deploy JBI artifacts
  • 10. A  Progress  So*ware  Company Apache Karaf - Deployment • OSGi bundles • JBI artifacts • WARs • Spring / Blueprint XML configs • Exploded archives • Monitor configuration files
  • 11. A  Progress  So*ware  Company Apache Karaf - logging • The logging subsystem combines output from various loggers to provide a standard OSGi Log service – Based on OPS4j Pax Logging (http://www.ops4j.org/projects/pax/logging) – Supports API for Apache Commons Logging, SLF4J, Log4j, Java Util Logging – Combines all output into one synchronized log – Uses Log4j configuration for easy management • Karaf also provides a set of console commands to display, view and change the log levels at runtime
  • 12. A  Progress  So*ware  Company Apache Karaf - Console • The console provides a command line interface, with which users can perform administrative tasks • Commands take the form {subshell}:{command} [options] – A sub-shell is a group of related commands – e.g. commands related to the OSGi framework begin with “osgi:” • The console provides an SSH port for connecting to and issuing commands in a remote instance of the kernel – The ssh connection can be made secure
  • 13. A  Progress  So*ware  Company Apache Karaf - Configuration • Configure bundles from multiple sources - properties files in the /etc directory, JDBC, … • Edit configuration values via the console – These changes are propagated immediately to all bundles • Can design bundles to dynamically detect configuration changes and auto-reconfigure • … all done through the OSGi ConfigAdmin service.
  • 14. A  Progress  So*ware  Company Modular deployment with ‘features’ • You can deploy almost anything into Karaf – War, Jar, bundle, spring, … • Prefer OSGi bundles for your routing / integration / business logic – More modular design, explicit versioning, classpath control. – Can share classes or objects (OSGi services) – Dynamic wiring of OSGi services allows live hot deployment of patches without impacting your production deployment. • Use the ‘feature’ mechanism to group and co-deploy bundles. <<jvm>> :ServiceMix4 a:bundle b:bundle c:bundle f1 f2 x:bundle y:bundle common smx:> features:addUrl file:my-features.xml smx:> features:install f1 my-features.xml
  • 15. A  Progress  So*ware  Company Spring DM vs. OSGi Blueprint
  • 16. A  Progress  So*ware  Company Spring DM and OSGi Blueprints • Spring-DM is an OSGi extension to Spring – First attempt at creating an easy dependency injection programming model for OSGi. – Now contributed to Eclipse (2009) as Gemini Blueprint project. • ‘OSGi Blueprint’ is the standardized version of Spring-DM – Implemented by Spring DM 2.x – Apache Aries Blueprint used within Karaf • Better support for namespace resolution and lifecycle • Lightweight - smaller than Spring DM
  • 17. A  Progress  So*ware  Company Spring DM - Concept <<karaf>> META-INF/MANIFEST.MF META-INF/spring/foo.xml META-INF/spring/bar.xml ... ... my-bundle.jar All XML files in the META- INF/spring directory are interpreted as the same ‘Spring Context’, and all beans are initiated on bundle start and destroyed on bundle stop.
  • 18. A  Progress  So*ware  Company OSGi Blueprint - concept <<karaf>> META-INF/MANIFEST.MF OSGI-INF/blueprint/foo.xml OSGI-INF/blueprint/bar.xml ... ... my-bundle.jar All XML files in the OSGI- INF/blueprint directory are interpreted as the same ‘Context’, and all beans are initiated on bundle start and destroyed on bundle stop.
  • 19. A  Progress  So*ware  Company Deploying POJO OSGi services
  • 20. A  Progress  So*ware  Company POJO OSGi Service public interface CustomerService { Customer lookupCustomer(String customerId); } public class CustomerServiceImpl implements CustomerService { public Customer lookupCustomer(String customerId) { Customer c = new Customer(); c.setFirstName("Ade"); c.setLastName("Trenaman"); c.setPhoneNumber("+1234567890"); c.setId(customerId); return c; } } Blah.xml
  • 21. A  Progress  So*ware  Company POJO OSGi Service <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <bean id="customerServiceImpl" class="com.fusesource.customer.impl.CustomerServiceImpl" init-method="init" destroy-method="destroy"> <property name="dbUrl" value="somedb://" /> </bean> <service ref="customerServiceImpl" interface="com.fusesource.customer.CustomerService" /> </blueprint> OSGI-INF/blueprint/customer-service.xml
  • 22. A  Progress  So*ware  Company ‘bnd’ magic within Maven handles the OSGi packaging… <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>${maven-bundle-plugin.version}</version> <extensions>true</extensions> <configuration> <instructions> <Export-Package> com.fusesource.customer </Export-Package> <Private-Package> com.fusesource.customer.impl </Private-Package> <Include-Resource>src/main/resources</Include-Resource> </instructions> </configuration> </plugin> pom.xml
  • 23. A  Progress  So*ware  Company Using a Karaf ‘features’ file to deploy
  • 24. A  Progress  So*ware  Company Using a Karaf features file <?xml version="1.0" encoding="UTF-8"?> <features> <!-- import other features files --> <repository>mvn:org.apache.servicemix/apache- servicemix/${servicemix.version}/xml/features</repository> <feature name="customer-jaxb" version="1.0.0"> <bundle>mvn:${pom.groupId}/customer-jaxb/1.0.0</bundle> </feature> <feature name="customer-logic" version="1.0.0"> <feature version="1.0.0">customer-jaxb</feature> <bundle>mvn:${pom.groupId}/customer-logic/1.0.0</bundle> </feature> . . . </features> src/main/filtere-resources/features.xml
  • 25. A  Progress  So*ware  Company • Use the features:addUrl command to register the features file. • Use the features:install / features:uninstall commands to start and stop each feature.
  • 26. A  Progress  So*ware  Company Deploying REST and Web Services with Apache CXF
  • 27. A  Progress  So*ware  Company REST Service private static Logger logger = LoggerFactory.getLogger(RESTfulCustomerService.class); private CustomerService customerServiceLogic; @GET @Path("/customers/{id}/") @Produces("application/xml") public Customer getCustomer(@PathParam("id") String id) { logger.info("Invoking getCustomer, Customer id is: " + id); // Make use of the backend customer service logic! // return customerServiceLogic.lookupCustomer(id); } RESTfulCustomerService.java
  • 28. A  Progress  So*ware  Company REST Service <jaxrs:server id="customerService" address="http://0.0.0.0:8182/crm"> <jaxrs:serviceBeans> <ref bean="customerSvc"/> </jaxrs:serviceBeans> </jaxrs:server> <bean id="customerSvc" class="com.fusesource.customer.rest.RESTfulCustomerService" init-method="init" destroy-method="destroy"> <property name="customerServiceLogic" ref="customerLogic"/> </bean> <osgi:reference id="customerLogic" interface="com.fusesource.customer.CustomerService"/> META-INF/spring/customer-rest.xml
  • 29. A  Progress  So*ware  Company SOAP Service @WebService( targetNamespace = "http://demo.fusesource.com/wsdl/CustomerService/", portName = "SOAPOverHTTP", serviceName = "CustomerService", name = "CustomerService" ) public class CustomerServiceImpl implements CustomerService { public LookupCustomerResponse lookupCustomer(LookupCustomer parameters) { // Invoke on the OSGi POJO Customer customer = customerServiceLogic.lookupCustomer(parameters.getCustomerId()); ... return response; } } CustomerServiceImpl.java
  • 30. A  Progress  So*ware  Company SOAP Service <jaxws:endpoint id="customerServiceJaxWSEndpoint" implementor="#customerServiceImpl" address="http://localhost:8083/soap/CustomerService" /> <bean id="customerServiceImpl" class="com.fusesource.demo.soap.customer.CustomerServiceImpl"> <property name="customerServiceLogic" ref="customerLogic"/> </bean> <osgi:reference id="customerLogic” interface="com.fusesource.customer.CustomerService"/> META-INF/spring/customer-soap.xml
  • 31. A  Progress  So*ware  Company Deploying EIP flows with Apache Camel
  • 32. A  Progress  So*ware  Company Camel Route from("file:/tmp/customerIds") .routeId("batchCustomerProcessor") .split(body(String.class).tokenize("n")) .to("bean:customerServiceLogic?method=lookupCustomer") .process(new Processor() { public void process(Exchange exchange) throws Exception { Customer c = exchange.getIn().getBody(Customer.class); logger.info("Processed customer " + c.getId() + ", name is " + c.getFirstName() + " " + c.getLastName()); } }); CustomerBatchProcessor.java
  • 33. A  Progress  So*ware  Company Camel Route <camelContext xmlns="http://camel.apache.org/schema/spring"> <routeBuilder ref="batchProcessor" /> </camelContext> <bean name="batchProcessor" class="com.fusesource.demo.batch.customer.CustomerBatchProcessor"/> <osgi:reference id="customerServiceLogic" interface="com.fusesource.customer.CustomerService"/> META-INF/spring/camel-route.xml
  • 34. A  Progress  So*ware  Company Summing up • OSGi provides goodness in terms of modularity. • Versioning, dependency management, classpath isolation, dynamic wiring • Apache Karaf augments core OSGi runtime with cross- functional-concerns • Logging, shell, configuration, security, … • Karaf is a good home for Camel EIPs, CXF services… • Apache ServiceMix pulls it all together. • All the code from this presentation is available from the author!
  • 35. A  Progress  So*ware  Company OSGi for real in enterprise integration with Apache Karaf Dr. Adrian Trenaman, Sr. Principal Solution Architect, FuseSource trenaman@fusesource.com twitter: adrian_trenaman | linked-in adrian.trenaman http://trenaman.blogspot.com http://slideshare.net/trenaman