You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Jean Francois LE BESCONT <jf...@gmail.com> on 2013/05/07 10:38:29 UTC

From bind to bind

Hi !

I would like to know if someone has already found a clean solution to this
point.

I have a directory with CSV file with :

A;1
B;2
...

The bind is like :

@CsvRecord(separator = ";" )
public class BindFileCSV {

@DataField(pos = 1)
public String COL1;

@DataField(pos = 2 )
public String COL2;

}

Classic...

i would like to bind output with differents schemas regarding to a header
value

   from("file://C:/Temp/camel/rep1/?noop=true")
            .routeId("ROUTE_1")
            .id("ROUTE_1")
            .split().tokenize("\n")
            .streaming()
                .unmarshal()
                .bindy(BindyType.Csv, Ticket.class)
                .choice()
                    .when( header("PROP").isEqualTo("1"))
                        .marshal()
                        .bindy(BindyType.Csv, TicketOUT1.class)

.recipientList(simple("stream:file?fileName=C:/Temp/camel/rep1/out/yop.csv"))
                    .end()
                    .when( header("PROP").isEqualTo("2"))
    .marshal()
                        .bindy(BindyType.Csv, TicketOUT2.class)

.recipientList(simple("stream:file?fileName=C:/Temp/camel/rep2/out/yop.csv"))
                    .end()
                    .otherwise()

            .end()
            .log("fin")
        .end()
        ;

I there an elegant way of to do the conversion from Ticket to TicketOUT1  ?

Thanks !

JF

Re: From bind to bind

Posted by Jean Francois LE BESCONT <jf...@gmail.com>.
Hey

Oh I mist this part on the dozer type conversion documentation ... :)

For community, with this pom :

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-dozer</artifactId>
<version>${org.apache.camel.version}</version>
</dependency>


And a spring config:

<bean id="dozerConverterLoader"
class="org.apache.camel.converter.dozer.DozerTypeConverterLoader" />

<bean id="org.dozer.mapper" class="org.dozer.DozerBeanMapper">
<property name="mappingFiles">
<list>
<value>META-INF/dozer-global-configuration.xml</value>
</list>
</property>
</bean>

Conversion based with dozer in xml works perfectly ( not with annotation)

Thanks ( like always )

Jeff



2013/5/10 Diether <di...@optis.be>

> Did you also configure the DozerTypeConverterLoader in the camel context?
>
>
> <!-- the registry will be scanned and 'mapper' below will be found and
> installed -->
> <bean id="dozerConverterLoader"
> class="org.apache.camel.converter.dozer.DozerTypeConverterLoader" />
>
> <bean id="mapper" class="org.dozer.DozerBeanMapper">
>   <property name="mappingFiles">
>     <list>
>       <value>mapping.xml</value>
>     </list>
>   </property>
> </bean>
>
>
> Regards,
> Diether
>
>
> ________________________________
> Van: jeff [via Camel] [ml-node+s465427n5732198h85@n5.nabble.com]
> Verzonden: woensdag 8 mei 2013 21:24
> To: Wuyts Diether
> Onderwerp: Re: From bind to bind
>
> My job works fine with a route which used a dozerMapper get from getBean of
> spring context.
>
> I have try with a simple convertbody :
>
> from("file://C:/Temp/camel/rep1/?noop=true")
> .split().tokenize("\n")
> .streaming()
> .unmarshal()
>
> .bindy(BindyType.Csv, Ticket.class)
>
> .convertBodyTo(TicketOUT.class)
>
> ...
> .to("log://after1")
> .marshal()
> .bindy(BindyType.Csv, TicketOUT.class)
> .to("log://after2")
>
> .recipientList(simple("stream:file?fileName=C:/Temp/camel/rep1/out/yop.csv"))
> .end()
> .log("fin")
> .end()
> ;
>
> But It throw the
> org.apache.camel.InvalidPayloadException: No body available of type:
> bean.ticketOut.TicketOUT but has value: bean.ticket.Ticket@547fa706 of
> type: bean.ticket.Ticket on: null. Caused by: No type converter available
> to convert from type: bean.ticket.Ticket to the required type:
> bean.ticketOut.TicketOUT with value
> [hidden email]<UrlBlockedError.aspx>[null]. Caused by:
> [org.apache.camel.NoTypeConversionAvailableException - No type converter
> available to convert from type: bean.ticket.Ticket to the required type:
> bean.ticketOut.TicketOUT with value bean.ticket.Ticket@547fa706]
>
>
> Do I have to configure something else ?
>
> thanks !
>
> Jeff
>
>
> 2013/5/8 jeff <[hidden email]<UrlBlockedError.aspx>>
>
> > Oh ! Great !
> >
> > Thanks
> >
> >
> >
> >
> >
> > --
> > View this message in context:
> >
> http://camel.465427.n5.nabble.com/From-bind-to-bind-tp5732109p5732195.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> >
>
>
> ________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://camel.465427.n5.nabble.com/From-bind-to-bind-tp5732109p5732198.html
> To start a new topic under Camel - Users, email
> ml-node+s465427n465428h15@n5.nabble.com
> To unsubscribe from Camel - Users, click here<
> http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=465428&code=ZGlldGhlci53dXl0c0BvcHRpcy5iZXw0NjU0Mjh8OTE4NjI3OTg5
> >.
> NAML<
> http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml
> >
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/From-bind-to-bind-tp5732109p5732243.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

