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/12/09 15:15:37 UTC

Trouble with converting from org.jdom.Document to String

Hi .

I've created a String to org.jdom.Document and org.jdom.Document to 
String type converter.
The trouble is the org.jdom.Document doesn't seem to work.

The converter code seems to be fine , as I tested it using the main 
method and it returns what I need.
But whether I output a message with org.jdom.Document body to a 
activemq:queue ot try to force conversion
by <convertBodyTo type="java.lang.String"/> I don't get the same result.

Instead , I get [Document:  No DOCTYPE declaration, Root is [Element: 
<project/>]]] which looks rather like an output
of org.jdom.Document.toString() method.

Any idea, why or how to make it use the converter ?

Thanks
Remi

Re: Trouble with converting from org.jdom.Document to String

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Dec 9, 2010 at 5:22 PM, Remi Malessa <re...@llgc.org.uk> wrote:
> On 12/09/2010 02:57 PM, Claus Ibsen wrote:
>>
>> Add some system out or something to see if it pickup your type converter.
>>
>> And mind that Camel can only choose your type converter if the message
>> body matches that type.
>> So make sure the body isn't wrapped into something else.
>
> It is not picking up the org.jdom.Document to String method from my type
> converted.
>
> I've added a logger before the transformation call with "showHeaders=true"
> option and it
> shows : "BodyType:org.jdom.Document."
>

Hmm you dont see any WARN in the log when Camel startup? It does this
if there are type converter clashes.

Can you try to add a 2nd method which convers the JDom to something
else than String. For example just an Integer or something and then
you just hardcode a fixed value to return. Just to see if Camel can
pickup JDom -> Integer.

Convertering to String is something that alot / many types can do. So
if we chose a JDom -> Integer combo then there shouldn't be any doubt
which type converter to pick.


>
> 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: Trouble with converting from org.jdom.Document to String

Posted by Remi Malessa <re...@llgc.org.uk>.
On 12/09/2010 02:57 PM, Claus Ibsen wrote:
> Add some system out or something to see if it pickup your type converter.
>
> And mind that Camel can only choose your type converter if the message
> body matches that type.
> So make sure the body isn't wrapped into something else.
It is not picking up the org.jdom.Document to String method from my type 
converted.

I've added a logger before the transformation call with 
"showHeaders=true" option and it
shows : "BodyType:org.jdom.Document."


Remi

Re: Trouble with converting from org.jdom.Document to String

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Dec 9, 2010 at 3:46 PM, Remi Malessa <re...@llgc.org.uk> wrote:
> Hi Claus.
>
> I've put my class in a jar and placed it in my ActiveMQ_home/lib folder.
> Additionally I've placed a file called TypeConverter in
> /META-INF/services/org/apache/camel/ directory of the jar
> package.
>
> Inside the file I've put the package name of my type converter.
>
> I've tested the String to org.jdom.Document converter and it works fine. The
> only problem is with
> org.jdom.Document to java.lang.String.
>
> Here is my org.jdom.Document to java.lang.String method:
>
>    @Converter
>    public static String toString(org.jdom.Document pDocument, Exchange
> pExchange){
>
>        Document tDocument =
> pExchange.getIn().getBody(org.jdom.Document.class);
>        XMLOutputter tXMLOutputter = new XMLOutputter();
>        return tXMLOutputter.outputString(tDocument);
>    }
>

Add some system out or something to see if it pickup your type converter.

And mind that Camel can only choose your type converter if the message
body matches that type.
So make sure the body isn't wrapped into something else.


>
>
> Remi
>
>
>
> On 12/09/2010 02:36 PM, Claus Ibsen wrote:
>>
>> How do you register the converter?
>>
>> See more here
>> http://camel.apache.org/type-converter.html
>>
>> Or chapter 3 in the Camel book
>>
>



-- 
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: Trouble with converting from org.jdom.Document to String

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

I've put my class in a jar and placed it in my ActiveMQ_home/lib folder.
Additionally I've placed a file called TypeConverter in 
/META-INF/services/org/apache/camel/ directory of the jar
package.

Inside the file I've put the package name of my type converter.

I've tested the String to org.jdom.Document converter and it works fine. 
The only problem is with
org.jdom.Document to java.lang.String.

Here is my org.jdom.Document to java.lang.String method:

     @Converter
     public static String toString(org.jdom.Document pDocument, Exchange 
pExchange){

         Document tDocument = 
pExchange.getIn().getBody(org.jdom.Document.class);
         XMLOutputter tXMLOutputter = new XMLOutputter();
         return tXMLOutputter.outputString(tDocument);
     }



Remi



On 12/09/2010 02:36 PM, Claus Ibsen wrote:
> How do you register the converter?
>
> See more here
> http://camel.apache.org/type-converter.html
>
> Or chapter 3 in the Camel book
>

Re: Trouble with converting from org.jdom.Document to String

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Dec 9, 2010 at 3:15 PM, Remi Malessa <re...@llgc.org.uk> wrote:
> Hi .
>
> I've created a String to org.jdom.Document and org.jdom.Document to String
> type converter.
> The trouble is the org.jdom.Document doesn't seem to work.
>
> The converter code seems to be fine , as I tested it using the main method
> and it returns what I need.
> But whether I output a message with org.jdom.Document body to a
> activemq:queue ot try to force conversion
> by <convertBodyTo type="java.lang.String"/> I don't get the same result.
>
> Instead , I get [Document:  No DOCTYPE declaration, Root is [Element:
> <project/>]]] which looks rather like an output
> of org.jdom.Document.toString() method.
>
> Any idea, why or how to make it use the converter ?
>

How do you register the converter?

See more here
http://camel.apache.org/type-converter.html

Or chapter 3 in the Camel book


> Thanks
> 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/