You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by eholsinger <er...@metronaviation.com> on 2013/11/14 14:51:55 UTC

xmljson convert XML from file to JSON straight into MongoDB issue

Hi,

Found this link on the web and thought I'd try it, seems straightforward
enough, but I haven't gotten it to work yet: 
http://www.andreagirardi.it/blog/route-a-message-to-mongodb/


What i include in this post is:
-my full camel-context.xml
-the XML directly from the file i'm trying to push into mongo with the route
described
-the JSON from a xmljson file > file route that does work

Any insight would be appreciated.

Thx, Eric



*My camel-context.xml file:*
<?xml version="1.0" encoding="UTF-8"?>


<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
       http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">


  <camel:camelContext id="camelContext"
xmlns="http://camel.apache.org/schema/spring">
  
  	
  	<dataFormats>
		<xmljson id="xmljsonWithOptions" forceTopLevelObject="true"
skipWhitespace="true" trimSpaces="true" skipNamespaces="true"
        	removeNamespacePrefixes="true"/>  
	</dataFormats> 

        
        <route>
  	  <from uri="file:/C:/____temp/xmlfiles?noop=true"/>
    	  <marshal ref="xmljsonWithOptions"/>   	
    	  <to
uri="file:/C:/____temp/jsonfiles?fileName=${file:name.noext}_${date:now:MMddyyyy_HHmmss}.json"
/> 
	</route> 
	
	
        
 	<route> 
  	  <from uri="file:/C:/____temp/xmlfiles?noop=true"/>
    	  <marshal ref="xmljsonWithOptions"/>		
	  <convertBodyTo type="java.lang.String"/> 				
	   <to
uri="mongodb:myDb?database=test&amp;collection=aixm&amp;operation=save" />
	</route>      
    
  </camel:camelContext>

  	
	<bean id="myDb" class="com.mongodb.Mongo">
		<constructor-arg index="0" value="localhost"/>
	</bean>


</beans>


*The XML from the file:*
<root><aps><alert>this is a test
message</alert></aps><key3>value3</key3><key2>value2</key2><key1>value1</key1></root>

