Versions Compared

Key

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

...

Tutoral

...

on

...

the

...

camel-example-reportincident

{:=
Info
title
Information
}

Work

in

progress

by

Claus

Ibsen.

Tutorial

to

be

part

of

Camel

1.5.

(CAMEL-601)

{info} h2. Introduction Creating this tutorial was inspired by a real life

Introduction

Creating this tutorial was inspired by a real life use-case

...

I

...

discussed

...

over

...

the

...

phone

...

with

...

a

...

college.

...

He

...

was

...

working

...

a

...

client

...

that

...

uses

...

a

...

heavy-weight

...

integration

...

platform

...

from

...

very

...

large

...

vendor.

...

He

...

was

...

in

...

talks

...

with

...

contractors

...

to

...

implement

...

a

...

new

...

integration

...

on

...

this

...

heavy

...

piece

...

of

...

platform

...

-

...

his

...

trouble

...

was

...

though

...

that

...

the

...

price

...

was

...

tripled

...

when

...

the

...

contractors

...

heard

...

it

...

had

...

to

...

be

...

on

...

this

...

platform.

...

So

...

I

...

was

...

wondering

...

how

...

we

...

could

...

do

...

this

...

integration

...

on

...

Camel.

...

Can

...

it

...

be

...

done

...

in

...

one

...

day.

...

This

...

tutorial

...

is

...

written

...

during

...

the

...

development

...

of

...

the

...

integration.

...

I

...

have

...

decided

...

to

...

start

...

off

...

with

...

a

...

sample

...

that

...

isn't

...

Camel's

...

but

...

standard

...

Java

...

and

...

then

...

plugin

...

Camel

...

as

...

we

...

goes.

...

Just

...

as

...

when

...

people

...

needed

...

to

...

learn

...

Spring

...

you

...

could

...

consume

...

it

...

piece

...

by

...

piece,

...

the

...

same

...

goes

...

with

...

Camel.

...

The

...

use-case

...

The

...

goal

...

is

...

to

...

allow

...

staff

...

to

...

report

...

incidents

...

into

...

a

...

central

...

administration.

...

For

...

that

...

they

...

use

...

client

...

software

...

where

...

they

...

report

...

the

...

incident

...

and

...

submit

...

it

...

to

...

the

...

central

...

administration.

...

As

...

this

...

is

...

an

...

integration

...

in

...

a

...

transition

...

phase

...

the

...

administration

...

should

...

get

...

these

...

incidents

...

by

...

email

...

whereas

...

they

...

are

...

manually

...

added

...

to

...

the

...

database.

...

The

...

client

...

software

...

should

...

gather

...

the

...

incident

...

and

...

submit

...

the

...

information

...

to

...

the

...

integration

...

platform

...

that

...

in

...

term

...

will

...

transform

...

the

...

report

...

into

...

an

...

email

...

and

...

send

...

it

...

to

...

the

...

central

...

administrator

...

for

...

manual

...

processing.

...

TODO:

...

Figure

...

with:

...


Client

...

->

...

Integration

...

Platform

...

->

...

Central

...

Administration

...

In

...

EIP

...

patterns

...

TODO:

...

Figure

...

with

...

EIP

...

patterns

...

Initial

...

Project

...

Setup

...

We

...

want

...

the

...

integration

...

to

...

be

...

a

...

standard

...

.war

...

application

...

that

...

can

...

be

...

deployed

...

in

...

any

...

web

...

container

...

such

...

as

...

Tomcat,

...

Jetty

...

or

...

even

...

heavy

...

weight

...

application

...

servers

...

such

...

as

...

WebLogic

...

or

...

WebSphere.

...

There

...

fore

...

we

...

start

...

off

...

with

...

the

...

standard

...

Maven

...

webapp

...

project

...

that

...

is

...

created

...

with

...

the

...

following

...

long

...

archetype

...

command:

{
Code Block
}
mvn archetype:create -DgroupId=org.apache.camel -DartifactId=camel-example-reportincident -DarchetypeArtifactId=maven-archetype-webapp
{code}

