Apache Wicket - web site

The tutorial is almost finished. We have to design the web page that we will use to consult the incidents published in the database. The web framework that we will use is Apache Wicket.

Step 1 : Web pages

To display the incidents in a web page, we will create the file HomePage.html in the directory src/main/java/org/apache/camel/example/reportincident. This file contain html tags with some wicket tags. One of the benefit of Apache Wicket compare to other web frameworks is that it try to keep the html page as clean as possible to facilitate the work of the web designer and integration with code made by the developers. It is a component framework like JSF but not based on programmable page like JSP, ...

<html>
<head>
	<title>Report Incident HomePage</title>
	<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
	<strong>Report Incident HomePage</strong>
	<br/>
	<p/>
	<span wicket:id="message">message will be here</span> (1)
	<p/>
	
	<table cellspacing="0" class="dataview">
    	<tr>
        	<th>Id</th>
        	<th>Incident Date</th>
        	<th>Incident Ref</th>
        	<th>First Name</th>
        	<th>Last Name</th>
        	<th>Summary</th>
        	<th>Details</th>
        	<th>Email</th>
        	<th>Phone</th>
        	<th>Origin</th>
        	<th>Creation date</th>
    	</tr>
    	<tr>
        	<td><span wicket:id="incidentId">[incidentId]</span></td>  (2)
        	<td><span wicket:id="incidentDate">[incidentDate]</span></td>
        	<td><span wicket:id="incidentRef">[incidentRef]</span></td>
        	<td><span wicket:id="givenName">[givenName]</span> </td>
       	 	<td><span wicket:id="familyName">[familyName]</span></td>
        	<td><span wicket:id="summary">[summary]</span></td>
        	<td><span wicket:id="details">[details]</span></td>
        	<td><span wicket:id="email">[email]</span></td>
        	<td><span wicket:id="phone">[phone]</span></td>
        	<td><span wicket:id="creationUser">[creationUser]</span></td>
        	<td><span wicket:id="creationDate">[creationDate]</span></td>
    	</tr>
	</table>

</body>
</html>

Remarks :
(1) - The tag wicket:id="message" is used to display top of the screen a message
(2) - The tags <td> are enriched with parameter wicket:id="" to allow to the wicket code page to replace this property with the property field of the Incident class.

Step 2 : Web page code

HomePage.java

package org.apache.camel.example.reportincident;

import java.util.Iterator;
import org.apache.camel.example.reportincident.model.Incident;
import org.apache.camel.example.reportincident.service.IncidentService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;

/**
 * Homepage
 */
public class HomePage extends WebPage {

	private static final long serialVersionUID = 1L;

	private static final transient Log LOG = LogFactory.getLog(HomePage.class);

	@SpringBean (1)
	private IncidentService incidentService;

	/**
	 * Constructor that is invoked when page is invoked without a session.
	 * 
	 * @param parameters
	 *            Page parameters
	 */
	public HomePage(final PageParameters parameters) {

		LOG.debug("Spring service : " + incidentService.toString());

		// Add the simplest type of label
		add(new Label("message", "List of incidents coming from web services or file : ")); (2)

		DataView dataView = new DataView("pageable", new IncidentProvider()) { (3)

			@Override
			protected void populateItem(final Item item) { (5) 
				Incident incident = (Incident) item.getModelObject();
				item.add(new Label("incidentId", String.valueOf(incident
						.getIncidentId())));
				item.add(new Label("incidentDate", String.valueOf(incident
						.getIncidentDate())));
				item.add(new Label("incidentRef", incident.getIncidentRef()));
				item.add(new Label("givenName", incident.getGivenName()));
				item.add(new Label("familyName", incident.getFamilyName()));
				item.add(new Label("summary", incident.getSummary()));
				item.add(new Label("details", incident.getDetails()));
				item.add(new Label("email", incident.getEmail()));
				item.add(new Label("phone", incident.getPhone()));
				item.add(new Label("creationUser", incident.getCreationUser()));
				item.add(new Label("creationDate", String.valueOf(incident
						.getCreationDate())));

				item.add(new AttributeModifier("class", true,
						new AbstractReadOnlyModel() {
							@Override
							public Object getObject() {
								return (item.getIndex() % 2 == 1) ? "even"
										: "odd";
							}
						}));
			}
		};
		
        add(dataView);


	}

	private class IncidentProvider implements IDataProvider { (4)

		public Iterator iterator(int first, int count) {
			return incidentService.findIncident().iterator();
		}

		public int size() {
			return incidentService.findIncident().size();
		}

		public IModel model(Object object) {
			return new Model((Incident) object);
		}

		public void detach() {
			// TODO Auto-generated method stub

		}
	}

	private class IncidentDetachModel extends LoadableDetachableModel {

		private long id;

		@Override
		protected Object load() {
			return incidentService.findIncident(String.valueOf(id));
		}

		/**
		 * @param c
		 */
		public IncidentDetachModel(Incident i) {
			this(i.getIncidentId());
		}

		public IncidentDetachModel(long id) {

			if (id == 0) {
				throw new IllegalArgumentException();
			}
			this.id = id;
		}

	}

}

Remarks :
(1) - The @SpringBean annotation is used to inject our spring IncidentService service
(2) - To set the message label of the HomePage.html, we call the method add(new Label()) and set the property "message" with the information that we want to display on the screen 'List of incidents coming from web services or file'
(3) - To populate the table of the web page, we will use a DataView object. The DataView class requires as a parameter a IncidentDataProvider which is in fact an inner class implementing the interface IDataProvider.
(4) - The class IncidentDataProvider will call our IncidentSaver service to retrieve from the database the list of Incidents reported.
(5) - The populateItem method of the DataView will map the content of our incident objects with the attributes (= items) of the web page

WicketApplication.java

To tell to the Apache Wicket framework that our application contains the page HomePage.html and class HomePage (1), we will create the class WebApplication in the directory src/main/java/org/apache/camel/example/reportincident) like this.

package org.apache.camel.example.reportincident;

import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;

/**
 * Application object for your web application. If you want to run this application without deploying, run the Start class.
 * 
 * @see org.apache.wicket.example.Start#main(String[])
 */
public class WicketApplication extends WebApplication
{    
	
	/**
	 * Init
	 */
    public void init() {
        super.init();
        addComponentInstantiationListener(new SpringComponentInjector(this)); (2)
    }

	
    /**
     * Constructor
     */
	public WicketApplication()
	{
	}
	
