이 콘텐츠는 선택한 언어로 제공되지 않습니다.

2.2. Create a Router Project


Overview

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

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

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:
mvn archetype:generate
-DarchetypeGroupId=org.apache.camel.archetypes
-DarchetypeArtifactId=camel-archetype-blueprint
-DarchetypeVersion=2.12.0.redhat-610379
-DgroupId=org.fusesource.example
-DartifactId=camel-basic
-Dversion=1.0-SNAPSHOT
Copy to Clipboard Toggle word wrap
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:
[INFO] Using property: groupId = org.fusesource.example
[INFO] Using property: artifactId = camel-basic
[INFO] Using property: version = 1.0-SNAPSHOT
[INFO] Using property: package = org.fusesource.example
[INFO] Using property: camel-version = 2.9.0.fuse-7-032
[INFO] Using property: log4j-version = 1.2.16
[INFO] Using property: maven-bundle-plugin-version = 2.3.4
[INFO] Using property: maven-compiler-plugin-version = 2.3.2
[INFO] Using property: maven-surefire-plugin-version = 2.11
[INFO] Using property: slf4j-version = 1.6.1
Confirm properties configuration:
groupId: org.fusesource.example
artifactId: camel-basic
version: 1.0-SNAPSHOT
package: org.fusesource.example
camel-version: 2.9.0.fuse-7-032
log4j-version: 1.2.16
maven-bundle-plugin-version: 2.3.4
maven-compiler-plugin-version: 2.3.2
maven-surefire-plugin-version: 2.11
slf4j-version: 1.6.1
Y: :
Copy to Clipboard Toggle word wrap
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

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:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://camel.apache.org/schema/blueprint"
       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/camel-blueprint.xsd">

  <camelContext id="blueprintContext"
                trace="false"
                xmlns="http://camel.apache.org/schema/blueprint">
    <route id="httpBridge">
      <from uri="jetty:http://0.0.0.0:8282/cxf/PersonServiceCF?matchOnUriPrefix=true"/>
      <delay><constant>5000</constant></delay>
      <to uri="jetty:http://localhost:8181/cxf/PersonServiceCF?bridgeEndpoint=true&amp;throwExceptionOnFailure=false"/>
    </route>
  </camelContext>

</blueprint>
Copy to Clipboard Toggle word wrap
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

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:
// Java
...
public class RouteTest extends CamelBlueprintTestSupport {
    ...
    @Test
    public void testRoute() throws Exception {
    ...
Copy to Clipboard Toggle word wrap
Now comment out the @Test annotation, as shown in the following snippet, and save the modified RouteTest.java file.
...
public class RouteTest extends CamelBlueprintTestSupport {
    ...
    // @Test
    // Disable test!
    public void testRoute() throws Exception {
    ...
Copy to Clipboard Toggle word wrap

Add the required Maven dependency

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:
<?xml version="1.0" encoding="UTF-8"?>
<project ...>
  ...
  <dependencies>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-core</artifactId>
      <version>2.12.0.redhat-610379</version>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-blueprint</artifactId>
      <version>2.12.0.redhat-610379</version>
    </dependency>
    <dependency>
      <groupId>org.apache.camel</groupId>
      <artifactId>camel-jetty</artifactId>
      <version>2.12.0.redhat-610379</version> </dependency>
    ...
  </dependencies>
  ...
</project>
Copy to Clipboard Toggle word wrap

Build the router project

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
Copy to Clipboard Toggle word wrap

Deploy and start the route

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
Copy to Clipboard Toggle word wrap
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
Copy to Clipboard Toggle word wrap
You can now start up the Web service using the start console command, specifying the bundle ID, as follows:
JBossFuse:karaf@root> start 230
Copy to Clipboard Toggle word wrap

Test the route with the WS client

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"
Copy to Clipboard Toggle word wrap
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...
Copy to Clipboard Toggle word wrap
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
Copy to Clipboard Toggle word wrap
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat