Red Hat JBoss Fuse 6.2.1 Tooling Tutorials

Red Hat JBoss Fuse 6.2.1 Tooling Tutorials

Red Hat JBoss Fuse 6.2.1

Tooling Tutorials

Building Solutions with Red Hat JBoss Fuse Tooling

JBoss A-MQ Docs Team

Red Hat JBoss Fuse 6.2.1 Tooling Tutorials

Building Solutions with Red Hat JBoss Fuse Tooling

JBo ss A-MQ Do cs Team

Co ntent Services fuse-do cs-suppo [email protected] m

Legal Notice

Co pyright © 20 15 Red Hat.

The text o f and illustratio ns in this do cument are licensed by Red Hat under a Creative

Co mmo ns Attributio n–Share Alike 3.0 Unpo rted license ("CC-BY-SA"). An explanatio n o f CC-

BY-SA is available at http://creativeco mmo ns.o rg/licenses/by-sa/3.0 /

. In acco rdance with CC-BY-SA, if yo u distribute this do cument o r an adaptatio n o f it, yo u must pro vide the URL fo r the o riginal versio n.

Red Hat, as the licenso r o f this do cument, waives the right to enfo rce, and agrees no t to assert,

Sectio n 4 d o f CC-BY-SA to the fullest extent permitted by applicable law.

Red Hat, Red Hat Enterprise Linux, the Shado wman lo go , JBo ss, MetaMatrix, Fedo ra, the Infinity

Lo go , and RHCE are trademarks o f Red Hat, Inc., registered in the United States and o ther co untries.

Linux ® is the registered trademark o f Linus To rvalds in the United States and o ther co untries.

Java ® is a registered trademark o f Oracle and/o r its affiliates.

XFS ® is a trademark o f Silico n Graphics Internatio nal Co rp. o r its subsidiaries in the United

States and/o r o ther co untries.

MySQL ® is a registered trademark o f MySQL AB in the United States, the Euro pean Unio n and o ther co untries.

No de.js ® is an o fficial trademark o f Jo yent. Red Hat So ftware Co llectio ns is no t fo rmally related to o r endo rsed by the o fficial Jo yent No de.js o pen so urce o r co mmercial pro ject.

The OpenStack ® Wo rd Mark and OpenStack Lo go are either registered trademarks/service marks o r trademarks/service marks o f the OpenStack Fo undatio n, in the United States and o ther co untries and are used with the OpenStack Fo undatio n's permissio n. We are no t affiliated with, endo rsed o r spo nso red by the OpenStack Fo undatio n, o r the OpenStack co mmunity.

All o ther trademarks are the pro perty o f their respective o wners.

Abstract

This guide co ntains a number o f simple tuto rials that demo nstrate ho w to use the to o ling pro vided by Red Hat JBo ss Fuse To o ling to develo p and test applicatio ns.

T able of Cont ent s

Table of Contents

PREREQ UISITES

DO WNLO ADING AND INSTALLING THE PREFABRICATED MESSAG E FILES

DO WNLO ADING AND INSTALLING THE PREFABRICATED CAMEL CO NTEXT FILES

4

4

4

G O ALS

PREREQ UISITES

CREATING THE FUSE PRO JECT

CREATING THE NEW RO UTING CO NTEXT

CREATING THE RO UTE

CREATING TEST MESSAG ES

NEXT STEPS

FURTHER READING

G O ALS

PREREQ UISITES

RUNNING THE RO UTE

VERIFYING THE RO UTE

FURTHER READING

G O ALS

PREREQ UISITES

ADDING AND CO NFIG URING A CO NTENT-BASED RO UTER

ADDING AND CO NFIG URING LO G G ING

ADDING AND CO NFIG URING MESSAG E HEADERS

ADDING AND CO NFIG URING AN O THERWISE BRANCH

NEXT STEPS

FURTHER READING

G O ALS

PREREQ UISITES

RECO NFIG URING THE EXISTING RO UTE FO R DIRECT CO NNECTIO N

ADDING THE SECO ND RO UTE

BUILDING AND CO NFIG URING THE USA BRANCH O F THE SECO ND RO UTE

BUILDING AND CO NFIG URING THE G REAT BRITAIN BRANCH O F THE SECO ND RO UTE

BUILDING AND CO NFIG URING THE G ERMANY BRANCH O F THE SECO ND RO UTE

BUILDING AND CO NFIG URING THE FRANCE BRANCH O F THE SECO ND RO UTE

SAVING THE NEW RO UTING CO NTEXT

NEXT STEPS

FURTHER READING

G O ALS

PREREQ UISITES

SETTING BREAKPO INTS

STEPPING THRO UG H THE CBRRO UTE RO UTING CO NTEXT

CHANG ING THE VALUE O F A VARIABLE

NEXT STEPS

34

36

37

38

40

32

32

32

33

42

43

23

23

23

25

26

27

30

31

20

20

20

21

22

17

19

19

8

11

6

6

13

47

52

58

44

44

44

1

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

G O ALS

PREREQ UISITES

ACCESSING FUSE INTEG RATIO N PERSPECTIVE

STARTING MESSAG E TRACING

DRO PPING MESSAG ES O N THE RUNNING CBRRO UTE PRO JECT

INITIALIZING AND CO NFIG URING MESSAG ES VIEW

ARRANG ING DIAG RAM VIEW

STEPPING THRO UG H MESSAG E TRACES

FINISHING UP

NEXT STEPS

O VERVIEW

G O ALS

PREREQ UISITES

DELETING THE EXISTING TEST CASE

CREATING THE NEW TEST CASE

MO DIFYING THE CAMELCO NTEXTXMLTEST FILE

MO DIFYING THE PO M.XML FILE

RUNNING THE JUNIT TEST

FURTHER READING

G O ALS

PREREQ UISITES

DEFINING A RED HAT JBO SS FUSE SERVER

CO NFIG URING THE PUBLISHING O PTIO NS

STARTING UP RED HAT JBO SS FUSE SERVER

CO NNECTING TO THE JBO SS FUSE 6 .2 RUNTIME SERVER

UNINSTALLING THE CBRRO UTE PRO JECT

70

74

78

8 1

8 2

6 9

6 9

6 9

70

6 2

6 3

6 5

6 5

59

59

59

6 1

6 6

6 8

8 4

8 4

8 4

8 9

9 0

9 2

9 3

2

T able of Cont ent s

3

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

CHAPTER 1. USING THE FUSE TOOLING RESOURCE FILES

Ab st ract

Experienced users may want to focus only on the tutorials that demonstrate the tooling's new features. To do so, you need to download and install the requisite resource files. The prefabricated message files are used by all tutorials, but the prefabricated Camel Context

files are specific to particular tutorials. With the exception of Chapter 2, To Create a New

Route

and Chapter 8, To Test a Route with JUnit , using these prefabricated resource files

enables you to complete most tutorials in any order. Without them, you must complete each tutorial sequentially, as the code generated by one tutorial is the starting point for the next tutorial.

PREREQUISIT ES

You must complete Chapter 2, To Create a New Route

, to create the project, the new routing context, and the folder that will hold the test messages. The code generated by this tutorial is

used by Chapter 3, To Run a Route and by

Chapter 4, To Add a Content-Based Router

.

You must successfully complete Chapter 8, To Test a Route with JUnit to generate a valid

JUnit test case before you can successfully complete Chapter 9, To Publish a Fuse Project to

Red Hat JBoss Fuse

.

DOWNLOADING AND INST ALLING T HE PREFABRICAT ED

MESSAGE FILES

Six prefabricated message files named messag e1. xml , messag e2. xml ,...,

messag e6 . xml are used in all of the tutorials. These files are provided in a downloadable

Messag es. zi p file. Follow the instructions for downloading and installing the messages in

the section called “ Creating test messages”

.

DOWNLOADING AND INST ALLING T HE PREFABRICAT ED CAMEL

CONT EXT FILES

Two prefabricated Camel Context files named camel C o ntext5. xml , and

camel C o ntext6 . xml are used in one or more of the tutorials. These files are provided in a downloadable .zip file.

1. Click here to download the camel C o ntexts. zi p file.

2. Unzip the camel C o ntexts. zi p file in a convenient location external to the

CBRroute project's workspace.

3. Delete the existing camel C o ntext. xml file from the

C BR ro ute/src/mai n/reso urces/O SG I-INF/bl uepri nt/ folder.

4. Install the camel C o ntext#. xml file that corresponds to the tutorial that you want to

4

CHAPT ER 1 . USING T HE FUSE T O O LING RESO URCE FILES

Install the camel C o ntext#. xml file that corresponds to the tutorial that you want to complete in the vacated C BR ro ute/src/mai n/reso urces/O SG I-

INF/bl uepri nt/ folder.

Use prefabricat ed Camel Cont ext file: camel C o ntext5. xml

T o complet e t ut orials:

To Ad d Ano ther Ro ute to the CBR

Ro uting Co ntext

camel C o ntext6 . xml

To Deb ug a Ro uting Co ntext

To Trace a Messag e Thro ug h a Ro ute

To Test a Ro ute with JUnit

5. Rename the camel C o ntext#. xml file camel C o ntext. xml .

6. In the Red Hat JBoss Fuse: Tooling Tutorials guide, follow the instructions for completing the target tutorial.

5

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

CHAPTER 2. TO CREATE A NEW ROUTE

Ab st ract

This tutorial walks you through the process of creating a new Fuse project, adding a route to it, and adding two endpoints to the route. It assumes that you have already set up your workspace and that Red Hat JBoss Fuse Tooling is running inside Red Hat JBoss

Developer Studio.

GOALS

In this tutorial you will: create a Fuse project create a new routing context create a route add endpoints to the route connect the endpoints configure the endpoints create a folder in your project to store test messages that you create for your route create the test messages

PREREQUISIT ES

No t e

You can use Fuse Integ rati o n perspective to work through all of the tutorials in this guide. However, because JBo ss perspective provides more room for the route editor's canvas to expand as you build the routing context, this and other tutorials use JBo ss perspective.

As you proceed through the remaining tutorials, you may find that you prefer using

Fuse Integ rati o n perspective exclusively.

When you first start up JBoss Developer Studio, it opens in JBo ss perspective, as shown in

Figure 2.1, “ JBoss View on initial startup”

.

Fig u re 2.1. JBo ss View o n in it ial st art u p

6

CHAPT ER 2 . T O CREAT E A NEW RO UT E

To provide more space for the canvas to expand as you build your projects:

1. Close the JBo ss C entral tab.

No t e

You can reopen a view whenever you need it. You can also drag the border of a view or panel to increase or decrease the space it occupies in the workspace.

2. Close the JMX Navi g ato r view at bottom, left of the workspace.

3. Drag O utl i ne view from top, right of the workspace, and drop it in the spot previously occupied by the JMX Navi g ato r view.

Your JBo ss perspective should now look like that shown in Figure 2.2, “ JBoss View rearranged ” :

Fig u re 2.2. JBo ss View rearran g ed

7

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

8

No t e

You can restore an open perspective to its original, default layout at any time by right-clicking the perspective's icon on the menubar to open its context menu, and then clicking Reset .

CREAT ING T HE FUSE PROJECT

To create a Fuse project, in JBo ss perspective:

1. On the Toolbar, select FileNewFu se Pro ject to open the New Fuse

pro ject wizard, as shown in

Figure 2.3

.

Fig u re 2.3. New Fu se p ro ject lo cat io n p ag e

CHAPT ER 2 . T O CREAT E A NEW RO UT E

2. Enter C BR ro ute in the P ro ject Name field.

3. Click Next> to open the New Fuse P ro ject details page, as shown in

Figure 2.4

.

Fig u re 2.4 . New Fu se p ro ject d et ails p ag e

4. Select camel -archetype-bl uepri nt.

9

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

4. Select camel -archetype-bl uepri nt.

5. Enter tuto ri al in the G ro up Id : field.

6. Enter cbr-ro ute in the Arti fact Id : field.

7. The Versi o n: field defaults to 1. 0 . 0 -SNAP SHO T . To change it, enter a different version identifier.

8. The P ackag e: field defaults to tuto ri al . cbr. ro ute, the name of the package that contains camel -archetype-bl uepri nt. To include the route in a different package, enter the name of that package.

9. Click Fi ni sh.

No t e

Click No when the O pen Asso ci ated P erspecti ve? dialog asks whether you want to open the Fuse Integ rati o n perspective now.

This procedure creates a Fuse project, C BR ro ute, in P ro ject Expl o rer that

