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.このコンテンツは選択した言語では利用できません。
Chapter 2. Getting Started with Developing
Abstract
This chapter explains how to get started with Maven-based development, with a two-part project that illustrates how to develop applications using Apache CXF and Apache Camel.
2.1. Create a Web Services Project リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Overview リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
This section describes how to generate a simple Web services project, which includes complete demonstration code for a server and a test client. The starting point for this project is the
servicemix-cxf-code-first-osgi-bundle
Maven archetype, which is a command-line wizard that creates the entire project from scratch. Instructions are then given to build the project, deploy the server to the Red Hat JBoss Fuse container, and run the test client.
Prerequisites リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
In order to access artifacts from the Maven repository, you need to add the
fusesource
repository to Maven's settings.xml
file. Maven looks for your settings.xml
file in the following standard location:
- UNIX:
home/User/.m2/settings.xml
- Windows:
Documents and Settings\User\.m2\settings.xml
If there is currently no
settings.xml
file at this location, you need to create a new settings.xml
file. Modify the settings.xml
file by adding the repository
element for fusesource
, as highlighted in the following example:
Create project from the command line リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
You can create a Maven project directly from the command line, by invoking the
archetype:generate
goal. First of all, create a directory to hold your getting started projects. Open a command prompt, navigate to a convenient location in your file system, and create the get-started
directory, as follows:
mkdir get-started cd get-started
mkdir get-started
cd get-started
You can now use the
archetype:generate
goal to invoke the servicemix-cxf-code-first-osgi-bundle
archetype, which generates a simple Apache CXF 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:
Press the Return key to accept the settings and generate the project. When the command finishes, you should find a new Maven project in the
get-started/cxf-basic
directory.
Customize the POM file リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Because this project will be configured using Blueprint XML, it is necessary to edit the project's
pom.xml
file, to declare the Blueprint dependency. Edit the cxf-basic/pom.xml
file and modify the Import-Package
element of the maven-bundle-plugin
by adding the lines highlighted in the following extract:
Blueprint XML configuration リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
We are going to use Blueprint XML to configure this project (Spring XML is not ideal in the context of OSGi, because it relies on the deprecated Spring-DM component to access OSGi services). Create the Blueprint XML file, as follows:
- Delete the redundant Spring XML file and its parent directories:
cd cxf-basic rm -rf src/main/resources/META-INF
cd cxf-basic rm -rf src/main/resources/META-INF
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Create a new directory to hold the Blueprint configuration files:
mkdir -p src/main/resources/OSGI-INF/blueprint
mkdir -p src/main/resources/OSGI-INF/blueprint
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Create a new Blueprint XML file. Using your favourite text editor, create the file,
cxf-basic/src/main/resources/OSGI-INF/blueprint/beans.xml
, and add the following content to it:Example 2.1. Blueprint XML for Web Services Endpoint
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The purpose of this Blueprint XML file is to create a WS endpoint (that is, an instance of a Web service). Thejaxws:endpoint
element creates the WS endpoint and, in this example, it requires two attributes, as follows:-
implementor
- Specifies the class that implements the Service Endpoint Interface (SEI).
-
address
- Specifies the WS endpoint address. In this example, instead of a HTTP URL, the address is specified as a relative path. In the context of JBoss Fuse, this is taken to mean that the Web service should be installed into the JBoss Fuse container's default Jetty container. By default, the specified path gets prefixed by
http://localhost:8181/cxf/
, so the actual address of the Web service becomes:http://localhost:8181/cxf/PersonServiceCF
http://localhost:8181/cxf/PersonServiceCF
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
Build the Web services project リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Build the Web services project and install the generated JAR file into your local Maven repository. From a command prompt, enter the following commands:
cd cxf-basic mvn install
cd cxf-basic
mvn install
Initialize container security リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
If you have not already done so, create one (or more users) by adding a line of the following form to the
InstallDir/etc/users.properties
file:
Username=Password[,RoleA][,RoleB]...
Username=Password[,RoleA][,RoleB]...
At least one of the users must have the
admin
role, to enable administration of the fabric. For example:
admin=secretpassword,admin
admin=secretpassword,admin
Start up the container リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Start up the JBoss Fuse container. Open a new command prompt and enter the following commands:
cd InstallDir/bin fuse
cd InstallDir/bin
fuse
You will see a welcome screen similar to this:
Install prerequisite features リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
If you are using the Red Hat JBoss Fuse 6.1.0 Medium Install package or the Red Hat JBoss Fuse 6.1.0 Minimal Install package, you need to install additional Karaf features, as follows:
JBossFuse:karaf@root> features:install cxf JBossFuse:karaf@root> features:install cxf-http-jetty JBossFuse:karaf@root> features:install cxf-jaxws
JBossFuse:karaf@root> features:install cxf
JBossFuse:karaf@root> features:install cxf-http-jetty
JBossFuse:karaf@root> features:install cxf-jaxws
Note
These features are pre-installed in the Red Hat JBoss Fuse 6.1.0 Full Install package.
Deploy and start the WS server リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
To install the
cxf-basic
Web service as an OSGi bundle, enter the following console command:
JBossFuse:karaf@root> install mvn:org.fusesource.example/cxf-basic/1.0-SNAPSHOT
JBossFuse:karaf@root> install mvn:org.fusesource.example/cxf-basic/1.0-SNAPSHOT
Note
If your local Maven repository is stored in a non-standard location, you might need to customize the value of the
org.ops4j.pax.url.mvn.localRepository
property in the InstallDir/etc/org.ops4j.pax.url.mvn.cfg
file, before you can use the mvn:
scheme to access Maven artifacts.
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: 229
Bundle ID: 229
You can now start up the Web service using the
start
console command, specifying the bundle ID, as follows:
JBossFuse:karaf@root> start 229
JBossFuse:karaf@root> start 229
Check that the bundle has started リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
To check that the bundle has started, enter the
list
console command, which gives the status of all the bundles installed in the container:
JBossFuse:karaf@root> list
JBossFuse:karaf@root> list
Near the end of the listing, you should see a status line like the following:
[ 229] [Active ] [ ] [Started] [ 60] Apache ServiceMix :: CXF Code First OSGi Bundle (1.0.0.SNAPSHOT)
[ 229] [Active ] [ ] [Started] [ 60]
Apache ServiceMix :: CXF Code First OSGi Bundle (1.0.0.SNAPSHOT)
Note
Actually, to avoid clutter, the
list
command only shows the bundles with a start level of 50 or greater (which excludes most of the system bundles).
Run the WS client リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
The
cxf-basic
project also includes a simple WS client, which you can use to test the deployed Web service. In a command prompt, navigate to the cxf-basic directory and run the simple WS client as follows:
cd get-started/cxf-basic mvn -Pclient
cd get-started/cxf-basic
mvn -Pclient
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... getPerson._getPerson_personId=Guillaume getPerson._getPerson_ssn=000-000-0000 getPerson._getPerson_name=Guillaume
INFO: Creating Service {http://example.fusesource.org/}PersonService from class org.fusesource.example.Person
Invoking getPerson...
getPerson._getPerson_personId=Guillaume
getPerson._getPerson_ssn=000-000-0000
getPerson._getPerson_name=Guillaume
Troubleshooting リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
If you have trouble running the client, there is an even simpler way to connect to the Web serivice. Open your favorite Web browser and navigate to the following URL to contact the JBoss Fuse Jetty container:
http://localhost:8181/cxf?wsdl
http://localhost:8181/cxf?wsdl
To query the WSDL directly from the PersonService Web service, navigate to the following URL:
http://localhost:8181/cxf/PersonServiceCF?wsdl
http://localhost:8181/cxf/PersonServiceCF?wsdl