Re: Question about using Splitter

2017-12-20 Thread Charles Berger
> You should be able to convert your ImageCollection into List
> by simply doing something like:
>
> from("activemq:requestQueue")
> .convertBodyTo(ImageCollection.class)
> .setBody(simple("${body.images}"))
> .log("${body}")
> .split(body())
> .log("${body}")
> .to("bean:downloadImageQueue")
> .marshal().json(JsonLibrary.Jackson)
> .to("activemq:ftpQueue");

That has worked - thank you so much - I had spent way too long trying
to get past that step.


Re: Question about using Splitter

2017-12-20 Thread Tadayoshi Sato
Hi,

The point is that to split object message body using Splitter DSL it needs
to be either Collection, Iterator, or array. ImageCollection is a custom
class so there's no way for Camel to know how to split it.

You should be able to convert your ImageCollection into List
by simply doing something like:

from("activemq:requestQueue")
.convertBodyTo(ImageCollection.class)
.setBody(simple("${body.images}"))
.log("${body}")
.split(body())
.log("${body}")
.to("bean:downloadImageQueue")
.marshal().json(JsonLibrary.Jackson)
.to("activemq:ftpQueue");



On Wed, Dec 20, 2017 at 5:07 PM, Charles Berger <
charlesb.yesm...@googlemail.com> wrote:

> Hi,
>
> Thanks for replying.
>
> > Instead of splitting ImageCollection as the body, I think you just need
> to
> > split List as the body.
>
> Are you suggesting that the ImageCollection class is actually
> superfluous and I should use the List as the output
> from the bean uploadRequestQueue instead?
>
> Or is there a way in the route that I can call the method
> ImageCollection.getImages() method to pass into the split?
>
> Thanks,
>
> Charles.
>


Re: Question about using Splitter

2017-12-20 Thread Charles Berger
Hi,

Thanks for replying.

> Instead of splitting ImageCollection as the body, I think you just need to
> split List as the body.

Are you suggesting that the ImageCollection class is actually
superfluous and I should use the List as the output
from the bean uploadRequestQueue instead?

Or is there a way in the route that I can call the method
ImageCollection.getImages() method to pass into the split?

Thanks,

Charles.


Re: Question about using Splitter

2017-12-19 Thread Tadayoshi Sato
Hi,

Instead of splitting ImageCollection as the body, I think you just need to
split List as the body.

On Wed, Dec 20, 2017 at 7:50 AM, Charles Berger <
charlesb.yesm...@googlemail.com> wrote:

> Hi,
>
> I'm building my first application using Camel and have a question
> about how to use a splitter.
>
> My route receives a serialized Java class which contains a private
> ArrayList of a POJO and getter and setter methods for the list.
>
> I convert the serialized class into a its Java representation and then
> apply it to a splitter.  What I want to get out of the Splitter is
> each individual instance of the POJOs in the List but what I get
> instead is the complete list.
>
> Here is some code to show what I mean
>
> public class ImageCollection {
>
> private List images = new ArrayList();
>
> public void setImages(List) { ... }
>
> public List getImages() { }
>
> }
>
> public class SingleImageModel {
>
> members ...
>
> getters & setters
>
> }
>
> Routes:
>
> The first route accepts a POST from a servlet, validates the incoming
> payload and converts it into an instance of ImageCollection, which is
> dispatched to the requestQueue, then returns a response to the client.
>
> from("servlet:uploadUrl")
> .log("Request: ${body}")
> .to("bean:uploadRequestQueue")
> .log("${body}")
> .marshal().json(JsonLibrary.Jackson)
> .wireTap("activemq:requestQueue")
> .to("bean:formatResponse")
> .end()
>
>
> The second route is supposed to take the ImageCollection and split it
> into the SingleImageModel instances
>
>
> from("activemq:requestQueue")
> .convertBodyTo(ImageCollection.class)
> .log("${body}")
> .split(bodyAs(ImageCollection.class))
> .log("${body}")
> .to("bean:downloadImageQueue")
> .marshal().json(JsonLibrary.Jackson)
> .to("activemq:ftpQueue");
>
> I think I need to use an Aggregator to return the individual instances
> of the SingleImageModel class from the list inside ImageCollection,
> but I can't work out what that should do.
>
> Instead, what is happening is that the bean registered for the
> downloadImageQueue is receiving an instance of ImageCollection when it
> expects an instance of SingleImageModel and the type conversion in
> that bean is failing.
>
> Any guidance much appreciated.
>
> Thanks,
>
> Charles.
>


