You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Tom Ellis <te...@gmail.com> on 2013/10/08 19:19:33 UTC

Default Type Conversions

Hi,

Is there some documentation around the strategy Camel takes when deciding
what to convert the body of an exchange to before sending to an endpoint?

For example, I have set a File object in the body of an exchange and send
this to a JMS endpoint. When the exchange is obtained from that endpoint,
the body contains a byte array of the contents of the file the File object
represents.

Given the File object is serializable I expected a File object to be
available at the other end. I could just send the File URI string and
create a new File object on the other side, but I wondered where/if the
conversion strategy for Camel is documented?

Cheers,

Tom

Re: Default Type Conversions

Posted by Tom Ellis <te...@gmail.com>.
Thanks Christian, sounds like Claim Check is what we're doing.

Cheers,

Tom


On 8 October 2013 22:35, Christian Müller <ch...@gmail.com>wrote:

> Hi Tom!
>
> Find my comments inline.
>
> Best,
> Christian
>
>
>
> On Tue, Oct 8, 2013 at 7:19 PM, Tom Ellis <te...@gmail.com> wrote:
>
> > Hi,
> >
> > Is there some documentation around the strategy Camel takes when deciding
> > what to convert the body of an exchange to before sending to an endpoint?
> >
> Camel will not convert the body of an exchange to BEFORE sending to an
> endpoint. The endpoint may convert the body to a know type which the
> endpoint can handle.
>
> >
> > For example, I have set a File object in the body of an exchange and send
> > this to a JMS endpoint. When the exchange is obtained from that endpoint,
> > the body contains a byte array of the contents of the file the File
> object
> > represents.
> >
> This is because the JMS component converts the body to a know type it can
> handle well (using the Camel type converter mechanism).
>
> >
> > Given the File object is serializable I expected a File object to be
> > available at the other end. I could just send the File URI string and
> > create a new File object on the other side, but I wondered where/if the
> > conversion strategy for Camel is documented?
> >
> This doesn't make sense. The "other end" could be a server on a different
> continent... You may looking for the claim check pattern (
> http://camel.apache.org/claim-check.html)?
>
> >
> > Cheers,
> >
> > Tom
> >
>

Re: Default Type Conversions

Posted by Christian Müller <ch...@gmail.com>.
Hi Tom!

Find my comments inline.

Best,
Christian



On Tue, Oct 8, 2013 at 7:19 PM, Tom Ellis <te...@gmail.com> wrote:

> Hi,
>
> Is there some documentation around the strategy Camel takes when deciding
> what to convert the body of an exchange to before sending to an endpoint?
>
Camel will not convert the body of an exchange to BEFORE sending to an
endpoint. The endpoint may convert the body to a know type which the
endpoint can handle.

>
> For example, I have set a File object in the body of an exchange and send
> this to a JMS endpoint. When the exchange is obtained from that endpoint,
> the body contains a byte array of the contents of the file the File object
> represents.
>
This is because the JMS component converts the body to a know type it can
handle well (using the Camel type converter mechanism).

>
> Given the File object is serializable I expected a File object to be
> available at the other end. I could just send the File URI string and
> create a new File object on the other side, but I wondered where/if the
> conversion strategy for Camel is documented?
>
This doesn't make sense. The "other end" could be a server on a different
continent... You may looking for the claim check pattern (
http://camel.apache.org/claim-check.html)?

>
> Cheers,
>
> Tom
>

Re: Default Type Conversions

Posted by Chris <cw...@gmail.com>.
I think if you turn on TRACE logging on the class
org.apache.camel.impl.converter.BaseTypeConverterRegistry,
you should see the type converter logic in action.

I also saw in a Camel core unit test, code along the lines of:

                 from("file://target/gf")
                     .convertBodyTo(File.class)
                     .to("mock:result");
...then

mock.message(0).body().isInstanceOf(File.class);
...which means it expects it to be still of type File at the other end.

I don't know how you're sending the File object (ProducerTemplate or 
replacing In Message) if you are not using a ProducerTemplate, you could 
try the 2-arg version of setBody(...), i.e.:

exchange.getIn().setBody(body, File.class);

or just try explicit conversions via the DSL:

  .convertBodyTo(File.class)


    -Chris

On 10/8/2013 1:19 PM, Tom Ellis wrote:
> Hi,
>
> Is there some documentation around the strategy Camel takes when deciding
> what to convert the body of an exchange to before sending to an endpoint?
>
> For example, I have set a File object in the body of an exchange and send
> this to a JMS endpoint. When the exchange is obtained from that endpoint,
> the body contains a byte array of the contents of the file the File object
> represents.
>
> Given the File object is serializable I expected a File object to be
> available at the other end. I could just send the File URI string and
> create a new File object on the other side, but I wondered where/if the
> conversion strategy for Camel is documented?
>
> Cheers,
>
> Tom
>