4 Replies Latest reply: Jun 28, 2013 1:42 PM by Henrique Oliveira RSS

Camel Jackson

Christos Vasilakis Newbie

Hi there,

 

I am trying to define the following route using camel json unmarshalling.

 

              from("switchyard://RegistrationRoute")

                  .choice()

                            .when(header("type").isEqualTo("register"))

                                      .unmarshal().json(JsonLibrary.Jackson, gr.forthnet.nms.svcrrd.service.messages.RegistrationCommandMessage.class)

        .bean(Routing.class, "addRouteFromRegistrationCommandMsg(gr.forthnet.nms.svcrrd.service.messages.RegistrationCommandMessage)")       

        .log("registration completed");

    }

 

When is deployed I get the following message

 

Failed to create route route1 at: >>> Choice[[When[{header(type) == register} -> [Marshal[org.apache.camel.model.dataformat.JsonDataFormat@3cf720d5], Bean[gr.forthnet.nms.svcrrd.service.singleton.Routing], Log[registration completed]]]]] <<< in route: Route[[From[switchyard://RegistrationRoute?namespace=urn%3As... because of Data format 'json-jackson' could not be created. Ensure that the dataformat is valid and the associated Camel component is present on the classpath

 

I added a component folder on the modules folder of JBoss As 7

 

../jboss-as-7.1.0.CR1b/modules/org/apache/camel/component/jackson/main

 

with the camel-jackson jar files

 

camel-jackson-2.8.0.jar

module.xml

 

where on module.xml I added the following:

 

<module xmlns="urn:jboss:module:1.0" name="org.apache.camel.component.jackson">

    <resources>

        <resource-root path="camel-jackson-2.8.0.jar"/>

    </resources>

 

    <dependencies>

        <module name="org.apache.camel.core"/>

        <module name="org.apache.camel.spring"/>

        <module name="org.apache.commons.logging"/>

        <module name="javax.jms.api"/>

        <module name="org.springframework"/>

        <module name="org.slf4j"/>

              <module name="org.codehaus.jackson.jackson-core-asl"/>

              <module name="org.codehaus.jackson.jackson-mapper-asl"/>

              <module name="org.codehaus.jackson.jackson-xc"/>

    </dependencies>

</module>

 

 

And then on camel/core/main/module.xml I added my dependency

....

<module name="org.apache.camel.component.jackson"/>

...

Failed to create route route1 at: >>> Choice[[When[{header(type) == register} -> [Marshal[org.apache.camel.model.dataformat.JsonDataFormat@63815614], Bean[gr.forthnet.nms.svcrrd.service.singleton.Routing], Log[registration completed]]]]] <<< in route: Route[[From[switchyard://RegistrationRoute?namespace=urn%3As... because of Data format 'json-jackson' could not be created. Ensure that the dataformat is valid and the associated Camel component is present on the classpath

 

 

I would like to ask what is the proper way to install the camel-jackson component?

 

Regards

Christos

 

 


 


  • 1. Re: Camel Jackson
    Keith Babo Master

    Take a look at the configuration of the maven jar plugin in this quickstart.  Try adding a similar section to your application's pom.xml, but with the following configuration instead:

     

    <manifestEntries>
        <Dependencies>org.apache.camel.component.jackson</Dependencies>
    </manifestEntries>
    

     

    I can't say for sure that will do it, but that's where I would start.  If it doesn't work, please zip up your project and attach to the thread.

     

    cheers,

    keith

  • 2. Re: Camel Jackson
    Christos Vasilakis Newbie

    Hi Keith,

     

    didn't work but digging around the modules directory I found the <imports><exports> tags. After adding this in:

     

    <jboss install dir>/modules/org/apache/camel/core/main/module.xml

     

     

    ....

    <module name="org.apache.camel.component.jackson" export="true">

         <imports>

              <include path="META-INF/services/org/apache/camel/dataformat"/>

         </imports>

     

         <exports>

              <include path="META-INF/services/org/apache/camel/dataformat"/>

         </exports>

    </module>

    ....

     

    You need to make to sure to install the camel-jakson component jar together with the module.xml in

     

    <jboss install dir>/modules/org/apache/camel/component/jackson/main    (create manually the folders as needed)

     

    My current module.xml looks like this

     

    <module xmlns="urn:jboss:module:1.0" name="org.apache.camel.component.jackson">

        <resources>

            <resource-root path="camel-jackson-2.8.0.jar"/>

        </resources>

     

        <dependencies>

           <module name="org.apache.camel.core"/>

           <module name="org.apache.camel.spring"/>

           <module name="org.apache.commons.logging"/>

           <module name="javax.jms.api"/>

           <module name="org.springframework"/>

           <module name="org.slf4j"/>

            <module name="org.codehaus.jackson.jackson-core-asl"/>

            <module name="org.codehaus.jackson.jackson-mapper-asl"/>

            <module name="org.codehaus.jackson.jackson-xc"/>

        </dependencies>

    </module>

     

    Don't know if this is the correct way but it works

     

    Regards,

    Christos

  • 3. Re: Camel Jackson
    Keith Babo Master

    Ah, yeah.  The import definition allows you to see the META-INF/services resources in the module dependency.  You can see an in-depth explanation of this requirement here:

     

    https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7

     

    You should be able to specify this in your application by specifying "services export" in addition to the module name as part of the Dependencies property, e.g.

     

    <manifestEntries>
       <Dependencies>org.apache.camel.component.jackson export services</Dependencies>
    </manifestEntries>

     

    This should work in theory, but I haven't tested it.  One advantage to specifying this in your application is that you don't have to mess with the other camel module definitions in AS7.  A disadvantage is that if you have lots of apps which will use this in your environment then you have to specify it in every application vs. specifying it once in the camel core module definition.  So it's really your choice.

  • 4. Re: Camel Jackson
    Henrique Oliveira Newbie

    I had the same problem, but using the Gson library.

    I just added the jboss-deployment-structure.xml file in my project with the content.

     

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-deployment-structure>
        <deployment>
            <dependencies>
                <module name="org.apache.camel.gson">
                    <imports>
                        <include path="META-INF/services/org/apache/camel/dataformat"/>
                    </imports>
                    <exports>
                        <include path="META-INF/services/org/apache/camel/dataformat"/>
                    </exports>
                </module>
            </dependencies>
        </deployment>
    </jboss-deployment-structure>
    

     

    Just to comment I added the modules "org.apache.camel.gson" and "com.google.gson" as well.

     

    <switchyard_home>/modules/org/apache/camel/gson/main/module.xml

     

    <module xmlns="urn:jboss:module:1.0" name="org.apache.camel.gson">
    
        <resources>
            <resource-root path="camel-gson-2.10.0.jar"/>
        </resources>
    
        <dependencies>
            <module name="org.slf4j"/>
            <module name="com.google.gson"/>
            <module name="org.apache.camel.core"/>
        </dependencies>
    </module>
    
    

     

    <switchyard_home>/modules/com/google/gson/main/module.xml

     

    <module xmlns="urn:jboss:module:1.1" name="com.google.gson">
         <resources>
            <resource-root path="gson-2.2.2.jar"/>
        </resources>
         <dependencies>
        </dependencies>
    </module>