contains everything needed to create and run routes. As shown in Figure 2.5

, the

files generated for C BR ro ute include:

C BR ro ute/po m. xml (Maven project file)

C BR ro ute/src/mai n/reso urces/O SG I-INF/bl uepri nt/bl uepri nt. xml

(Blueprint XML file containing the routing rules)

Fig u re 2.5. G en erat ed p ro ject f iles

10

No t e

When you create a new project, the Fuse Tooling downloads from the Maven repository all of the files it needs to build the project. This operation can take several minutes.

CHAPT ER 2 . T O CREAT E A NEW RO UT E

CREAT ING T HE NEW ROUT ING CONT EXT

To create the new routing context:

1. In P ro ject Expl o rer, locate C BR ro ute/src/mai n/reso urces/O SG I-

INF/bl uepri nt/bl uepri nt. xml .

2. Right-click it to open the context menu, then select D el ete.

You're going to replace the old bl uepri nt. xml file with your own to create a new route.

3. In the D el ete dialog, click O K to confirm the operation.

4. In P ro ject Expl o rer, select C BR ro ute/src/mai n/reso urces/O SG I-

INF/bl uepri nt.

5. Right-click it to open the context menu.

6. Select NewCamel XML File to open the C amel XML Fi l e wizard, as shown in

Figure 2.6

.

Fig u re 2.6 . Camel XML File wiz ard

7. Check that /C BR ro ute/src/mai n/reso urces/O SG I-INF/bl uepri nt appears in the C o ntai ner: field. Otherwise enter it manually, or select it using the

button.

11

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

No t e

The button opens a dialog that displays the folders of all active projects, which you can browse to find and select the files you need.

8. Check that camel C o ntext. xml appears in the Fi l e Name: field. Otherwise enter it manually.

9. Check that O SG I Blu ep rin t appears in the Framewo rk field, or select it from the field's drop-down list.

10. Click Fi ni sh.

The camelContext.xml file opens in the route editor's D esi g n view, displayed as an

empty canvas, as shown in Figure 2.7

.

Fig u re 2.7. New camelCo n t ext .xml f ile in Desig n view

12

11. Click the So urce tab at the bottom, left of the canvas to open the new

camel C o ntext. xml file in the route editor's So urce view, as shown in

Figure 2.8,

“ New camelContext file in source view” .

Fig u re 2.8. New camelCo n t ext f ile in so u rce view

CHAPT ER 2 . T O CREAT E A NEW RO UT E

CREAT ING T HE ROUT E

To create the route:

1. Click the D esi g n tab at the bottom, left of the canvas to return to the route editor's

D esi g n view.

2. Drag a Fi l e component ( ) from the P al ette's C o mpo nents drawer to the canvas.

No t e

The Fi l e component changes to a fi l e: d i recto ryNam. . . node on the canvas.

3. Drag another Fi l e component from the P al ette's C o mpo nents drawer to the canvas.

4. Select the first fi l e: d i recto ryName node you dragged onto the canvas.

The P ro perti es editor, located below the canvas, displays the node's property fields for editing.

5. In the P ro perti es editor, select the Ad vanced tab:

You need to create a folder for the project's source data and enter that folder's name in the D i recto ry Name field.

13

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

6. In P ro ject Expl o rer, right-click C BR ro ute/src to open the context menu.

7. Select NewFo ld er to open the New Fo l d er wizard:

14

8. Check that CBRroute/src appears in the Enter o r sel ect the parent fo l d er: field. Otherwise enter it manually, or select it from the graphical representation of the project's hierarchy.

9. In the Fo l d er name: field, enter data, and then click Fi ni sh.

The new d ata folder appears in P ro ject Expl o rer, under the src folder:

10. Return to the Ad vanced tab, in the P ro perti es editor.

11. On the P ath tab, click the button next to the D i recto ry Name field, to browse to the src/d ata folder you just created in your C BR R o ute project.

12. Click O pen.

The full path appears in the D i recto ry Name field.

13. Delete everything in the path string, except src/d ata:

CHAPT ER 2 . T O CREAT E A NEW RO UT E

14. Click the C o nsumer tab, and enable the No o p option by clicking its check box.

The No o p option prevents the message#.xml files being deleted from the src/d ata folder, and it enables idempotency to ensure that each message#.xml file is consumed only once.

15. Click the G eneri c tab to open the file node's D etai l s page

Fig u re 2.9 . File Det ails p ag e

The tooling automatically populates the Uri field with the D i recto ry name and

No o p properties you configured on the Ad vanced tab.

16. Select the second fi l e: d i recto ryName node you dragged onto the canvas.

17. In the G eneri c tab's Uri field, replace directoryName with

targ et/messag es/o thers. Leave the other fields blank.

Fig u re 2.10. File d est in at io n p ro p ert y ed it o r

No t e

The targ et/messag es/o thers folder will be created at runtime.

15

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

18. On the canvas, select the first file: node (fi l e: src/d ata?no o p= true), and drag it's connector arrow ( ) to the second file node

(fi l e: targ et/messag es/o thers), then release it.

A segmented line connects the two endpoints, as shown in Figure 2.11

.

Fig u re 2.11. Co mp let ed ro u t e, d iag ram view

16

No t e

You can drag the line's bendpoint (orange dot) to change the angle of the line's segments. Doing so creates two new bendpoints, one on either side of the original. This behavior enables you to easily adjust your diagram to accommodate increasingly complex routes.

19. To quickly align the connected endpoints, right-click the canvas to open the context menu, and then select Layo u t Diag ram.

20. Select FileSave to save the route.

21. Click the So urce tab at bottom, left of the canvas.

So urce view displays the XML for the route. The camel C o ntext element will look

like Example 2.1

.

Examp le 2.1. XML f o r CBRro u t e

<?xml version="1.0" encoding="UTF-8"?>

<blueprint xmlns = "http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:camel = "http://camel.apache.org/schema/blueprint" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.osgi.org/xmlns/blueprint/v1.0.0

http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd

http://camel.apache.org/schema/blueprint

http://camel.apache.org/schema/blueprint/camelblueprint.xsd" >

<camelContext trace = "false" xmlns = "http://camel.apache.org/schema/blueprint" >

CHAPT ER 2 . T O CREAT E A NEW RO UT E

<route>

<from uri = "file:src/data?noop=true" />

<to uri = "file:target/messages/others" />

</route>

</camelContext>

</blueprint>

CREAT ING T EST MESSAGES

Before you can run your route, you need to create test messages to send through it.

1. In P ro ject Expl o rer, right-click C BR ro ute to open the context menu.

2. Click NewFu se Messag e to open the Fuse Messag e Fi l e wizard:

3. Check that CBRroute/src/data appears in the Enter o r sel ect the parent

fo l d er field. Otherwise enter it manually, or select it from the graphical representation of the project's hierarchy.

4. In Fi l e Name: , enter messag e1. xml .

5. Click Fi ni sh to open the test message, messag e1. xml , in D esi g n View:

17

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

6. Click the So urce tab at the bottom, right of the canvas to switch to So urce view:

18

7. In So urce view, enter this text:

<?xml version="1.0" encoding="UTF-8"?>

<order>

<customer>

<name> Brooklyn Zoo </name>

<city> Brooklyn </city>

<country> USA </country>

</customer>

<orderline>

<animal> wombat </animal>

<quantity> 15 </quantity>

<maxAllowed> 25 </maxAllowed>

</orderline>

</order>

8. Save the file.

CHAPT ER 2 . T O CREAT E A NEW RO UT E

9. Click Messages.zip

to download the five remaining preconstructed test message files

(messag e2. xml through messag e6 . xml ), and then unpack them into the

C BR ro ute/src/d ata folder. You will use all six test messages in the remaining

Fuse Tooling tutorials.

Table 2.1

shows the contents of each preconstructed message file.

T ab le 2.1. Preco n st ru ct ed t est messag es

msg#

2

3

4

5

6

< name> < cit y>

San

Dieg o

Zo o

Lo nd o n

Zo o

Bristo l

Zo o

Paris

Zo o

San

Dieg o

Lo nd o n

Bristo l

Paris

Hellab ru nn

G ard ens

Munich

< count r y>

USA

< animal> < quant it y>

< maxAllo wed>

g iraffe 3 2

G reat

Britain

G reat

Britain

France

G ermany p eng uin emu g iraffe p eng uin

12

5

2

18

20

4

2

20

NEXT ST EPS

After you have created and designed your route, you can run it by deploying it into your local Apache Camel runtime, as described in

Chapter 3, To Run a Route

.

FURT HER READING

To learn more about: using the editor, see Red Hat JBoss Fuse Tooling: JBoss Fuse Tooling User Guide at https://access.redhat.com/documentation/en-

US/Red_Hat_JBoss_Fuse/6.2.1/html/Tooling_User_Guide/RiderDevPart.html

.

Apache Camel endpoints, see Red Hat JBoss Fuse: Component Reference .

19

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

CHAPTER 3. TO RUN A ROUTE

Ab st ract

This tutorial walks you through the process of running a route.

GOALS

In this tutorial you will: run a route as a local Apache Camel Context (without tests) send messages through the route examine the messages received by the endpoints

PREREQUISIT ES

To complete this tutorial you will need the CBRroute project created in Chapter 2, To Create a

New Route

.

RUNNING T HE ROUT E

To run the route:

1. Open the CBRro u t e project you created in the section called “ Creating the Fuse project” .

2. In P ro ject Expl o rer, select C BR ro ute/src/mai n/reso urces/O SG i -

INF/bl uepri nt/camel C o ntext. xml .

3. Right-click it to open the context menu, then select Ru n AsLo cal Camel

Co n t ext ( wit h o u t t est s) .

No t e

If you select Lo cal Camel Co n t ext instead, the tooling automatically runs the routing context against the supplied JUnit test, and it will fail. In the

Chapter 8, To Test a Route with JUnit tutorial, you will replace the supplied

JUnit test with one you create for the this project.

The C o nso l e panel opens to display log messages that reflect the progress of the project's execution. At the beginning, Maven downloads the resources necessary to update the local Maven repository, which may take a few minutes.

20

CHAPT ER 3. T O RUN A RO UT E

Messages similar to the following indicate that the route executed successfully.

[INFO] Starting Camel ... [mel.test.blueprint.Main.main()]

MainSupport INFO Apache Camel 2.13.2 starting

[mel.test.blueprint.Main.main()] Activator INFO Camel activator starting [mel.test.blueprint.Main.main()] Activator

INFO Camel activator started [mel.test.blueprint.Main.main()]

BlueprintExtender INFO No quiesce support is available, so blueprint components will not participate in quiesce operations [ Blueprint Extender: 1] BlueprintContainerImpl

INFO Bundle cbr-route is waiting for namespace handlers

[http://camel.apache.org/schema/blueprint] [ Blueprint

Extender: 1] BlueprintCamelContext INFO Apache Camel 2.13.2

(CamelContext: blueprintContext) is starting [ Blueprint

Extender: 1] ManagedManagementStrategy INFO JMX is enabled

[heysmbp.home:1099/jmxrmi/camel] DefaultManagementAgent INFO

JMX Connector thread started and listening at: service:jmx:rmi:///jndi/rmi://janemurpheysmbp.home:1099/jmxrmi

/camel [ Blueprint Extender: 1] BlueprintCamelContext INFO

AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance. [ Blueprint

Extender: 1] BlueprintCamelContext INFO StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/streamcaching.html [ Blueprint Extender: 1] FileEndpoint INFO

Endpoint is configured with noop=true so forcing endpoint to be idempotent as well [ Blueprint Extender: 1] FileEndpoint

INFO Using default memory based idempotent repository with cache max size: 1000 [ Blueprint Extender: 1] XPathBuilder

INFO Created default XPathFactory [email protected] 46e48 d4 [ Blueprint Extender: 1] BlueprintCamelContext INFO Route:

Route1 started and consuming from: Endpoint[file://src/data?

noop=true] [ Blueprint Extender: 1] BlueprintCamelContext INFO

Total 1 routes, of which 1 is started. [ Blueprint Extender:

1] BlueprintCamelContext INFO Apache Camel 2.13.2

(CamelContext: blueprintContext) started in 1.073 seconds

4. To shutdown the route, click located at the top, right of the C o nso l e panel.

VERIFYING T HE ROUT E

To verify that the route executed properly:

1. In P ro ject Expl o rer, select C BR ro ute.

2. Right-click it to open the context menu, then select Ref resh .

