You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by cloud <cl...@domolo.com> on 2015/06/09 11:11:01 UTC

Is there a tools to convert java dsl to xml ?

hi team,

Is there a tools to convert java dsl to xml ?   
Is every java dsl code  have a equal xml counterpart?

When I am reading the camel document's , there are many snippets code that
writen by java dsl .

As a new user , sometimes I have to use xml instead of java dsl  .

In fact , I want to know how could I convert the below code to xml 

from("direct:start")
  .setHeader("decisionSlip").method(OrderProcessorBean.class,
"calculateRoute")
  .routingSlip("decisionSlip");


thanks.





--
View this message in context: http://camel.465427.n5.nabble.com/Is-there-a-tools-to-convert-java-dsl-to-xml-tp5768015.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Is there a tools to convert java dsl to xml ?

Posted by Tim Dudgeon <td...@gmail.com>.
I was playing with just this a few weeks ago. Here's an example of what 
I got working.
The one gotcha I encountered was that you can't use beans inline in the 
Java DSL. Instead you need to put the bean in the registry and reference 
it from there. Other than that it seems to work "as expected".

Tim

/**
  * Example of how to add a new route to a running Camel context.
  * The route is set as XML. The tricky bit is that any beans used in 
the route
  * need to be set to the registry before setting the route.
*/

package foo

import org.apache.camel.model.language.XQueryExpression
import org.apache.camel.model.language.GroovyExpression
import org.apache.camel.model.*
import org.apache.camel.*
import org.apache.camel.builder.RouteBuilder
import org.apache.camel.impl.DefaultCamelContext
import org.apache.camel.impl.SimpleRegistry

// define route 1 as XML
String xml1 = '''<?xml version="1.0"?>
<routes xmlns="http://camel.apache.org/schema/spring">\n\
     <route id="bar">
         <from uri="timer://foo?fixedRate=true&amp;period=500"/>
         <process ref="simpleProcessor1"/>
         <log message="Hello from XML!"/>
     </route>
</routes>'''

// generate route 2 and convert to XML
RoutesDefinition routes = new RoutesDefinition()
RouteDefinition route = routes.route()
route.from("timer://foo?fixedRate=true&period=200")
route.log("Hello from Java!")
route.processRef("simpleProcessor2") // the reference to the bean in the 
registry

String xml2 = ModelHelper.dumpModelAsXml(null, routes)
println xml2

// create and start context
long t0 = System.currentTimeMillis();
SimpleRegistry registry = new SimpleRegistry()
CamelContext camelContext = new DefaultCamelContext(registry)
camelContext.start()
long t1 = System.currentTimeMillis();
System.out.println("Camel Context creation took " + (t1 - t0));

// add beans to the registry
registry.put("simpleProcessor1", new SimpleProcessor("simpleProcessor1"))
registry.put("simpleProcessor2", new SimpleProcessor("simpleProcessor2"))
// set route to context
RoutesDefinition routes1 = camelContext.loadRoutesDefinition(new 
ByteArrayInputStream(xml1.bytes))
camelContext.addRouteDefinitions(routes1.getRoutes())
long t3 = System.currentTimeMillis();
RoutesDefinition routes2 = camelContext.loadRoutesDefinition(new 
ByteArrayInputStream(xml2.bytes))
camelContext.addRouteDefinitions(routes2.getRoutes())
long t4 = System.currentTimeMillis();
System.out.println("New route creation took " + (t4 - t3));

// shutdown
sleep(5000)
camelContext.stop()


On 09/06/2015 16:32, Claus Ibsen wrote:
> Hi
>
> At runtime you can output any Camel route as xml, there is api on
> camel context or jmx api to do so.
>
> This is what tooling such as the camel commands / hawtio etc uses to
> visualize the running routes.
>
> On Tue, Jun 9, 2015 at 11:11 AM, cloud <cl...@domolo.com> wrote:
>> hi team,
>>
>> Is there a tools to convert java dsl to xml ?
>> Is every java dsl code  have a equal xml counterpart?
>>
>> When I am reading the camel document's , there are many snippets code that
>> writen by java dsl .
>>
>> As a new user , sometimes I have to use xml instead of java dsl  .
>>
>> In fact , I want to know how could I convert the below code to xml
>>
>> from("direct:start")
>>    .setHeader("decisionSlip").method(OrderProcessorBean.class,
>> "calculateRoute")
>>    .routingSlip("decisionSlip");
>>
>>
>> thanks.
>>
>>
>>
>>
>>
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/Is-there-a-tools-to-convert-java-dsl-to-xml-tp5768015.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>


Re: Is there a tools to convert java dsl to xml ?

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

At runtime you can output any Camel route as xml, there is api on
camel context or jmx api to do so.

This is what tooling such as the camel commands / hawtio etc uses to
visualize the running routes.

On Tue, Jun 9, 2015 at 11:11 AM, cloud <cl...@domolo.com> wrote:
> hi team,
>
> Is there a tools to convert java dsl to xml ?
> Is every java dsl code  have a equal xml counterpart?
>
> When I am reading the camel document's , there are many snippets code that
> writen by java dsl .
>
> As a new user , sometimes I have to use xml instead of java dsl  .
>
> In fact , I want to know how could I convert the below code to xml
>
> from("direct:start")
>   .setHeader("decisionSlip").method(OrderProcessorBean.class,
> "calculateRoute")
>   .routingSlip("decisionSlip");
>
>
> thanks.
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Is-there-a-tools-to-convert-java-dsl-to-xml-tp5768015.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@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/