*The JSON from the file > file route that does work:*
{"root":{"aps":["this is a
testmessage"],"key3":"value3","key2":"value2","key1":"value1"}}




--
View this message in context: http://camel.465427.n5.nabble.com/xmljson-convert-XML-from-file-to-JSON-straight-into-MongoDB-issue-tp5743285.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: xmljson convert XML from file to JSON straight into MongoDB issue

Posted by eholsinger <er...@metronaviation.com>.
Could someone take my setup and try it out - I'd very much appreciate it. 
Love to have some feedback from the Camel devs.  If I can get this working,
this particular EIP in my project is going to save me buku time and
effort...  

I would also like to know if it's possible to inject a class somewhere in
the mongo route adapter so that I can monitor what's going on?

Thanks much,

Eric



--
View this message in context: http://camel.465427.n5.nabble.com/xmljson-convert-XML-from-file-to-JSON-straight-into-MongoDB-issue-tp5743285p5743353.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: xmljson convert XML from file to JSON straight into MongoDB issue

Posted by eholsinger <er...@metronaviation.com>.
Here's the console output from camel as this was run w/maven...i don't see
anything that pops right out.  No exceptions anyway.  And it does pick up
the route and seems to have successfully parsed the data to the endpoint.



[pache.camel.spring.Main.main()] DefaultManagementAgent         DEBUG
Registered
 MBean with ObjectName:
org.apache.camel:context=lt-userpc1/camelContext,type=
threadpools,name="FileConsumer(0x64dcdb5a)"
[pache.camel.spring.Main.main()] DefaultExecutorServiceManager  DEBUG
Created ne
w ScheduledThreadPool for source:
Consumer[file:///C:/____temp/xmlfiles?noop=tru
e] with name: file:///C:/____temp/xmlfiles?noop=true. ->
org.apache.camel.util.c
oncurrent.SizedScheduledExecutorService@627c1f3b[file:///C:/____temp/xmlfiles?no
op=true]
[pache.camel.spring.Main.main()] ScheduledPollConsumerScheduler DEBUG
Scheduling
 poll (fixed delay) with initialDelay: 1000, delay: 500 (milliseconds) for:
Endp
oint[file:///C:/____temp/xmlfiles?noop=true]
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  Route:
rou
te1 started and consuming from:
Endpoint[file:///C:/____temp/xmlfiles?noop=true]

[pache.camel.spring.Main.main()] ultManagementLifecycleStrategy DEBUG Load
perfo
rmance statistics enabled
[pache.camel.spring.Main.main()] DefaultManagementAgent         DEBUG
Registered
 MBean with ObjectName:
org.apache.camel:context=lt-userpc1/camelContext,type=
services,name=TimerListenerManager
[pache.camel.spring.Main.main()] DefaultManagementAgent         DEBUG
Registered
 MBean with ObjectName:
org.apache.camel:context=lt-userpc1/camelContext,type=
threadpools,name="TimerListenerManager"
[pache.camel.spring.Main.main()] DefaultExecutorServiceManager  DEBUG
Created ne
w ScheduledThreadPool for source:
org.apache.camel.support.TimerListenerManager@
22fc32f0 with name: ManagementLoadTask. ->
org.apache.camel.util.concurrent.Size
dScheduledExecutorService@14c4c7d7[ManagementLoadTask]
[pache.camel.spring.Main.main()] TimerListenerManager           DEBUG
Started sc
heduled TimerListener task to run with interval 1000 ms
[pache.camel.spring.Main.main()] DefaultComponent               DEBUG
Creating e
ndpoint uri=[spring-event://default], path=[default]
[pache.camel.spring.Main.main()] SpringCamelContext             DEBUG
spring-eve
nt://default converted to endpoint: Endpoint[spring-event://default] by
componen
t: org.apache.camel.component.event.EventComponent@8f7a71b
[pache.camel.spring.Main.main()] DefaultManagementAgent         DEBUG
Registered
 MBean with ObjectName:
org.apache.camel:context=lt-userpc1/camelContext,type=
endpoints,name="spring-event://default"
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  Total
1 ro
utes, of which 1 is started.
[pache.camel.spring.Main.main()] SpringCamelContext             INFO  Apache
Cam
el 2.12.1 (CamelContext: camelContext) started in 0.546 seconds
[pache.camel.spring.Main.main()] MainSupport                    DEBUG
Starting S
pring ApplicationContext:
org.springframework.context.support.ClassPathXmlApplic
ationContext@106761e6
[pache.camel.spring.Main.main()] SpringCamelContext             DEBUG
onApplicat
ionEvent:
org.springframework.context.event.ContextStartedEvent[source=org.sprin
gframework.context.support.ClassPathXmlApplicationContext@106761e6: startup
date
 [Thu Nov 14 11:36:17 EST 2013]; root of context hierarchy]
[- file:///C:/____temp/xmlfiles] FileEndpoint                   DEBUG
Parameters
 for Generic file process strategy {readLock=markerFile, noop=true,
readLockTime
out=10000, readLockLoggingLevel=WARN, readLockMinLength=1,
readLockCheckInterval
=1000}
[- file:///C:/____temp/xmlfiles] FileEndpoint                   DEBUG Using
Gene
ric file process strategy:
org.apache.camel.component.file.strategy.GenericFileR
enameProcessStrategy@58e28d65
[- file:///C:/____temp/xmlfiles] rFileExclusiveReadLockStrategy DEBUG
Prepare on
 startup by deleting orphaned lock files from: C:\____temp\xmlfiles
[- file:///C:/____temp/xmlfiles] FileConsumer                   DEBUG Took
0.031
 seconds to poll: C:\____temp\xmlfiles
[- file:///C:/____temp/xmlfiles] FileConsumer                   DEBUG Total
1 fi
les to consume
[- file:///C:/____temp/xmlfiles] FileConsumer                   DEBUG About
to p
rocess file: GenericFile[C:\____temp\xmlfiles\message1.xml] using exchange:
Exch
ange[message1.xml]
[- file:///C:/____temp/xmlfiles] GenericFileConverter           DEBUG Read
file
C:\____temp\xmlfiles\message1.xml (no charset)
[- file:///C:/____temp/xmlfiles] XMLSerializer                  INFO  Using
defa
ult type string
[- file:///C:/____temp/xmlfiles] SendProcessor                  DEBUG >>>>
Endpo
int[mongodb://myDb?collection=aixm&database=test&operation=save]
Exchange[Messag
e: {"root":{"aps":["this is a
testmessage"],"key3":"value3","key2":"value2","key
1":"value1"}}]
[- file:///C:/____temp/xmlfiles] GenericFileOnCompletion        DEBUG Done
proce
ssing file: GenericFile[C:\____temp\xmlfiles\message1.xml] using exchange:
Excha
nge[Message: N/A]
[- file:///C:/____temp/xmlfiles] FileUtil                       DEBUG
Retrying a
ttempt 0 to delete file: C:\____temp\xmlfiles\message1.xml.camelLock
[- file:///C:/____temp/xmlfiles] FileUtil                       DEBUG Tried
1 to
 delete file: C:\____temp\xmlfiles\message1.xml.camelLock with result: true
[- file:///C:/____temp/xmlfiles] FileConsumer                   DEBUG Took
0.000
 seconds to poll: C:\____temp\xmlfiles
[- file:///C:/____temp/xmlfiles] FileConsumer                   DEBUG Took
0.000
 seconds to poll: C:\____temp\xmlfiles



--
View this message in context: http://camel.465427.n5.nabble.com/xmljson-convert-XML-from-file-to-JSON-straight-into-MongoDB-issue-tp5743285p5743295.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: xmljson convert XML from file to JSON straight into MongoDB issue

Posted by eholsinger <er...@metronaviation.com>.
I've not seen any exceptions.  I'll try and grab the console output and post
it.



--
View this message in context: http://camel.465427.n5.nabble.com/xmljson-convert-XML-from-file-to-JSON-straight-into-MongoDB-issue-tp5743285p5743293.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: xmljson convert XML from file to JSON straight into MongoDB issue

Posted by Raul Kripalani <ra...@evosent.com>.
Do you see any exceptions?

Regards,

*Raúl Kripalani*
Apache Camel PMC Member & Committer | Enterprise Architect, Open Source
Integration specialist
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk

On Thu, Nov 14, 2013 at 2:51 PM, eholsinger <
eric.holsinger@metronaviation.com> wrote:

> Hi,
>
> Found this link on the web and thought I'd try it, seems straightforward
> enough, but I haven't gotten it to work yet:
> http://www.andreagirardi.it/blog/route-a-message-to-mongodb/
>
>
> What i include in this post is:
> -my full camel-context.xml
> -the XML directly from the file i'm trying to push into mongo with the
> route
> described
> -the JSON from a xmljson file > file route that does work
>
> Any insight would be appreciated.
>
> Thx, Eric
>
>
>
> *My camel-context.xml file:*
> <?xml version="1.0" encoding="UTF-8"?>
>
>
> <beans xmlns="http://www.springframework.org/schema/beans"
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>        xmlns:camel="http://camel.apache.org/schema/spring"
>        xsi:schemaLocation="
>        http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
>        http://camel.apache.org/schema/spring
> http://camel.apache.org/schema/spring/camel-spring.xsd">
>
>
>   <camel:camelContext id="camelContext"
> xmlns="http://camel.apache.org/schema/spring">
>
>
>         <dataFormats>
>                 <xmljson id="xmljsonWithOptions" forceTopLevelObject="true"
> skipWhitespace="true" trimSpaces="true" skipNamespaces="true"
>                 removeNamespacePrefixes="true"/>
>         </dataFormats>
>
>
>         <route>
>           <from uri="file:/C:/____temp/xmlfiles?noop=true"/>
>           <marshal ref="xmljsonWithOptions"/>
>           <to
>
> uri="file:/C:/____temp/jsonfiles?fileName=${file:name.noext}_${date:now:MMddyyyy_HHmmss}.json"
> />
>         </route>
>
>
>
>         <route>
>           <from uri="file:/C:/____temp/xmlfiles?noop=true"/>
>           <marshal ref="xmljsonWithOptions"/>
>           <convertBodyTo type="java.lang.String"/>
>            <to
> uri="mongodb:myDb?database=test&amp;collection=aixm&amp;operation=save" />
>         </route>
>
>   </camel:camelContext>
>
>
>         <bean id="myDb" class="com.mongodb.Mongo">
>                 <constructor-arg index="0" value="localhost"/>
>         </bean>
>
>
> </beans>
>
>
> *The XML from the file:*
> <root><aps><alert>this is a test
>
> message</alert></aps><key3>value3</key3><key2>value2</key2><key1>value1</key1></root>
>
> *The JSON from the file > file route that does work:*
> {"root":{"aps":["this is a
> testmessage"],"key3":"value3","key2":"value2","key1":"value1"}}
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/xmljson-convert-XML-from-file-to-JSON-straight-into-MongoDB-issue-tp5743285.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>