	/**
	 * @see org.apache.wicket.Application#getHomePage()
	 */
	public Class<HomePage> getHomePage() (1)
	{
		return HomePage.class;
	}

}

To inject Spring into Wicket, we have used the approach described on the following web site of Apache Wicki documentation and added the line addComponentInstantiationListener(new SpringComponentInjector(this)); into the class (2)

Step 3 : web.xml configuration

Now that the code/web pages are ready, we have to create the web.xml file in the directory src/main/webapp/WEB-INF

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
	version="2.4">

	<display-name>reportincident.web</display-name>

	<context-param>
		<param-name>contextClass</param-name>
		<param-value>org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext</param-value> (2)
	</context-param>

	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> (1) 
	</listener>

	<filter>
		<filter-name>camel.example.reportincident.web</filter-name>
		<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
		<init-param>
		    <param-name>applicationClassName</param-name>
		    <param-value>org.apache.camel.example.reportincident.WicketApplication</param-value>
		    <param-name>applicationFactoryClassName</param-name>
		    <param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value> (1)
    	</init-param>
	</filter>
	<filter-mapping>
		<filter-name>camel.example.reportincident.web</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>


</web-app>

Remarks :

(1) - Wicket applications have a global application object which is a subclass of Application. This global application object is only created once per application and is never serialized (since it contains no user-specific data and thus remains the same across all nodes in the cluster). These qualities make it a good candidate to act as a service locator for the rest of the application. Wicket allows you to provide a custom factory for creating this object, the wicket-contrib-spring project provides such a factory (SpringWebApplicationFactory) that, instead of creating an instance, pulls it out of the spring application context. Wicket keeps the instance of the application object in a threadlocal variable and provides various helper methods in components to get to it, so it is easy to retrieve dependencies in wicket components.
(2) - Spring DM provides a dedicated, OSGi-aware, web application context (called OsgiBundleXmlWebApplicationContext) that offers the same functionality and behaviour to its Spring-MVC brethren, XmlWebApplicationContext. The application context is aware of the web application BundleContext and thus is able to load resources from the OSGi space, import and export OSGi services and support the BundleContextAware and component scanning across the bundles included in the classpath.

Step 4 : Add spring stuffs

To allow our web bundle to have access to the osgi (1) service org.apache.camel.example.reportincident.service.IncidentService, we have to add the following line in the file called applicationContext that we create in the directory src/main/webapp/WEB-INF.

<?xml version="1.0"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="http://www.springframework.org/schema/beans
                    http://www.springframework.org/schema/beans/spring-beans.xsd
                    http://www.springframework.org/schema/osgi
                    http://www.springframework.org/schema/osgi/spring-osgi.xsd">
                    
 <osgi:reference id="incidentService" interface="org.apache.camel.example.reportincident.service.IncidentService"/> (1)
 
</beans>

Step 4 : Adapt the pom.xml file

The pom of this project is different from the bundles projects because :
(1) - the packaging here is war and not bundle,
(2) - The MANIFEST.MF file generated must be copied in the WAR
(3) - we must tell to maven that the plugin in charge to generate the MANIFEST.MF file must be called during the goal/phase : process-classes
(4) - we want to define the web application context <Webapp-Context> who will be published by PAX Web

<?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.apache.camel.example</groupId>
	<artifactId>reportincident.web</artifactId>
	<packaging>war</packaging> (1)
	<version>1.0-SNAPSHOT</version>
	<name>Report Incident Web Bundle</name>

	<parent>
		<groupId>org.apache.camel.example</groupId>
	    <artifactId>reportincident.parent</artifactId>
	    <version>1.0-SNAPSHOT</version>
	</parent>

	<dependencies>
		<dependency>
			<groupId>org.apache.camel.example</groupId>
			<artifactId>reportincident.service</artifactId>
			<version>1.0-SNAPSHOT</version>
			<scope>provided</scope>
		</dependency>
		
		<!-- SPRING DEPENDENCIES -->
	    <dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>${spring-version}</version>
			<scope>provided</scope>
		</dependency>
	    <dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-beans</artifactId>
			<version>${spring-version}</version>
			<scope>provided</scope>
		</dependency>
		<!-- 
	    <dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>${spring-version}</version>
			<scope>provided</scope>
		</dependency>
		 -->
		<!--  WICKET DEPENDENCIES -->
		<dependency>
			<groupId>org.apache.wicket</groupId>
			<artifactId>wicket</artifactId>
			<version>${wicket.version}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.wicket</groupId>
			<artifactId>wicket-spring</artifactId>
			<version>${wicket.version}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.wicket</groupId>
			<artifactId>wicket-ioc</artifactId>
			<version>${wicket.version}</version>
			<scope>provided</scope>
		</dependency>
                <dependency>
                        <groupId>org.apache.wicket</groupId>
			<artifactId>wicket-extensions</artifactId>
			<version>${wicket.version}</version>
			<scope>provided</scope>
		</dependency>

		<!-- LOGGING DEPENDENCIES - LOG4J -->
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.4.2</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.14</version>
			<scope>test</scope>
		</dependency>

		<!--  JUNIT DEPENDENCY FOR TESTING -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.2</version>
			<scope>test</scope>
		</dependency>

		<!--  JETTY DEPENDENCIES FOR TESTING  -->
		<dependency>
			<groupId>org.mortbay.jetty</groupId>
			<artifactId>jetty</artifactId>
			<version>${jetty.version}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.mortbay.jetty</groupId>
			<artifactId>jetty-util</artifactId>
			<version>${jetty.version}</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.mortbay.jetty</groupId>
			<artifactId>jetty-management</artifactId>
			<version>${jetty.version}</version>
			<scope>provided</scope>
		</dependency>
	</dependencies>
	<build>
		<resources>
			<resource>
				<filtering>false</filtering>
				<directory>src/main/resources</directory>
			</resource>
			<resource>
				<filtering>false</filtering>
				<directory>src/main/java</directory>
				<includes>
					<include>**</include>
				</includes>
				<excludes>
					<exclude>**/*.java</exclude>
				</excludes>
			</resource>
		</resources>
		<testResources>
			<testResource>
				<filtering>false</filtering>
				<directory>src/test/java</directory>
				<includes>
					<include>**</include>
				</includes>
				<excludes>
					<exclude>**/*.java</exclude>
				</excludes>
			</testResource>
		</testResources>
		<plugins>

			<plugin>
				<inherited>true</inherited>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.5</source>
					<target>1.5</target>
					<optimise>true</optimise>
					<debug>true</debug>
				</configuration>
			</plugin>

			<plugin>
				<groupId>org.mortbay.jetty</groupId>
				<artifactId>maven-jetty-plugin</artifactId>
			</plugin>


			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.1-alpha-2</version>
				<configuration>
					<archive>
						<!-- add the generated manifest to the war --> (2)
						<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
					</archive>
					<!-- 
					<webResources>
						<resource>
							<directory>src/main/resources/META-INF/spring</directory>
							<targetPath>META-INF/spring</targetPath>
						</resource>
					</webResources>
					 -->
				</configuration>

			</plugin>


			<!-- to generate the MANIFEST-FILE required by the bundle -->
			<plugin>
				<groupId>org.apache.felix</groupId>
				<artifactId>maven-bundle-plugin</artifactId>
				<version>${felix-version}</version>
				<extensions>true</extensions>
				<executions> (3)
					<execution>
						<id>bundle-manifest</id>
						<phase>process-classes</phase>
						<goals>
							<goal>manifest</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<supportedProjectTypes>
						<supportedProjectType>bundle</supportedProjectType> (3)
						<supportedProjectType>war</supportedProjectType>
					</supportedProjectTypes>
					<instructions>
						<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
						<Bundle-ClassPath>
							.,
							WEB-INF/classes,
						</Bundle-ClassPath>
						<Import-Package>
							javax.servlet;version="[2.5.0, 3.0.0)",
							javax.servlet.http;version="[2.5.0, 3.0.0)",
							javax.servlet.resources;version="[2.5.0, 3.0.0)",
							org.apache.camel.example.reportincident.service,
							org.springframework.web.context;version="[2.5.6, 3.0.0)",
							org.springframework.web.context.support;version="[2.5.6, 3.0.0)",
							org.springframework.osgi.web.context.support,
							org.xml.sax;resolution:=optional,
							org.w3c.dom;resolution:=optional,
							*
						</Import-Package>
						<Private-Package>org.apache.camel.example.reportincident</Private-Package>
						<Export-Package></Export-Package>
						<Webapp-Context>reportincidentweb</Webapp-Context> (4)
						<_failok>true</_failok>
					</instructions>
				</configuration>

			</plugin>
		</plugins>
	</build>
