Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.2.2. Create a Router Project
Overview Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
This section describes how to generate a router project, which acts as a proxy for the WS server described in Section 2.1, “Create a Web Services Project”. The starting point for this project is the
camel-archetype-blueprint
Maven archetype.
Prerequisites Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
This project depends on the
cxf-basic
project and requires that you have already generated and built the cxf-basic
project, as described in Section 2.1, “Create a Web Services Project”.
Create project from the command line Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Open a command prompt and change directory to the
get-started
directory. You can now use the archetype:generate
goal to invoke the camel-archetype-blueprint
archetype, which generates a simple Apache Camel demonstration, as follows:
Note
The arguments of the preceding command are shown on separate lines for readability, but when you are actually entering the command, the entire command must be entered on a single line.
You will be prompted to confirm the project settings, with a message similar to this one:
Type Return to accept the settings and generate the project. When the command finishes, you should find a new Maven project in the
get-started/camel-basic
directory.
Modify the route Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
You are going to modify the default route generated by the archetype and change it into a route that implements a HTTP bridge. This bridge will be interposed between the WS client and Web service, enabling us to apply some routing logic to the WSDL messages that pass through the route.
Using your favorite text editor, open
camel-basic/src/main/resources/OSGI-INF/blueprint/blueprint.xml
. Remove the existing bean
element and the camelContext
element and replace them with the camelContext
element highlighted in the following example:
The
from
element defines a new HTTP server port, which listens on IP port 8282. The to
element defines a HTTP client endpoint that attempts to connect to the real Web service, which is listening on IP port 8181. To make the route a little more interesting, we add a delay
element, which imposes a five second (5000 millisecond) delay on all requests passing through the route.
For a detailed discussion and explanation of the HTTP bridge, see Proxying with HTTP.
Disable the test Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The generated project includes a built-in unit test, which employs the
camel-test
testing toolkit. The Apache Camel testing toolkit is a useful and powerful testing library, but it will not be used in this example.
To disable the test, open the
RouteTest.java
file from the src/test/java/org/fusesource/example
directory using a text editor and look for the @Test
annotation, as shown in the following snippet:
Now comment out the
@Test
annotation, as shown in the following snippet, and save the modified RouteTest.java
file.
Add the required Maven dependency Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Because the route uses the Apache Camel Jetty component, you must add a Maven dependency on the
camel-jetty
artifact, so that the requisite JAR files are added to the classpath. To add the dependency, edit the camel-basic/pom.xml
file and add the following highlighted dependency as a child of the dependencies
element:
Build the router project Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Build the router project and install the generated JAR file into your local Maven repository. From a command prompt, enter the following commands:
cd camel-basic mvn install
cd camel-basic
mvn install
Deploy and start the route Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
If you have not already started the Red Hat JBoss Fuse container and deployed the Web services bundle, you should do so now—see the section called “Deploy and start the WS server”.
To install the
camel-basic
route as an OSGi bundle, enter the following console command:
JBossFuse:karaf@root> install mvn:org.fusesource.example/camel-basic/1.0-SNAPSHOT
JBossFuse:karaf@root> install mvn:org.fusesource.example/camel-basic/1.0-SNAPSHOT
If the bundle is successfully resolved and installed, the container responds by giving you the ID of the newly created bundle—for example:
Bundle ID: 230
Bundle ID: 230
You can now start up the Web service using the
start
console command, specifying the bundle ID, as follows:
JBossFuse:karaf@root> start 230
JBossFuse:karaf@root> start 230
Test the route with the WS client Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The
cxf-basic
project includes a simple WS client, which you can use to test the deployed route and Web service. In a command prompt, navigate to the cxf-basic
directory and run the simple WS client as follows:
cd ../cxf-basic mvn -Pclient -Dexec.args="http://localhost:8282/cxf/PersonServiceCF"
cd ../cxf-basic
mvn -Pclient -Dexec.args="http://localhost:8282/cxf/PersonServiceCF"
If the client runs successfully, you should see output like the following:
INFO: Creating Service {http://example.fusesource.org/}PersonService from class org.fusesource.example.Person Invoking getPerson...
INFO: Creating Service {http://example.fusesource.org/}PersonService from class org.fusesource.example.Person
Invoking getPerson...
After a five second delay, you will see the following response:
getPerson._getPerson_personId=Guillaume getPerson._getPerson_ssn=000-000-0000 getPerson._getPerson_name=Guillaume
getPerson._getPerson_personId=Guillaume
getPerson._getPerson_ssn=000-000-0000
getPerson._getPerson_name=Guillaume