Forum Home » Fuse Distributions » Fuse ESB

Thread: Hello world Java DSL with camel-archetype-java

 
This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 7 - Last Post: Jul 6, 2012 7:12 PM Last Post By: alexcmak
alexcmak

Posts: 7
Registered: 07/05/12
Hello world Java DSL with camel-archetype-java
Posted: Jul 5, 2012 8:48 PM
 
  Click to reply to this thread Reply
Greetings,

I'd like to create a simple Hello World app with Java DSL.

From the Fuse IDE, I choose "camel-archetype-java."

I saw that a sample application is created for me.
A src folder with two xml messages were generated. A sample route is generated:

from("file:src/data?noop=true")
.choice()
.when(xpath("/person/city = 'London'"))
.to("file:target/messages/uk")
.otherwise()
.to("file:target/messages/others");

How do I deploy this application in Fuse ESB?

When I do a "mvn install" I'd get a jar file.

I installed it like so. Is this correct?

FuseESB:karaf@root> osgi:install -s file:c:/work/workspace/myjava/target/myjava-1.0.0-SNAPSHOT.jar
Bundle ID: 294

I see that it is really started in fuseesb.

294 Active [ ] [ ] 60 file:c:/work/workspace/myjava/target/myjava-1.0.0-SNAPSHOT.jar

Where is my src/data folder to trigger the route?
I placed messages.xml to the src/data folder and nothing happens.

Is there an archetype that can use Java DSL and create a war file?

Thanks,

Alex

ffang

Posts: 1,320
Registered: 12/24/07
Re: Hello world Java DSL with camel-archetype-java
Posted: Jul 5, 2012 11:24 PM   in response to: alexcmak in response to: alexcmak
 
  Click to reply to this thread Reply
Hi,

There should be a src folder in $FUSE_ESB after you install/start that bundle.
So put files in $FUSE_ESB/data/src should do the trick.

Freeman
alexcmak

Posts: 7
Registered: 07/05/12
Re: Hello world Java DSL with camel-archetype-java
Posted: Jul 6, 2012 1:46 AM   in response to: ffang in response to: ffang
 
  Click to reply to this thread Reply
Thanks for your reply.

Does Fuse ESB rely on environment variables? when I installed Fuse ESB there was no %FUSE_ESB% set.

I start fuse-esb here:

C:\fuse-esb-full-7.0.0.fuse-061\fuse-esb-7.0.0.fuse-061\bin

I place the XML messages here

C:\fuse-esb-full-7.0.0.fuse-061\fuse-esb-7.0.0.fuse-061\src\data

nothing happens. I set %FUSE_ESB% and it didn't help.

The camel-archetype-java works perfectly fine with

mvn jetty:run

as the generated ReadMe.txt suggested, but that's not deploy within FuseESB.

Thanks,
Alex

ffang

Posts: 1,320
Registered: 12/24/07
Re: Hello world Java DSL with camel-archetype-java
Posted: Jul 6, 2012 3:05 AM   in response to: alexcmak in response to: alexcmak
 
  Click to reply to this thread Reply
Hi,

No, Fuse ESB doesn't rely on environment variables FUSE_ESB set.
When I mentioned the $FUSE_ESB, I just refer to the location where you install Fuse ESB.

Did a close look at the camel-archetype-java, the package in pom.xml is plain jar, so it's not designed to be deployed into OSGi container, you should use camel-archetype-blueprint instead which demonstrate how to generate blueprint bundle and deploy to OSGi container. Take a look at [1] to get different camel archetypes purpose.

However, adapt the camel-archetype-java to be able to deployed into OSGi container isn't difficult, you just need edit the generated pom.xml
change
<packaging>jar</packaging>
to
<packaging>bundle</packaging>

also add
<!-- to generate the MANIFEST-FILE of the bundle -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.4</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>mytest-blueprint</Bundle-SymbolicName>
<Import-Package>*,org.apache.camel.osgi</Import-Package>
</instructions>
</configuration>
</plugin>
to the <plugins> tag, then build it and drop the jar to $FUSE_ESB/deploy folder, then you can see $FUSE_ESB/src/data folder get generated automatically for you, then you can copy message1|2.xml into this folder and you can find in $FUSE_ESB/target there's the output files.

[1]http://camel.apache.org/camel-maven-archetypes.html

Freeman

alexcmak

Posts: 7
Registered: 07/05/12
Re: Hello world Java DSL with camel-archetype-java
Posted: Jul 6, 2012 5:56 PM   in response to: ffang in response to: ffang
 
  Click to reply to this thread Reply
Freeman,

Thanks for your reply.
I changed the <packaging> to bundle and added the <plugin> as prescribed.
Nothing happens when I drop the jar file in FuseESB's deploy.

I did osgi:install like I did before and the "list" looks better, showing the <name> in pom.xml instead of the file:

304 Active [ ] [ ] 60 Alex Camel Route (1.0.0.SNAPSHOT)

However, dropping messages.xml files in src/data still did not trigger anything.

I will try a camel-archetype-blueprint.

From the list of available archetypes, only these are OSGi ready: camel-archetype-blueprint, camel-archetype-scala and camel-archetype-spring-dm. It would be nice to have a Java one?

Alex

davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Hello world Java DSL with camel-archetype-java
Posted: Jul 6, 2012 6:56 AM   in response to: alexcmak in response to: alexcmak
Helpful
  Click to reply to this thread Reply
Hi

You should use the blueprint or spring / spring-dm archetype to create a new project. Then its OSGi based, and will kick start your Camel apps. The Java DSL can still be used, as you can use the <routeBuilderRef> or <packageScan> to refer to your java classes with the Java DSL.

In the pure Java archetype there is no XML file that automatic kick-start your app in the OSGi container. So your app starts, but don't start your Camel app. For that you would need to code your own OSGi Bundle Activator class and put inside your own JAR, and add a meta data in the MANIFEST.MF file so the OSGi container is aware of your custom OSGi bundle activator so it can start|stop it accordingly to the lifecycle of your bundle. When you have a XML file (blueprint or spring) then that happens automatic for you.

In the future with CDI annotations we may be able to have a way of also automatic to kick-start your app, by you annotation your Java DSL class or something alike.
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Hello world Java DSL with camel-archetype-java
Posted: Jul 6, 2012 6:57 AM   in response to: davsclaus in response to: davsclaus
 
  Click to reply to this thread Reply
There is a sample of using <routeBuilderRef> and <packageScan> at
http://camel.apache.org/spring.html

This applies for blueprint as well.
alexcmak

Posts: 7
Registered: 07/05/12
Re: Hello world Java DSL with camel-archetype-java
Posted: Jul 6, 2012 7:12 PM   in response to: davsclaus in response to: davsclaus
 
  Click to reply to this thread Reply
I generated a new camel-archetype-blueprint project.
I replaced the route in the blueprint.xml with a <routeBuilder>, and then specified a bean id for the class.

I created a new RouteBuilder class with my route written in Java and everything worked.

Thank you all for your responds.

Alex