You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by vdhawan <va...@gmail.com> on 2014/07/28 11:18:56 UTC

How to pass multiple custom objects to processor

I have a wsdl with multiple operations and the typical structure of the
message looks like

<Envelope>
  <Header>
     <MyHeader>
          ....
         .....
     </MyHeader>
  <Header>
  <Body>
      <MyBody>
           .........
           ..........
      </MyBody>
  <Body>
<Envelope>

Can i unmarshal camel context and send MyHeader and MyBody objects to the
processor in properties or headers?
I do not want to write my custom type converters since there are multiple
"types" of MyBody (because there are multiple operations)

Currently, i have managed to make it work as following
public void myMethod(Exchange exchange,@XPath(//MyHeader) DOMNodeList
header, @Xpath(//MyBody mybody)
-- Do unmarshalling
-- Edit the message
-- Marshal
-- Set Body in outgoing exhange

Is this the right way to do it?



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-pass-multiple-custom-objects-to-processor-tp5754502.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to pass multiple custom objects to processor

Posted by vdhawan <va...@gmail.com>.
Thanks Matt.

<setProperty propertyName="bodyPart">
				<xpath resultType="javax.xml.transform.Source">//MyXpath</xpath>
</setProperty>

And the corresponding getter i.e exchange.getProperties().get("bodyPart")
gives me null. Same with Result. 



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-pass-multiple-custom-objects-to-processor-tp5754502p5754575.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to pass multiple custom objects to processor

Posted by Arnaud Deprez <ar...@gmail.com>.
Hi,

As I don't know your data structure, it's difficult for me to give you a
specific (or "best") way.
But you have 2 possibilities (see http://camel.apache.org/aggregator.html)
:

   1. Use a custom aggregation strategy in java code
   2. Use the option "grouped exchanges" or use a "custom aggregation
   strategy"

Find the solution that suits to your needs.


2014-07-29 12:04 GMT+02:00 vdhawan <va...@gmail.com>:

> Thanks arnaudeprez.
>
> This sounds like that this could work.
>
> 1. Splitting - i understand , i can unmarshal header and body via xpath
> separately and i am good.
>
> Any specific way to collect these two objects and in collection ? And, if i
> manage to put my two objects in a collection, in what format should i send
> it to processor.
>
> Thanks again!!
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/How-to-pass-multiple-custom-objects-to-processor-tp5754502p5754577.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: How to pass multiple custom objects to processor

Posted by vdhawan <va...@gmail.com>.
Thanks arnaudeprez. 

This sounds like that this could work. 

1. Splitting - i understand , i can unmarshal header and body via xpath
separately and i am good. 

Any specific way to collect these two objects and in collection ? And, if i
manage to put my two objects in a collection, in what format should i send
it to processor. 

Thanks again!!



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-pass-multiple-custom-objects-to-processor-tp5754502p5754577.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to pass multiple custom objects to processor

Posted by Arnaud Deprez <ar...@gmail.com>.
If I get you correctly, I think the best pattern that matches your need is
:

   1. split your messages by headers and bodies (by using XPath or the
   tokenizer with regex expression)
   2. then aggregate it in the object you want (a collection or whatever
   you want)
   3. then call a processor with your result

In my opinion, when I see your process, I have the feeling that you
reinvent the wheel and you did by hand what camel can do for you.


2014-07-28 20:05 GMT+02:00 Matt Sicker <bo...@gmail.com>:

> If you're using XPath, couldn't you convert to Source or Result? Both from
> javax.xml.transform.
>
>
> On 28 July 2014 04:18, vdhawan <va...@gmail.com> wrote:
>
> > I have a wsdl with multiple operations and the typical structure of the
> > message looks like
> >
> > <Envelope>
> >   <Header>
> >      <MyHeader>
> >           ....
> >          .....
> >      </MyHeader>
> >   <Header>
> >   <Body>
> >       <MyBody>
> >            .........
> >            ..........
> >       </MyBody>
> >   <Body>
> > <Envelope>
> >
> > Can i unmarshal camel context and send MyHeader and MyBody objects to the
> > processor in properties or headers?
> > I do not want to write my custom type converters since there are multiple
> > "types" of MyBody (because there are multiple operations)
> >
> > Currently, i have managed to make it work as following
> > public void myMethod(Exchange exchange,@XPath(//MyHeader) DOMNodeList
> > header, @Xpath(//MyBody mybody)
> > -- Do unmarshalling
> > -- Edit the message
> > -- Marshal
> > -- Set Body in outgoing exhange
> >
> > Is this the right way to do it?
> >
> >
> >
> > --
> > View this message in context:
> >
> http://camel.465427.n5.nabble.com/How-to-pass-multiple-custom-objects-to-processor-tp5754502.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> >
>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>

Re: How to pass multiple custom objects to processor

Posted by Matt Sicker <bo...@gmail.com>.
If you're using XPath, couldn't you convert to Source or Result? Both from
javax.xml.transform.


On 28 July 2014 04:18, vdhawan <va...@gmail.com> wrote:

> I have a wsdl with multiple operations and the typical structure of the
> message looks like
>
> <Envelope>
>   <Header>
>      <MyHeader>
>           ....
>          .....
>      </MyHeader>
>   <Header>
>   <Body>
>       <MyBody>
>            .........
>            ..........
>       </MyBody>
>   <Body>
> <Envelope>
>
> Can i unmarshal camel context and send MyHeader and MyBody objects to the
> processor in properties or headers?
> I do not want to write my custom type converters since there are multiple
> "types" of MyBody (because there are multiple operations)
>
> Currently, i have managed to make it work as following
> public void myMethod(Exchange exchange,@XPath(//MyHeader) DOMNodeList
> header, @Xpath(//MyBody mybody)
> -- Do unmarshalling
> -- Edit the message
> -- Marshal
> -- Set Body in outgoing exhange
>
> Is this the right way to do it?
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/How-to-pass-multiple-custom-objects-to-processor-tp5754502.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Matt Sicker <bo...@gmail.com>

Re: How to pass multiple custom objects to processor

Posted by sandeepreddip <sa...@gmail.com>.
Hi,
you can something like 

Assuming JAXB
DataFormat jaxbDataFormat = new
JaxbDataFormat(ObjectFactory.class.getPackage().getName());

where ObjectFactory will be in your generated classes.


			.from("direct:start")
			.unmarshal(jaxbDataFormat)
			.process(new SomeProcessor())
			.end();

Similarly you can marshal back.

Checkout the link below  Camel Data Format
<http://camel.apache.org/data-format.html>  



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-pass-multiple-custom-objects-to-processor-tp5754502p5754539.html
Sent from the Camel - Users mailing list archive at Nabble.com.