Default Type Conversions

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Default Type Conversions

tellisnz
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
Reply | Threaded
Open this post in threaded view
|

Re: Default Type Conversions

Chris Wolf
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
>
Reply | Threaded
Open this post in threaded view
|

Re: Default Type Conversions

Christian Mueller
Administrator
In reply to this post by tellisnz
Hi Tom!

Find my comments inline.

Best,
Christian



On Tue, Oct 8, 2013 at 7:19 PM, Tom Ellis <[hidden email]> 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
>
Reply | Threaded
Open this post in threaded view
|

Re: Default Type Conversions

tellisnz
Thanks Christian, sounds like Claim Check is what we're doing.

Cheers,

Tom


On 8 October 2013 22:35, Christian Müller <[hidden email]>wrote:

> Hi Tom!
>
> Find my comments inline.
>
> Best,
> Christian
>
>
>
> On Tue, Oct 8, 2013 at 7:19 PM, Tom Ellis <[hidden email]> 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
> >
>