You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by H2SO4 <da...@web.de> on 2015/03/11 12:54:19 UTC

beginner: download json > transform to xml > send to ftp

Hello,

I already have some experience wit jave but I'm new to camel.

So at the moment I have some problems with the starting. I think I
understand the basics of camel (I'm reading "Camel in action") but still not
sure how to start. Hopefully someone can help me. 

What I want to do.

I want to download a json from a REST endpoint
after this I need to transform it into an xml file while I also add some
static fields to it.
After this I need to send this xml file to an ftp server

So lets say I want to download a json from
www.mypage.com/stuff/my-stuff with a GET

The json looks like the following

{
   id:1
   name: Hello World
}

I want to transform this in the following xml structure

<message>
  <id>1</id>
  <name>Hello World</name>
  <staticfield>1.2.3</staticfield>
</message


after this I want to send it to the ftp server
www.myftpServer.com/suppage?username=admin&password=secret with PUT

As far as I understood it should be something like

from("rest:get:www.mypage.com/stuff/my-stuff)
to("ftp:www.myftpServer.com/suppage?username=admin&password=secret")
.process(new MyTransformationBean())
;

The Spring MyTransformationBean needs a public method like

public ?? map(MyObjectFromJson input){
  // TODO Here happens one miracle
}

Is this so at least from a 10.000 feet view ok?



--
View this message in context: http://camel.465427.n5.nabble.com/beginner-download-json-transform-to-xml-send-to-ftp-tp5764007.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: beginner: download json > transform to xml > send to ftp

Posted by richardgroote <ri...@gmail.com>.
Hello,

I'am using Spring configuration to configure the camel. Below is a example
of the things you described may be it's usefull

<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://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
         http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd ">


	<bean id="xml2json"
class="org.apache.camel.dataformat.xmljson.XmlJsonDataFormat">
		<property name="typeHints" value="YES"/>
		<property name="expandableProperties" value="objects"/>
		<property name="forceTopLevelObject" value="true"/>
		<property name="trimSpaces" value="true"/>
		<property name="rootName" value="request"/>
		<property name="skipNamespaces" value="true"/>
		<property name="removeNamespacePrefixes" value="true"/>
	</bean>

<camel:camelContext id="biStandardCamelContext" trace="true"
xmlns="http://camel.apache.org/schema/spring">

	    <camel:route>
	    	<camel:from uri="direct:RetrieveJSONAndSendToFTP"/>
	    		
	    	<camel:to uri="http://www.mypage.com/stuff/my-stuff"/>
	    	
	    		
	    	<camel:unmarshal ref="xml2json"/>
	    	
	    	
	    	<camel:to uri="xslt:file:///some.xslt" />
	    	
	    	
	    	<camel:to
uri="ftp:www.myftpServer.com/suppage?username=admin&password=secret"/>
	    </camel:route>

</camel:camelContext>       
</beans>






--
View this message in context: http://camel.465427.n5.nabble.com/beginner-download-json-transform-to-xml-send-to-ftp-tp5764007p5764078.html
Sent from the Camel - Users mailing list archive at Nabble.com.