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
Fuse ESB Enterprise container, and run the test client.
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.xmlWindows:
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:
<settings>
<profiles>
<profile>
<id>my-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>fusesource</id>
<url>http://repo.fusesource.com/nexus/content/groups/public/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
...
</repositories>
</profile>
</profiles>
...
</settings>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
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:
mvn archetype:generate -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-cxf-code-first-osgi-bundle -DarchetypeVersion=2012.01.0.fuse-71-047 -DgroupId=org.fusesource.example -DartifactId=cxf-basic -Dversion=1.0-SNAPSHOT
![]() | 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 = cxf-basic [INFO] Using property: version = 1.0-SNAPSHOT [INFO] Using property: package = org.fusesource.example Confirm properties configuration: groupId: org.fusesource.example artifactId: cxf-basic version: 1.0-SNAPSHOT package: org.fusesource.example Y: :
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/cxf-basic directory.
If you look in the
cxf-basic/src/main/resources/META-INF/spring/beans.xml file, you
can see an example of Spring XML configuration, as follows:
Example 2. Spring XML for Web Services Endpoint
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated by Apache ServiceMix Archetype -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<jaxws:endpoint id="HTTPEndpoint"
implementor="org.fusesource.example.PersonImpl"
address="/PersonServiceCF"/>
</beans>The purpose of this Spring XML file is to create a WS endpoint (that is, an
instance of a Web service). The jaxws:endpoint element creates the WS
endpoint and, in this example, it requires two attributes, as follows:
implementorSpecifies the class that implements the Service Endpoint Interface (SEI).
addressSpecifies the WS endpoint address. In this example, instead of a HTTP URL, the address is specified as a relative path. In the context of Fuse ESB Enterprise, this is taken to mean that the Web service should be installed into the Fuse ESB Enterprise 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
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
If you have not already done so, create one (or more users) by adding a line of
the following form to the
file:ESBInstallDir/etc/users.properties
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
Start up the Fuse ESB Enterprise container. Open a new command prompt and enter the following commands:
cd ESBInstallDir/bin
fuseesbYou will see a welcome screen like the following:
Please wait while Fuse ESB is loading... ______ _____ _____ ______ | ___| | ___|/ ___|| ___ \ | |_ _ _ ___ ___ | |__ \ `--. | |_/ / | _|| | | |/ __| / _ \ | __| `--. \| ___ \ | | | |_| |\__ \| __/ | |___ /\__/ /| |_/ / \_| \__,_||___/ \___| \____/ \____/ \____/ Fuse ESB (7.1.0.fuse-044) http://fusesource.com/products/fuse-esb-enterprise/ Hit '<tab>' for a list of available commands and '[cmd] --help' for help on a specific command. Hit '<ctrl-d>' or 'osgi:shutdown' to shutdown Fuse ESB. FuseESB:karaf@root>
To install the cxf-basic Web service as an OSGi bundle, enter the
following console command:
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
|
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
You can now start up the Web service using the start console command,
specifying the bundle ID, as follows:
karaf@root> start 229
To check that the bundle has started, enter the list console command,
which gives the status of all the bundles installed in the container:
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)
![]() | Note |
|---|---|
Actually, to avoid clutter, the |
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
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=GuillaumeIf 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 Fuse ESB Enterprise Jetty container:
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






![[Note]](imagesdb/note.gif)


