Monday, September 27, 2010

Custom XStream driver configuration added to Camel XStream data format

Apache Camel provides support for XStream data transformation. However until now it was very difficult to provide XML pull parser driver different then default XppDriver. Few days ago I created patch for Apache Camel XStream data format (with help from Willem Jiang with hacking Spring DSL for it). My improvment has been submitted to the Camel codebase. It should be included in Camel 2.5 .

Now you can pass reference of the HierarchicalStreamDriver instance directly in the Spring DSL with driverRef attribute:

<bean id="jsonDriver" 
class="com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver"/>

<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
  <dataFormats>
    <xstream id="xstream" driverRef="jsonDriver"/>            
  </dataFormats>

  <route>
    <from uri="direct:start"/>
    <marshal ref="xstream"/>
    <to uri="mock:result"/>
    </route>
</camelContext>

Friday, September 24, 2010

Camel supports field omitting for XStream data format

I committed patch to the Apache Camel XStream data format. It provides support for omitting selected fields. Claus Ibsen added Spring DSL to it and now it's ready to go to the next version of Camel (2.5).

Omitting selected fields is an useful option of XStream. By default XStream includes all fields of the object in the XML (un)marshalling process. Method XStream.omitFields() configures XStream to ignore selected fields for given class and not taking them under consideration during the XML (de)serialization process.

Here is the sample usage with Camel:

<camelContext xmlns="http://camel.apache.org/schema/spring">

  <dataFormats>
    <xstream id="xstream">
    <!-- omit the qux field from the Bar class -->
      <omitFields>
        <omitField class="foo.Bar">
          <field>qux</field>
        </omitField>
      </omitFields>
    </xstream>
  </dataFormats>
  
  <route>
    <from uri="direct:start"/>
    <marshal ref="xstream"/>
    <convertBodyTo type="String"/>
    <to uri="mock:result"/>
  </route>

</camelContext>

Tuesday, September 21, 2010

How to find desired Maven archetype?

To search for the Maven archetype you need, display list of all available ones from of the selected catalogs:

hekonsek@jorge:/tmp$ mvn archetype:generate -DarchetypeCatalog=internal,remote,local | grep -i camel
47: remote -> camel-component (null)
48: remote -> camel-router (null)
49: remote -> camel-archetype-activemq (Creates a new Camel project that configures and interacts with ActiveMQ.)
50: remote -> camel-archetype-component (Creates a new Camel component.)
51: remote -> camel-archetype-java (Creates a new Camel project using Java DSL.)
52: remote -> camel-archetype-scala (Creates a new Camel project using Scala DSL.)
53: remote -> camel-archetype-spring (Creates a new Camel project with added Spring DSL support.)
54: remote -> camel-archetype-war (Creates a new Camel project that deploys the Camel Web Console, REST API, and your routes as a WAR)
98: remote -> servicemix-camel-service-unit (null)

Now you can execute Maven in interctive mode and enter id of the desired artifact:

hekonsek@jorge:/tmp$ mvn archetype:generate
...
Choose archetype:
...
Choose a number: 80: 98
Choose version: 
1: 3.2
2: 3.2.1
3: 3.2.2
4: 3.2.3
Choose a number: : 4
...
Define value for property 'groupId': : foo
Define value for property 'artifactId': : bar
Define value for property 'version': 1.0-SNAPSHOT:
...

Ta-da! Project from archetype is ready to go.

Monday, September 20, 2010

Types of Maven archetypes catalogs

Maven Archetype plug-in allows to publish available archetypes using the catalogs. To be exact four kinds of archetype catalogs are supported:

By default Archetype plug-in (Maven 2.2.1, Archetype Plug-in 2.0-alpha-5) uses local and remote repositories to list available artifacts. You can specify catalogs to use with -DarchetypeCatalog option:

mvn archetype:generate
-DarchetypeCatalog=internal,http://foo.com/archetype-catalog.xml

Tuesday, September 14, 2010

I passed Sun Certified Enterprise Architect for Java EE 5 exam

Today I successfully passed Sun Certified Enterprise Architect exam with the result 82%. Actually now this certificate is called Oracle Certified Master, Java EE 5 Enterprise Architect. The exam is the first step in achieving Oracle Certified Ninja title. Now I need to create the project (step 2) and write an essay about it (step 3).

I've been learning for the exam for 3 weeks (excluding the weekends which are supposed to relax with family and friends, get drunk and enjoy downhill riding). Average 2 hours of study per working day.

I used Sun Certified Enterprise Architect for Java EE Study Guide and WhizLabs SCEA simulator. Some people reports that WhizLabs is easier than real exam. However I disagree since questions presented in both SCEA book and WhizLabs are pretty similar to these I encountered during the exam.

    Differences between WhizLabs and real SCEA exam?
  • no CORBA-related questions on real exam
  • easier security questions on real exam
  • less general Object Oriented design questions (these easy ones)

As I expected I'm the best (100%) at "Messaging and Integration" and "Design Patterns" and worst (50%) at "Business Tier Technologies" (since I'm the Spring hacker and don't work with EJBs on regular basis).