Question about using Splitter

2017-12-19 Thread Charles Berger
Hi,

I'm building my first application using Camel and have a question
about how to use a splitter.

My route receives a serialized Java class which contains a private
ArrayList of a POJO and getter and setter methods for the list.

I convert the serialized class into a its Java representation and then
apply it to a splitter.  What I want to get out of the Splitter is
each individual instance of the POJOs in the List but what I get
instead is the complete list.

Here is some code to show what I mean

public class ImageCollection {

private List images = new ArrayList();

public void setImages(List) { ... }

public List getImages() { }

}

public class SingleImageModel {

members ...

getters & setters

}

Routes:

The first route accepts a POST from a servlet, validates the incoming
payload and converts it into an instance of ImageCollection, which is
dispatched to the requestQueue, then returns a response to the client.

from("servlet:uploadUrl")
.log("Request: ${body}")
.to("bean:uploadRequestQueue")
.log("${body}")
.marshal().json(JsonLibrary.Jackson)
.wireTap("activemq:requestQueue")
.to("bean:formatResponse")
.end()


The second route is supposed to take the ImageCollection and split it
into the SingleImageModel instances


from("activemq:requestQueue")
.convertBodyTo(ImageCollection.class)
.log("${body}")
.split(bodyAs(ImageCollection.class))
.log("${body}")
.to("bean:downloadImageQueue")
.marshal().json(JsonLibrary.Jackson)
.to("activemq:ftpQueue");

I think I need to use an Aggregator to return the individual instances
of the SingleImageModel class from the list inside ImageCollection,
but I can't work out what that should do.

Instead, what is happening is that the bean registered for the
downloadImageQueue is receiving an instance of ImageCollection when it
expects an instance of SingleImageModel and the type conversion in
that bean is failing.

Any guidance much appreciated.

Thanks,

Charles.


Re: question about using splitter(?) and jsonpath expression

2014-11-20 Thread Claus Ibsen
Hi

Maybe use camel-jackson to unmarshal the json to a java.util.Map (it
does that by default)
http://camel.apache.org/json.html

And then you can use recipient list to call the 3 mongodb endpoints.
http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html

And from the java.util.Map object you can use the simple langue or
groovy etc to access the entry you want

simple("mongodb:${body['name']}&collection=name")


On Thu, Nov 20, 2014 at 10:21 PM, gmh  wrote:
> All,
> I am trying to come up with a processing pattern for a business case.
> Assume we have something like this form a queue (ActiveMQ/Rabbbitmq) does
> not matter
> Below is the json
> {
>"name":"xyz"
>"address": "123 Somewhere, USA"
>"ssn": "1234"
> }
> For each name/value pair I want to make a call to the database with the
> value that is provided.
> so essentially it will be something like this:
>Get value from name, insert value "xyz"  into db with the collection
> called name
>Get value for address, insert value "123..." into mongodb with the
> collection called
>
> from (activemq:queue name)
> .to (mongodb:insert ($.name[0])&collection"name")
>
> How do I create different routes/queues via jsonpath expression to make it
> happen? assuming we will always have the same name:value pair and therefore
> the same collections.
>
> Gordon
>
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/question-about-using-splitter-and-jsonpath-expression-tp5759384.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-
Red Hat, Inc.
Email: cib...@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/


question about using splitter(?) and jsonpath expression

2014-11-20 Thread gmh
All,
I am trying to come up with a processing pattern for a business case.
Assume we have something like this form a queue (ActiveMQ/Rabbbitmq) does
not matter 
Below is the json
{
   "name":"xyz"
   "address": "123 Somewhere, USA"
   "ssn": "1234"
}
For each name/value pair I want to make a call to the database with the
value that is provided.
so essentially it will be something like this: 
   Get value from name, insert value "xyz"  into db with the collection
called name
   Get value for address, insert value "123..." into mongodb with the
collection called 

from (activemq:queue name)
.to (mongodb:insert ($.name[0])&collection"name")

How do I create different routes/queues via jsonpath expression to make it
happen? assuming we will always have the same name:value pair and therefore
the same collections.

Gordon




--
View this message in context: 
http://camel.465427.n5.nabble.com/question-about-using-splitter-and-jsonpath-expression-tp5759384.html
Sent from the Camel - Users mailing list archive at Nabble.com.