{"id":6059,"date":"2017-01-04T15:34:48","date_gmt":"2017-01-04T20:34:48","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=6059"},"modified":"2017-01-04T15:36:09","modified_gmt":"2017-01-04T20:36:09","slug":"simple-jboss-fusekaraf-camel-route-deployment","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2017\/01\/04\/simple-jboss-fusekaraf-camel-route-deployment\/","title":{"rendered":"Simple JBOSS Fuse\/Karaf Camel route deployment"},"content":{"rendered":"<p>To get started with Camel for routing, you can simply drop a file in the deploy directory under your Fuse installation. However, in a production environment, it is advisable to have more controlled process for deploying routes. That is the purpose of this post. As always, the goal is to produce a simple test case with as few steps as possible, yet provide a system connection example so you can read the documentation from a more &#8220;kinetic&#8221; learning standpoint.<\/p>\n<p>Start with a maven project.<\/p>\n<pre>\r\n[esb@cmhlcarchapp01 poc]$ mvn archetype:generate -DgroupId=com.express.it.arch.poc.osgi \\\r\n                                                 -DartifactId=osgipoc \\\r\n                                                 -DarchetypeArtifactId=maven-archetype-quickstart \\\r\n                                                 -DinteractiveMode=false\r\n[INFO] Scanning for projects...\r\n\r\n\r\n\r\n[INFO] BUILD SUCCESS\r\n[INFO] ------------------------------------------------------------------------\r\n[INFO] Total time: 2.924 s\r\n[INFO] Finished at: 2016-12-14T13:53:54-05:00\r\n[INFO] Final Memory: 15M\/149M\r\n[INFO] ------------------------------------------------------------------------\r\n[esb@cmhlcarchapp01 poc]$\r\n\r\n<\/pre>\n<p>Create an Activator class in your newly created directory tree that matches the name in your pom.xml.  Please note that we added additional code to show when the bundle was activated, as we initially had issues getting this to work.  This is, of course, not production ready, but we retained it as it is just a simple POC.<\/p>\n<pre>\r\npackage com.express.it.arch.poc.osgi;\r\n\r\nimport java.io.File;\r\nimport java.io.FileWriter;\r\nimport java.io.PrintStream;\r\nimport org.osgi.framework.BundleActivator;\r\nimport org.osgi.framework.BundleContext;\r\n\r\npublic class Activator\r\n  implements BundleActivator\r\n{\r\n  public void start(BundleContext context)\r\n  {\r\n    try\r\n    {\r\n      FileWriter fw = new FileWriter(new File(\"\/tmp\/foo.txt\"));\r\n      fw.write(\"test\");\r\n      fw.close();\r\n    }\r\n    catch (Exception localException) {}\r\n    System.out.println(\"Starting the bundle\");\r\n  }\r\n\r\n  public void stop(BundleContext context)\r\n  {\r\n    System.out.println(\"Stopping the bundle\");\r\n  }\r\n}\r\n<\/pre>\n<p>The base pom.xml for this example is shown below&#8230;<\/p>\n<pre>\r\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\">\r\n\r\n    <modelVersion>4.0.0<\/modelVersion>\r\n\r\n    <groupId>com.express.it.arch.poc.osgi<\/groupId>\r\n    <artifactId>osgipoc<\/artifactId>\r\n    <version>1.0<\/version>\r\n    <packaging>bundle<\/packaging>\r\n\r\n    <name>com.express.it.arch.poc.osgi Bundle<\/name>\r\n    <description>com.express.it.arch.poc.osgi POC bundle project.<\/description>\r\n\r\n   <properties>\r\n     <version>2.15.1<\/version>\r\n   <\/properties>\r\n\r\n   <dependencies>\r\n      <dependency>\r\n         <groupId>org.osgi<\/groupId>\r\n         <artifactId>org.osgi.core<\/artifactId>\r\n         <version>4.2.0<\/version>\r\n         <scope>provided<\/scope>\r\n      <\/dependency>\r\n\r\n      <dependency>\r\n         <groupId>org.apache.camel<\/groupId>\r\n         <artifactId>camel-blueprint<\/artifactId>\r\n         <version>${version}<\/version>\r\n      <\/dependency>\r\n\r\n      <dependency>\r\n         <groupId>org.apache.camel<\/groupId>\r\n         <artifactId>camel-core<\/artifactId>\r\n         <version>${version}<\/version>\r\n      <\/dependency>\r\n   <\/dependencies>\r\n\r\n   <build>\r\n      <defaultGoal>install<\/defaultGoal>\r\n        <plugins>\r\n            <plugin>\r\n                <groupId>org.apache.felix<\/groupId>\r\n                <artifactId>maven-bundle-plugin<\/artifactId>\r\n                <version>2.3.7<\/version>\r\n                <extensions>true<\/extensions>\r\n                <configuration>\r\n                  <instructions>\r\n                    <Bundle-SymbolicName>${project.artifactId}<\/Bundle-SymbolicName>\r\n                    <Bundle-Version>${project.version}<\/Bundle-Version>\r\n                    <Bundle-Activator>com.express.it.arch.poc.osgi.Activator<\/Bundle-Activator>\r\n                    <Export-Package>\r\n                       com.express.it.arch.poc.osgi*;version=${project.version}\r\n                    <\/Export-Package>\r\n                    <Import-Package>\r\n                      *\r\n                    <\/Import-Package>\r\n                  <\/instructions>\r\n                <\/configuration>\r\n            <\/plugin>\r\n         <plugin>\r\n            <groupId>org.apache.maven.plugins<\/groupId>\r\n            <artifactId>maven-compiler-plugin<\/artifactId>\r\n         <\/plugin>\r\n\r\n         <plugin>\r\n            <groupId>org.apache.maven.plugins<\/groupId>\r\n            <artifactId>maven-resources-plugin<\/artifactId>\r\n         <\/plugin>\r\n\r\n         <plugin>\r\n            <groupId>org.codehaus.mojo<\/groupId>\r\n            <artifactId>build-helper-maven-plugin<\/artifactId>\r\n         <\/plugin>\r\n\r\n         <plugin>\r\n            <groupId>org.codehaus.mojo<\/groupId>\r\n            <artifactId>versions-maven-plugin<\/artifactId>\r\n         <\/plugin>\r\n        <\/plugins>\r\n    <\/build>\r\n<\/project>\r\n<\/pre>\n<p>Create a simple route in a camel context file with what is below, creating the noted location under your project directory&#8230;<\/p>\n<pre>\r\n[esb@cmhlcarchapp01 fuse]$ cat src\/main\/resources\/OSGI-INF\/blueprint\/camel-context.xml\r\n<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n<bp:blueprint\r\n   xmlns=\"http:\/\/camel.apache.org\/schema\/blueprint\"\r\n   xmlns:bp=\"http:\/\/www.osgi.org\/xmlns\/blueprint\/v1.0.0\"\r\n   xmlns:cm=\"http:\/\/aries.apache.org\/blueprint\/xmlns\/blueprint-cm\/v1.1.0\"\r\n   xmlns:ext=\"http:\/\/aries.apache.org\/blueprint\/xmlns\/blueprint-ext\/v1.1.0\"\r\n   xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n   xsi:schemaLocation=\"http:\/\/camel.apache.org\/schema\/blueprint\r\n                       http:\/\/camel.apache.org\/schema\/blueprint\/camel-blueprint-2.15.1.xsd\r\n                       http:\/\/www.osgi.org\/xmlns\/blueprint\/v1.0.0\r\n                       https:\/\/osgi.org\/xmlns\/blueprint\/v1.0.0\/blueprint.xsd\r\n                       http:\/\/aries.apache.org\/blueprint\/xmlns\/blueprint-cm\/v1.1.0\r\n                       http:\/\/aries.apache.org\/schemas\/blueprint-cm\/blueprint-cm-1.1.0.xsd\r\n                       http:\/\/aries.apache.org\/blueprint\/xmlns\/blueprint-ext\/v1.1.0\r\n                       http:\/\/aries.apache.org\/schemas\/blueprint-ext\/blueprint-ext-1.1.xsd\">\r\n\r\n   <cm:property-placeholder\r\n      id=\"test-properties\"\r\n      persistent-id=\"mypack\"\r\n      update-strategy=\"reload\">\r\n      <cm:default-properties>\r\n         <cm:property\r\n            name=\"enableTracing\"\r\n            value=\"false\" \/>\r\n      <\/cm:default-properties>\r\n   <\/cm:property-placeholder>\r\n\r\n   <camelContext\r\n      id=\"mypack\"\r\n      trace=\"{{enableTracing}}\">\r\n      <route id=\"test-route\">\r\n         <from uri=\"{{in.endpoint}}\" \/>\r\n         <inOnly uri=\"{{out.endpoint}}\" \/>\r\n         <setOutHeader headerName=\"X-Camel-Message-ID\">\r\n            <simple>${id}<\/simple>\r\n         <\/setOutHeader>\r\n         <transform>\r\n            <constant><\/constant>\r\n         <\/transform>\r\n      <\/route>\r\n   <\/camelContext>\r\n<\/bp:blueprint>\r\n\r\n<\/pre>\n<p>After doing what is above and placing the contents of the pom.xml in the prebuilt pom.xml, build the project from the osgipoc directory with the following&#8230;<\/p>\n<pre>\r\nmvn install\r\n<\/pre>\n<p>Create a properties file under your Fuse installation in the etc directory.  Name the file whatever the persistentID is above, in our case, mypack.cfg.<\/p>\n<pre>\r\n[esb@cmhlcarchapp01 fuse]$ cat etc\/mypack.cfg\r\nin.endpoint = file:foo2\r\nout.endpoint = file:bar2\r\n[esb@cmhlcarchapp01 fuse]$\r\n<\/pre>\n<p>Create a &#8220;features&#8221; file with the following contents, changing the location to wherever you want to place the generated jar file&#8230;<\/p>\n<pre>\r\n[esb@cmhlcarchapp01 fuse]$ cat osgipoc.xml\r\n<features>\r\n  <feature name='osgipoc' version='1.0'>\r\n    <bundle>file:\/\/\/opt\/fuse\/osgipoc.jar<\/bundle>\r\n  <\/feature>\r\n<\/features>\r\n<\/pre>\n<p>Then copy the generated jar file to this location, and install the bundle in Karaf with what is below&#8230;<\/p>\n<pre>\r\n[esb@cmhlcarchapp01 fuse]$ bin\/client\r\nJBossFuse:admin@root> features:addurl file:\/\/\/opt\/fuse\/osgipoc.xml\r\nJBossFuse:admin@root> features:install osgipoc\r\nJBossFuse:admin@root> osgi:list | grep poc.osgi\r\n[ 357] [Active     ] [Created     ] [       ] [   80] com.express.it.arch.poc.osgi Bundle (1.0)\r\nJBossFuse:admin@root>\r\n<\/pre>\n<p>Navigate to the base of your Fuse directory, and create a file in the foo2 directory.  You should see it immediately copied to the bar2 directory.<\/p>\n<p>Our next example will include additional java code that contains a route and additional business logic.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To get started with Camel for routing, you can simply drop a file in the deploy directory under your Fuse installation. However, in a production environment, it is advisable to have more controlled process for deploying routes. That is the&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2017\/01\/04\/simple-jboss-fusekaraf-camel-route-deployment\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[70,69,80],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/6059"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=6059"}],"version-history":[{"count":13,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/6059\/revisions"}],"predecessor-version":[{"id":6120,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/6059\/revisions\/6120"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=6059"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=6059"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=6059"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}