You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Remi Malessa <re...@llgc.org.uk> on 2010/11/22 11:33:10 UTC

Type converter

Hi.
I have a route when I'm sending from activemq to a Java class (POJO).
The problem is the message is of type JDom. I've read the type converter 
http://camel.apache.org/type-converter.html manual
but can't find how to use a type converter with a POJO.

Could somebody give me a hint, please ?

Cheers
Remi

Re: Type converter

Posted by Remi Malessa <re...@llgc.org.uk>.
Claus,

On 11/22/2010 10:42 AM, Claus Ibsen wrote:
> But if the message was sent as an Object JMS message then you can just
> define the parameter as the same type
It works perfectly fine. Thanks.

Remi

Re: Type converter

Posted by Remi Malessa <re...@llgc.org.uk>.
Thanks Claus , I will have a go with it.

Remi

On 11/22/2010 10:42 AM, Claus Ibsen wrote:
> On Mon, Nov 22, 2010 at 11:33 AM, Remi Malessa<re...@llgc.org.uk>  wrote:
>> Hi.
>> I have a route when I'm sending from activemq to a Java class (POJO).
>> The problem is the message is of type JDom. I've read the type converter
>> http://camel.apache.org/type-converter.html manual
>> but can't find how to use a type converter with a POJO.
>>
> You can implement your custom type converter and have Camel pickup and
> use it automatic.
> http://camel.apache.org/type-converter.html
>
> Camel in Action book chapter 3 covers this as well.
>
>
> But if the message was sent as an Object JMS message then you can just
> define the parameter as the same type
>
> public void doSomething(JDom dom) {
>    ...
> }
>
>
>
>
>> Could somebody give me a hint, please ?
>>
>> Cheers
>> Remi
>>
>
>


Re: Type converter

Posted by Remi Malessa <re...@llgc.org.uk>.
Yes, it looks much easier. Thanks for the hints.

Remi

On 11/23/2010 01:50 PM, davsclaus wrote:
> Use the examples from the book.
>
> Its much easier just to use @Converter.
>
> Remember to add that TypeConverter file in the JAR. It tells Camel to
> automatic pickup and us your @Converter as type converters.
>
> This is the same technique we use in camel-core and all its components to
> auto register the type converters when Camel startup.


Re: Type converter

Posted by Remi Malessa <re...@llgc.org.uk>.
Claus and Tim, thanks a lot. Its working now.
I had placed a full name of the class together with the package (just 
like log4j) before, so it didn't work..

Remi


On 11/24/2010 06:14 AM, Claus Ibsen wrote:
> Hi
>
> See for example camel-mina which has custom type converters as well:
> https://svn.apache.org/repos/asf/camel/trunk/components/camel-mina/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
>
> And camel-core have 3 packages listed
> https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
>


On 11/23/2010 06:12 PM, Tim wrote:
> 1. I think you mean META-INF
> 2. Also you don't have to include "org.apache.activemq.camel.converter"
> 3. You should have uk.org.llgc.camel in the TypeConverter file as that
> is your package not your class.
>
> If you jar tvf your compiled jar (type_converter.jar in your case) you
> should see something like:
>
>      39 Mon Nov 22 18:30:58 CST 2010
> META-INF/services/org/apache/camel/TypeConverter
>
> Lastly turn on debug logging and you will see messages that camel
> found your Converter


Re: Type converter

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

See for example camel-mina which has custom type converters as well:
https://svn.apache.org/repos/asf/camel/trunk/components/camel-mina/src/main/resources/META-INF/services/org/apache/camel/TypeConverter

And camel-core have 3 packages listed
https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/main/resources/META-INF/services/org/apache/camel/TypeConverter


On Tue, Nov 23, 2010 at 6:24 PM, Remi Malessa <re...@llgc.org.uk> wrote:
> Still no luck.
>
> Remi
>
> On 11/23/2010 05:15 PM, Remi Malessa wrote:
>>
>> Hmmm, I think I know . . . "The contents are expected to be comma
>> separated package names..."
>>
>> Remi
>
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Type converter

Posted by Tim <ch...@gmail.com>.
1. I think you mean META-INF
2. Also you don't have to include "org.apache.activemq.camel.converter"
3. You should have uk.org.llgc.camel in the TypeConverter file as that
is your package not your class.

If you jar tvf your compiled jar (type_converter.jar in your case) you
should see something like:

    39 Mon Nov 22 18:30:58 CST 2010
META-INF/services/org/apache/camel/TypeConverter

Lastly turn on debug logging and you will see messages that camel
found your Converter



On Tue, Nov 23, 2010 at 11:24 AM, Remi Malessa <re...@llgc.org.uk> wrote:
> Still no luck.
>
> Remi
>
> On 11/23/2010 05:15 PM, Remi Malessa wrote:
>>
>> Hmmm, I think I know . . . "The contents are expected to be comma
>> separated package names..."
>>
>> Remi
>
>

Re: Type converter

Posted by Remi Malessa <re...@llgc.org.uk>.
Still no luck.

Remi

On 11/23/2010 05:15 PM, Remi Malessa wrote:
> Hmmm, I think I know . . . "The contents are expected to be comma 
> separated package names..."
>
> Remi