RE: From bind to bind

Posted by Diether <di...@optis.be>.
Did you also configure the DozerTypeConverterLoader in the camel context?


<!-- the registry will be scanned and 'mapper' below will be found and installed -->
<bean id="dozerConverterLoader" class="org.apache.camel.converter.dozer.DozerTypeConverterLoader" />

<bean id="mapper" class="org.dozer.DozerBeanMapper">
  <property name="mappingFiles">
    <list>
      <value>mapping.xml</value>
    </list>
  </property>
</bean>


Regards,
Diether


________________________________
Van: jeff [via Camel] [ml-node+s465427n5732198h85@n5.nabble.com]
Verzonden: woensdag 8 mei 2013 21:24
To: Wuyts Diether
Onderwerp: Re: From bind to bind

My job works fine with a route which used a dozerMapper get from getBean of
spring context.

I have try with a simple convertbody :

from("file://C:/Temp/camel/rep1/?noop=true")
.split().tokenize("\n")
.streaming()
.unmarshal()

.bindy(BindyType.Csv, Ticket.class)

.convertBodyTo(TicketOUT.class)

...
.to("log://after1")
.marshal()
.bindy(BindyType.Csv, TicketOUT.class)
.to("log://after2")
.recipientList(simple("stream:file?fileName=C:/Temp/camel/rep1/out/yop.csv"))
.end()
.log("fin")
.end()
;

But It throw the
org.apache.camel.InvalidPayloadException: No body available of type:
bean.ticketOut.TicketOUT but has value: bean.ticket.Ticket@547fa706 of
type: bean.ticket.Ticket on: null. Caused by: No type converter available
to convert from type: bean.ticket.Ticket to the required type:
bean.ticketOut.TicketOUT with value
[hidden email]<UrlBlockedError.aspx>[null]. Caused by:
[org.apache.camel.NoTypeConversionAvailableException - No type converter
available to convert from type: bean.ticket.Ticket to the required type:
bean.ticketOut.TicketOUT with value bean.ticket.Ticket@547fa706]


Do I have to configure something else ?

thanks !

Jeff


2013/5/8 jeff <[hidden email]<UrlBlockedError.aspx>>

> Oh ! Great !
>
> Thanks
>
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/From-bind-to-bind-tp5732109p5732195.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


________________________________
If you reply to this email, your message will be added to the discussion below:
http://camel.465427.n5.nabble.com/From-bind-to-bind-tp5732109p5732198.html
To start a new topic under Camel - Users, email ml-node+s465427n465428h15@n5.nabble.com
To unsubscribe from Camel - Users, click here<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=465428&code=ZGlldGhlci53dXl0c0BvcHRpcy5iZXw0NjU0Mjh8OTE4NjI3OTg5>.
NAML<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>




--
View this message in context: http://camel.465427.n5.nabble.com/From-bind-to-bind-tp5732109p5732243.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: From bind to bind

Posted by Jean Francois LE BESCONT <jf...@gmail.com>.
My job works fine with a route which used a dozerMapper get from getBean of
spring context.

I have try with a simple convertbody :

from("file://C:/Temp/camel/rep1/?noop=true")
.split().tokenize("\n")
.streaming()
.unmarshal()

.bindy(BindyType.Csv, Ticket.class)

.convertBodyTo(TicketOUT.class)

...
.to("log://after1")
.marshal()
.bindy(BindyType.Csv, TicketOUT.class)
.to("log://after2")
.recipientList(simple("stream:file?fileName=C:/Temp/camel/rep1/out/yop.csv"))
.end()
.log("fin")
.end()
;

But It throw the
org.apache.camel.InvalidPayloadException: No body available of type:
bean.ticketOut.TicketOUT but has value: bean.ticket.Ticket@547fa706 of
type: bean.ticket.Ticket on: null. Caused by: No type converter available
to convert from type: bean.ticket.Ticket to the required type:
bean.ticketOut.TicketOUT with value
bean.ticket.Ticket@547fa706.Exchange[null]. Caused by:
[org.apache.camel.NoTypeConversionAvailableException - No type converter
available to convert from type: bean.ticket.Ticket to the required type:
bean.ticketOut.TicketOUT with value bean.ticket.Ticket@547fa706]