3. In P ro ject Expl o rer, locate the folder targ et/messag es/ and expand it, as shown in

Figure 3.1

.

21

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

Fig u re 3.1. T arg et messag e d est in at io n in Pro ject Exp lo rer t ree

4. Verify that the targ et/messag es/o thers folder contains the six message files,

messag e1. xml through messag e6 . xml .

5. Double-click messag e1. xml to open it in the editor's D esi g n view, then select the

So urce tab at the bottom, left of the canvas to see the xml code.

It's contents should match that shown in

Example 3.1

.

Examp le 3.1. Co n t en t s o f messag e1.xml

<?xml version="1.0" encoding="UTF-8"?>

<order>

<customer>

<name> Brooklyn Zoo </name>

<city> Brooklyn </city>

<country> USA </country>

</customer>

<orderline>

<animal> wombat </animal>

<quantity> 15 </quantity>

<maxAllowed> 25 </maxAllowed>

</orderline>

</order>

22

FURT HER READING

To learn more about: configuring runtime profiles, see Red Hat JBoss Fuse Tooling: JBoss Fuse Tooling User

Guide at https://access.redhat.com/documentation/en-

US/Red_Hat_JBoss_Fuse/6.2.1/html/Tooling_User_Guide/RiderEditRunProfile.html

.

deploying Apache Camel applications see Red Hat JBoss Fuse: Deploying into the

Container .

CHAPT ER 4 . T O ADD A CO NT ENT - BASED RO UT ER

CHAPTER 4. TO ADD A CONTENT-BASED ROUTER

Ab st ract

This tutorial walks you through adding a content-based router with logging to a route.

GOALS

In this tutorial you will: add a content-based router to your route configure the content-based router add a log endpoint to each output branch of the content-based router add a SetHeader EIP after each log endpoint add an Otherwise branch to the content-based router

PREREQUISIT ES

To complete this tutorial you will need the CBRro u t e project you created in Chapter 2, To

Create a New Route

.

ADDING AND CONFIGURING A CONT ENT -BASED ROUT ER

To add and configure a content-based router for your route:

1. In P ro ject Expl o rer, double-click C BR ro ute/src/mai n/reso urces/O SG I-

INF/bl uepri nt/camel C o ntext. xml to open your C BR ro ute project.

2. Select the connector joining the two f ile: nodes fi l e: src/d ata?no o p= true and

fi l e: targ et/messag es/o thers.

3. Right-click it to open the context menu, and select Remo ve to delete the connector.

No t e

Alternatively, you can delete the connector by selecting it, then selecting

Delet e from the toolbar's Ed it menu.

23

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

4. On the canvas, select the terminal f ile: node, fi l e: targ et/messag es/o thers, and in the P ro perti es editor, change the Uri and Id properties to:

Uri : fi l e: targ et/messag es/val i d O rd ers

Id : to Val i d

Then drag the node out of the way. You will connect it to another node later in this tutorial.

5. On the canvas, select the starting fi l e: node, fi l e: src/d ata?no o p= true, and right-click it to open the context menu.

6. Select Ad d Ro u t in g Ch o ice.

A cho i ce node ( ) appears on the canvas connected to the starting fi l e: node.

7. In the P ro perti es editor, enter cho i ce1 in the Id field.

8. On the canvas, select the cho i ce node, then right-click it to open the context menu.

9. Select Ad d Ro u t in g Wh en .

A when node appears on the canvas connected to the cho i ce node. The

P ro perti es editor opens, displaying the when node's property fields for you to edit, as shown:

24

No t e

When a required property is blank, the P ro perti es editor marks it with .

The number of properties that require configuring is displayed in the title bar. Error icons and message disappear when you configure the required properties.

CHAPT ER 4 . T O ADD A CO NT ENT - BASED RO UT ER

10. In the Expressi o n field, enter /o rd er/o rd erl i ne/q uanti ty/text() >

/o rd er/o rd erl i ne/maxAl l o wed /text() .

This expression determines which messages will transit this path in the route.

11. From the Lang uag e drop-down menu, select xpath.

12. In the Id field, enter when1.

Figure 4.1

shows the when1 node configured.

Fig u re 4 .1. wh en 1 co n f ig u rat io n

ADDING AND CONFIGURING LOGGING

To add logging to your route:

1. On the canvas, select the when1 node, and then right-click it to open the context menu.

2. Select Ad d Co mp o n en t sLo g .

A lo g node appears on the canvas, connected to the wh en 1 node. The

P ro perti es editor opens, displaying the l o g node's property fields for you to edit.

3. In the Messag e field, enter q uanti ty req uested exceed s the maxi mum

al l o wed - co ntact custo mer.

4. In the Id field, enter l o g 1.

Figure 4.2

shows the lo g 1 node configured.

Fig u re 4 .2. Lo g 1 co n f ig u rat io n

25

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

No t e

In Fuse Integ rati o n perspective's Messag es Vi ew, the tooling inserts the contents of the log node's Id field in the T race No d e Id column for

