This document outlines what it takes to get started with your first XFire service. This is a fairly simple process. This document will lead you through setting up the XFire servlet. This document also presupposes that you are familiar with setting up servlets in your servlet container.
This example can be found under "examples/book" in the XFire Distribution.
The general procedure is:
- Set up the directory structure
- Gather dependencies
- Set up your web.xml
- Write a service
- Create your XFire configuration
- Drop it into your servlet container
If you are using Maven 2.x, you can let it to generate steps 1-5 for you, using Maven Archetypes.
It is also possible to embed XFire within your application. See the Using the XFire API section of the Users's Guide.
Set up the directory structure
The directory structure for the web app is simple:
The code that goes along with this guide uses the maven war plugin to build a war for your servlet container. These files can be found under the "resources" directory in that distribution.
XFire has a few dependencies. These will need to be added to your WEB-INF/lib directory. For a detailed description of what dependencies are need see the Dependency Guide.
Write a service
For this case, lets write a simple service which "finds" a book:
And the corresponding book class:
Create your XFire configuration
You will need to create a services.xml file which describes the services you are deploying. Put this file on your class path in "META-INF/xfire/services.xml". (Try "WEB-INF/classes/META-INF/xfire/services.xml" if the system cannot find the file.)
Create your web.xml
Follow the instructions on how to create a web.xml file here.
Add the war to your servlet container
To create the war in the example code using maven 2, do "mvn war:war". This will place a war in the "target" directory. Just drop this into your favorite servlet container and you should be set to go!
Access the WSDL via: http://localhost:8080/xfire-book-1.1/services/BookService?wsdl
What went on here
The services.xml gave XFire information on how to construct your service. Using the ObjectServiceFactory, your class was introspected for methods which were turned into web service operations. Likewise the Book class was bound to an XML schema. Once this was done, the Service generated from ObjectServiceFactory.create() was registered with the XFire ServiceFactory. At that point, your service was exposed and available!