Re: Is there a tools to convert java dsl to xml ?

Posted by cloud <cl...@domolo.com>.
thanks for all !

jkorab , I will read you book , and follow you on Twitter . 


thanks .






--
View this message in context: http://camel.465427.n5.nabble.com/Is-there-a-tools-to-convert-java-dsl-to-xml-tp5768015p5768088.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Is there a tools to convert java dsl to xml ?

Posted by Wilson MacGyver <wm...@gmail.com>.
I'm the opposite. I avoid XML, and use Java DSL exclusively. I really like
the way it reads, and easy to test using camel test
On Tue, Jun 9, 2015 at 10:48 AM Dan Moore <dm...@katasi.com> wrote:

> I also am a new user and tend to like XML.  Maybe that will change as I get
> used to Camel.
>
> I don't know of any automated way, but you can get edit access to camel and
> make the changes yourself:
> http://camel.apache.org/how-do-i-edit-the-website.html
>
> Dan
>
> On Tue, Jun 9, 2015 at 3:11 AM, cloud <cl...@domolo.com> wrote:
>
> > hi team,
> >
> > Is there a tools to convert java dsl to xml ?
> > Is every java dsl code  have a equal xml counterpart?
> >
> > When I am reading the camel document's , there are many snippets code
> that
> > writen by java dsl .
> >
> > As a new user , sometimes I have to use xml instead of java dsl  .
> >
> > In fact , I want to know how could I convert the below code to xml
> >
> > from("direct:start")
> >   .setHeader("decisionSlip").method(OrderProcessorBean.class,
> > "calculateRoute")
> >   .routingSlip("decisionSlip");
> >
> >
> > thanks.
> >
> >
> >
> >
> >
> > --
> > View this message in context:
> >
> http://camel.465427.n5.nabble.com/Is-there-a-tools-to-convert-java-dsl-to-xml-tp5768015.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> >
>

Re: Is there a tools to convert java dsl to xml ?

Posted by Dan Moore <dm...@katasi.com>.
I also am a new user and tend to like XML.  Maybe that will change as I get
used to Camel.

I don't know of any automated way, but you can get edit access to camel and
make the changes yourself:
http://camel.apache.org/how-do-i-edit-the-website.html

Dan

On Tue, Jun 9, 2015 at 3:11 AM, cloud <cl...@domolo.com> wrote:

> hi team,
>
> Is there a tools to convert java dsl to xml ?
> Is every java dsl code  have a equal xml counterpart?
>
> When I am reading the camel document's , there are many snippets code that
> writen by java dsl .
>
> As a new user , sometimes I have to use xml instead of java dsl  .
>
> In fact , I want to know how could I convert the below code to xml
>
> from("direct:start")
>   .setHeader("decisionSlip").method(OrderProcessorBean.class,
> "calculateRoute")
>   .routingSlip("decisionSlip");
>
>
> thanks.
>
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Is-there-a-tools-to-convert-java-dsl-to-xml-tp5768015.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Is there a tools to convert java dsl to xml ?

Posted by jkorab <ja...@gmail.com>.
I should also say that there is a runtime tool that allows you to see the XML
of running routes - HawtIO (http://hawt.io).

Jakub



--
View this message in context: http://camel.465427.n5.nabble.com/Is-there-a-tools-to-convert-java-dsl-to-xml-tp5768015p5768024.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Is there a tools to convert java dsl to xml ?

Posted by jkorab <ja...@gmail.com>.
Hi,


cloud wrote
> Is there a tools to convert java dsl to xml ?   

No, although you can see an XML representation of a route defined in any DSL
(Java, XML, Groovy, Scala etc.) by calling a method called dumpRouteAsXml()
when looking at it though JMX. 


cloud wrote
> Is every java dsl code  have a equal xml counterpart?
> 
> When I am reading the camel document's , there are many snippets code that
> writen by java dsl .
> 
> As a new user , sometimes I have to use xml instead of java dsl  .

Yes it does. A good reference (shameless self-promotion) is the Apache Camel
Developer's Cookbook - it contains examples of every DSL element in both the
Java and XML DSLs.


cloud wrote
> In fact , I want to know how could I convert the below code to xml 
> 
> from("direct:start")
>   .setHeader("decisionSlip").method(OrderProcessorBean.class,
> "calculateRoute")
>   .routingSlip("decisionSlip");

<from uri="direct:start">
<setHeader name="decisionSlip">
  <method ref="myOrderProcessorBean" method="calculateRoute"/>
</setHeader>
<routingSlip>
  <header>decisionSlip</header>
</routingSlip>

Hope that helps.

Jakub




--
View this message in context: http://camel.465427.n5.nabble.com/Is-there-a-tools-to-convert-java-dsl-to-xml-tp5768015p5768023.html
Sent from the Camel - Users mailing list archive at Nabble.com.