Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

To summarize, the application is listening for incidents coming from web service or files. According to the origin, the content (= incidents) are transformed into their corresponding objects using for the CSV file, a new camel component : camel-bindy and for the Web Service camel-cxf component. Each message transformed is placed in a queue handled by ActiveMQ engine. All the messages (containing the objects) are next processed by a Bean service who will (with the help of injection of dependency provided by Spring) save the incidents in a DB using Spring and Hibernate frameworks.
A small Apache Wicket web application running in Jetty Web server provide to the users an a screen to consult the incidents created.

...

As you can see, some are considered as OSGI bundles and others no. An important point to mention here concerns the granularity : each layer of our application will be deployed as separate bundlesbundle. This will facilitate the maintenance and release management. Of course, you can argue that the granularity is too small. SOA is not an exact science and depending of the size of the application, the team in charge to develop, release management procedure this cutting will be redefined. You can imagine that the parameters used to configure Hibernate and Spring are bundles together instead inside the persistence project. Service bundle could be split into several bundles; one by service type, ... There are no rules of thumb except that the project must be manageable and maintainable.

...

Code Block
 
mvn archetype:create -DartifactId=simple -DgroupId=org.apache.camel.example -DartifactId=reportincident.model -Dversion=1.0-SNAPSHOT
cd reportincident.db
mvn eclipse:eclipse

For the OSGI bundles, different approaches are available depending on the tools that you prefer to use :

...

  • pom.xml file generated is very simple and only include dependencies, plugin requiredto use and to understand,
  • project can be designed with several modules,
  • project can be tested with PAX Exam and launched using PAX runner
  • generate all the folders required including also the META-INF,
  • manifest file is generated automatically,
  • can be imported easily in Eclipse

...

Code Block
mvn org.ops4j:maven-pax-plugin:create-bundle -Dpackage=org.apache.camel.example.reportincident.model -DbundleGroupId=reportincident.model -DbundleName=reportincident.model -Dversion=1.0-SNAPSHOT

2) Move to the folder created and execute the following command :

Code Block

mvn org.ops4j:maven-pax-plugin:eclipse

2) Import the generated eclipse project in Eclipse workspace
3) Delete non required files like readme.txt and the folders internal + java class created
4) Enable dependency management (see sonatype site).

...

  • reportincident.activemq
  • reportincident.camelqueueservicereportincident.features
  • reportincident.persistence
  • reportincident.routing
  • reportincident.service
  • reportincident.web
  • reportincident.webservice

...

It is time now to begin serious things. One of the most important part of a project (if not the most important) concerns the design of the model.
The reportincident model is really simple because it only contains one class that we will use :

  • to map information with the database, CSV file

...

  • ,
  • to transport information to web screens.

Here is the definition of the incident class ( that you can create in the reportincident.model project ( directory src/main/java/org/apache/camel/example/reportincident/model or use the code imported)

Code Block
import java.io.Serializable;

public class Incident implements Serializable{

	private static final long serialVersionUID = 1L;
	
	protected long incidentId;

	protected String incidentRef;
	
	protected Date incidentDate;
	
	protected String givenName;
	
	protected String familyName;
	
	protected String summary;
	
	protected String details;
	
	protected String email;
	
	protected String phone;
	
	protected String creationUser;
	
	protected Date creationDate;
	
	
	public long getIncidentId() {
		return incidentId;
	}

	public void setIncidentId(long incidentId) {
		this.incidentId = incidentId;
	}
	
	public String getIncidentRef() {
		return incidentRef;
	}

	public void setIncidentRef(String incidentRef) {
		this.incidentRef = incidentRef;
	}

	public Date getIncidentDate() {
		return incidentDate;
	}

	public void setIncidentDate(Date incidentDate) {
		this.incidentDate = incidentDate;
	}

	public String getGivenName() {
		return givenName;
	}

	public void setGivenName(String givenName) {
		this.givenName = givenName;
	}

	public String getFamilyName() {
		return familyName;
	}

	public void setFamilyName(String familyName) {
		this.familyName = familyName;
	}

	public String getSummary() {
		return summary;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}

	public String getDetails() {
		return details;
	}

	public void setDetails(String details) {
		this.details = details;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getCreationUser() {
		return creationUser;
	}

	public void setCreationUser(String creationUser) {
		this.creationUser = creationUser;
	}

	public Date getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

}

...

To map our model with the database, we will use the ORM framework Hibernate. Annotation can also be used since the last version of Hibernate but to avoid to overload our class and reduce its readability, we will use the old way using a XML file describing the mapping between the model and the database.

Code Block
<hibernate-mapping schema="REPORT">
	<class name="org.apache.camel.example.reportincident.model.Incident" table="T_INCIDENT">
		<meta attribute="extends">Abstract</meta>
		<id name="incidentId" column="INCIDENT_ID"  type="long">
			<generator class="native" />
		</id>
		
		<property column="INCIDENT_REF" name="incidentRef" length="55" type="string" />
		<property column="INCIDENT_DATE" lazy="false" length="8" name="incidentDate" type="timestamp" />
		<property column="GIVEN_NAME" length="35" name="givenName" type="string" />
		<property column="FAMILY_NAME" length="35" name="familyName" type="string" />
		<property column="SUMMARY" length="35" name="summary" type="string" />
		<property column="DETAILS" length="255" name="details" type="string" />
		<property column="EMAIL" length="60" name="email" type="string" />
		<property column="PHONE" length="35" name="phone" type="string" />

		<property column="CREATION_DATE" generated="never" lazy="false" name="creationDate" type="timestamp" />
		<property column="CREATION_USER" generated="never" lazy="false" name="creationUser" type="string" />
	</class>
</hibernate-mapping>

Remark : This file Incident.hbm.xml must be created in the directory src\main\resources\META-INF\org\apache\camel\example\reportincident\model\Incident.hbm.xml of the project reportincident.model.

Step 6 : Database creation

To create the data base modeldatabase, we will use hibernate maven plugin file. The plugin will use the following configuration file to generate the SQL script and create table T_Incident.

...

Here is the content of the hibernate.cfg.xml that you must create in the folder src/config of hibernate.db

Code Block
<!-- MySQL DB -->

<hibernate-configuration>
	<session-factory name="reportincident">
		<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
		<property name="hibernate.connection.url">jdbc:mysql:///report</property>
		<property name="hibernate.connection.username">root</property>
		<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
		<property name="hibernate.connection.password" />
		<property name="hibernate.show_sql">true</property>
		
		<!-- mapping files -->
        <mapping resource="META-INF/org/apache/camel/example/reportincident/model/Incident.hbm.xml"/>
		
	</session-factory>
</hibernate-configuration>

...

  • Dependency with reportincident.model project must be added because the plugin requires the file Incident.hbm.xml to generate the script/db
  • If you prefer to use another DB instead of MySql, change the dependency in the pom.xml and hibernate.connection.driver_class and hibernate.connection.url in the cfg file

To create the table + SQL script, simply launch the

Code Block

mvn clean install

command in the folder of reportincident.db

...