Do I have to configure something else ?

thanks !

Jeff


2013/5/8 jeff <jf...@gmail.com>

> Oh ! Great !
>
> Thanks
>
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/From-bind-to-bind-tp5732109p5732195.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

RE: From bind to bind

Posted by jeff <jf...@gmail.com>.
Oh ! Great !

Thanks





--
View this message in context: http://camel.465427.n5.nabble.com/From-bind-to-bind-tp5732109p5732195.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: From bind to bind

Posted by Diether <di...@optis.be>.
There is a camel component for dozer: http://camel.apache.org/dozer-type-conversion.html
It allows you to simply use .convertBodyTo(...)
No custom processor needed!

Regards,
Diether

________________________________
Van: jeff [via Camel] [ml-node+s465427n5732116h43@n5.nabble.com]
Verzonden: dinsdag 7 mei 2013 13:45
To: Wuyts Diether
Onderwerp: Re: From bind to bind

I have found a trick with dozer :

<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
<version>5.4.0</version>
</dependency>


with a processor which convert from Ticket  to TicketOUT

new Processor() {

   public void process(Exchange exchange) throws Exception {
      Ticket ticket = (Ticket) exchange.getIn().getBody();
      TicketOUT ticketOUT = dozerBeanMapper.map(ticket, TicketOUT.class);
      exchange.getIn().setBody(ticketOUT);
}
})

With :

@CsvRecord(separator = ";" )
public class Ticket {

@DataField(pos = 1, required = true)
@Mapping("TCK_TYPE2")
public String TCK_TYPE;
[...]
}

And

@CsvRecord(separator = ";" )
public class TicketOUT {

@DataField(pos = 2, required = true)
public String TCK_TYPE2;

[...]
}


Not necessary the best intergration solution but it is fast and pretty
clean. With 20 fields per class, the route convert 68 000 body per second.

Jeff




2013/5/7 Jean Francois LE BESCONT <[hidden email]<UrlBlockedError.aspx>>

> Ho By the way , I am using JRE 1.7 and CAMEL 2.11
>
>
> 2013/5/7 Jean Francois LE BESCONT <[hidden email]<UrlBlockedError.aspx>>
>
>> Hi !
>>
>> I would like to know if someone has already found a clean solution to
>> this point.
>>
>> I have a directory with CSV file with :
>>
>> A;1
>> B;2
>> ...
>>
>> The bind is like :
>>
>> @CsvRecord(separator = ";" )
>> public class BindFileCSV {
>>
>> @DataField(pos = 1)
>> public String COL1;
>>
>> @DataField(pos = 2 )
>>  public String COL2;
>>
>> }
>>
>> Classic...
>>
>> i would like to bind output with differents schemas regarding to a header
>> value
>>
>>    from("file://C:/Temp/camel/rep1/?noop=true")
>>             .routeId("ROUTE_1")
>>             .id("ROUTE_1")
>>             .split().tokenize("\n")
>>             .streaming()
>>                 .unmarshal()
>>                 .bindy(BindyType.Csv, Ticket.class)
>>                 .choice()
>>                     .when( header("PROP").isEqualTo("1"))
>>                         .marshal()
>>                         .bindy(BindyType.Csv, TicketOUT1.class)
>>
>> .recipientList(simple("stream:file?fileName=C:/Temp/camel/rep1/out/yop.csv"))
>>                     .end()
>>                     .when( header("PROP").isEqualTo("2"))
>>     .marshal()
>>                         .bindy(BindyType.Csv, TicketOUT2.class)
>>
>> .recipientList(simple("stream:file?fileName=C:/Temp/camel/rep2/out/yop.csv"))
>>                     .end()
>>                     .otherwise()
>>
>>             .end()
>>             .log("fin")
>>         .end()
>>         ;
>>
>> I there an elegant way of to do the conversion from Ticket to TicketOUT1
>>  ?
>>
>> Thanks !
>>
>> JF
>>
>
>


________________________________
If you reply to this email, your message will be added to the discussion below:
http://camel.465427.n5.nabble.com/From-bind-to-bind-tp5732109p5732116.html
To start a new topic under Camel - Users, email ml-node+s465427n465428h15@n5.nabble.com
To unsubscribe from Camel - Users, click here<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=465428&code=ZGlldGhlci53dXl0c0BvcHRpcy5iZXw0NjU0Mjh8OTE4NjI3OTg5>.
NAML<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>




--
View this message in context: http://camel.465427.n5.nabble.com/From-bind-to-bind-tp5732109p5732118.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: From bind to bind

Posted by Jean Francois LE BESCONT <jf...@gmail.com>.
I have found a trick with dozer :