Notice

...

that

...

the

...

groupId

...

etc.

...

doens't

...

have

...

to

...

be

...

org.apache.camel

...

it

...

can

...

be

...

com.mycompany.whatever.

...

But

...

I

...

have

...

used

...

these

...

package

...

names

...

as

...

the

...

example

...

is

...

an

...

official

...

part

...

of

...

the

...

Camel

...

distribution.

...

Then

...

we

...

have

...

the

...

basic

...

maven

...

folder

...

layout.

...

We

...

start

...

out

...

with

...

the

...

webservice

...

part

...

where

...

we

...

want

...

to

...

use

...

Apache

...

CXF

...

for

...

the

...

webservice

...

stuff.

...

So

...

we

...

add

...

this

...

to

...

the

...

pom.xml

Code Block
xml
xml

{code:xml}
    <properties>
        <cxf.version>2.1.1</cxf.version>
    </properties>

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-core</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>${cxf.version}</version>
    </dependency>
{code}

h2. Developing the WebService
As we want to develop webservice with the contract first approach we create our .wsdl file. As this is a example we have simplified the model of the incident to only include 8 fields. In real life the model would be a bit more complex, but not to much.

We put the wsdl file in the folder {{

Developing the WebService

As we want to develop webservice with the contract first approach we create our .wsdl file. As this is a example we have simplified the model of the incident to only include 8 fields. In real life the model would be a bit more complex, but not to much.

We put the wsdl file in the folder src/main/webapp/WEB-INF/wsdl

...

and

...

name

...

the

...

file

...

report_incident.wsdl

...

.

Code Block
xml
xml


{code:xml}
<?xml version="1.0" encoding="ISO-8859-1"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
	xmlns:tns="http://reportincident.example.camel.apache.org"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
	xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
	targetNamespace="http://reportincident.example.camel.apache.org">

	<!-- Type definitions for input- and output parameters for webservice -->
	<wsdl:types>
		<xs:schema targetNamespace="http://reportincident.example.camel.apache.org">
			<xs:element name="inputReportIncident">
				<xs:complexType>
					<xs:sequence>
						<xs:element type="xs:string"  name="incidentId"/>
						<xs:element type="xs:string"  name="incidentDate"/>
						<xs:element type="xs:string"  name="givenName"/>
						<xs:element type="xs:string"  name="familyName"/>
						<xs:element type="xs:string"  name="summary"/>
						<xs:element type="xs:string"  name="details"/>
						<xs:element type="xs:string"  name="email"/>
						<xs:element type="xs:string"  name="phone"/>
					</xs:sequence>
				</xs:complexType>
			</xs:element>
			<xs:element name="outputReportIncident">
				<xs:complexType>
					<xs:sequence>
						<xs:element type="xs:string" name="code"/>
					</xs:sequence>
				</xs:complexType>
			</xs:element>
		</xs:schema>
	</wsdl:types>

	<!-- Message definitions for input and output -->
	<wsdl:message name="inputReportIncident">
		<wsdl:part name="parameters" element="tns:inputReportIncident"/>
	</wsdl:message>
	<wsdl:message name="outputReportIncident">
		<wsdl:part name="parameters" element="tns:outputReportIncident"/>
	</wsdl:message>

	<!-- Port (interface) definitions -->
	<wsdl:portType name="ReportIncidentService">
		<wsdl:operation name="ReportIncident">
			<wsdl:input message="tns:inputReportIncident"/>
			<wsdl:output message="tns:outputReportIncident"/>
		</wsdl:operation>
	</wsdl:portType>

	<!-- Port bindings to transports and encoding - HTTP, document literal encoding is used -->
	<wsdl:binding name="ReportIncidentBinding" type="tns:ReportIncidentService">
		<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
		<wsdl:operation name="ReportIncident">
			<soap:operation
				soapAction="http://reportincident.example.camel.apache.org/ReportIncident"
				style="document"/>
			<wsdl:input>
				<soap:body parts="parameters" use="literal"/>
			</wsdl:input>
			<wsdl:output>
				<soap:body parts="parameters" use="literal"/>
			</wsdl:output>
		</wsdl:operation>
	</wsdl:binding>

	<!-- Service definition -->
	<wsdl:service name="ReportIncidentService">
		<wsdl:port name="ReportIncidentPort" binding="tns:ReportIncidentBinding">
			<soap:address location="http://reportincident.example.camel.apache.org"/>
		</wsdl:port>
	</wsdl:service>

</wsdl:definitions>
{code}
h3. CXF wsdl2java
Then we integration the CXF wsdl2java generator in the 

CXF wsdl2java

Then we integration the CXF wsdl2java generator in the pom.xml

...

so

...

we

...

have

...

CXF

...

generate

...

the

...

needed

...

POJO

...

classes

...

for

...

our

...

webservice

...

contract.

...


However

...

at

...

first

...

we

...

must

...

configure

...

maven

...

to

...

live

...

in

...

the

...

modern

...

world

...

of

...

Java

...

1.5

...

so

...

we

...

must

...

add

...

this

...

to

...

the

...

pom.xml

Code Block
xml
xml

{code:xml}
			<!-- to compile with 1.5 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.5</source>
					<target>1.5</target>
				</configuration>
			</plugin>
{code}

And

...

then

...

we

...

can

...

add

...

the

...

CXF

...

wsdl2java

...

code

...

generator

...

that

...

will

...

hook

...

into

...

the

...

compile

...

goal

...

so

...

its

...

automatic

...

run

...

all

...

the

...

time:

Code Block
xml
xml

{code:xml}
			<!-- CXF wsdl2java generator, will plugin to the compile goal -->
			<plugin>
				<groupId>org.apache.cxf</groupId>
				<artifactId>cxf-codegen-plugin</artifactId>
				<version>${cxf.version}</version>
				<executions>
					<execution>
						<id>generate-sources</id>
						<phase>generate-sources</phase>
						<configuration>
							<sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
							<wsdlOptions>
								<wsdlOption>
									<wsdl>${basedir}/src/main/webapp/WEB-INF/wsdl/report_incident.xml</wsdl>
								</wsdlOption>
							</wsdlOptions>
						</configuration>
						<goals>
							<goal>wsdl2java</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
{code}

You

...

are

...

now

...

setup

...

and

...

should

...

be

...

able

...

to

...

compile

...

the

...

project.

...

So

...

running

...

the

...

mvn

...

compile

...

should

...

run

...

the

...

CXF

...

wsdl2java

...

and

...

generate

...

the

...

source

...

code

...

in

...

the

...

folder

...

&{basedir}/target/generated/src/main/java

...

that

...

we

...

specified

...

in

...

the

...

pom.xml

...

above.

...

Since

...

its

...

in

...

the

...

target/generated/src/main/java

...

maven

...

will

...

pick

...

it

...

up

...

and

...

include

...

it

...

in

...

the

...

build

...

process.

...

Configuration of the web.xml

...

Next

...

up

...

is

...

to

...

configure

...

the

...

web.xml

...

to

...

be

...

ready

...

to

...

use

...

CXF

...

so

...

we

...

can

...

expose

...

the

...

webservice.

...


TODO:

...

how

...

to

...

configure

...

the

...

web.xml,

...

spring

...

context

...

listener,

...

cxf

...

files

...

etc.

...

Running

...

our

...

webservice

...

TODO:

...

Adding

...

Jetty

...

to

...

pom

...


TODO:

...

Generation

...

the

...

code

...


TODO:

...

Adding

...

the

...

System.out

...

and

...

dummy

...

response

...


TODO:

...

Starting

...

Jetty

...

and

...

using

...

SoapUI

...

to

...

hit

...

the

...

webservice

...


TODO:

...

Starting

...

Jetty

...

in

...

debug

...

mode

...

so

...

we

...

can

...

debug

...

online

...

Adding

...

a

...

unit

...

test

...

TODO:

...

CXF

...

unit

...

test

...

End

...

of

...

part

...

1

...

TODO:

...

Conclusion.

...


Then

...