</project>

Remark : To deploy the war in your maven repository, execute the following maven command

mvn clean install

One big advantage of the approach followed here is that the web application will not be packages with the jar required in the lib directory but only with the classes/pages/... which are part of the application. The jar required by the Web Application must be deployed separately on the OSGI server. Another positive aspect is the clear separation between the front layer from the service/persistence layers. Our application uses OSGI services which are injected in the configuration. So you are no more dependent of a big WAR/EAR file as it was the case with monolithic J2EE applications (wink)

Build and Package the application

Build

To build the project, you must execute the following maven command in the root of the installation directory :

mvn clean install -Dtest=false  -DfailIfNoTests=false

Package

To simplify our deployment procedure, we will use the provisioning mechanism of Apache Felix Karaf called 'Feature'. In a feature xml file, we will define the bundles that we will package and their dependencies. The bundles can be linked to a feature and features can be linked together. This file will be packaged in a jar.

The advantage of the feature is that you avoid to deploy manually your bundles in your OSGI server and they can be versioned as you will see in the file. Moreover, the feature can be seen as a contract between your development and the deployment team. Different versions can be created according to the environment where the code will be deployed (development, acceptance and production).

If you prefer to generate automatically the file based on the dependencies of yours pom, then you can use the maven plugin maven-features-plugin

Create the file reportincident.features-1.0-SNAPSHOT-features.xml in the directory src/main of the project reportincident.features

Remarks :
(1) - The reportincident feature has the number version 1.0
(2) - Each feature is a collection of bundles or bundles/features. The bundle tag contains the URI syntax used by PAX URI to install the JAR or the resource on the OSGI server. We us the mvn protocol to download the jar from Maven repository but other protocols exist (see OPS4J for more info)
(3) - The camel feature include a list of camel-xx features.