<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
<version>5.4.0</version>
</dependency>


with a processor which convert from Ticket  to TicketOUT

new Processor() {

   public void process(Exchange exchange) throws Exception {
      Ticket ticket = (Ticket) exchange.getIn().getBody();
      TicketOUT ticketOUT = dozerBeanMapper.map(ticket, TicketOUT.class);
      exchange.getIn().setBody(ticketOUT);
}
})

With :

@CsvRecord(separator = ";" )
public class Ticket {

@DataField(pos = 1, required = true)
@Mapping("TCK_TYPE2")
public String TCK_TYPE;
[...]
}

And

@CsvRecord(separator = ";" )
public class TicketOUT {

@DataField(pos = 2, required = true)
public String TCK_TYPE2;

[...]
}


Not necessary the best intergration solution but it is fast and pretty
clean. With 20 fields per class, the route convert 68 000 body per second.

Jeff




2013/5/7 Jean Francois LE BESCONT <jf...@gmail.com>

> Ho By the way , I am using JRE 1.7 and CAMEL 2.11
>
>
> 2013/5/7 Jean Francois LE BESCONT <jf...@gmail.com>
>
>> Hi !
>>
>> I would like to know if someone has already found a clean solution to
>> this point.
>>
>> I have a directory with CSV file with :
>>
>> A;1
>> B;2
>> ...
>>
>> The bind is like :
>>
>> @CsvRecord(separator = ";" )
>> public class BindFileCSV {
>>
>> @DataField(pos = 1)
>> public String COL1;
>>
>> @DataField(pos = 2 )
>>  public String COL2;
>>
>> }
>>
>> Classic...
>>
>> i would like to bind output with differents schemas regarding to a header
>> value
>>
>>    from("file://C:/Temp/camel/rep1/?noop=true")
>>             .routeId("ROUTE_1")
>>             .id("ROUTE_1")
>>             .split().tokenize("\n")
>>             .streaming()
>>                 .unmarshal()
>>                 .bindy(BindyType.Csv, Ticket.class)
>>                 .choice()
>>                     .when( header("PROP").isEqualTo("1"))
>>                         .marshal()
>>                         .bindy(BindyType.Csv, TicketOUT1.class)
>>
>> .recipientList(simple("stream:file?fileName=C:/Temp/camel/rep1/out/yop.csv"))
>>                     .end()
>>                     .when( header("PROP").isEqualTo("2"))
>>     .marshal()
>>                         .bindy(BindyType.Csv, TicketOUT2.class)
>>
>> .recipientList(simple("stream:file?fileName=C:/Temp/camel/rep2/out/yop.csv"))
>>                     .end()
>>                     .otherwise()
>>
>>             .end()
>>             .log("fin")
>>         .end()
>>         ;
>>
>> I there an elegant way of to do the conversion from Ticket to TicketOUT1
>>  ?
>>
>> Thanks !
>>
>> JF
>>
>
>

Re: From bind to bind

Posted by Jean Francois LE BESCONT <jf...@gmail.com>.
Ho By the way , I am using JRE 1.7 and CAMEL 2.11


2013/5/7 Jean Francois LE BESCONT <jf...@gmail.com>

> Hi !
>
> I would like to know if someone has already found a clean solution to this
> point.
>
> I have a directory with CSV file with :
>
> A;1
> B;2
> ...
>
> The bind is like :
>
> @CsvRecord(separator = ";" )
> public class BindFileCSV {
>
> @DataField(pos = 1)
> public String COL1;
>
> @DataField(pos = 2 )
>  public String COL2;
>
> }
>
> Classic...
>
> i would like to bind output with differents schemas regarding to a header
> value
>
>    from("file://C:/Temp/camel/rep1/?noop=true")
>             .routeId("ROUTE_1")
>             .id("ROUTE_1")
>             .split().tokenize("\n")
>             .streaming()
>                 .unmarshal()
>                 .bindy(BindyType.Csv, Ticket.class)
>                 .choice()
>                     .when( header("PROP").isEqualTo("1"))
>                         .marshal()
>                         .bindy(BindyType.Csv, TicketOUT1.class)
>
> .recipientList(simple("stream:file?fileName=C:/Temp/camel/rep1/out/yop.csv"))
>                     .end()
>                     .when( header("PROP").isEqualTo("2"))
>     .marshal()
>                         .bindy(BindyType.Csv, TicketOUT2.class)
>
> .recipientList(simple("stream:file?fileName=C:/Temp/camel/rep2/out/yop.csv"))
>                     .end()
>                     .otherwise()
>
>             .end()
>             .log("fin")
>         .end()
>         ;
>
> I there an elegant way of to do the conversion from Ticket to TicketOUT1
>  ?
>
> Thanks !
>
> JF
>