concept Java in category esb

appears as: Java, Java, The Java
Open-Source ESBs in Action: Example Implementations in Mule and ServiceMix

This is an excerpt from Manning's book Open-Source ESBs in Action: Example Implementations in Mule and ServiceMix.

This book focuses on a specific kind of ESB, the open source ESB. Open source ESBs are also built on JMS and other Java technologies. Although graphical tools are also available for most of the open source ESBs, as we’ll see later in this book, open source ESBs are more focused on Java and XML development. In this book we show many code examples that include Java and XML snippets, because that’s the typical place to implement integration logic within an open source ESB. This means that you shouldn’t be afraid of doing a bit of Java coding and XML configuration when using an open source ESB.

Listing 2.7. Camel route using Java

To check your version of Java, run java-version from the command line. This command should return something similar to this:

java version "1.6.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0_06-b02)
Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)

Notice that this is the output of a Java 6 runtime environment, but Java 5 is also fine. If the Java version shown is below 1.5, then please install a newer version from http://java.sun.com/javase/downloads/index.jsp.

When you’re working with integration tools, you’re often working with XML. XML provides a standard format for exchanging information between systems. However, working with XML directly from Java is a bit cumbersome. In our integration logic, we want to work with standard Java objects, but we still need a generic format that can be sent between the various components. Many open source libraries are available that allow you to easily transform a Java object to XML and back again, such as Java Architecture for XML Binding (JAXB) and Service Data Objects (SDOs).

When you want to go from XML to Java, you must use similar steps. But instead of using an IMarshallingContext, you should use an IUnmarshallingContext, as you can see in the following code snippet:

IUnmarshallingContext ctx = BindingDirectory.getFactory(Person.class)
    .createUnmarshallingContext();
Object obj = ctx.unmarshalDocument(new StringReader(data));

You’ve now seen how to configure binding files for JiBX, how to run the binding compiler, and how to invoke the JiBX bindings from Java. So if you want to use JiBX from your application code, you can use the code snippets we showed you to do so. In the next section, you’ll learn how to use JiBX together with ServiceMix and Mule.