XFire

Home
Bug/Issue Reporting
Download
FAQ
Get Involved
License
News
Stack Comparison
Support
User's Guide
XFire Team

M5

Javadocs
Reports

M6-SNAPSHOT

Javadocs
Reports

Developers

Developer Space
CVS
Building
Architecture
Interesting Projects
Release Process

Overview

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:

  1. Set up the directory structure
  2. Gather dependencies
  3. Set up your web.xml
  4. Write a service
  5. Create your XFire configuration
  6. Drop it into your servlet container

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:

xfire/
+-WEB-INF/
   +-web.xml
   +-lib/ (holds dependencies)

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.

Gather dependencies

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:

public class BookService
{
    private Book onlyBook;
    
    public BookService()
    {
        onlyBook = new Book();
        onlyBook.setAuthor("Dan Diephouse");
        onlyBook.setTitle("Using XFire");
        onlyBook.setIsbn("0123456789");
    }

    public Book[] getBooks()
    {
        return new Book[] { onlyBook };
    }
    
    public Book findBook(String isbn)
    {
        if (isbn.equals(onlyBook.getIsbn()))
            return onlyBook;
        
        return null;
    }
}

And the corresponding book class:

public class Book
{
    private String title;
    private String isbn;
    private String author;
  
    public String getIsbn()
    {
        return isbn;
    }

    public void setIsbn(String isbn)
    {
        this.isbn = isbn;
    }

    public String getTitle()
    {
        return title;
    }

    public void setTitle(String title)
    {
        this.title = title;
    }
 
    public String getAuthor()
    {
        return author;
    }

    public void setAuthor(String author)
    {
        this.author = author;
    }
}

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".

<xfire>

  <services>
    <service>
      <!-- The service name -->
      <name>BookService</name>
      
      <!-- The default namespace for the service -->
      <namespace>urn:xfire:BookService</namespace>
      
      <!-- Document, Wrapped or RPC? -->
      <style>wrapped</style>
      
      <!-- The class for the service -->
      <serviceClass>org.codehaus.xfire.BookService</serviceClass>
    </service>
  </services>
  
</xfire>

Create your web.xml

Follow the instructions on how to create a web.xml file here.

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
    
<web-app>

  <servlet>
    <servlet-name>XFire</servlet-name>
    <display-name>XFire Servlet</display-name>
    <servlet-class>
        org.codehaus.xfire.transport.http.XFireConfigurableServlet
    </servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>XFire</servlet-name>
    <url-pattern>/servlet/XFireServlet/*</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>XFire</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>
</web-app>

Add the war to your servlet container

To create the war in the example code, do "maven 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-demo/services/Echo?wsdl