Hi All, I have come across an issue in Camel's mongo component. Problem is if you try some operation through camel mongo and give incorrect json (i.e. wrong format extra comma or something) it throws NoTypeConversionAvailableException or so. If you try again but with correct json, exception will be raised again. I think somewhere a cache sort is maintained for failures and is maybe being used for subsequent bodies in exchange wrongly. Below is test case and logs corresponding to it.
@Test public void test() throws UnknownHostException { String json = "{\"name\":\"Ron\"}"; try { template.sendBody("direct:mongo", "{\"name\":\"Ron\",\"helloz\"}"); } catch (Exception e) { e.printStackTrace(); } try { template.sendBody("direct:mongo", json); } catch (Exception e) { e.printStackTrace(); } MongoClient mongoclient = new MongoClient(new ServerAddress("localhost",27017)); DB db = mongoclient.getDB("test"); DBCollection test = db.getCollection("test"); assertNotNull(test.find(BasicDBObjectBuilder.start("name","Ron").get()).next()); } *LOGS: * [2014-01-16 17:55:01,657] com.examples.camel.mongo.CamelMongoTester INFO - ******************************************************************************** [2014-01-16 17:55:01,658] com.examples.camel.mongo.CamelMongoTester INFO - Testing: test(com.examples.camel.mongo.CamelMongoTester) [2014-01-16 17:55:01,658] com.examples.camel.mongo.CamelMongoTester INFO - ******************************************************************************* [2014-01-16 17:55:01,833] org.apache.camel.component.mongodb.MongoDbEndpoint INFO - Initialising MongoDb endpoint: Endpoint[mongodb://myDb?collection=test&database=test&operation=insert] [2014-01-16 17:55:01,833] org.apache.camel.spring.SpringCamelContext INFO - Route: route2 started and consuming from: Endpoint[direct://mongo] [2014-01-16 17:55:01,834] org.apache.camel.spring.SpringCamelContext INFO - Total 1 routes, of which 1 is started. [2014-01-16 17:55:01,834] org.apache.camel.spring.SpringCamelContext INFO - Apache Camel 2.12.1 (CamelContext: camelContext) started in 0.012 seconds [2014-01-16 17:55:01,835] route2 INFO - Body : {"name":"Anand","helloz"} [2014-01-16 17:55:01,835] org.apache.camel.component.mongodb.converters.MongoDbBasicConverters WARN - String -> DBObject conversion selected, but the following exception occurred. Returning null. com.mongodb.util.JSONParseException: {"name":"Anand","helloz"} ^ at com.mongodb.util.JSONParser.read(JSON.java:272) at com.mongodb.util.JSONParser.parseObject(JSON.java:230) at com.mongodb.util.JSONParser.parse(JSON.java:195) at com.mongodb.util.JSONParser.parse(JSON.java:145) at com.mongodb.util.JSON.parse(JSON.java:81) at com.mongodb.util.JSON.parse(JSON.java:66) at org.apache.camel.component.mongodb.converters.MongoDbBasicConverters.fromStringToDBObject(MongoDbBasicConverters.java:65) at com.examples.camel.mongo.CamelMongoTester.test(CamelMongoTester.java:24 [2014-01-16 17:55:01,992] org.apache.camel.component.mongodb.converters.MongoDbBasicConverters WARN - Conversion has fallen back to generic Object -> DBObject, but unable to convert type org.apache.camel.impl.DefaultMessage. Returning null. [2014-01-16 17:55:01,994] org.apache.camel.processor.DefaultErrorHandler ERROR - Failed delivery for (MessageId: ID-TME-A-A-1200096-55103-1389891301125-1-1 on ExchangeId: ID-TME-A-A-1200096-55103-1389891301125-1-2). Exhausted after delivery attempt: 1 caught: org.apache.camel.component.mongodb.CamelMongoDbException: MongoDB operation = insert, Body is not conversible to type DBObject nor List<DBObject> Message History --------------------------------------------------------------------------------------------------------------------------------------- RouteId ProcessorId Processor Elapsed (ms) [route2 ] [route2 ] [direct://mongo ] [ 158] [route2 ] [log2 ] [log ] [ 0] [route2 ] [to2 ] [mongodb:myDb?database=test&collection=test&operation=insert ] [ 158] Exchange --------------------------------------------------------------------------------------------------------------------------------------- Exchange[ Id ID-TME-A-A-1200096-55103-1389891301125-1-2 ExchangePattern InOnly Headers {breadcrumbId=ID-TME-A-A-1200096-55103-1389891301125-1-1, CamelRedelivered=false, CamelRedeliveryCounter=0} BodyType String Body {"name":"Anand","helloz"} ] Stacktrace --------------------------------------------------------------------------------------------------------------------------------------- org.apache.camel.component.mongodb.CamelMongoDbException: MongoDB operation = insert, Body is not conversible to type DBObject nor List<DBObject> at org.apache.camel.component.mongodb.MongoDbProducer.doInsert(MongoDbProducer.java:261) at org.apache.camel.component.mongodb.MongoDbProducer.invokeOperation(MongoDbProducer.java:106) at org.apache.camel.component.mongodb.MongoDbProducer.process(MongoDbProducer.java:72) at [2014-01-16 17:55:02,015] route2 INFO - Body : {"name":"Ron"} org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[Message: {"name":"Anand","helloz"}] at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1360) at org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:622) at Caused by: org.apache.camel.component.mongodb.CamelMongoDbException: MongoDB operation = insert, Body is not conversible to type DBObject nor List<DBObject> at org.apache.camel.component.mongodb.MongoDbProducer.doInsert(MongoDbProducer.java:261) at org.apache.camel.component.mongodb.MongoDbProducer.invokeOperation(MongoDbProducer.java:106) at org.apache.camel.component.mongodb.MongoDbProducer.process(MongoDbProducer.java:72) [2014-01-16 17:55:02,077] org.apache.camel.component.mongodb.converters.MongoDbBasicConverters WARN - Conversion has fallen back to generic Object -> DBObject, but unable to convert type org.apache.camel.impl.DefaultMessage. Returning null. [2014-01-16 17:55:02,078] org.apache.camel.processor.DefaultErrorHandler ERROR - Failed delivery for (MessageId: ID-TME-A-A-1200096-55103-1389891301125-1-3 on ExchangeId: ID-TME-A-A-1200096-55103-1389891301125-1-4). Exhausted after delivery attempt: 1 caught: org.apache.camel.component.mongodb.CamelMongoDbException: MongoDB operation = insert, Body is not conversible to type DBObject nor List<DBObject> Message History --------------------------------------------------------------------------------------------------------------------------------------- RouteId ProcessorId Processor Elapsed (ms) [route2 ] [route2 ] [direct://mongo ] [ 64] [route2 ] [log2 ] [log ] [ 0] [route2 ] [to2 ] [mongodb:myDb?database=test&collection=test&operation=insert ] [ 63] Exchange --------------------------------------------------------------------------------------------------------------------------------------- Exchange[ Id ID-TME-A-A-1200096-55103-1389891301125-1-4 ExchangePattern InOnly Headers {breadcrumbId=ID-TME-A-A-1200096-55103-1389891301125-1-3, CamelRedelivered=false, CamelRedeliveryCounter=0} BodyType String Body {"name":"Ron"} ] Stacktrace --------------------------------------------------------------------------------------------------------------------------------------- org.apache.camel.component.mongodb.CamelMongoDbException: MongoDB operation = insert, Body is not conversible to type DBObject nor List<DBObject> at org.apache.camel.component.mongodb.MongoDbProducer.doInsert(MongoDbProducer.java:261) at org.apache.camel.component.mongodb.MongoDbProducer.invokeOperation(MongoDbProducer.java:106) at org.apache.camel.component.mongodb.MongoDbProducer.process(MongoDbProducer.java:72) at org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[Message: {"name":"Ron"}] at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1360) at org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:622) Caused by: org.apache.camel.component.mongodb.CamelMongoDbException: MongoDB operation = insert, Body is not conversible to type DBObject nor List<DBObject> at org.apache.camel.component.mongodb.MongoDbProducer.doInsert(MongoDbProducer.java:261) at org.apache.camel.component.mongodb.MongoDbProducer.invokeOperation(MongoDbProducer.java:106) at org.apache.camel.component.mongodb.MongoDbProducer.process(MongoDbProducer.java:72) [2014-01-16 17:55:02,141] com.examples.camel.mongo.CamelMongoTester INFO - ******************************************************************************* java.util.NoSuchElementException: no more at com.mongodb.DBApiLayer$Result.next(DBApiLayer.java:384) at com.mongodb.DBApiLayer$Result.next(DBApiLayer.java:346) at com.mongodb.DBCursor._next(DBCursor.java:421) Camel version is 2.12.1 and mongodb is 2.4. Please tell me if there is something wrong in my implementation because this is causing problems in my web application. I cannot afford to restart the server again and again if someone tries with some bad input :) -- View this message in context: http://camel.465427.n5.nabble.com/Camel-MongoDB-Bug-related-to-Type-Conversion-tp5746090.html Sent from the Camel - Users mailing list archive at Nabble.com.