message instances, when tracing is enabled on the route (see Figure 7.11,

“ Fuse Integration perspective's message tracing components” ). In the

C o nso l e, it adds the contents of the log node's Messag e field to the log data whenever the route runs.

ADDING AND CONFIGURING MESSAGE HEADERS

To add and configure message headers:

1. On the canvas, select the l o g 1 node, and then right-click it to open the context menu.

2. Select Ad d T ran sf o rmat io n Set Head er.

A set Head er node ( ) appears on the canvas, connected to the lo g 1 node. The

P ro perti es editor opens, displaying the setHead er node's property fields for you to edit, as shown:

26

3. In the Head er Name field, enter D esti nati o n.

4. In the Expressi o n field, enter Inval i d O rd ers.

5. Select co n st an t from the Lan g u ag e drop-down menu.

6. In the Id field, enter setHead 1.

CHAPT ER 4 . T O ADD A CO NT ENT - BASED RO UT ER

Figure 4.3

shows the set Head 1 node configured.

Fig u re 4 .3. set Head 1 co n f ig u rat io n

7. On the canvas, select the setHead 1 node, and then right-click it to open the context menu.

8. Select Ad d Co mp o n en t sFile.

A f ile:d irect o ryName node appears on the canvas, connected to the set Head 1 node. The P ro perti es editor opens, displaying the fi l e: d i recto ryName node's property fields for you to edit.

9. On the G eneri c tab, replace directoryName with

targ et/messag es/i nval i d O rd ers in the Uri field, and enter to Inval i d in the

Id field.

ADDING AND CONFIGURING AN OT HERWISE BRANCH

To add and configure the otherwise branch to your route:

1. On the canvas, reselect the Ch o ice node, then right-click it to open the context menu.

2. Select Ad d Ro u t in g O t h erwise.

An o t h erwise node appears on the canvas, connected to the ch o ice node. The

P ro perti es editor opens, displaying the o therwi se node's property fields for you to edit.

3. In the Id field, enter el se2 .

The else2 node will eventually route to the terminal f ile: node

(fi l e: targ et/messag es/val i d O rd ers) any message that does not match the

XPath expression set for the wh en 1 node.

4. On the canvas, select the el se2 node, and then right-click it to open the context menu.

27

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

5. Select Ad d Co mp o n en t sLo g .

A lo g node appears on the canvas, connected to the else2 node. The P ro perti es editor opens, displaying the l o g node's property fields for you to edit.

6. In the Messag e field, enter val i d o rd er - pro cess, and in the Id field, enter

l o g 2.

7. On the canvas, select the l o g 2 node, and then right-click it to open the context menu.

8. Select Ad d T ran sf o rmat io n Set Head er.

A set Head er node ( ) appears on the canvas, connected to the lo g 2 node. The

P ro perti es editor opens, displaying the setHead er node's property fields for you to edit.

9. In the Head er Name field, enter D esti nati o n.

10. In the Expressi o n field, enter D i spatcher.

11. Select co n st an t from the Lan g u ag e drop-down menu.

12. In the Id field, enter setHead 2.

13. On the canvas, drag the terminal fi l e: node,

fi l e: targ et/messag es/val i d O rd ers, close to the setHead 2 node.

14. Select the set Head 2 node, and then drag its connector arrow ( ) to the terminal

fi l e: node and release it.

15. To quickly realign all of the nodes on the canvas, right-click the canvas to open the context menu, and then select Layo u t Diag ram.

The route on the canvas should resemble Figure 4.4

.

Fig u re 4 .4 . Co mp let ed co n t en t - b ased ro u t er wit h lo g s an d messag e h ead ers

28

CHAPT ER 4 . T O ADD A CO NT ENT - BASED RO UT ER

16. On the toolbar, select FileSave to save the completed route.

17. Click the So urce tab at the bottom, left of the canvas to display the XML for the route.

The camel C o ntext element will look like that shown in

Example 4.1

.

Examp le 4 .1. XML f o r co n t en t - b ased ro u t er

<?xml version="1.0" encoding="UTF-8"?>

<blueprint xmlns = "http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:camel = "http://camel.apache.org/schema/blueprint" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.osgi.org/xmlns/blueprint/v1.0.0

http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd

http://camel.apache.org/schema/blueprint

http://camel.apache.org/schema/blueprint/camelblueprint.xsd" >

<camelContext trace = "false" xmlns = "http://camel.apache.org/schema/blueprint" >

<route>

<from uri = "file:src/data?noop=true" />

<choice id = "choice1" >

<when id = "when1" >

<xpath> /order/orderline/quantity/text() >

/order/orderline/maxAllowed/text() </xpath>

<log message = "quantity requested exceeds maximum allowed - contact customer" id = "log1" />

<setHeader headerName = "Destination" id = "setHead1" >

<constant> InvalidOrders </constant>

</setHeader>

<to uri = "file:target/messages/invalidOrders" id = "toInvalid" />

</when>

<otherwise id = "else2" >

<log message = "valid order - process" id = "log2" />

<setHeader headerName = "Destination" id = "setHead2" >

29

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

<constant> Dispatcher </constant>

</setHeader>

<to uri = "file:target/messages/validOrders" id = "toValid" />

</otherwise>

</choice>

</route>

</camelContext>

</blueprint>

NEXT ST EPS

You can run the new route as described in the section called “ Running the route”

.

After you run it, you can easily verify whether the route executed properly by checking the target destinations in P ro ject Expl o rer:

1. Select C BR ro ute.

2. Right-click it to open the context menu, then select Ref resh .

3. Under the project root node (C BR ro ute), locate the folder targ et/messag es/ and expand it, as shown in

Figure 4.5

.

Fig u re 4 .5. T arg et messag e d est in at io n s in Pro ject Exp lo rer

30

4. Check that the targ et/messag es/i nval i d O rd ers folder contains

messag e2. xml and messag e4 . xml .

In these messages, the value of the quantity element should exceed the value of the maxAllowed element.

5. Check that the targ et/messag es/val i d O rd ers folder contains the four message files that contain valid orders: messag e1. xml , messag e3. xml , messag e5. xml and messag e6 . xml .

In these messages, the value of the quantity element should be less than or equal to the value of the maxAllowed element.

CHAPT ER 4 . T O ADD A CO NT ENT - BASED RO UT ER

No t e

To view message content, double-click each message to open it in the route editor's xml editor.

FURT HER READING

To learn more about message enrichment see: the Red Hat JBoss Fuse: Apache Camel Development Guide the Red Hat JBoss Fuse 6.x documentation

31

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

CHAPTER 5. TO ADD ANOTHER ROUTE TO THE CBR

ROUTING CONTEXT

Ab st ract

This tutorial walks you through adding a second route to the camel C o ntext. xml file in the

CBRroute project. The second route: takes messages directly from the terminal end of the first route's otherwise branch sorts the messages according to customers' country sends each message to the corresponding C BR ro ute/targ et/messag es/<co untry> directory

GOALS

In this tutorial you will: reconfigure the existing route for direct connection to a second route add a second route to your camelContext configure the new route to take messages directly from the otherwise branch of the first route add a content-based router to the new route add and configure a message header, logging, and target destination to each output branch of the new route's content-based router

PREREQUISIT ES

To complete this tutorial you will need the CBRro u t e project you modified in Chapter 4, To

Add a Content-Based Router

.

No t e

If you skipped any tutorial after Chapter 2, To Create a New Route

, you can use the prefabricated camel C o ntext5. xml file to work through this tutorial (for details,

see Chapter 1, Using the Fuse Tooling Resource Files ).

32

RECONFIGURING T HE EXIST ING ROUT E FOR DIRECT

CONNECT ION

CHAPT ER 5. T O ADD ANO T HER RO UT E T O T HE CBR RO UT ING CO NT EXT

To configure the existing route for direct connection with the new route:

1. Open your C BR ro ute/src/mai n/reso urces/O SG I-

INF/bl uepri nt/camel C o ntext. xml in the route editor.

2. Click the canvas to display the existing route's properties in the P ro perti es editor.

3. Enter R o ute1 in the Id field.

4. Select the terminal fi l e: node fi l e: targ et/messag es/to Val i d to display its properties in the P ro perti es editor.

5. In the Uri field, delete the existing text, and then enter

d i rect: O rd erFul fi l l ment.

6. In the Id field, enter to Ful fi l l .

ADDING T HE SECOND ROUT E

No t e

The route editor displays each route in a multiroute routing context on its own slice of canvas.

To add a route to the routing context:

1. Select Ro u t esAd d Ro u t e.

The tooling adds another route to your camelContext, and the route editor opens a clean canvas for you to construct the second route.

O utl i ne view, shown here, displays both routes and their components. Clicking on a route in O utl i ne view displays it on the route editor's canvas.

33

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

Or you can switch between routes by selecting Ro u t esRo u t e:RouteName on the menu bar, where RouteName is the string you entered in the route's Id field in the

P ro perti es editor.

2. Click the canvas to display the new route's properties in the P ro perti es editor.

3. Enter R o ute2 in the Id field.

BUILDING AND CONFIGURING T HE USA BRANCH OF T HE

SECOND ROUT E

With R o ute2 displayed on the route editor's canvas:

1. Drag an G eneri c element ( ) from the P al ette's C o mpo nents drawer onto the canvas.

2. In the P ro perti es editor, enter d i rect: O rd erFul fi l l ment in the Uri field.

3. Right-click the d i rect: O rd erFul fi . . . node to open the context menu, and select Ad d Ro u t in g Ch o ice.

4. In the P ro perti es editor, enter cho i ce2 in the Id field.

5. Right-click the cho i ce2 node to open the context menu, and select Ad d

Ro u t in g Wh en .

6. In the P ro perti es editor:

34

Enter /o rd er/custo mer/co untry = ' USA' in the Expressi o n field.

Select xpath from the Lang uag e drop-down menu.

Enter when/usa in the Id field.

7. Right-click the when/usa node to open the context menu, and select Ad d

T ran sf o rmat io n Set Head er.

8. In the P ro perti es editor:

CHAPT ER 5. T O ADD ANO T HER RO UT E T O T HE CBR RO UT ING CO NT EXT

Enter D esti nati o n in the Head er Name field.

Enter USA in the Expressi o n field.

Select co n st an t from the Lan g u ag e drop-down menu.

Enter setHead _usa in the Id field,

9. Right-click the setHead _usa node to open the context menu, and select Ad d

Co mp o n en t sLo g .

10. In the P ro perti es editor:

Enter Val i d o rd er - shi p ani mal s to USA custo mer in the Messag e field.

Enter l o g _usa in the Id field.

11. Right-click the l o g _usa node to open the context menu, and select Ad d

Co mp o n en t sFile.

12. In the P ro perti es editor:

35

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

Replace directoryName with targ et/messag es/USA in the Uri field.

Enter to US in the Id field.

The USA branch of R o ute2 should look like this:

36

BUILDING AND CONFIGURING T HE GREAT BRIT AIN BRANCH OF

T HE SECOND ROUT E

With R o ute2 displayed on the canvas:

1. Right-click the cho i ce2 node again to open the context menu, and select Ad d

Ro u t in g Wh en .

2. In the P ro perti es editor:

Enter /o rd er/custo mer/co untry = ' G reat Bri tai n' in the Expressi o n field.

Select xpath from the Lang uag e drop-down menu.

Enter when/g b in the Id field.

3. Right-click the when/g b node to open the context menu, and select Ad d

T ran sf o rmat io n Set Head er.

4. In the P ro perti es editor:

Enter D esti nati o n in the Head er Name field.

Enter UK in the Expressi o n field.

CHAPT ER 5. T O ADD ANO T HER RO UT E T O T HE CBR RO UT ING CO NT EXT

Select co n st an t from the Lan g u ag e drop-down menu.

EntersetHead _uk in the Id field,

5. Right-click the setHead _uk node to open the context menu, and select Ad d

Co mp o n en t sLo g .

6. In the P ro perti es editor:

Enter Val i d o rd er - shi p ani mal s to UK custo mer in the Messag e field.

Enter l o g _uk in the Id field.

7. Right-click the l o g _uk node to open the context menu, and select Ad d

Co mp o n en t sFile.

8. In the P ro perti es editor:

Replace directoryName with targ et/messag es/G reatBri tai n in the Uri field.

Enter to UK in the Id field.

The Great Britain branch of R o ute2 should look like this:

BUILDING AND CONFIGURING T HE GERMANY BRANCH OF T HE

SECOND ROUT E

With R o ute2 displayed on the canvas:

1. Right-click the cho i ce2 node again to open the context menu, and select Ad d

Ro u t in g Wh en .

2. In the P ro perti es editor:

Enter /o rd er/custo mer/co untry = ' G ermany' in the Expressi o n field.

Select xpath from the Lang uag e drop-down menu.

Enter when/g er in the Id field.

37

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

3. Right-click the when/g er node to open the context menu, and select Ad d

T ran sf o rmat io n Set Head er.

4. In the P ro perti es editor:

Enter D esti nati o n in the Head er Name field.

Enter G ermany in the Expressi o n field.

Select co n st an t from the Lan g u ag e drop-down menu.

Enter setHead _g er in the Id field,

5. Right-click the setHead _g er node to open the context menu, and select Ad d

Co mp o n en t sLo g .

6. In the P ro perti es editor:

Enter Val i d o rd er - shi p ani mal s to G ermany custo mer in the

Messag e field.

Enter l o g _g er in the Id field.

7. Right-click the l o g _g er node to open the context menu, and select Ad d

Co mp o n en t sFile.

8. In the P ro perti es editor:

Replace directoryName with targ et/messag es/G ermany in the Uri field.

Enter to G R in the Id field.

The Germany branch of R o ute2 should look like this:

38

BUILDING AND CONFIGURING T HE FRANCE BRANCH OF T HE

SECOND ROUT E

With R o ute2 displayed on the canvas:

CHAPT ER 5. T O ADD ANO T HER RO UT E T O T HE CBR RO UT ING CO NT EXT

1. Right-click the cho i ce2 node again to open the context menu, and select Ad d

Ro u t in g O t h erwise.

2. In the P ro perti es editor:

Enter el se/fr in the Id field.

3. Right-click the el se/fr node to open the context menu, and select Ad d

T ran sf o rmat io n Set Head er.

4. In the P ro perti es editor:

Enter D esti nati o n in the Head er Name field.

Enter France in the Expressi o n field.

Select co n st an t from the Lan g u ag e drop-down menu.

Enter setHead _fr in the Id field,

5. Right-click the setHead _fr node to open the context menu, and select Ad d

Co mp o n en t sLo g .

6. In the P ro perti es editor:

Enter Val i d o rd er - shi p ani mal s to France custo mer in the

Messag e field.

Enter l o g _fr in the Id field.

7. Right-click the l o g _fr node to open the context menu, and select Ad d

Co mp o n en t sFile.

8. In the P ro perti es editor:

Replace directoryName with targ et/messag es/France in the Uri field.

Enter to FR in the Id field.

39

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

The France branch of R o ute2 should look like this:

SAVING T HE NEW ROUT ING CONT EXT

1. On the toolbar, select FileSave to save the routing context.

The routes on the canvas should look like this:

Fig u re 5.1. Co mp let ed ro u t e1

Fig u re 5.2. Co mp let ed ro u t e2

4 0

2. Click the So urce tab at the bottom, left of the canvas to display the XML for the route.

CHAPT ER 5. T O ADD ANO T HER RO UT E T O T HE CBR RO UT ING CO NT EXT

The camel C o ntext element should look like that shown in

Example 5.1

.

Examp le 5.1. XML f o r d u al- ro u t e co n t en t - b ased ro u t er

<?xml version="1.0" encoding="UTF-8"?>

<blueprint xmlns = "http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:camel = "http://camel.apache.org/schema/blueprint" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://www.osgi.org/xmlns/blueprint/v1.0.0

http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd

http://camel.apache.org/schema/blueprint

http://camel.apache.org/schema/blueprint/camelblueprint.xsd" >

<camelContext trace = "false" xmlns = "http://camel.apache.org/schema/blueprint" >

<route id = "Route1" >

<from uri = "file:src/data?noop=true" />

<choice id = "choice1" >

<when id = "when1" >

<xpath> /order/orderline/quantity/text() >

/order/orderline/maxAllowed/text() </xpath>

<log message = "quantity requested exceeds maximum allowed - contact customer" id = "log1" />

<setHeader headerName = "Destination" id = "setHead1" >

<constant> InvalidOrders </constant>

</setHeader>

<to uri = "file:target/messages/invalidOrders" id = "toInvalid" />

</when>

<otherwise id = "else2" >

<log message = "valid order - process" id = "log2" />

<setHeader headerName = "Destination" id = "setHead2" >

<constant> Dispatcher </constant>

</setHeader>

<to uri = "direct:OrderFulfillment" id = "toFulfill" />

</otherwise>

</choice>

</route>

<route id = "Route2" >

<from uri = "direct:OrderFulfillment" />

<choice id = "choice2" >

<when id = "when/usa" >

<xpath> /order/customer/country = 'USA' </xpath>

<setHeader headerName = "Destination" id = "setHead_usa" >

<constant> USA </constant>

</setHeader>

<log message = "Valid order - ship animals to USA customer" id = "log_usa" />

<to uri = "file:target/messages/USA" id = "toUS" />

</when>

4 1

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

<when id = "when/gb" >

<xpath> /order/customer/country = 'Great

Britain' </xpath>

<setHeader headerName = "Destination" id = "setHead_uk" >

<constant> UK </constant>

</setHeader>

<log message = "Valid order - ship animals to UK customer" id = "log_uk" />

<to uri = "file:target/messages/GreatBritain" id = "toUK" />

</when>

<when id = "when/ger" >

<xpath> /order/customer/country = 'Germany' </xpath>

<setHeader headerName = "Destination" id = "setHead_ger" >

<constant> Germany </constant>

</setHeader>

<log message = "Valid order - ship animals to Germany customer" id = "log_ger" />

<to uri = "file:target/messages/Germany" id = "toGR" />

</when>

<otherwise id = "else/fr" >

<setHeader headerName = "Destination" id = "setHead_fr" >

<constant> France </constant>

</setHeader>

<log message = "Valid order - ship animals to France customer" id = "log_fr" />

<to uri = "file:target/messages/France" id = "toFR" />

</otherwise>

</choice>

</route>

</camelContext>

</blueprint>

NEXT ST EPS

You can run the new route as described in the section called “ Running the route”

.

Check the end of the Console's output. You should see these lines:

4 2

Check the target destinations in P ro ject Expl o rer to verify that the routes executed properly:

CHAPT ER 5. T O ADD ANO T HER RO UT E T O T HE CBR RO UT ING CO NT EXT

1. Select C BR ro ute.

2. Right-click it to open the context menu, then select Ref resh .

3. Expand the folder targ et/messag es/ as shown in Figure 5.3

. The messag e*. xml

files should be dispersed in your target destinations like this:

Fig u re 5.3. T arg et messag e d est in at io n s in Pro ject Exp lo rer

No t e

To view message content, double-click a message to open it in the route editor's xml editor.

FURT HER READING

To learn more about the direct component see the Red Hat JBoss Fuse: Apache Camel

Component Reference at Red Hat JBoss Fuse 6.x documentation

4 3

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

CHAPTER 6. TO DEBUG A ROUTING CONTEXT

Ab st ract

The Camel debugger works only on the routing context. The routing context and each node with a breakpoint set must have a unique ID. You can set them manually or let the tooling set them automatically.

GOALS

In this tutorial you will:

In So urce view, enter a unique ID for the camelContext element

In D esi g n view, set breakpoints on the nodes of interest in Route1

Switch to Route2, and set breakpoints on the nodes of interest

Invoke the Camel debugger

Step through the route, examining route and message variables as they change

Step through the route again, changing the value of message variables and observing the effects

PREREQUISIT ES

To complete this tutorial you will need the C BR ro ute project you updated in Chapter 5, To

Add Another Route to the CBR Routing Context

.

No t e

If you skipped any tutorial after Chapter 2, To Create a New Route

you can use the prefabricated camel C o ntext6 . xml file to work through this tutorial (for details,

see Chapter 1, Using the Fuse Tooling Resource Files ).

SET T ING BREAKPOINT S

You can set both conditional and unconditional breakpoints, but in this tutorial, you will set unconditional breakpoints only.

1. If necessary, open your C BR ro ute/src/mai n/reso urces/O SG I-

INF/bl uepri nt/camel C o ntext. xml in the route editor.

4 4

CHAPT ER 6 . T O DEBUG A RO UT ING CO NT EXT

By default, the route editor displays Route1 on the canvas.

2. Click the So urce tab at the bottom of the route editor to switch to So urce view.

3. In the camelContext element, add i d = "bl uepri ntC o ntext" like this:

<camelContext trace = "false" id = "blueprintContext" xmlns = "http://camel.apache.org/schema/blueprint" >

4. Click FileSave to save your routing context file.

5. Click the D esi g n tab at the bottom of the route editor to switch to Design view.

6. Select the cho i ce1 node, and then click its icon to set an unconditional breakpoint.

No t e

In the route editor, you can disable or delete a specific breakpoint by clicking the node's icon or its icon, respectively. You can delete all set breakpoints by right-clicking the canvas and selecting D el ete al l

breakpo i nts.

No t e

If you had not already set unique ID on the camel C o ntext element and the nodes in your routing context, the P l ease C o nfi rm dialog would have appeared now prompting you to let the tooling do it for you.

7. Repeat

Step 6 to set an unconditional breakpoint on the following Route1 nodes:

l o g 1 setHead 1 to Inval i d

4 5

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials l o g 2 setHead 2 to Ful fi l l

8. Click FileSave to save your routing context file.

9. Click Ro u t esRo u t e2 to open Route2 on the canvas.

10. Repeat

Step 6 to set an unconditional breakpoint on the following Route2 nodes:

cho i ce2 setHead _usa l o g _usa to USA setHead _uk l o g _uk to UK setHead _g er l o g _g er to G R setHead _fr l o g _fr to FR

11. Click FileSave to save your routing context file.

4 6

CHAPT ER 6 . T O DEBUG A RO UT ING CO NT EXT

No t e

Each time you modify your routing context, be sure to save it before you invoke the

Camel debugger, otherwise the changes you made will not be included in the debugging session.

ST EPPING T HROUGH T HE CBRROUT E ROUT ING CONT EXT

You can step through the routing context in two ways:

Step over ( )—Jumps to the next node of execution in the routing context, regardless of breakpoints.

Resume ( )—Jumps to the next active breakpoint in the routing context.

No t e

You can temporarily narrow then later re-expand the debugger's focus by disabling and re-enabling the breakpoints you set in the routing context. This enables you, for example, to focus on problematic nodes in your routing context. To do so, open the Breakpo i nts tab and clear the check box of each breakpoint you want to temporarily disable. Then use to step through the route. It will skip over the disabled breakpoints.

1. In P ro ject Expl o rer, expand the root node CBRro u t e to expose the

camel C o ntext. xml file in the C amel C o ntexts folder.

2. Right-click the camel C o ntext. xml file to open its context menu, and then click

Deb u g As...Lo cal Camel Co n t ext ( wit h o u t t est s) .

No t e

If you select Lo cal Camel Co n t ext , it will fail to run because you have not yet created a JUnit test for the CBRroute project. You will do that later in

Chapter 8, To Test a Route with JUnit .

The Camel debugger suspends execution at the first breakpoint it encounters and asks whether you want to open D ebug perspective now.

4 7

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

3. Click Y es.

No t e

If you click No , the confirmation pane appears several more times. After the third refusal, it disappears, and the Camel debugger resumes execution. To interact with the debugger at this point, you need to open the D ebug perspective by clicking Win d o wO p en Persp ect iveDeb u g .

D ebug perspective opens with the routing context suspended at cho i ce1 i n

R o ute1 [camel C o ntext] as shown in D ebug view.

4 8

No t e

Breakpoints are held for a maximum of five minutes before the debugger automatically resumes, moving on to the next breakpoint or to the end of the routing context, whichever comes next.

4. In Vari abl es view, expand the nodes to expose the variables and values available for each node.

As you step through the routing context, the variables whose values have changed since the last breakpoint are highlighted in yellow. You may need to expand the nodes at each breakpoint to reveal variables that have changed.

5. Click to step to the next breakpoint, l o g 2 i n R o ute1 [camel C o ntext].

CHAPT ER 6 . T O DEBUG A RO UT ING CO NT EXT

6. Expand the nodes in Vari abl es view to examine the variables that have changed since the last breakpoint at cho i ce1 i n R o ute1 [camel C o ntext].

7. Click to step to the next breakpoint, setHead 2 i n R o ute1 [camel C o ntext].

Examine the variables that changed since the breakpoint at l o g 2 i n R o ute1

[camel C o ntext].

8. In D ebug view, click l o g 2 i n R o ute1 [camel C o ntext] to populate

Vari abl es view with the variable values from the breakpoint l o g 2 i n R o ute1

[camel C o ntext] for a quick comparison.

In D ebug view, you can switch between breakpoints within the same message flow to quickly compare and monitor changing variable values in Vari abl es view.

No t e

Message flows can vary in length. For messages that transit the

i nval i d O rd ers branch of R o ute1, the message flow is short. For messages that transit the val i d O rd ers branch of R o ute1, which continues on to R o ute2, the message flow is longer.

9. Continue stepping through the routing context. When one message completes the routing context and the next message enters it, the new message flow appears in

D ebug view, tagged with a new breadcrumb ID.

4 9

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

In this case, ID -janemurpheysmbp-ho me-559 86 -14 2315554 8173-0 -3 identifies the second message flow, corresponding to messag e2. xml having entered the routing context. Breadcrumb IDs are incremented by 2.

No t e

Exchange and Message IDs are identical and remain unchanged throughout a message's passage through the routing context. Their IDs are constructed from the message flow's breadcrumb ID, and incremented by 1.

So, in the case of messag e2. xml , its Exchang eId and Messag eId are

ID -janemurpheysmbp-ho me-559 86 -14 2315554 8173-0 -4 .

10. When messag e3. xml enters the breakpoint cho i ce1 i n R o ute1

[camel C o ntext], examine the Processor variables. The values displayed are the metrics accumulated for messag e1. xml and messag e2. xml , which previously transited the routing context.

50

CHAPT ER 6 . T O DEBUG A RO UT ING CO NT EXT

Timing metrics are in milliseconds.

11. Continue stepping each message through the routing context, examining variables and console output at each processing step. When messag e6 . xml enters the breakpoint to G R i n R o ute2 [camel C o ntext], the debugger begins shutting down the breadcrumb threads.

12. In the Menu bar, click to terminate the Camel debugger. This will cause the

Console to terminate, but you will have to manually clear the output.

No t e

With a thread or endpoint selected under the Camel Context node in Debug view, you need to click twice—first to terminate the thread or endpoint and second to terminate the Camel Context, thus the session.

13. In the Menu bar, right-click to close D ebug perspective.

to open the context menu, and then select Clo se

51

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

Doing so automatically returns you to JBo ss perspective.

14. In P ro ject Expl o rer, open the project's context menu, and select Ref resh to refresh the display.

No t e

If you terminated the session prematurely, before all messages transited the routing context, you might see, under the C BR ro ute/C amel C o ntexts/ folder, a file that looks like this:targ et/. C amel C o ntextInD ebug _xxxxxxxxxxxxxxxxxx_temp/c

amel C o ntext. xml . To remove it, open P ro ject Expl o rer's context menu and click Ref resh .

15. Expand the C BR ro ute/targ et/messag es/* directories to check that the messages were delivered to their expected destinations:

16. Leave the routing context as is, with all previous breakpoints set and enabled.

CHANGING T HE VALUE OF A VARIABLE

52

In this session, you will add variables to a watch list to easily check how their values change as messages pass through the routing context. You will also change the value of a variable in the body of two messages and observe how the change affects each message's route through the routing context.

Follow Step 1

through

Step 3

in the section called “ Stepping through the CBRroute routing context” to rerun the Camel debugger on the CBRroute project.

1. With message1 stopped at the first breakpoint, cho i ce1 i n R o ute1

[camel C o ntext. xml ], add the variables No d eId and R o uteId (in the

Exchang e category) and Messag eBo d y and C amel Fi l eName (in the Messag e category) to the watch list.

For each of the four variables: a. In Vari abl es view, expand the appropriate category to expose the target

CHAPT ER 6 . T O DEBUG A RO UT ING CO NT EXT

a. In Vari abl es view, expand the appropriate category to expose the target variable: b. Right-click the variable (in this case, No d eId in the Exchang e category) to open the context menu and select Wat ch :

The Expressi o ns tab opens, listing the variable you selected to watch:

c. Repeat Step 1.b

for each of the three remaining variables.

d. Switch back to Vari abl es view.

2. Step message1 through the routing context until it reaches the fourth breakpoint,

to Ful fi l l i n R o ute1 [camel C o ntext. xml ].

3. In Vari abl es view, expand the Message category.

4. Repeat

Step 1.b

to add the variable D esti nati o n to the watch list.

Expressi o ns view should now contain these variables:

No t e

The pane below the list of variables displays the value of the selected variable.

53

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

No t e

Expressi o ns view retains all variables you add to the list until you explicitly remove them.

5. Step message1 through the rest of the routing context.

6. Stop message2 at cho i ce1 i n R o ute1 [camel C o ntext. xml ].

7. In Vari abl es view, expand the Messag e category to expose the Messag eBo d y variable.

8. Right-click Messag eBo d y to open its context menu, and select Ch an g e Valu e....

9. Change the value of quantity from 3 to 2.

54

This changes the in-memory value only.

10. Click O K.

11. Switch to Expressi o ns view, and select the Messag eBo d y variable.

The pane below the list of variables displays the entire body of message2, making it easy to check the current value of order items:

CHAPT ER 6 . T O DEBUG A RO UT ING CO NT EXT

No t e

Creating a watch list makes it easy for you to quickly check the current value of multiple variables of interest.

12. Click to step to the next breakpoint.

Instead of following the branch leading to Inval i d O rd ers, message2 now follows the branch leading to to Ful fi l l .

13. Step message2 through the routing context, checking D ebug view, Vari abl es view, and C o nso l e output at each step.

14. Stop message3 at cho i ce1 i n R o ute1 [camel C o ntext. xml ].

15. Switch to Breakpo i nts view, and disable all breakpoints (12) between cho i ce1 and to Ful fi l l :

55

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

16. Switch back to Vari abl es view.

17. Click to step to the next breakpoint.

The debugger jumps to to Ful Fi l l i n R o ute1 [camel C o ntext. xml ].

18. Click again to step to the next breakpoint.

56

The debugger jumps to to UK i n R o ute2 [camel C o ntext. xml ].

19. Switch to Breakpo i nts view, and re-enable all disabled breakpoints.

20. Switch back to Vari abl es view.

21. Click to step to the next breakpoint, and stop message4 at cho i ce1 i n

R o ute1 [camel C o ntext. xml ].

22. Right-click Messag eBo d y to open its context menu, and select C hang e Val ue. . . .

23. Change the value of quantity from 5 to 4 .

CHAPT ER 6 . T O DEBUG A RO UT ING CO NT EXT

24. Click O K.

25. Switch to Expressi o ns view, and select the Messag eBo d y variable to check the value of quantity in the body of message4.

26. Repeat

Step 12 and Step 13 to step message4 through the routing context.

27. Click repeatedly to quickly step message5 and message6 through the routing context.

28. In the Menu bar, click to terminate the Camel debugger.

This will also cause the Console to terminate, but you will have to click its button to clear the output.

29. In the Menu bar, right-click to close D ebug perspective.

to open the context menu, and then select Clo se

Doing so automatically returns you to JBo ss perspective.

30. In P ro ject Expl o rer, open the project's context menu, and select Ref resh to refresh the display.

31. Expand the C BR ro ute/targ et/messag es/* directories to check whether the messages were delivered as expected:

57

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

messages were delivered as expected:

You should see that no messages were sent to the i nval i d O rd ers folder. Instead,

messag e2. xml should appear in the USA folder, and messag e4 . xml should appear the G reatBri tai n folder.

NEXT ST EPS

Next you will trace messages through your routing context to see where you can optimize

and fine tune your routing context's performance, as described in Chapter 7, To Trace a

Message Through a Route

.

58

CHAPT ER 7 . T O T RACE A MESSAG E T HRO UG H A RO UT E

CHAPTER 7. TO TRACE A MESSAGE THROUGH A ROUTE

Ab st ract

This tutorial walks you through the process of tracing a message through a route.

GOALS

In this tutorial you will: run the CBRroute in the Fuse Integ rati o n perspective enable tracing on the CBRroute drop messages onto the CBRroute and track them through all route nodes

PREREQUISIT ES

To complete this tutorial you will need the C BR ro ute project you updated in Chapter 5, To

Add Another Route to the CBR Routing Context

.

No t e

If you skipped any tutorial after Chapter 2, To Create a New Route

, you can use the prefabricated camel C o ntext6 . xml file to work through this tutorial (for details,

see Chapter 1, Using the Fuse Tooling Resource Files ).

ACCESSING FUSE INT EGRAT ION PERSPECT IVE

To open Fuse Integ rati o n perspective and optimally arrange its layout:

1. Select Win d o wO p en Persp ect iveO t h er...Fu se In t eg rat io n to open the Fuse Integ rati o n perspective, as shown in

Figure 7.1

.

No t e

You can use the O pen P erspecti ve icon ( ) in the perspectives tab to access the list of available perspectives.

Fig u re 7.1. Fu se In t eg rat io n p ersp ect ive

59

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

60

No t e

To make it easy to access a Camel Context . xml file, especially when a project consists of multiple contexts, the tooling lists them in the C amel

C o ntexts folder, beneath the project's root folder in P ro ject Expl o rer; for example:

2. Drag the D i ag ram Vi ew tab and the Shel l tab, located to the left of the JMX

Navi g ato r tab, and drop them to the right of the JMX Navi g ato r tab, as shown in

Figure 7.2

.

Fig u re 7.2. Fu se In t eg rat io n p ersp ect ive rearran g ed

CHAPT ER 7 . T O T RACE A MESSAG E T HRO UG H A RO UT E

This layout will provide more space for D i ag ram Vi ew to display the route's nodes in a graphical representation, enabling you to visually trace the path that messages take in traversing the routing context.

ST ART ING MESSAGE T RACING

To start message tracing on the CBRroute project:

1. In P ro ject Expl o rer, expand the C BR ro ute project to expose the

src/mai n/reso urces/O SG I-INF/bl uepri nt/camel C o ntext. xml file.

2. Select Ru n AsLo cal Camel Co n t ext ( wit h o u t t est s) from the

camel C o ntext. xml file's context menu.

3. In JMX Navi g ato r, expand Lo cal P ro cesses.

4. Double click Lo cal C amel C o ntext[Id][D i sco nnected ] to connect to it and

expand the elements of your route, as shown in Figure 7.3, “ Route elements in JMX

Navigator” .

Fig u re 7.3. Ro u t e elemen t s in JMX Navig at o r

61

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

5. Right-click the b lu ep rin t Co n t ext node to open the context menu, and select St art

T racin g .

The tooling displays a graphical representation of your route in D i ag ram Vi ew, as shown in

Figure 7.4

.

Fig u re 7.4 . Ro u t es' g rap h ical rep resen t at io n

62

DROPPING MESSAGES ON T HE RUNNING CBRROUT E PROJECT

To drop messages on the running CBRroute project:

1. In P ro ject Expl o rer, expand C BR ro ute/src/d ata, so you can access the

message files (messag e1. xml through messag e6 . xml ), as shown in Figure 7.5,

“ Message files in CBRroute project” .

Fig u re 7.5. Messag e f iles in CBRro u t e p ro ject

CHAPT ER 7 . T O T RACE A MESSAG E T HRO UG H A RO UT E

2. Drag messag e1. xml and drop it on the

bl uepri ntC o ntext>End po i nts>fi l e>src/d ata?no o p= true node in JMX

Navi g ato r, as shown in

Figure 7.6

.

Fig u re 7.6 . Lo cal Camel Co n t ext t ree exp an d ed t o in p u t so u rce n o d e

As the message traverses the route, the tooling traces and records its passage at each step. To update D i ag ram Vi ew with the new message count, you need to click the bl uepri ntC o ntext node in JMX Navi g ato r.

No t e

The Lo cal C amel C o ntext[xxx] tree collapses to the

bl uepri ntC o ntext node after you drop the next message on the input src node. You need not re-expand it. When dragging the other messages, hover over each node in the tree to expose the next node, until you reach the

src/d ata?no o p= true node. Then drop the message on it. This method prevents the tooling from redrawing the graphical representation in

D i ag ram Vi ew.

INIT IALIZING AND CONFIGURING MESSAGES VIEW

63

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

You need to initialize Messag es Vi ew before it will display message traces. You also need to configure the columns in Messag es Vi ew to persist across all message traces.

1. Switch from C o nso l e to Messag es Vi ew.

2. Click the bl uepri ntC o ntext node in JMX Navi g ato r to initialize Messag es

Vi ew with messag e1. xml 's details.

No t e

You can control columnar layout in all of the tooling's tables. Use the drag method to temporarily rearrange tabular format. For example, drag a column's border rule to expand or contract its width. To hide a column, totally contract its borders. Drag the column header to relocate a column within the table. For your arrangement to persist, you must use the View

Men u Co n f ig u re Co lu mn s... method instead.

3. In Messag es Vi ew, click the icon on the panel's menu bar, and select

Co n f ig u re Co lu mn s... to open the Co n f ig u re Co lu mn s wizard, as shown in

Figure 7.7

.

Fig u re 7.7. Co n f ig u re Co lu mn s d ef au lt s

64

No t e

Notice that the message header, D esti nati o n, which you set for the messages in your routing context, appears in the list.

You can include or exclude items from Messag es Vi ew by selecting or deselecting them. You can rearrange the columnar order in which items appear in Messag es

Vi ew by highlighting individual, selected items and moving them up or down in the list.

4. In the C o nfi g ure C o l umns wizard, select and order the items as shown in

Figure 7.8

.

CHAPT ER 7 . T O T RACE A MESSAG E T HRO UG H A RO UT E

Fig u re 7.8. Co n f ig u re Co lu mn s set

These items and their order will persist in Messag es Vi ew until you change them again.

ARRANGING DIAGRAM VIEW

To see all message flow paths clearly, you'll probably need to rearrange the nodes by dragging them to fit neatly in D i ag ram Vi ew. You may also need to adjust the size of the other views and tabs in Red Hat JBoss Developer Studio to allow D i ag ram Vi ew to expand.

ST EPPING T HROUGH MESSAGE T RACES

To step through the message traces:

1. In Messag es Vi ew, click the (Refresh button) on top, right of the panel's menu bar to populate the view with messag e1. xml 's message traces.

Each time you drop a message on the input src node in JMX Navi g ato r, you need to refresh Messag es Vi ew to populate it with the message traces.

2. Click one of the message traces to see more details about it in P ro perti es view, as shown in

Figure 7.9

.

Fig u re 7.9 . Messag e t race select ed

65

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

The tooling displays the details about a message trace (including message headers when they are set) in the top half of the P ro perti es panel and the contents of the message instance in the bottom half of the P ro perti es panel. So, if your application sets headers at any step within a route, you can check the Messag e

D etai l s to see whether they were set as expected.

You can step through the message instances by highlighting each one to see how a particular message traversed the route and whether it was processed as expected at each step in the route.

In D i ag ram Vi ew, the associated step in the route is highlighted, as shown in

Figure 7.10

.

Fig u re 7.10. Diag ram View: messag e t race n o d e

66

FINISHING UP

1. Drag messag e2. xml and drop it on thebl uepri ntC o ntext>End po i nts>fi l e>src/d ata?no o p= true node in JMX

Navi g ato r.

Hover over each node in the tree until you expose the src/d ata?no o p= true node, then drop messag e2. xml on it.

2. Switch from C o nso l e to Messag es Vi ew.

3. In Messag es Vi ew, click the (Refresh button) on top, right of the panel's menu bar to populate the view with messag e2. xml 's message traces.

CHAPT ER 7 . T O T RACE A MESSAG E T HRO UG H A RO UT E

No t e

You can repeat Step 2

through Step 2

for the remaining messages in

C BR ro ute/src/d ata/ at any time, as long as tracing remains enabled.

On each subsequent drop, remember to click the (Refresh button) on the panel's menu bar to populate Messag es Vi ew with the new message traces.

As shown in

Figure 7.11

, the tooling draws the route in D i ag ram Vi ew, tagging paths exiting a processing step with timing and performance metrics (in milliseconds). Only the metric T o tal exchang es is displayed in the diagram.

Fig u re 7.11. Fu se In t eg rat io n p ersp ect ive' s messag e t racin g co mp o n en t s

Hovering over the displayed metrics reveals additional metrics about message flow, as shown in

Figure 7.12

.

Fig u re 7.12. Ad d it io n al messag e met rics

mean time the step took to process a message

67

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

maximum time the step took to process a message minimum time the step took to process a message

4. When done:

In JMX Navi g ato r, right-click b lu ep rin t Co n t ext and select St o p T racin g

Co n t ext from the context menu.

Open the C o nso l e and click the button in the upper right of the panel to stop the Console. Then click the button to clear console output.

NEXT ST EPS

After you create a JUnit test case for your project, you can run your project with it, as

described in Chapter 8, To Test a Route with JUnit .

68

CHAPT ER 8 . T O T EST A RO UT E WIT H JUNIT

CHAPTER 8. TO TEST A ROUTE WITH JUNIT

Ab st ract

This tutorial walks you through the process of using the New Camel Test Case wizard to create a test case for your route and using it test the route.

OVERVIEW

The New C amel JUni t T est C ase wi zard generates a boilerplate JUnit test case. This means that when you create or modify a route (for example, adding more processors to it), you'll need to modify the generated test case to add expectations and assertions specific to the new route you've created, so the test is valid for the new route.

GOALS

In this tutorial you will: delete the existing JUnit test case generate a new JUnit test case for the CBRroute project modify the newly generated JUnit test case modify the CBRroute project's po m. xml file run the CBRroute with the New JUnit test case observe the output

PREREQUISIT ES

To complete this tutorial you will need the CBRro u t e project you used in Chapter 7, To

Trace a Message Through a Route

No t e

If you skipped any tutorial after Chapter 2, To Create a New Route

, you can use the prefabricated camel C o ntext6 . xml file to work through this tutorial (for details,

see Chapter 1, Using the Fuse Tooling Resource Files ).

Delete any trace-generated messages from the C BR ro ute project's /src/d ata/ directory and /targ et/messag es/ subdirectories in P ro ject Expl o rer. Trace-generated

messages begin with the ID - prefix. For example, Figure 8.1, “ Trace-generated messages”

shows six trace-generated messages:

69

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

Fig u re 8.1. T race- g en erat ed messag es

Select all trace-generated messages in batch, right-click to open the context menu, and select Delet e.

DELET ING T HE EXIST ING T EST CASE

To delete the existing Apache Camel test case:

1. In P ro ject Expl o rer, expand src/test/java to expose the

C amel C o ntextXml T est file, as shown in

Figure 8.2

.

Fig u re 8.2. CamelCo n t ext XmlT est .java f ile lo cat io n

70

2. Right-click it to open the context menu, and select Delet e.

A dialog box opens asking you to confirm deletion of the test case file.

3. Click O K.

4. Verify that the existing test case has been deleted by right-clicking C BR ro ute and selecting Ref resh .

The src/test/java/tuto ri al . cbr. ro ute directory should be empty.

CREAT ING T HE NEW T EST CASE

To create a new Apache Camel test case:

CHAPT ER 8 . T O T EST A RO UT E WIT H JUNIT

1. In P ro ject Expl o rer, select src/test/java.

2. Right-click it to open the context menu, and then select NewCamel T est Case to open the New C amel JUni t T est C ase wizard, as shown in

Figure 8.3

.

Fig u re 8.3. New Camel JUn it T est Case wiz ard

3. Make sure the So urce fo l d er field contains C BR ro ute/src/test/java.

No t e

If needed, you can click to find the proper folder.

4. The P ackag e field defaults to tuto ri al . cbr. ro ute. To include the test case in a different package, enter the name of the package.

5. In the C amel XML fi l e und er test field, enter src/mai n/reso urces/O SG I-

INF/bl uepri nt/camel C o ntext. xml , or use explorer, configured to screen for XML files, to locate the file.

to open a file

No t e

The Name field defaults to CamelContextXmlTest for the name of the test file.

6. Click Next> to open the T est End po i nts page, shown in

Figure 8.4

.

71

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

Fig u re 8.4 . T est En d p o in t s p ag e

72

7. By default, all endpoints are selected and will be included in the test case. Leave them selected for this tutorial.

No t e

You can select or deselect all endpoints by clicking the Sel ect Al l or

D esel ect Al l button, or you can select and deselect individual endpoints by clicking the check box next to each.

8. Click Fi ni sh.

No t e

If prompted, add JUnit to the build path.

The artifacts for the test are added to your project and appear in P ro ject Expl o rer under

src/test/java. The class implementing the test case opens in the tooling's Java editor: package tutorial.cbr.route; import org.apache.camel.EndpointInject; import org.apache.camel.Produce; import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.test.blueprint.CamelBlueprintTestSupport; import org.junit.Test; public class CamelContextXmlTest extends CamelBlueprintTestSupport {

CHAPT ER 8 . T O T EST A RO UT E WIT H JUNIT

// TODO Create test message bodies that work for the route(s) being tested

// Expected message bodies

protected Object[] expectedBodies = {

"<something id='1'>expectedBody1</something>" ,

"<something id='2'>expectedBody2</something>" ;

// Templates to send to input endpoints

@ Produce (uri = "file:src/data?noop=true" ) protected ProducerTemplate inputEndpoint;

// Mock endpoints used to consume messages from the output endpoints and then perform assertions

@ EndpointInject (uri = "mock:output" ) protected MockEndpoint outputEndpoint;

@ EndpointInject (uri = "mock:output2" ) protected MockEndpoint output2Endpoint;

@ EndpointInject (uri = "mock:output3" ) protected MockEndpoint output3Endpoint;

@ EndpointInject (uri = "mock:output4" ) protected MockEndpoint output4Endpoint;

@ EndpointInject (uri = "mock:output5" ) protected MockEndpoint output5Endpoint;

@ Test public void testCamelRoute() throws Exception {

// Create routes from the output endpoints to our mock endpoints so we can assert expectations

context.addRoutes( new RouteBuilder() {

@ Override public void configure() throws Exception {

from( "file:target/messages/Germany" ).to(output4Endpoint);

from( "file:target/messages/GreatBritain" ).to(output3Endpoint);

from( "file:target/messages/USA" ).to(output2Endpoint);

from( "file:target/messages/France" ).to(output5Endpoint);

from( "file:target/messages/invalidOrders" ).to(outputEndpoint);

}

});

// Define some expectations

// TODO Ensure expectations make sense for the route(s) we're testing

output4Endpoint.expectedBodiesReceivedInAnyOrder(expectedBodies);

// Send some messages to input endpoints

for (Object expectedBody : expectedBodies) {

inputEndpoint.sendBody(expectedBody);

}

// Validate our expectations

assertMockEndpointsSatisfied();

}

@ Override protected String getBlueprintDescriptor() {

73

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

return "OSGI-INF/blueprint/camelContext.xml" ;

}

}

This generated JUnit test case is insufficient for the CBRroute project, and it will fail to run

successfully. You need to modify it and the project's po m. xml , as described in the section called “ Modifying the CamelContextXmlTest file ” and the section called “ Modifying the

pom.xml file” .

MODIFYING T HE CAMELCONT EXT XMLT EST FILE

You need to modify the C amel C o ntextXml T est. java file to: import several classes that support required file functions create variables for holding the content of the various source . xml files read the content of the source . xml files define appropriate expectations

1. In P ro ject Expl o rer, expand the CBRroute project to expose the

C amel C o ntextXml T est item.

74

2. Double-click C amel C o ntextXml T est to open the file in the route editor.

3. In the route editor, click the expand button next to i mpo rt

o rg . apache. camel . End po i ntInject; to expand the list.

4. Add the three lines shown here:

CHAPT ER 8 . T O T EST A RO UT E WIT H JUNIT

5. Scroll down to the lines that follow directly after // Expected messag e bo d i es.

6. Replace those lines—pro tected O bject[] expected Bo d i es= { . . . . . .

expected Bo d y2</so methi ng >"};— with the pro tected Stri ng bo d y#; lines shown here:

7. Scroll down to the line publ i c vo i d testcamel R o ute() thro ws Excepti o n

{, and insert directly after it the lines bo d y# =

Fi l eUti l s. read Fi l eT o Stri ng (new Fi l e("src/d ata/messag e#. xml "));

shown here:

8. Scroll down to the lines that follow directly after // T O D O Ensure expectati o ns

make sense fo r the ro ute(s) we' re testi ng .

9. Replace the block of code that begins with

o utput4 End po i nt. expected Bo d i esR ecei ved InAnyO rd er(expected Bo d i e

s); and ends with ...i nputEnd po i nt. send Bo d y(expected Bo d y); } with the lines shown here:

75

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

76

Leave the remaining code as is.

10. Save the file.

11. Check that your updated C amel C o ntextXml T est. java file has the required modifications. It should look something like this: package tutorial.cbr.route; import org.apache.camel.EndpointInject; import org.apache.camel.Produce; import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.test.blueprint.CamelBlueprintTestSupport; import org.apache.commons.io.FileUtils; import org.junit.Test; import java.io.File; import java.util.Scanner; public class CamelContextXmlTest extends

CamelBlueprintTestSupport {

// TODO Create test message bodies that work for the route(s) being tested

// Expected message bodies

// To assert that everything works as it should, read the content of created xml files.

protected String body1; protected String body2; protected String body3; protected String body4; protected String body5; protected String body6;

// Templates to send to input endpoints

@ Produce (uri = "file:src/data?noop=true" ) protected ProducerTemplate inputEndpoint;

// Mock endpoints used to consume messages from the output

CHAPT ER 8 . T O T EST A RO UT E WIT H JUNIT

// endpoints and then perform assertions

@ EndpointInject (uri = "mock:output" ) protected MockEndpoint outputEndpoint;

@ EndpointInject (uri = "mock:output2" ) protected MockEndpoint output2Endpoint;

@ EndpointInject (uri = "mock:output3" ) protected MockEndpoint output3Endpoint;

@ EndpointInject (uri = "mock:output4" ) protected MockEndpoint output4Endpoint;

@ EndpointInject (uri = "mock:output5" ) protected MockEndpoint output5Endpoint;

@ Test public void testCamelRoute() throws Exception {

// Easy way of reading content of xml files to a String object.

// But you must add dependency on commons-io project to pom.xml

body1 = FileUtils.readFileToString( new

File( "src/data/message1.xml" ));

body3 = FileUtils.readFileToString( new

File( "src/data/message3.xml" ));

body5 = FileUtils.readFileToString( new

File( "src/data/message5.xml" ));

body6 = FileUtils.readFileToString( new

File( "src/data/message6.xml" ));

// Invalid orders.

body2 = FileUtils.readFileToString( new

File( "src/data/message2.xml" ));

body4 = FileUtils.readFileToString( new

File( "src/data/message4.xml" ));

// Create routes from the output endpoints to our mock endpoints

// so we can assert expectations

context.addRoutes( new RouteBuilder() {

@ Override public void configure() throws Exception {

from( "file:target/messages/Germany" ).to(output4Endpoint); from( "file:target/messages/GreatBritain" ).to(output3Endpoint);

from( "file:target/messages/USA" ).to(output2Endpoint);

from( "file:target/messages/France" ).to(output5Endpoint); from( "file:target/messages/invalidOrders" ).to(outputEndpoint);

}

});

// Define some expectations

// TODO Ensure expectations make sense for the route(s) we're testing

// Invalid orders

77

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

outputEndpoint.expectedBodiesReceived(body2, body4);

// For each country one order

output2Endpoint.expectedBodiesReceived(body1);

output3Endpoint.expectedBodiesReceived(body3);

output4Endpoint.expectedBodiesReceived(body6);

output5Endpoint.expectedBodiesReceived(body5);

// Validate our expectations

assertMockEndpointsSatisfied();

}

@ Override protected String getBlueprintDescriptor() { return "OSGI-INF/blueprint/camelContext.xml" ;

}

}

MODIFYING T HE POM.XML FILE

You need to add a dependency on the commons-io project to the CBRroute project's

po m. xml file.

1. In P ro ject Expl o rer, double-click po m. xml , located below the targ et folder, to open the file in the route editor.

2. Click the po m. xml tab at the bottom of the page to open the file for editing.

3. Add these lines to the end of the <d epend enci es> section:

<dependency>

<groupId>commons-io</groupId>

<artifactId>commons-io</artifactId>

<version> 2.4

</version>

<scope>test</scope>

</dependency>

4. Save the file.

The contents of the entire po m. xml file should look like this:

<?xml version= "1.0" encoding= "UTF-8" ?>

<project xsi:schemaLocation= "http://maven.apache.org/POM/4.0.0

http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns= "http://maven.apache.org/POM/4.0.0"

xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" >

<modelVersion> 4.0.0

</modelVersion>

<groupId>tutorial</groupId>

78

CHAPT ER 8 . T O T EST A RO UT E WIT H JUNIT

<artifactId>cbr-route</artifactId>

<version> 1.0.0

-SNAPSHOT</version>

<packaging>bundle</packaging>

<name>A Camel Blueprint Route</name>

<url>http:

//www.myorganization.org</url>

<properties>

<project.reporting.outputEncoding>UTF8 </project.reporting.outp

utEncoding>

<project.build.sourceEncoding>UTF8 </project.build.sourceEncodin

g>

</properties>

<dependencies>

<dependency>

<groupId>org.apache.camel</groupId>

<artifactId>camel-core</artifactId>

<version> 2.15.0

</version>

</dependency>

<dependency>

<groupId>org.apache.camel</groupId>

<artifactId>camel-blueprint</artifactId>

<version> 2.15.0

</version>

</dependency>

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>slf4j-api</artifactId>

<version> 1.7.7

</version>

</dependency>

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>slf4j-log4j12</artifactId>

<version> 1.7.7

</version>

</dependency>

<dependency>

<groupId>org.slf4j</groupId>

<artifactId>jcl-over-slf4j</artifactId>

<version> 1.7.7

</version>

</dependency>

<dependency>

<groupId>log4j</groupId>

<artifactId>log4j</artifactId>

<version> 1.2.17

</version>

</dependency>

<dependency>

<groupId>org.apache.camel</groupId>

<artifactId>camel-test-blueprint</artifactId>

<version> 2.15.0

</version>

<scope>test</scope>

</dependency>

<dependency>

<groupId>org.apache.camel<</groupId>

<artifactId>camel-infinispan</artifactId>

<version> 2.15.0

</version>

</dependency>

<dependency>

79

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

<groupId>org.apache.camel</groupId>

<artifactId>camel-jgroups</artifactId>

<version> 2.15.0

</version>

</dependency>

<dependency>

<groupId>org.apache.camel</groupId>

<artifactId>camel-test</artifactId>

<version> 2.15.0

</version>

<scope>test</scope>

</dependency>

<dependency>

<groupId>commons-io</groupId>

<artifactId>commons-io</artifactId>

<version> 2.4

</version>

<scope>test</scope>

</dependency>

</dependencies>

<build>

<defaultGoal>install</defaultGoal>

<plugins>

<plugin>

<artifactId>maven-compiler-plugin</artifactId>

<version> 2.5.1

</version>

<configuration>

<source> 1.6

</source>

<target> 1.6

</target>

</configuration>

</plugin>

<plugin>

<artifactId>maven-resources-plugin</artifactId>

<version> 2.6

</version>

<configuration>

<encoding>UTF8 </encoding>

</configuration>

</plugin>

<plugin>

<groupId>org.apache.felix</groupId>

<artifactId>maven-bundle-plugin</artifactId>

<version> 2.3.7

</version>

<extensions> true </extensions>

<configuration>

<instructions>

<Bundle-SymbolicName>cbr-route</Bundle-

SymbolicName>

<Private-Package>tutorial.cbr.route.*</Private-

Package>

<Import-Package>*</Import-Package>

</instructions>

</configuration>

</plugin>

<plugin>

<groupId>org.apache.camel</groupId>

<artifactId>camel-maven-plugin</artifactId>

<version> 2.15.0

</version>

<configuration>

<useBlueprint> true </useBlueprint>

80

CHAPT ER 8 . T O T EST A RO UT E WIT H JUNIT

</configuration>

</plugin>

</plugins>

</build>

</project>

RUNNING T HE JUNIT T EST

To run the test:

1. Switch to JBo ss perspective to free up more workspace.

2. Select the project root, C BR ro ute, in the P ro ject Expl o rer.

3. Open the context menu.

4. Select Ru n AsJUn it T est .

No t e

By default, JUni t view opens in the sidebar. (To provide a better view, drag it to the bottom, right panel that displays the C o nso l e, Servers, and

P ro perti es tabs.)

5. If the test runs successfully, you'll see something like this:

Fig u re 8.5. Su ccessf u l JUn it ru n

If the test fails, you'll see something like this:

Fig u re 8.6 . Failed JUn it ru n

81

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

No t e

JUnit will fail if your execution environment is not set to Java SE 7 or above.

The message bar at the top of the JUnit tab will display an error message indicating that it cannot find the correct SDK.

To resolve the issue, open the project's context menu, and select Ru n As

Ru n Co n f ig u rat io n sJRE t ab . Click the Envi ro nments button next to the Executi o n envi ro nment: field to locate and select a Java SE 7 environment.

6. Examine the output and take action to resolve any test failures.

To see more of the errors displayed in the JUnit panel, click on the panel's menu bar to maximize the view. You can also check the surefire reports in the surefi re-

repo rts tab in P ro ject Expl o rer, as shown in

Figure 8.7

.

Fig u re 8.7. JUn it su ref ire rep o rt s

82

Before you run the JUnit test case again, delete any JUnit-generated test messages from the CBRroute project's /src/d ata folder in P ro ject Expl o rer (see

Figure 8.1, “ Trace-generated messages”

).

FURT HER READING

To learn more about JUnit testing:

see JUnit

CHAPT ER 8 . T O T EST A RO UT E WIT H JUNIT

83

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

CHAPTER 9. TO PUBLISH A FUSE PROJECT TO RED HAT

JBOSS FUSE

Ab st ract

This tutorial walks you through the process of deploying an Apache Camel project into Red

Hat JBoss Fuse. It assumes that you have an instance of Red Hat JBoss Fuse installed on the same machine on which you are running the Red Hat JBoss Fuse Tooling.

GOALS

In this tutorial you will: define a Red Hat JBoss Fuse server configure the publishing options start up the Red Hat JBoss Fuse server and publish the CBRroute project connect to the Red Hat JBoss Fuse server verify whether the CBRroute project's bundle was successfully built and published uninstall the CBRroute project

PREREQUISIT ES

To complete this tutorial you will need access to a Red Hat JBoss Fuse 6.2 instance the CBRro u t e project you updated in

Chapter 8, To Test a Route with JUnit

DEFINING A RED HAT JBOSS FUSE SERVER

To define a server:

1. Open Fuse Integ rati o n perspective.

2. Click the Servers tab in the lower, right panel to open the Servers view.

3. Click the link No servers are avai l abl e. C l i ck thi s l i nk to create a

new server. . . to open the D efi ne a New Server page.

84

CHAPT ER 9 . T O PUBLISH A FUSE PRO JECT T O RED HAT JBO SS FUSE

No t e

To define a new server when one is already defined, right-click inside

Servers view to open the context menu, and then select NewServer.

4. Expand the JBo ss Fuse node to expose the available server options:

5. Click JBo ss Fuse 6 . 2 Server.

6. Accept the defaults for Server' s ho st name (localhost) and Server name (JBoss

Fuse 6.2 Runtime Server), and then click Next to open the JBo ss Fuse R unti me page:

85

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

86

No t e

If you do not have JBoss Fuse 6.2 already installed, you can download it now using the D o wnl o ad and i nstal l runti me. . . link.

No t e

If you have already defined a JBoss Fuse 6.2 server, the tooling skips this

page, and instead displays the configuration details page shown in Step

11 .

7. Accept the default for Name (JBoss Fuse 6.2 Runtime).

8. In Ho me D i recto ry, enter the path where the JBoss Fuse 6.2 installation is located, or click Bro wse to find and select it.

9. Select the runtime JRE from the drop-down menu next to Executi o n Envi ro nment.

Select either JavaSE-1.7 or JavaSE-1.8. If neither appears as an option, click the

Envi ro nments. . . button and select either version from the list.

No t e

The JBoss Fuse 6.2 server requires Java 7 or Java 8. To select either version for the Executi o n Envi ro nment, you must have previously installed it.

10. Leave the Al ternate JR E option as is.

11. Click Next to save the runtime definition for JBoss Fuse 6.2 Server and open the

JBo ss Fuse server co nfi g urati o n d etai l s page:

CHAPT ER 9 . T O PUBLISH A FUSE PRO JECT T O RED HAT JBO SS FUSE

12. Accept the default for SSH P o rt (8101).

The runtime uses the SSH port to connect to the server's Karaf shell. If this default is incorrect, you can discover the correct port number by looking in the Red Hat JBoss

Fuse installDir/etc/o rg . apache. karaf. shel l . cfg file.

13. In User Name, enter the name used to log into the server.

This is a user name stored in the Red Hat JBoss Fuse

installDir/etc/users. pro perti es file.

No t e

If the default user has been activated (uncommented) in the

/etc/users. pro perti es file, the tooling autofills User Name and

P asswo rd with the default user's name and password, as shown in

Step

11 .

If one has not been set, you can either add one to that file using the format

user= passwo rd ,ro l e (for example, jo e= secret,Ad mi ni strato r), or you can set one using the karaf jaas command set:

jaas: real ms—to list the realms

jaas: manag e --i nd ex 1—to edit the first (server) realm

jaas: userad d <username> <passwo rd >—to add a user and associated password

jaas: ro l ead d <username> Ad mi ni strato r—to specify the new user's role

jaas: upd ate—to update the realm with the new user information

87

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

If a jaas realm has already been selected for the server, you can discover the user name by issuing the command JBo ssFuse: [email protected] ro o t>jaas: users.

14. In P asswo rd : , enter the password required for User name to log into the server.

This is the password set either in Red Hat JBoss Fuse's

installDir/etc/users. pro perti es file or by the karaf jaas commands.

15. Click Next to open the Ad d and R emo ve resources page:

16. Select C BR ro ute, and click Ad d > to assign it to the JBoss Fuse server.

17. Click Fi ni sh.

JBo ss Fuse 6 . 2 R unti me Server [sto pped ] appears in Servers view.

18. In Servers view, expand JBo ss Fuse 6 . 2 R unti me Server [sto pped ]:

88

The C BR ro ute module and JMX[D i sco nnected ] appear as nodes under JBo ss

Fuse 6 . 2 R unti me Server [sto pped ] entry.

CHAPT ER 9 . T O PUBLISH A FUSE PRO JECT T O RED HAT JBO SS FUSE

CONFIGURING T HE PUBLISHING OPT IONS

Using publishing options, you can configure how and when your CBRroute project is published to a running server:

Automatically, immediately upon saving changes made to the project

Automatically, at configured intervals after you have changed and saved the project

Manually, when you select a publish operation

In this tutorial, you are going to configure immediate publishing upon saving changes to the

CBRroute project. To do so:

1. In Servers view, double-click the JBo ss Fuse 6 . 2 R unti me Server

[sto pped ] entry to open the server's editor:

2. On the server editor's O vervi ew page, expand the P ubl i shi ng section to expose the options.

Make sure the option Au t o mat ically p u b lish wh en reso u rces ch an g e is enabled.

Change the value of Pu b lish in g in t erval to speed up or delay publishing the project when changes have been made.

89

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

No t e

To configure manual publishing: disable the If server started , publ i sh chang es i mmed i atel y option on the server's Ad d and R emo ve page enable the Never publ i sh auto mati cal l y option on the server editor's

O vervi ew page

Then to manually publish changes made to selective resources configured on the running server, use the Fu ll Pu b lish option on the resource's context menu in

Servers view. The In cremen t al Pu b lish option is not supported and clicking it results in a full publish.

ST ART ING UP RED HAT JBOSS FUSE SERVER

Because you enabled the automatic publishing option, when you start up the JBo ss Fuse

6 . 2 R unti me Server, the publish mechanism automatically publishes the CBRroute to the server.

1. In Servers view, select JBo ss Fuse 6 . 2 R unti me Server and click to start it.

Imp o rt an t

A warning that the host identification has changed may appear. Click yes to replace the key ONLY if the JBoss Fuse 6.2 server runtime is installed on the same machine where Red Hat JBoss Fuse Tooling is running! Otherwise click no and contact your system administrator.

2. Wait a few seconds for JBoss Fuse 6.2 Server to start up. When it does:

Shel l view displays the JBoss Fuse splash screen:

90

CHAPT ER 9 . T O PUBLISH A FUSE PRO JECT T O RED HAT JBO SS FUSE

Servers view displays:

JBo ss Fuse 6 . 2 R unti me Server [Started , Synchro ni zed ]

No t e

For a server, synchronized means that all modules published on the server are identical to their local counterparts.

C BR ro ute [Started , Synchro ni zed ]

No t e

For a module, synchronized means that the published module is identical to its local counterpart. Because automatic publishing is enabled, changes made to the CBRroute project are published in seconds (according to the value of the Pu b lish in g in t erval).

JMX[D i sco nnected ]

JMX Navi g ato r displays JBo ss Fuse 6 . 2 R unti me

Server[D i sco nnected ]:

91

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

CONNECT ING T O T HE JBOSS FUSE 6.2 RUNT IME SERVER

When you connect to the JBo ss Fuse 6 . 2 R unti me Server, you can see the published elements of your CBRroute project and interact with them.

1. In Servers view, double-click JMX[D i sco nnected ] to connect to the runtime server.

92

Imp o rt an t

If the CBRroute project contains a failed JUnit test, the published module will not be started nor its bundle installed. The published module will appear in Servers view under JBo ss Fuse 6 . 2 R unti me

Server[Started , Synchro ni zed ] as C BR ro ute[Synchro ni zed ].

You need to correct the JUnit test case (see the section called “ Modifying the CamelContextXmlTest file ” for details) so that it runs on the CBRroute

without errors, and save the updated test file. Saving the test file will trigger immediate publishing when that option is enabled. The module should then be started and its bundle installed.

CHAPT ER 9 . T O PUBLISH A FUSE PRO JECT T O RED HAT JBO SS FUSE

2. Expand the C amel node in JMX Navi g ato r to expose the elements of the

CBRroute.

You can interact with the CBRroute routing context using either Servers view or JMX

Navi g ato r, but JMX Navi g ato r provides more room to expand the routing context's nodes, making it easier for you to access them.

No t e

Once the bl uepri ntC amel node appears in JMX Navi g ato r under

Server C o nnecti o ns (or in Servers view under JMX[C o nnected ]),

you can start tracing on it, as described in Chapter 7, To Trace a Message

Through a Route

.

3. Click the Bu n d les node to populate Pro p ert ies view with the list of bundles installed on the JBo ss Fuse 6 . 2 R unti me Server.

Start typing cbr-route in Pro p ert ies view's Search tool to quickly determine whether your project's cbr-ro ute bundle is included in the list. Note that it is the last bundle in the list, identified by its Symb o lic Name, cbr-ro ute, which is the Artifact Id you gave it in

Step 6

when you created the CBRroute project.

No t e

Alternatively, you can issue the l i st command in Sh ell view to see a generated list of installed bundles.

UNINST ALLING T HE CBRROUT E PROJECT

No t e

You do not need to disconnect the JMX connection or stop the server to uninstall a published resource.

93

Red Hat JBoss Fuse 6 .2 .1 T ooling T ut orials

To remove the CBRroute resource from JBoss Fuse 6.2 Runtime Server:

1. In Servers view, right-click JBo ss Fuse 6 . 2 R unti me Server to open the context menu.

2. Select Ad d an d Remo ve:

94

3. In the C o nfi g ured column, select C BR ro ute, and then click R emo ve to move the

CBRroute resource to the Avai l abl e column.

4. Click Fi ni sh.

5. In Servers view, right-click JMX[C o nnected ] to open the context menu, and then click Ref resh .

The C amel tree under JMX[C o nnected ] disappears.

No t e

In JMX Navi g ato r, the C amel tree under Server C o nnecti o ns >

JBo ss Fuse 6 . 2 R unti me Server[C o nnected ] also disappears.

6. With the Bund l es page displayed, start typing cbr-route in Pro p ert ies view's

Search tool to verify that the bundle has been removed.

Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement