Sorry Gret, I messed up code from 2 samples. But they are similar only
difference is in name of objects..

-------------------------------------------

In correct sample which I have put at the end..


convertBodyTo->LogInfo is does not have the problem as the body is
picked correctly from the Stream

LogTransformer is expected to be used when doing
(.to("jpa:org.apache.servicemix.samples.logging.LogEntity")

LogEntity bean expects the strcuture to be like <{}jobLog> but it gets
<{}log>

That is why the error :

ERROR | pool-flow.seda.servicemix-camel-thread-1 |
>> DeadLetterChannel        | .apache.camel.processor.Logger  143 | On
>> delivery attempt: 0 caught: org.apache.camel.RuntimeCamelException:
>> javax.xml.bind.UnmarshalException: unexpected element (uri:"",
>> local:"log"). Expected elements are <{}jobLog>



Camel-Route used is as follows
----------------------------

public class PersistLogRoute extends SpringRouteBuilder {
    public void configure() throws Exception {

from("jbi:endpoint:http://servicemix.apache.org/samples/logging-sample/p
ersist/log")
           .convertBodyTo(LogInfo.class)
           .to("jpa:org.apache.servicemix.samples.logging.LogEntity");
    }
}

Custom Converter Code is as follows..
----------------------------
>> @Converter
>> public class LogTransformer {
>>     private static final transient Log LOG =
>> LogFactory.getLog(LogTransformer.class);
>>     private JpaTemplate template;
>>
>>     public LogTransformer(JpaTemplate template) {
>>         this.template = template;
>>     }
>>
>>     /**
>>      * A transformation method to convert a LogInfo into a LogEntity
>>      * entity
>>      */
>>     @Converter
>>     public LogEntity toJobLog(LogInfo doc) {
>>         String jobId = doc.getJobId();
>>         LogEntity jobLog = findLogEntityByJobId(jobId);
>>
>>         // lets convert information from the document into the entity

>> bean
>>
>>         jobLog.setStepId(doc.getStepId());
>>         jobLog.setDate(doc.getDate());
>>         jobLog.setStatus(doc.getStatus());
>>
>>
>>         LOG.debug("Created jobLog: " + jobLog);
>>         return jobLog;
>>     }
>>
>>     /**
>>      * Finds a customer for the given username, or creates and
>> inserts
>>
>
>
>> a new one
>>      */
>>     protected LogEntity findLogEntityByJobId(String jobId) {
>>         LOG.debug("Log Entity: Job Id" + jobId);
>>         List<LogEntity> list = template.find("select x from " +
>> LogEntity.class.getName() + " x where x.jobId = ?1", jobId);
>>         if (list.isEmpty()) {
>>             LogEntity answer = new LogEntity();
>>             answer.setJobId(jobId);
>>             template.persist(answer);
>>             return answer;
>>         } else {
>>             return list.get(0);
>>         }
>>     }
>> }
>> --------------------------






The information contained in this electronic message and any attachments to 
this message are intended for the exclusive use of the addressee(s) and may 
contain proprietary, confidential or privileged information. If you are not the 
intended recipient, you should not disseminate, distribute or copy this e-mail. 
Please notify the sender immediately and destroy all copies of this message and 
any attachments.

WARNING: Computer viruses can be transmitted via email. The recipient should 
check this email and any attachments for the presence of viruses. The company 
accepts no liability for any damage caused by any virus transmitted by this 
email.

www.wipro.com

Reply via email to