The easiest way to bootstrap a route in Karaf is to use Blueprint. I’m assuming you’ve already converted your jar to an OSGi bundle.
If you add a small XML file to src/main/resources/OSGI-INF/blueprint (assuming you’re using Maven for this) the route should startup in Karaf when you install your bundle. The XML file will look something like this <?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <bean id="route-builder" class="my.route.Builder" /> <camelContext xmlns="http://camel.apache.org/schema/blueprint"> <routeBuilder ref="route-builder" /> </camelContext> </blueprint> HTH > On Sep 4, 2018, at 10:10 AM, John F. Berry <bohnje...@yahoo.com.INVALID> > wrote: > > I've posted a few questions over the past month about various steps in a > camel route. I had developed both a Spring version and a Java DSL version > simultaneously at the beginning, because of either the lack or abundance of > certain endpoint development in each. The Java DSL version worked out best > in the continuing development, but then the "powers that be" asked me to make > a Windows service for it. > I ended up being able to package it to en executable jar, but then found that > perhaps I should use Karaf as an OSGi container run as a windows service. I > have Karaf installed with it's awaiting service container, but it looks like > it's a pain to configure a Camel Java DSL route to an OSGi container, but > what I did seem to find was people have used a Spring OSGi Camel package and > overrode the configuration to execute a java "bean". > My question is: Can the entire Camel Context developed in Spring be pointed > to the completed Java DSL developed package? Can I just add a shell around > my already completed work? My route runs fine from maven using "mvn > exec:java" or running java - jar <package> . > Now that I got this running, I'd rather not disassemble and re-wire, although > it would be a good educational experience. > > MyRouteBuilder.java : > > import java.util.Base64; > import org.apache.camel.spi.DataFormat; > > > import ca.uhn.hl7v2.parser.Parser; > import org.apache.commons.dbcp2.BasicDataSource; > import org.apache.camel.component.sql.SqlComponent; > > public class MyRouteBuilder extends RouteBuilder { > @Override > public void configure() throws Exception { > BasicDataSource basicDataSource = new BasicDataSource(); > > basicDataSource.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); > > basicDataSource.setUrl("jdbc:sqlserver://XXX:52739;databaseName=XXX;"); > basicDataSource.setUsername("XXX"); > basicDataSource.setPassword("XXX"); > SqlComponent sqlComponent = new SqlComponent(); > sqlComponent.setDataSource(basicDataSource); > getContext().addComponent("psoft-sql", sqlComponent); > > > from("mllp://ZZZ:8888") > .log("..Received HL7 message with control id > ${header.CamelMllpMessageControlId}") > .convertBodyTo(String.class) > .unmarshal() > .hl7(false) > .process(new Processor() { > public void process(Exchange exchange) throws Exception { > Message message = exchange.getIn().getBody(Message.class); > ca.uhn.hl7v2.util.Terser terser = new Terser(message); > String obx5 = terser.get("/.OBX-5-5"); > String EDMId = terser.get("/.OBR-3") + ".pdf"; > String voucher = terser.get("/.OBR-2"); > > byte[] decoded = Base64.getDecoder().decode(obx5); > exchange.getOut().setBody(decoded); > exchange.getOut().setHeader("voucher", voucher); > exchange.getOut().setHeader("CamelFileName", EDMId ); > } > } ) > .log("..Processed voucher ${header.voucher} to file > ${header.CamelFileName}") > .to("file:target/messages/others") > .recipientList(simple("psoft-sql:INSERT INTO lawsonprod.PeopleSoftVCR > (Voucher, Facility, image) VALUES ('12345', '1', '${header.CamelFileName}')") > ) > ; > > } > > } > > POM.xml (given there's a lot of extras in here not used due to attempts > during development) > > <?xml version="1.0" encoding="UTF-8"?> > <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/maven-v4_0_0.xsd"> > > <modelVersion>4.0.0</modelVersion> > > <groupId>org.ZZZ.camel</groupId> > <artifactId>EDMtoPSoft-java</artifactId> > <packaging>jar</packaging> > <version>1.0-SNAPSHOT</version> > > <name>EDM base64 HL7 documents to PeopleSoft</name> > > <properties> > <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> > <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> > </properties> > > <dependencyManagement> > <dependencies> > <!-- Camel BOM --> > <dependency> > <groupId>org.apache.camel</groupId> > <artifactId>camel-parent</artifactId> > <version>2.21.1</version> > <scope>import</scope> > <type>pom</type> > </dependency> > </dependencies> > </dependencyManagement> > > <dependencies> > > <dependency> > <groupId>org.apache.camel</groupId> > <artifactId>camel-core</artifactId> > </dependency> > > <!-- logging --> > <dependency> > <groupId>org.apache.logging.log4j</groupId> > <artifactId>log4j-api</artifactId> > <scope>runtime</scope> > </dependency> > <dependency> > <groupId>org.apache.logging.log4j</groupId> > <artifactId>log4j-core</artifactId> > <scope>runtime</scope> > </dependency> > <dependency> > <groupId>org.apache.logging.log4j</groupId> > <artifactId>log4j-slf4j-impl</artifactId> > <scope>runtime</scope> > </dependency> > > <!-- testing --> > <dependency> > <groupId>org.apache.camel</groupId> > <artifactId>camel-test</artifactId> > <scope>test</scope> > </dependency> > > <dependency> > <groupId>javax.xml.bind</groupId> > <artifactId>jaxb-api</artifactId> > <version>2.2.11</version> > </dependency> > <dependency> > <groupId>javax.activation</groupId> > <artifactId>activation</artifactId> > <version>1.1.1</version> > </dependency> > <dependency> > <groupId>org.apache.camel</groupId> > <artifactId>camel-mllp</artifactId> > <version>2.21.1</version> > </dependency> > > <!-- Project stuff --> > <dependency> > <groupId>org.apache.camel</groupId> > <artifactId>camel-hl7</artifactId> > <version>2.21.1</version> > </dependency> > > <dependency> > <groupId>org.apache.camel</groupId> > <artifactId>camel-netty4</artifactId> > <version>2.21.1</version> > </dependency> > > <dependency> > <groupId>org.apache.camel</groupId> > <artifactId>camel-base64</artifactId> > <version>2.21.1</version> > </dependency> > > <dependency> > <groupId>org.apache.camel</groupId> > <artifactId>camel-sql</artifactId> > <version>2.21.1</version> > </dependency> > > <dependency> > <groupId>org.apache.commons</groupId> > <artifactId>commons-dbcp2</artifactId> > <version>2.5.0</version> > </dependency> > > <dependency> > <groupId>com.microsoft.sqlserver</groupId> > <artifactId>mssql-jdbc</artifactId> > <version>7.0.0.jre10</version> > </dependency> > > > </dependencies> > > <build> > <defaultGoal>install</defaultGoal> > > <plugins> > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-compiler-plugin</artifactId> > <version>3.7.0</version> > <configuration> > <source>1.8</source> > <target>1.8</target> > </configuration> > </plugin> > <plugin> > <groupId>org.apache.maven.plugins</groupId> > <artifactId>maven-resources-plugin</artifactId> > <version>3.0.2</version> > <configuration> > <encoding>UTF-8</encoding> > </configuration> > </plugin> > > <!-- Allows the example to be run via 'mvn compile exec:java' --> > <plugin> > <groupId>org.codehaus.mojo</groupId> > <artifactId>exec-maven-plugin</artifactId> > <version>1.6.0</version> > <configuration> > <mainClass>org.ZZZ.camel.MainApp</mainClass> > <includePluginDependencies>false</includePluginDependencies> > </configuration> > </plugin> > > <plugin> > <artifactId>maven-assembly-plugin</artifactId> > <configuration> > <descriptorRefs> > <descriptorRef>jar-with-dependencies</descriptorRef> > </descriptorRefs> > <archive> > <manifest> > <mainClass>org.ZZZ.camel.MainApp</mainClass> > </manifest> > </archive> > </configuration> > <executions> > <execution> > > <phase>package</phase> <!-- bind to the packaging > phase --> > <goals> > <goal>single</goal> > </goals> > </execution> > </executions> > </plugin> > > > <plugin> > <groupId>org.apache.felix</groupId> > <artifactId>maven-bundle-plugin</artifactId> > <version>2.3.7</version> > <extensions>true</extensions> > <configuration> > <instructions> > <Bundle-Name>${project.name}</Bundle-Name> > > <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName> > <Export-Package> > org.ZZZ.camel > </Export-Package> > </instructions> > </configuration> > </plugin> > > </plugins> > </build> > > </project> >