<?xml version="1.0" encoding="UTF-8"?>
<!--
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<features>
	
   <feature name="reportincident" version="1.0-SNAPSHOT">
	<bundle>mvn:org.apache.camel.example/reportincident.activemq/1.0-SNAPSHOT</bundle>
	<bundle>mvn:org.apache.camel.example/reportincident.queueservice/1.0-SNAPSHOT</bundle>
	<bundle>mvn:org.apache.camel.example/reportincident.model/1.0-SNAPSHOT</bundle>
	<bundle>mvn:org.apache.camel.example/reportincident.persistence/1.0-SNAPSHOT</bundle>
	<bundle>mvn:org.apache.camel.example/reportincident.service/1.0-SNAPSHOT</bundle>
	<bundle>mvn:org.apache.camel.example/reportincident.webservice/1.0-SNAPSHOT</bundle>
	<bundle>mvn:org.apache.camel.example/reportincident.routing/1.0-SNAPSHOT</bundle>
        <bundle>mvn:org.apache.camel.example/reportincident.web/1.0-SNAPSHOT/war</bundle>
    </feature>
	
    <feature name="transaction" version="1.0.0">
	<bundle>mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1</bundle>
        <bundle>mvn:org.apache.geronimo.specs/geronimo-j2ee-connector_1.5_spec/2.0.0</bundle>
        <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.howl/1.0.1-1_1</bundle>
   	<bundle>mvn:org.apache.geronimo.components/geronimo-transaction/2.2-r634076</bundle>
  	<bundle>mvn:org.apache.servicemix.transaction/org.apache.servicemix.transaction/1.0.0</bundle> 
    </feature>

    <feature name="connector" version="4.0.0">
        <feature version="1.0.0">transaction</feature>
        <bundle>mvn:org.apache.geronimo.specs/geronimo-j2ee-connector_1.5_spec/2.0.0</bundle>
        <bundle>mvn:org.apache.geronimo.components/geronimo-connector/2.1.3</bundle>
        <bundle>mvn:org.apache.geronimo.specs/geronimo-jms_1.1_spec/1.1.1</bundle>
        <bundle>mvn:org.apache.geronimo.specs/geronimo-servlet_2.5_spec/1.1.2</bundle> 
        <bundle>mvn:org.springframework/spring-tx/2.5.6.SEC01</bundle>
        <bundle>mvn:org.jencks/jencks/2.2</bundle>
    </feature>
		
   <feature name="activemq" version="5.3.0">
        <feature version="4.0.0">connector</feature>
        <bundle>mvn:org.apache.geronimo.specs/geronimo-j2ee-management_1.1_spec/1.0.1</bundle>
        <bundle>mvn:commons-pool/commons-pool/1.4</bundle>
        <bundle>mvn:org.apache.xbean/xbean-spring/3.5</bundle>
        <bundle>mvn:org.apache.activemq/kahadb/5.3.0</bundle>
        <bundle>mvn:org.apache.activemq/activemq-core/5.3.0</bundle>
        <bundle>mvn:org.apache.activemq/activemq-ra/5.3.0</bundle>
        <bundle>mvn:org.apache.activemq/activemq-console/5.3.0</bundle>
        <bundle>mvn:org.apache.activemq/activemq-pool/5.3.0</bundle>
        <!-- <bundle>mvn:org.apache.servicemix.activemq/org.apache.servicemix.activemq.commands/4.0.0</bundle> -->
    </feature>
	
    <feature name="activemq-camel" version="5.3.0">
        <bundle>mvn:org.apache.activemq/activemq-camel/5.3.0</bundle>
    </feature>
	
    <feature name="spring-web">
        <bundle>mvn:org.springframework/spring-web/2.5.6.SEC01</bundle>
        <bundle>mvn:org.springframework.osgi/spring-osgi-web/1.2.0</bundle> 
    </feature>
   
    <feature name="hibernate">
        <bundle>mvn:org.springframework/spring-orm/2.5.6.SEC01</bundle>
        <bundle>mvn:org.springframework/spring-jdbc/2.5.6.SEC01</bundle>
    	<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/1.6.1_2</bundle>
    	<bundle>mvn:org.antlr/com.springsource.antlr/2.7.7</bundle>
    	<bundle>mvn:org.jgroups/com.springsource.org.jgroups/2.5.1</bundle>
    	<bundle>mvn:org.jboss.javassist/com.springsource.javassist/3.3.0.ga</bundle>
    	<bundle>mvn:org.hibernate/com.springsource.org.hibernate/3.3.1.GA</bundle>
    </feature>
    
    <feature name="jdbc-driver">
	<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-dbcp/1.2.2_3</bundle>
    	<bundle>mvn:com.mysql.jdbc/com.springsource.com.mysql.jdbc/5.1.8</bundle>
    </feature>
    
    <feature name="wicket" version="1.4.7">
    	<bundle>mvn:org.apache.wicket/wicket/1.4.7</bundle>
    	<bundle>mvn:org.apache.wicket/wicket-ioc/1.4.7</bundle>
    	<bundle>mvn:org.apache.wicket/wicket-spring/1.4.7</bundle>
    	<!-- <bundle>mvn:org.apache.wicket/wicket-spring-annot/1.4.7</bundle> -->
    	<bundle>mvn:org.apache.wicket/wicket-extensions/1.4.7</bundle>
    </feature> 
     
</features>

To generate the jar file containing the feature xml file, adapt the pom.xml like this :

<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.apache.camel.example</groupId>
	<artifactId>reportincident.features</artifactId>
	<packaging>jar</packaging>
	<version>1.0-SNAPSHOT</version>
	<name>Reportincident :: Project Features</name>
	
	<parent>
		<groupId>org.apache.camel.example</groupId>
	    <artifactId>reportincident.parent</artifactId>
	    <version>1.0-SNAPSHOT</version>
	</parent>

	<build>
		<resources>
			<!-- standard Maven folder -->
			<resource>
				<directory>src/main/resources</directory>
			</resource>
		</resources>

		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<version>2.3</version>
				<executions>
					<execution>
						<phase>copy-resources</phase>
						<goals>
							<goal>resources</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

</project>

During the execution of the following maven command :

mvn clean install

