Re: Camel route set map object in body
.setBody(new SimpleExpression(bodyMap.toString())) .convertBodyTo(Map.class) Aren't you converting the object twice? First to a String and then telling it to convert the String to a Map (which it doesn't know how to handle)? bodyMap.toString(). Assuming it does that correctly you are now passing it to a converter and telling it to convert the string to a map. Perhaps put some .log("${body}") in between them and see what you are getting there. On Sat, Apr 9, 2016 at 9:33 PM, VinothKR wrote: > Hi, > I'm accessing a route through both producertemplate and a QuartzScheduler. > > *Route:* > > > > select * from table where empId=${in.body.EmpId} > > > > > > *I'm able to successfully pass employee id using producer template like > below,* > > Map bodyMap = new HashMap(); > bodyMap.put("EmpId", "23456"); > Object out = ProducerTemplate.requestBody("direct:hivein",bodyMap); > > But unable to achieve the same using quartzScheduler route, > camel.addRoutes( new RouteBuilder() { > @Override > public void configure() throws Exception { > > from("quartz2://sampleGroup/sampleTimer?trigger.repeatCount=1") > .routeId("scheduler").noAutoStartup() > .setBody(new > SimpleExpression(bodyMap.toString())) > .convertBodyTo(Map.class) > .to("direct:hivein"); > } > }); > > Facing the issue, > Caused by: org.apache.camel.NoTypeConversionAvailableException: No type > converter available to convert from type: java.lang.String to the required > type: java.util.Map > > Is there any other way to achieve similar logic as ProducerTemplate in > QuartzScheduler? > > Thanks, > Vinoth. > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/Camel-route-set-map-object-in-body-tp5780863.html > Sent from the Camel - Users mailing list archive at Nabble.com. >
Re: Camel route set map object in body
By the way, when the quartz timer fires what are you expecting that data to be in the bodyMap? Is that just an instance variable at that point? Perhaps if you posted the complete code it would make that a bit clearer. >From what I can see of your route snippet I'd expect some quartz timer event to be received. Again, putting a .log() statement in there would let you see what you are getting. If you look at an example of Quartz in action from the Camel web page you can see. from("file:inbox?scheduler=quartz2&scheduler.cron=0/2+*+*+*+*+?") .to("bean:process"); You can see that it is using the timer to fire a read from a file. In your case you appear to be firing the timer and sending a timer event into your route. It's been a while since I've used Quartz so take that observation with a grain of salt but I'd definitely put a log statement in to see what you are getting there. Brad On Sat, Apr 9, 2016 at 10:47 PM, Brad Johnson wrote: > .setBody(new SimpleExpression(bodyMap.toString())) > .convertBodyTo(Map.class) > > Aren't you converting the object twice? First to a String and then > telling it to convert the String to a Map (which it doesn't know how to > handle)? > > bodyMap.toString(). Assuming it does that correctly you are now passing > it to a converter and telling it to convert the string to a map. Perhaps > put some .log("${body}") in between them and see what you are getting there. > > On Sat, Apr 9, 2016 at 9:33 PM, VinothKR wrote: > >> Hi, >> I'm accessing a route through both producertemplate and a QuartzScheduler. >> >> *Route:* >> >> >> >> select * from table where empId=${in.body.EmpId} >> >> >> >> >> >> *I'm able to successfully pass employee id using producer template like >> below,* >> >> Map bodyMap = new HashMap(); >> bodyMap.put("EmpId", "23456"); >> Object out = ProducerTemplate.requestBody("direct:hivein",bodyMap); >> >> But unable to achieve the same using quartzScheduler route, >> camel.addRoutes( new RouteBuilder() { >> @Override >> public void configure() throws Exception { >> >> from("quartz2://sampleGroup/sampleTimer?trigger.repeatCount=1") >> .routeId("scheduler").noAutoStartup() >> .setBody(new >> SimpleExpression(bodyMap.toString())) >> .convertBodyTo(Map.class) >> .to("direct:hivein"); >> } >> }); >> >> Facing the issue, >> Caused by: org.apache.camel.NoTypeConversionAvailableException: No type >> converter available to convert from type: java.lang.String to the required >> type: java.util.Map >> >> Is there any other way to achieve similar logic as ProducerTemplate in >> QuartzScheduler? >> >> Thanks, >> Vinoth. >> >> >> >> -- >> View this message in context: >> http://camel.465427.n5.nabble.com/Camel-route-set-map-object-in-body-tp5780863.html >> Sent from the Camel - Users mailing list archive at Nabble.com. >> > >
Re: Camel route set map object in body
Hi Ranx, Thanks for the response. I will not be able to pass any object type other string to setBody or simpleExpression methods. I just want to pass a dynamic value to the route. The message i'm getting is, Message History --- RouteId ProcessorId Processor Elapsed (ms) [scheduler ] [scheduler ] [quartz2://sampleGroup/sampleTimer?trigger.repeatCount=1 ] [31] [scheduler ] [setBody2 ] [setBody[simple{{ObligorId=23456}}] ] [ 0] [scheduler ] [convertBodyTo1] [convertBodyTo[java.util.Map] ] [16] Exchange --- Exchange[ Id ID-PHX2MYMV32-65463-1460269525386-0-3 ExchangePattern InOnly Headers {breadcrumbId=ID-PHX2MYMV32-65463-1460269525386-0-2, calendar=null, CamelRedelivered=false, CamelRedeliveryCounter=0, fireTime=Sat Apr 09 23:25:31 MST 2016, jobDetail=JobDetail 'sampleGroup.sampleTimer': jobClass: 'org.apache.camel.component.quartz2.CamelJob concurrentExectionDisallowed: false persistJobDataAfterExecution: false isDurable: false requestsRecovers: false, jobInstance=org.apache.camel.component.quartz2.CamelJob@3cd6fd7f, jobRunTime=-1, mergedJobDataMap=org.quartz.JobDataMap@ec12eb0, nextFireTime=null, previousFireTime=Sat Apr 09 23:25:26 MST 2016, refireCount=0, result=null, scheduledFireTime=Sat Apr 09 23:25:27 MST 2016, scheduler=org.quartz.impl.StdScheduler@45106922, trigger=Trigger 'sampleGroup.sampleTimer': triggerClass: 'org.quartz.impl.triggers.SimpleTriggerImpl calendar: 'null' misfireInstruction: 1 nextFireTime: null, triggerGroup=sampleGroup, triggerName=sampleTimer} BodyTypeString Body{ObligorId=23456} ] The use case i'm trying to achieve is from a jsp page i will be sending a employee id and for the employee id i will trigger a quartz scheduled job to fetch employee record from table every specified time. The cron expression and the employee id will be from the jsp page. So i want to set them in body and access it in route. The concern is not about the quartz scheduler but passing a map object through the body to the route. Thanks, Vinoth. -- View this message in context: http://camel.465427.n5.nabble.com/Camel-route-set-map-object-in-body-tp5780863p5780868.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel route set map object in body
I gathered you wanted to send a map of data and not the quartz data. What wasn't clear from your code snippet is where the bodyMap was coming from. I'm not sure why you are calling toString on the bodyMap in your SimpleExpression and then calling convertToMap after it. Isn't it already the map you want to use? // You are converting your bodyMap to a string [setBody[simple{{ObligorId=23456}}] //Why are you converting the string to a map now? [scheduler ] [convertBodyTo1] [convertBodyTo[java.util.Map] Here's an easy way to get a grip on what is happening with data types and data transformation in a route. Create a method on the class that takes Object and that simply return the same thing they received and then print what they receive along with the class name of the object. public Object invoke(Object toDisplay) { System.out.println(toDispaly.getClass().getName()); //Print anything else you might want to see. return toDisplay; } I'm more used to doing this in Blueprint so can't recall the exact Java DSL syntax but it would be something like: from("quartz2://sampleGroup/sampleTimer?trigger.repeatCount=1") .routeId("scheduler").noAutoStartup().beanRef(this, "invoke") .setBody(new SimpleExpression(bodyMap.toString())).beanRef(this, "invoke") That will then shown you the body class type before and after the setBody call. It would also let you access any data. It could be used as a poor man's converter as well. In fact, you should be able to do what you want with the same sort of structure. If you just want to invoke your ProducerTemplate you can do that as well. It all depends on your objectives. Map bodyMap = new HashMap(); bodyMap.put("EmpId", "23456"); Object out = ProducerTemplate.requestBody("direct:hivein",bodyMap); But unable to achieve the same using quartzScheduler route, camel.addRoutes( new RouteBuilder() { @Override public void configure() throws Exception { from("quartz2://sampleGroup/sampleTimer?trigger.repeatCount=1") .routeId("scheduler").noAutoStartup().beanRef(this, "invokeRoute"); } }); public Object invokeRoute(Ojbect o) { //What do you get for "o" here. If you are just taking the bodyMap instance variable from the object object then you could just us that. Object out = ProducerTemplate.requestBody("direct:hivein",bodyMap); return out; } On Sun, Apr 10, 2016 at 1:32 AM, VinothKR wrote: > Hi Ranx, > Thanks for the response. > I will not be able to pass any object type other string to setBody or > simpleExpression methods. I just want to pass a dynamic value to the route. > The message i'm getting is, > Message History > > --- > RouteId ProcessorId Processor > Elapsed (ms) > [scheduler ] [scheduler ] > [quartz2://sampleGroup/sampleTimer?trigger.repeatCount=1 > ] [31] > [scheduler ] [setBody2 ] > [setBody[simple{{ObligorId=23456}}] > ] [ 0] > [scheduler ] [convertBodyTo1] [convertBodyTo[java.util.Map] > ] [16] > > Exchange > > --- > Exchange[ > Id ID-PHX2MYMV32-65463-1460269525386-0-3 > ExchangePattern InOnly > Headers > {breadcrumbId=ID-PHX2MYMV32-65463-1460269525386-0-2, > calendar=null, CamelRedelivered=false, CamelRedeliveryCounter=0, > fireTime=Sat Apr 09 23:25:31 MST 2016, jobDetail=JobDetail > 'sampleGroup.sampleTimer': jobClass: > 'org.apache.camel.component.quartz2.CamelJob concurrentExectionDisallowed: > false persistJobDataAfterExecution: false isDurable: false > requestsRecovers: > false, jobInstance=org.apache.camel.component.quartz2.CamelJob@3cd6fd7f, > jobRunTime=-1, mergedJobDataMap=org.quartz.JobDataMap@ec12eb0, > nextFireTime=null, previousFireTime=Sat Apr 09 23:25:26 MST 2016, > refireCount=0, result=null, scheduledFireTime=Sat Apr 09 23:25:27 MST 2016, > scheduler=org.quartz.impl.StdScheduler@45106922, trigger=Trigger > 'sampleGroup.sampleTimer': triggerClass: > 'org.quartz.impl.triggers.SimpleTriggerImpl calendar: 'null' > misfireInstruction: 1 nextFireTime: null, triggerGroup=sampleGroup, > triggerName=sampleTimer} > BodyTypeString > Body{ObligorId=23456} > ] > > > > > > The use case i'm trying to achieve is from a jsp page i will be sending a > employee id and for the employee id i will trigger a quartz scheduled job > to > fetch employee record from table every specified time. The cron expression > and the employee id will be from the jsp page. So i want to se
Re: Camel route set map object in body
Hi Ranx, Thanks. I was able to send a Map object to the body using bean. Converter class: public Map myConverter(String toDisplay) { logger.debug("Invoking my converter for type "+toDisplay.getClass().getName()+" toDisplay "+toDisplay); Gson gson = new Gson(); Type mapType = new TypeToken>(){}.getType(); Map requiredData = gson.fromJson(toDisplay, mapType); logger.debug("Output from converter: "+requiredData); return requiredData; } PropertiesMap: final Map propertiesMap = new HashMap(); propertiesMap.put("EmpId", "23456"); Route: from("quartz2://sampleGroup/sampleTimer?trigger.repeatCount=1") .routeId("scheduler").noAutoStartup() .setBody(new SimpleExpression(propertiesMap.toString())) .bean(new QuartzStandaloneTest(), "myConverter") .to("direct:hivein"); Thanks, Vinoth. -- View this message in context: http://camel.465427.n5.nabble.com/Camel-route-set-map-object-in-body-tp5780863p5780880.html Sent from the Camel - Users mailing list archive at Nabble.com.