provides software and services that enable enterprises
Live Chat 1-888-673-6564

Open Source Software Technical Articles

  • Home
  • Search
  • Contact Us
  • Products and Support
  • Services
  • Enterprise OSS Blog
  • Wazi Technical Blog
  • About Wazi
  • Attributions and Licensing
  • Supply Chain Compliance
  • How to Contribute
  • Contributors
  • Resources Library
  • Cloud Services
  • Partners
  • Customers
  • Community
  • Company
  • Careers
  • News and Events

Subscribe to Wazi by Email

Your email:


Enterprise Developer Support 24 x 7, Get a Support Quote Now!


click-here-to-chat-with-an-online-representative

download-oss-discovery

Latest Posts

  • The secret to great reporting with Drupal 7
  • A more colorful LibreOffice unveiled
  • Toward a more colorful LibreOffice
  • Flexible administration with Puppet's Facter and templates
  • Knock for OpenSSH
  • Get more out of phpMyAdmin
  • Image annotation in GIMP, Dia, and OpenOffice Draw
  • Solr, Drupal 7, and faceted search
  • Using FreeNAS' new full disk encryption for ZFS
  • Create distributed storage with Gluster

Connect with Us!

Current Articles | RSS Feed RSS Feed

ServiceMix metapackage eases Java development process

Posted by Rares Aioanei on Thu, Sep 13, 2012
  
Email This Email Article  
Tweet  
  

Apache ServiceMix (SMX) can boost your efficiency when you work on complex Java projects, because it integrates several popular technologies, allowing you to get a simple application ready quickly.

You could define SMX as an enterprise service bus (ESB) integration provider powered by OSGi. Using ESB helps developers create interoperating applications that respect the service-oriented architecture model. SOA defines a set of rules and principles in software design that allow developers to create little pieces of software that each create services as part of a bigger design scheme. For example, an enterprise email client may comprise many components: email, calendar software, RSS facilities, and so on. With SOA, instead of developing them all in one piece, and thereby perhaps creating obscure bugs and chunky code, one develops the components separately then glues them together by working with a platform like SMX. Components communicate using events: a component generates an event, an event manager routes it to its destination, where another component receives it and processes it, and perhaps generates its own event. If you read our article on ActiveMQ, you have the idea. Finally, OSGi (formerly the Open Services Gateway initiative) is a spec collection for a framework standard.

Before you start developing with SMX, I suggest you take a tour of its website and look at its documentation page. To use SMX, you must have Java 6 installed, because it isn't guaranteed to work smoothly with Java 7. Select a download directory on your machine, which may also be the work/binary directory, as you choose, then download the package you need.

After extracting the contents of the archive, go to the bin/ directory and type ./start, then ./servicemix. The software starts at a console, just like a Linux terminal, and you can start exploring it by pressing the tab key and playing with the commands. One command you will find useful is the one to enable the web console on port 8181. Type features:list to see all the installed components, then use grep to see if web console is installed:

karaf@root> features:list | grep web 

By default the web console is not installed; you can run features:install webconsole to install it. You can install ActiveMQ's web console as well with a similar command, should you choose to. Yes, ActiveMQ is part of SMX, as is Karaf, the runtime behind SMX functionality; Camel, the integration framework; and CXF, the services framework. SMX also includes Jetty, a web server written entirely in Java, and once you've installed the web console, you can manage Karaf from a browser at http://localhost:8181/system/console, with smx/smx as user/password pair.

servicemixweb resized 600

A simple example

To get started learning SMX, try this simple example that uses Blueprint, a part of the Apache Aries project. Blueprint, according to its website, "provides a dependency injection framework for OSGi and was standardized by the OSGi alliance." In frameworks such as these, services can become unavailable even though other services might still depend on them. With Blueprint you can write an XML file, include the necessary element with code like xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0, and you're good to go. Take a look at this example XML code:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint
 xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="
 http://www.osgi.org/xmlns/blueprint/v1.0.0
 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
      <route>
        <from uri="file:input"/>
        <log message="Copying ${file:name} to the output directory"/>
        <to uri="file:output"/>
      </route>
    </camelContext>

</blueprint>

In this code, the xmlns attribute stands for XML NameSpace. xmlns is also used in XHTML, so there's a great chance you've seen it before. In XML, namespaces have the same puropse and meaning as they do in every other language that uses them: They avoid conflicts between element names, so when you want to group logically similar and unique elements, you use namespaces. Next, xsi stands for XML Schema Instance, and as you can see, this directive indicates the physical location of the schema documents. The lines containing from, log, and to are the core of our XML file; they define the source and the destination of the test file, as well as the log message. Do not dismiss logging; later, when your code becomes more complex than this 15-line XML file, you will need it to debug things. It's common programming practice to use printfs, couts, echos, or other functions used for outputting text to see where a problem lies. Finally, you can replace input and output with something more imaginative if you so desire, and please note how the file is copied into the output directory.

Now copy this file, naming it as you feel appropriate, into the deploy/ directory inside the SMX installation. Restart ServiceMix by running the commands ./stop and ./start inside the bin/ location. If you then enter the shell and look at the logs (with log:display) you will see the message defined in the XML code above. You can alter the file at your discretion to see how SMX works.

Using SMX implies finding out about a lot of other interesting technologies. Once you start working with it, you will find yourself learning about new and exciting things as you create your applications.

Follow @openlogic
Follow @OSCloudServices

This work is licensed under a Creative Commons Attribution 3.0 Unported License
Creative Commons License.
Tags: Tutorial, Programming, Java

Comments

Currently, there are no comments. Be the first to post one!
Post Comment
Name
 *
Email
 *
Website (optional)
Comment
 *

Allowed tags: <a> link, <b> bold, <i> italics

Loading...
Error sending email
Email sent successfully

Email article
Email To : 
Your name : 
Message : (maximum 200 characters)
Home | Search | Contact Us | Products and Support | Services | Enterprise OSS Blog | Wazi Technical Blog | Resources Library | Cloud Services | Partners | Customers | Community | Company | Careers | News and Events
Products
OpenLogic Exchange (OLEX)
License Compliance Module
OSS Discovery
OSS Deep Discovery
OpenUpdate
Services
Open Source Support
CentOS Support
Scanning & Compliance
Open Source Training
Professional Services
Solutions
Support & Indemnification
Open Source Governance
Open Source Scanning
Open Source Provisioning
Consulting & Training
Contact Us
1-888-673-6564


© 2013 OpenLogic, Inc. All rights reserved.
Site Map  |  Privacy Policy