Re: Type converter

Posted by Remi Malessa <re...@llgc.org.uk>.
Hmmm, I think I know . . . "The contents are expected to be comma 
separated package names..."

Remi

On 11/23/2010 05:07 PM, Remi Malessa wrote:
>
> inside the TypeConverter there is apache license disclaimer + two lines:
>
> org.apache.activemq.camel.converter
> uk.org.llgc.camel.JdomTypeConverter

Re: Type converter

Posted by Remi Malessa <re...@llgc.org.uk>.
On 11/23/2010 03:53 PM, Claus Ibsen wrote:
> You put that file inside your own JAR. And in that file you add a text
> line which is a package name for the package where your @Converter
> class is.
Claus, if you have a minute, please tell me if I am doing it right.

Here is my String to Jdom type converter:

package uk.org.llgc.camel;

import java.io.IOException;
import java.io.StringReader;

import org.apache.camel.Converter;
import org.apache.camel.Exchange;
import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

@Converter
public class JdomTypeConverter {

     @Converter
     public static Document toJdomDocument(String pString, Exchange 
pExchange) throws JDOMException, IOException{

         SAXBuilder tBuilder = new SAXBuilder();
         Document tDoc = tBuilder.build(new 
StringReader((String)pExchange.getIn().getBody(String.class)));
         return tDoc;
     }
}

I place the JdomTypeConverter.class in a type_converter.jar .
I also add the TypeConverter inside the type_converter.jar .
inside the TypeConverter there is apache license disclaimer + two lines:

org.apache.activemq.camel.converter
uk.org.llgc.camel.JdomTypeConverter

I've tried placing the TypeConverter directly inside my jar, inside the 
METS-INF directory and also tried placing the whole:
services/org/apache/camel/TypeConverter structure, both directly and 
inside the METS-INF directory (of my jar).

My jar file is in the activemq_home/lib directory.

I've also tried placing the above set-ups inside the 
activemq/webapps/camel/METS-INF with same results.


Remi

Re: Type converter

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Nov 23, 2010 at 4:49 PM, Remi Malessa <re...@llgc.org.uk> wrote:
> Hi again.
>
> On 11/23/2010 01:50 PM, davsclaus wrote:
>>
>> Remember to add that TypeConverter file in the JAR. It tells Camel to
>> automatic pickup and us your @Converter as type converters.
>
> I have my Camel inside an Activemq server and I can't find
> /META-INF/services/org/apache/camel/TypeConverter /anywhere
> I had added my class as a jar into the activemg_home/lib dir , but that
> didn't work.
>
> Any chance you know how to register a type converter with such set-up ?
>

You put that file inside your own JAR. And in that file you add a text
line which is a package name for the package where your @Converter
class is.



>
> Cheers
> Remi
> /
> /
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Type converter

Posted by Remi Malessa <re...@llgc.org.uk>.
Hi again.

On 11/23/2010 01:50 PM, davsclaus wrote:
> Remember to add that TypeConverter file in the JAR. It tells Camel to
> automatic pickup and us your @Converter as type converters.

I have my Camel inside an Activemq server and I can't find 
/META-INF/services/org/apache/camel/TypeConverter /anywhere
I had added my class as a jar into the activemg_home/lib dir , but that 
didn't work.

Any chance you know how to register a type converter with such set-up ?


Cheers
Remi
/
/

Re: Type converter

Posted by davsclaus <ci...@yahoo.dk>.
Use the examples from the book.

Its much easier just to use @Converter.

Remember to add that TypeConverter file in the JAR. It tells Camel to
automatic pickup and us your @Converter as type converters.

This is the same technique we use in camel-core and all its components to
auto register the type converters when Camel startup.
-- 
View this message in context: http://camel.465427.n5.nabble.com/Camel-QuickFIXJ-Proxool-jar-dependency-issues-tp3271906p3276817.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Type converter

Posted by Remi Malessa <re...@llgc.org.uk>.
Hi Claus

On 11/22/2010 10:42 AM, Claus Ibsen wrote:
> You can implement your custom type converter and have Camel pickup and
> use it automatic.
> http://camel.apache.org/type-converter.html
>
> Camel in Action book chapter 3 covers this as well.
In the Camel in Action book, Listing 3.12 shows a "plain" class, where 
the class on the
Camel's website implements TypeConverter.

I've noticed you are the author of the book. Could you tell me which 
example to follow ?

Cheers
Remi

Re: Type converter

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Nov 22, 2010 at 11:33 AM, Remi Malessa <re...@llgc.org.uk> wrote:
> Hi.
> I have a route when I'm sending from activemq to a Java class (POJO).
> The problem is the message is of type JDom. I've read the type converter
> http://camel.apache.org/type-converter.html manual
> but can't find how to use a type converter with a POJO.
>

You can implement your custom type converter and have Camel pickup and
use it automatic.
http://camel.apache.org/type-converter.html

Camel in Action book chapter 3 covers this as well.


But if the message was sent as an Object JMS message then you can just
define the parameter as the same type

public void doSomething(JDom dom) {
  ...
}




> Could somebody give me a hint, please ?
>
> Cheers
> Remi
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/