maven will put the file reportincident.features-1.0-SNAPSHOT-features.xml in the jar and the jar will be installed in your Maven local repository under the directory {{localMavenRepository/org/apache/camel/example/reportincident.features/1.0-SNAPSHOT

Deploy

The deployment process is very simple and two steps will be necessary :

Step 1 : Copy properties files in etc directory

Copy the files containing your properties file org.apache.camel.example.reportincident.datasource.cfg, ... in the etc directory of Apache Felix Karaf and customize them if required

Step 2 : Edit the file org.apache.felix.karaf.features.cfg

To use the feature file created in the previous section, we must adapt the file org.apache.felix.karaf.features.cfg that you find in the etc directory

Replace the current featureRepositories line with the following :

featuresRepositories=mvn:org.apache.felix.karaf/apache-felix-karaf/1.4.0/xml/features,mvn:org.apache.camel.karaf/apache-camel/2.2.0/xml/features,jar:mvn:org.apache.camel.example/reportincident.features/1.0-SNAPSHOT!/reportincident.features-1.0-SNAPSHOT-features.xml

This line will be processed by PAX Url who will pickup the reportincident.features-1.0-SNAPSHOT-features.xml file from the jar located in the maven repository localMavenRepo/org.apache.camel.example/reportincident.features/1.0-SNAPSHOT

and

replace the existing line containing the featuresBoot parameter

by

featuresBoot=spring,spring-dm,camel,camel-bindy,camel-jms,activemq,activemq-camel,http,war,spring-web,camel-cxf,hibernate,jdbc-driver,wicket,reportincident

By adding these two lines, we will configure our Apache Felix Karaf server to install bundles from features defined in the order appearing at the line of featuresBoot

The deployment order of the bundle is critical in an OSGI environement. This is why for the purposes of this project/tutorial we have organised in consequence. If you plan to change something in the application, be aware of that

The /etc/system.property file must be modified to define the environment variable servicemix.base used by activemq bundle

Add the following line
servicemix.base=root

Test it

Step 1 : launch application

It is time to launch the karaf server and to test if our application works well. If this is not yet done, download Apache Felix Karaf 1.4.0 server and install it. Launch the server by executing the command in the bin folder:

c:\apache-felix-karaf-1.4.0\bin>karaf

If this is the first time that Karaf is started, then you will see that a new data folder is created. This directory will contain subfolders :

  • cache : containing the bundlles deployed
  • log : where the log file is updated by the application

Step 2 : Check osgi list

When the following prompt appears on the screen :

c:\apache-felix-karaf-1.0.0\bin>karaf
        __ __                  ____
       / //_/____ __________ _/ __/
      / ,<  / __ `/ ___/ __ `/ /_
     / /| |/ /_/ / /  / /_/ / __/
    /_/ |_|\__,_/_/   \__,_/_/

  Apache Felix Karaf (1.4.0)

Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.

karaf@root>

execute the command :

karaf@root:/> osgi:list

During the first launch of Karaf, it will install all the bundles defined in the features (one by one) in the order defined. 134 bundles must be deployed, so be patient because it can take time depending of your internet connection, cpu, processor of your machine.

but after a few minutes, you must see the following list

karaf@root> osgi:list
START LEVEL 100
   ID   State         Blueprint      Spring    Level  Name
[   0] [Active     ] [            ] [       ] [    0] System Bundle (2.0.4)
[   1] [Active     ] [            ] [       ] [    5] OPS4J Pax Url - mvn: (1.1.2)
[   2] [Active     ] [            ] [       ] [    5] OPS4J Pax Url - wrap: (1.1.2)
[   3] [Active     ] [            ] [       ] [    8] OPS4J Pax Logging - API (1.4)
[   4] [Active     ] [            ] [       ] [    8] OPS4J Pax Logging - Service (1.4)
[   5] [Active     ] [            ] [       ] [   10] Apache Felix Configuration Admin Service (1.2.4)
[   6] [Active     ] [            ] [       ] [   10] Apache Felix Preferences Service (1.0.4)
[   7] [Active     ] [            ] [       ] [   11] Apache Felix File Install (2.0.8)
[   8] [Active     ] [Created     ] [       ] [   20] Apache Geronimo Blueprint Bundle (1.0.0)
[   9] [Active     ] [Created     ] [       ] [   30] Apache Felix Karaf :: Features Management (1.4.0)
[  10] [Active     ] [Created     ] [       ] [   30] Apache Felix Karaf :: Spring Deployer (1.4.0)
[  11] [Active     ] [Created     ] [       ] [   30] Apache Felix Karaf :: Features Deployer (1.4.0)
[  12] [Active     ] [Created     ] [       ] [   30] Apache Felix Karaf :: Shell Various Commands (1.4.0)
[  13] [Active     ] [            ] [       ] [   30] Apache Mina SSHD :: Core (0.3.0)
[  14] [Active     ] [Created     ] [       ] [   30] Apache Felix Karaf :: Shell Development Commands (1.4.0)
[  15] [Active     ] [Created     ] [       ] [   30] Apache Felix Karaf :: Features Core (1.4.0)
[  16] [Active     ] [Created     ] [       ] [   30] Apache Felix Karaf :: Shell ConfigAdmin Commands (1.4.0)
[  17] [Active     ] [Created     ] [       ] [   30] Apache Felix Karaf :: Shell PackageAdmin Commands (1.4.0)
[  18] [Active     ] [Created     ] [       ] [   30] Apache Felix Karaf :: Blueprint Deployer (1.4.0)
[  19] [Active     ] [Created     ] [       ] [   30] Apache Felix Karaf :: JAAS Modules (1.4.0)
[  20] [Active     ] [Created     ] [       ] [   30] Apache Felix Karaf :: Admin Management (1.4.0)
[  21] [Active     ] [Created     ] [       ] [   30] Apache Felix Karaf :: Shell OSGi Commands (1.4.0)
[  22] [Active     ] [Created     ] [       ] [   30] Apache Felix Karaf :: JAAS Config (1.4.0)
[  23] [Active     ] [            ] [       ] [   30] org.osgi.impl.bundle.jmx (4.2.0.200907080519)
[  24] [Active     ] [Created     ] [       ] [   30] Apache Felix Karaf :: Features Command (1.4.0)
[  25] [Active     ] [            ] [       ] [   30] Apache Felix Gogo Shell Runtime (0.2.2)
[  26] [Active     ] [            ] [       ] [   30] Apache MINA Core (2.0.0.RC1)
[  27] [Active     ] [Created     ] [       ] [   30] Apache Felix Karaf :: Shell Console (1.4.0)
[  28] [Active     ] [Created     ] [       ] [   30] Apache Felix Karaf :: Admin Core (1.4.0)
[  29] [Active     ] [Created     ] [       ] [   30] Apache Felix Karaf :: Management (1.4.0)
[  30] [Active     ] [Created     ] [       ] [   30] Apache Felix Karaf :: Admin Command (1.4.0)
[  31] [Active     ] [Created     ] [       ] [   30] Apache Felix Karaf :: Shell Log Commands (1.4.0)
[  32] [Active     ] [Created     ] [       ] [   30] Apache Felix Karaf :: Shell SSH (1.4.0)
[  33] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: aopalliance-1.0 (1.0.0.3)
[  34] [Active     ] [            ] [       ] [   60] Spring Core (2.5.6.SEC01)
[  35] [Active     ] [            ] [       ] [   60] Spring Beans (2.5.6.SEC01)
[  36] [Active     ] [            ] [       ] [   60] Spring AOP (2.5.6.SEC01)
[  37] [Active     ] [            ] [       ] [   60] Spring Context (2.5.6.SEC01)
[  38] [Active     ] [            ] [       ] [   60] Spring Context Support (2.5.6.SEC01)
[  39] [Active     ] [            ] [       ] [   60] Apache ServiceMix Specs :: ACTIVATION API 1.4 (1.4.0)
[  40] [Active     ] [            ] [       ] [   60] Apache ServiceMix Specs :: JAXB API 2.1 (1.4.0)
[  41] [Active     ] [            ] [       ] [   60] Apache ServiceMix Specs :: STAX API 1.0 (1.4.0)
[  42] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: jaxb-impl-2.1.12 (2.1.12.1)
[  43] [Active     ] [            ] [       ] [   60] Commons Management (1.0)
[  44] [Active     ] [            ] [       ] [   60] camel-core (2.2.0)
[  45] [Active     ] [            ] [       ] [   60] Spring Transaction (2.5.6.SEC01)
[  46] [Active     ] [            ] [       ] [   60] geronimo-jta_1.1_spec (1.1.1)
[  47] [Active     ] [            ] [       ] [   60] Commons Pool (1.5.4)
[  48] [Active     ] [            ] [       ] [   60] geronimo-jms_1.1_spec (1.1.1)
[  49] [Active     ] [            ] [       ] [   60] Spring JMS (2.5.6.SEC01)
[  50] [Active     ] [            ] [       ] [   60] camel-jms (2.2.0)
[  51] [Active     ] [            ] [       ] [   60] geronimo-servlet_2.5_spec (1.1.2)
[  52] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: jetty-6.1.22 (6.1.22.1)
[  53] [Active     ] [            ] [       ] [   60] OPS4J Pax Web - API (0.7.2)
[  54] [Active     ] [            ] [       ] [   60] OPS4J Pax Web - Service SPI (0.7.2)
[  55] [Active     ] [            ] [       ] [   60] OPS4J Pax Web - Runtime (0.7.2)
[  56] [Active     ] [            ] [       ] [   60] OPS4J Pax Web - Jetty (0.7.2)
[  57] [Active     ] [            ] [       ] [   60] camel-bindy (2.2.0)
[  58] [Active     ] [            ] [       ] [   60] activemq-camel (5.3.0)
[  59] [Active     ] [            ] [Started] [   60] Reportincident :: ActiveMQ Queuing Engine (1.0.0.SNAPSHOT)
[  60] [Active     ] [            ] [Started] [   60] Reportincident :: Camel Queuing Service (1.0.0.SNAPSHOT)
[  61] [Active     ] [            ] [       ] [   60] Reportincident :: Model Bundle (1.0.0.SNAPSHOT)
[  62] [Active     ] [            ] [Started] [   60] Reportincident :: Persistence Bundle (1.0.0.SNAPSHOT)
[  63] [Active     ] [            ] [Started] [   60] Reportincident :: Service Bundle (1.0.0.SNAPSHOT)
[  64] [Active     ] [            ] [       ] [   60] Reportincident :: Webservice Bundle (1.0.0.SNAPSHOT)
[  65] [Active     ] [            ] [Started] [   60] Reportincident :: Routing Bundle (1.0.0.SNAPSHOT)
[  66] [Active     ] [            ] [       ] [   60] Reportincident :: Web Bundle (1.0.0.SNAPSHOT)
[  67] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: commons-dbcp-1.2.2 (1.2.2.3)
[  68] [Active     ] [            ] [       ] [   60] MySQL AB's JDBC Driver for MySQL (5.1.6)
[  69] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: cglib-2.1_3 (2.1.0.3_4)
[  70] [Active     ] [            ] [       ] [   60] spring-osgi-io (1.2.0)
[  71] [Active     ] [            ] [       ] [   60] spring-osgi-core (1.2.0)
[  72] [Active     ] [            ] [       ] [   60] spring-osgi-extender (1.2.0)
[  73] [Active     ] [            ] [       ] [   60] spring-osgi-annotation (1.2.0)
[  74] [Active     ] [Created     ] [       ] [   60] Apache Felix Karaf :: Spring Deployer (1.2.0)
[  75] [Active     ] [            ] [       ] [   60] camel-spring-osgi (2.2.0)
[  76] [Active     ] [            ] [       ] [   60] Spring Web (2.5.6.SEC01)
[  77] [Active     ] [            ] [       ] [   60] spring-osgi-web (1.2.0)
[  78] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: jetty-6.1.14 (6.1.14.1)
[  79] [Active     ] [            ] [       ] [   60] OPS4J Pax Web - API (0.7.1)
[  80] [Active     ] [            ] [       ] [   60] OPS4J Pax Web - Service SPI (0.7.1)
[  81] [Active     ] [            ] [       ] [   60] OPS4J Pax Web - Runtime (0.7.1)
[  82] [Active     ] [            ] [       ] [   60] OPS4J Pax Web - Jetty (0.7.1)
[  83] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: asm-2.2.3 (2.2.3.3)
[  84] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: jetty-6.1.19 (6.1.19.2)
[  85] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: commons-codec-1.3 (1.3.0.2)
[  86] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: jdom-1.1 (1.1.0.2)
[  87] [Active     ] [            ] [       ] [   60] jettison (1.2)
[  88] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: ant-1.7.0 (1.7.0.3)
[  89] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: bcel-5.2 (5.2.0.2)
[  90] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: xalan-2.7.1 (2.7.1.2)
[  91] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: xercesImpl-2.9.1 (2.9.1.3)
[  92] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: xmlbeans-2.4.0 (2.4.0.3)
[  93] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: xmlsec-1.4.3 (1.4.3.2)
[  94] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: xmlresolver-1.2 (1.2.0.2)
[  95] [Active     ] [            ] [       ] [   60] Woodstox XML-processor (4.0.7)
[  96] [Active     ] [            ] [       ] [   60] Stax2 API (3.0.1)
[  97] [Active     ] [            ] [       ] [   60] XmlSchema (1.4.5)
[  98] [Active     ] [            ] [       ] [   60] Commons Lang (2.4)
[  99] [Active     ] [            ] [       ] [   60] Commons Collections (3.2.1)
[ 100] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: antlr-2.7.7 (2.7.7.2)
[ 101] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: oro-2.0.8 (2.0.8.3)
[ 102] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: velocity-1.6.2 (1.6.2.3)
[ 103] [Active     ] [            ] [       ] [   60] Axiom API (1.2.8)
[ 104] [Active     ] [            ] [       ] [   60] Axiom API (1.2.8)
[ 105] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: mail-1.4.1 (1.4.1.2)
[ 106] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: neethi-2.0.4 (2.0.4.2)
[ 107] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: abdera-0.4.0-incubating (0.4.0.incubating_3)
[ 108] [Active     ] [            ] [       ] [   60] geronimo-jaxws_2.1_spec (1.0)
[ 109] [Active     ] [            ] [       ] [   60] geronimo-annotation_1.0_spec (1.1.1)
[ 110] [Active     ] [            ] [       ] [   60] Apache ServiceMix Specs :: SAAJ API 1.3 (1.4.0)
[ 111] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: wsdl4j-1.6.2 (1.6.2.2)
[ 112] [Active     ] [            ] [       ] [   60] Apache ServiceMix Specs :: JSR311 API 1.0 (1.4.0)
[ 113] [Active     ] [            ] [       ] [   60] geronimo-ws-metadata_2.0_spec (1.1.2)
[ 114] [Active     ] [            ] [Started] [   60] Apache CXF Bundle Jar (2.2.6)
[ 115] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: commons-io-1.3.2 (1.3.2.3)
[ 116] [Active     ] [            ] [       ] [   60] camel-cxf (2.2.0)
[ 117] [Active     ] [            ] [       ] [   60] geronimo-j2ee-connector_1.5_spec (2.0.0)
[ 118] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: howl-1.0.1-1 (1.0.1.1_1)
[ 119] [Active     ] [            ] [       ] [   60] Geronimo TxManager :: Transaction (2.2.0.r634076)
[ 120] [Active     ] [            ] [Started] [   60] Apache ServiceMix Transaction (1.0.0)
[ 121] [Active     ] [            ] [       ] [   60] Geronimo TxManager :: Connector (2.1.3)
[ 122] [Active     ] [            ] [       ] [   60] Jencks (2.2)
[ 123] [Active     ] [            ] [       ] [   60] geronimo-j2ee-management_1.1_spec (1.0.1)
[ 124] [Active     ] [            ] [       ] [   60] Apache Commons Pool Bundle (1.4)
[ 125] [Active     ] [            ] [       ] [   60] xbean-spring (3.5)
[ 126] [Active     ] [            ] [       ] [   60] kahadb (5.3.0)
[ 127] [Active     ] [            ] [       ] [   60] activemq-core (5.3.0)
[ 128] [Active     ] [            ] [       ] [   60] activemq-ra (5.3.0)
[ 129] [Active     ] [            ] [       ] [   60] activemq-console (5.3.0)
[ 130] [Active     ] [            ] [       ] [   60] activemq-pool (5.3.0)
[ 131] [Active     ] [            ] [       ] [   60] OPS4J Pax Web - Jsp Support (0.7.2)
[ 132] [Active     ] [            ] [       ] [   60] OPS4J Pax Web - Extender - WAR (0.7.2)
[ 133] [Active     ] [            ] [       ] [   60] OPS4J Pax Web - Extender - Whiteboard (0.7.2)
[ 134] [Active     ] [            ] [       ] [   60] OPS4J Pax Url - war:, war-i: (1.1.2)
[ 135] [Active     ] [Created     ] [       ] [   60] Apache Felix Karaf :: WAR Deployer (1.4.0)
[ 136] [Active     ] [            ] [       ] [   60] Wicket (1.4.7)
[ 137] [Active     ] [            ] [       ] [   60] Wicket IoC common code (1.4.7)
[ 138] [Active     ] [            ] [       ] [   60] Wicket Spring Integration (1.4.7)
[ 139] [Active     ] [            ] [       ] [   60] Wicket Extensions (1.4.7)
[ 140] [Active     ] [            ] [       ] [   60] Spring ORM (2.5.6.SEC01)
[ 141] [Active     ] [            ] [       ] [   60] Spring JDBC (2.5.6.SEC01)
[ 142] [Active     ] [            ] [       ] [   60] Apache ServiceMix Bundles: dom4j-1.6.1 (1.6.1.2)
[ 143] [Active     ] [            ] [       ] [   60] ANTLR (2.7.7)
[ 144] [Active     ] [            ] [       ] [   60] JGroups Toolkit (2.5.1)
[ 145] [Active     ] [            ] [       ] [   60] Javassist Java Programming Assistant (3.3.0.ga)
[ 146] [Active     ] [            ] [       ] [   60] JBoss Hibernate Object-Relational Mapper (3.3.1.GA)

If errors happen during installation of the bundles, the list could be not completed. In this is the case, the feature provisioning system has stopped the installation. You have to check the log file of karaf and depending of the error reported, correction made, the installation can be relaunched in the menu 'feature' using the command :

karaf@root> features:list
  State          Version       Name
[uninstalled]  [      0.0.0] hibernate

karaf@root> features:install hibernate

If a problem occurs with a bundle, you can by example recompile the code, regenerate the jar and update the bundle using the command

karaf@root> osgi:update xxx

where xxx corresponds to the bundle to be updated

The features list can also be very helpfull to see which features has been installed

karaf@root> features:list

State         Version        Name                     Repository
[installed  ] [2.2.0       ] camel                    repo-0
[installed  ] [2.2.0       ] camel-core               repo-0
[installed  ] [2.2.0       ] camel-spring-osgi        repo-0
[uninstalled] [2.2.0       ] camel-spring             repo-0
[uninstalled] [2.2.0       ] camel-osgi               repo-0
[uninstalled] [2.2.0       ] camel-test               repo-0
[installed  ] [2.2.0       ] camel-cxf                repo-0
[uninstalled] [2.2.0       ] camel-cache              repo-0
[uninstalled] [2.2.0       ] camel-castor             repo-0
[uninstalled] [2.2.0       ] camel-dozer              repo-0
[uninstalled] [2.2.0       ] camel-http               repo-0
[uninstalled] [2.2.0       ] camel-mina               repo-0
[uninstalled] [2.2.0       ] camel-jetty              repo-0
[uninstalled] [2.2.0       ] camel-servlet            repo-0
[installed  ] [2.2.0       ] camel-jms                repo-0
[uninstalled] [2.2.0       ] camel-amqp               repo-0
[uninstalled] [2.2.0       ] camel-atom               repo-0
[uninstalled] [2.2.0       ] camel-bam                repo-0
[installed  ] [2.2.0       ] camel-bindy              repo-0
[uninstalled] [2.2.0       ] camel-cometd             repo-0
[uninstalled] [2.2.0       ] camel-csv                repo-0
[uninstalled] [2.2.0       ] camel-flatpack           repo-0
[uninstalled] [2.2.0       ] camel-freemarker         repo-0
[uninstalled] [2.2.0       ] camel-ftp                repo-0
[uninstalled] [2.2.0       ] camel-guice              repo-0
[uninstalled] [2.2.0       ] camel-groovy             repo-0
[uninstalled] [2.2.0       ] camel-hl7                repo-0
[uninstalled] [2.2.0       ] camel-ibatis             repo-0
[uninstalled] [2.2.0       ] camel-irc                repo-0
[uninstalled] [2.2.0       ] camel-jaxb               repo-0
[uninstalled] [2.2.0       ] camel-jcr                repo-0
[uninstalled] [2.2.0       ] camel-jing               repo-0
[uninstalled] [2.2.0       ] camel-jdbc               repo-0
[uninstalled] [2.2.0       ] camel-josql              repo-0
[uninstalled] [2.2.0       ] camel-jpa                repo-0
[uninstalled] [2.2.0       ] camel-jxpath             repo-0
[uninstalled] [2.2.0       ] camel-juel               repo-0
[uninstalled] [2.2.0       ] camel-ldap               repo-0
[uninstalled] [2.2.0       ] camel-mail               repo-0
[uninstalled] [2.2.0       ] camel-msv                repo-0
[uninstalled] [2.2.0       ] camel-mvel               repo-0
[uninstalled] [2.2.0       ] camel-ognl               repo-0
[uninstalled] [2.2.0       ] camel-printer            repo-0
[uninstalled] [2.2.0       ] camel-protobuf           repo-0
[uninstalled] [2.2.0       ] camel-quartz             repo-0
[uninstalled] [2.2.0       ] camel-restlet            repo-0
[uninstalled] [2.2.0       ] camel-rmi                repo-0
[uninstalled] [2.2.0       ] camel-rss                repo-0
[uninstalled] [2.2.0       ] camel-saxon              repo-0
[uninstalled] [2.2.0       ] camel-scala              repo-0
[uninstalled] [2.2.0       ] camel-script             repo-0
[uninstalled] [2.2.0       ] camel-smpp               repo-0
[uninstalled] [2.2.0       ] camel-snmp               repo-0
[uninstalled] [2.2.0       ] camel-spring-integration repo-0
[uninstalled] [2.2.0       ] camel-sql                repo-0
[uninstalled] [2.2.0       ] camel-stream             repo-0
[uninstalled] [2.2.0       ] camel-string-template    repo-0
[uninstalled] [2.2.0       ] camel-tagsoup            repo-0
[uninstalled] [2.2.0       ] camel-velocity           repo-0
[uninstalled] [2.2.0       ] camel-xmlbeans           repo-0
[uninstalled] [2.2.0       ] camel-xmlsecurity        repo-0
[uninstalled] [2.2.0       ] camel-xmpp               repo-0
[uninstalled] [2.2.0       ] camel-xstream            repo-0
[installed  ] [2.5.6.SEC01 ] spring                   karaf-1.4.0
[installed  ] [1.2.0       ] spring-dm                karaf-1.4.0
[uninstalled] [1.4.0       ] wrapper                  karaf-1.4.0
[uninstalled] [1.4.0       ] obr                      karaf-1.4.0
[installed  ] [1.4.0       ] http                     karaf-1.4.0
[installed  ] [1.4.0       ] war                      karaf-1.4.0
[uninstalled] [1.4.0       ] webconsole               karaf-1.4.0
[installed  ] [1.4.0       ] ssh                      karaf-1.4.0
[installed  ] [1.4.0       ] management               karaf-1.4.0
[installed  ] [1.0-SNAPSHOT] reportincident           repo-0
[installed  ] [1.0.0       ] transaction              repo-0
[installed  ] [4.0.0       ] connector                repo-0
[installed  ] [5.3.0       ] activemq                 repo-0
[installed  ] [5.3.0       ] activemq-camel           repo-0
[installed  ] [0.0.0       ] spring-web               repo-0
[installed  ] [0.0.0       ] hibernate                repo-0
[installed  ] [0.0.0       ] jdbc-driver              repo-0
[installed  ] [1.4.7       ] wicket                   repo-0
[uninstalled] [0.0.0       ] http-reportingincident   repo-0

Step 3 : Incident file

To test the Camel routing, we have to produce an incident file report and put it in the file defined in the from uri of your inittial route. Create a file containing csv lines :

001,29-04-2009,Claus,Ibsen,incident camel-001,this is a report incident for camel-001,cibsen@gmail.com,+111 10 20 300
002,29-04-2009,Charles,Moulliard,incident smx-002,this is a report incident for smx-002,cmoulliard@gmail.com,+222 10 20 300
003,28-04-2009,Guillaume,Nodet,incident camel-123,this is a report incident for camel-123,gnodet@gmail.com,+333 10 20 300
004,25-04-2009,Gert,Vanthienen,incident camel-454,this is a report incident for camel-454,gvanthienen@gmail.com,+444 10 20 300
005,24-04-2009,James,Anstey,incident smx-023,this is a report incident for smx-023,janstey@gmail.com,+555 10 20 300
007,01-04-2009,Willem,Jiang,incident smx-456,this is a report incident for smx-456,wjiang@gmail.com,+666 10 20 300
008,27-04-2009,Matt,Raibble,incident appfuse-123,this is a report incident for appfuse-123,mraibble@gmail.com,+777 10 20 300
009,12-04-2009,Jean-Baptiste,Onofré,incident smx3-088,this is a report incident for smx3-088,cjbonofre@gmail.com,+888 10 20 300
010,17-04-2009,Hadrian,Zbarcea,incident camel-005,this is a report incident for camel-005,hzbarcea@gmail.com,+999 10 20 300

Save your file and copy it in the folder

Check the log of SMX and you must see something like this

log_file_servicemix.txt

Next, open the web page of your application : http://localhost:8080/reportincidentweb/

Step 4 : Call a webservice

You can use the tool Soapui to call the web service of the application.

Use the following url from Soapui, to generate the client interface to communicate with the web service : http://localhost:8080/cxf/camel-example/incident?wsdl.

Call the web service with the request : http://localhost:8080/cxf/camel-example/incident
and the following SOAP message request by example :

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rep="http://reportincident.example.camel.apache.org">
   <soapenv:Header/>
   <soapenv:Body>
      <rep:inputReportIncident>
         <incidentId>000</incidentId>
         <incidentDate>29-04-2009</incidentDate>
         <givenName>Charles</givenName>
         <familyName>Moulliard</familyName>
         <summary>This is an web service report incident</summary>
         <details>This is an web service report incident,This is an web service report incident.</details>
         <email>cmoulliard@gmail.com</email>
         <phone>+222 10 20 30 40</phone>
      </rep:inputReportIncident>
   </soapenv:Body>
</soapenv:Envelope>

Check the Karaf log :

log_file_servicemix2.txt

and web screen result : http://localhost:8080/reportincidentweb/

Conclusion

Well, this tutorial was a little bit long but we have tried to provide you all the required information to design a real application using Apache Camel, Felix Karaf, OSGI, CXF and Apache Wicket frameworks. We hope that we have reached the goals defined in the introduction and will continue to improve its content based on Apache frameworks evolution. A part which is not covered but we plan to add it in the future concerns the testing/debugging of the application and transactional aspects.

#Resources

© 2004-2015 The Apache Software Foundation.
Apache Camel, Camel, Apache, the Apache feather logo, and the Apache Camel project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram