Working with XFire

So, finally got time at the project to dive in the last piece of used technology: XFire. We are using version 1.1.2 at our project. To get a better understanding of XFire I have setup a simple case in which I create a webservice with similar configuration to the one we use in our project. In this blog I will show you how to create this web service with XFire in Eclipse and how to deploy it to JBoss. Lets start with setting up the tooling.
I assume that JBoss 4.0.5.GA and Eclipse 3.2.2 are installed on your machine (it might work with other versions too but I haven’t checked that). To start I have defined the following directory structure:


Inside the lib directory I place all the libs necessary for my webservice and for XFire to generate the webservice. Here are the necessary libraries:


The next piece of code I want to share is the Ant build file I used to build my webservice. This file is placed in the root directory of the project ‘XFireTest’. Here it is:

<?xml version="1.0"?>
<project name="XFireTest" default="jboss-deploy" basedir=".">

		Ant build script for the XFireTest module

	<!-- Directory-specifications -->
	<property name="compile.debug" value="true" />
	<property name="compile.optimize" value="false" />
	<property file="${basedir}/conf/" />
	<property name="lib.dir" value="${basedir}/lib" />
	<property name="build.dir" value="${basedir}/build" />
	<property name="src.dir" value="${basedir}/src/main/java" />
	<property name="web.dir" value="${basedir}/src/web" />
	<property name="dist.dir" value="${basedir}/dist" />
	<property name="conf.dir" value="${basedir}/conf" />
	<property name="jboss.home.dir" value="${jboss.home}" />
	<property name="jboss.deploy.dir" value="${jboss.home}/${jboss.deploy}" />
	<property name="war.file" value="${dist.dir}/${}.war" />

	<!-- == CLASSPATH definitions == -->
	<path id="build.classpath">
		<fileset dir="${lib.dir}">
			<include name="**/*.jar" />

	<!-- === preparations === -->
	<target name="prepare">
		<mkdir dir="${build.dir}" />
		<mkdir dir="${dist.dir}" />

	<!-- == cleans the module == -->
	<target name="clean">
		<delete dir="${build.dir}" />
		<delete dir="${report.dir}" />
		<delete dir="${dist.dir}" />

	<!-- === compiles the module === -->
	<target name="compile" depends="prepare">
		<javac sourcepath="" srcdir="${src.dir}" destdir="${build.dir}" debug="${compile.debug}" optimize="${compile.optimize}">
			<classpath refid="build.classpath" />

	<target name="dist" depends="clean, prepare, compile, war" />

	<target name="jboss-deploy" depends="war">
		<delete file="${deployed.war.file}" />
		<copy file="${war.file}" todir="${jboss.deploy.dir}" />

	<!-- === creates the war file === -->
	<target name="war" depends="clean, compile" description="WAR build">
		<war destfile="${war.file}" webxml="${web.dir}/WEB-INF/web.xml">
			<webinf dir="${web.dir}/WEB-INF">
				<include name="*/**" />
				<exclude name="web.xml" />
			<classes dir="${build.dir}">
				<include name="**/*.class" />
			<classes dir="${conf.dir}">
				<include name="META-INF/xfire/services.xml" />
				<include name="log4j.xml" />
			<lib dir="${lib.dir}">
				<include name="*.jar" />
				<exclude name="servlet-api-2.3.jar" />
				<exclude name="j2ee.jar" />
			<fileset dir="${web.dir}">
				<include name="**/*" />
				<exclude name="WEB-INF/**/*" />

With this build file goes a file which is placed in the ‘conf’ directory. Here are my settings but these may need some adjustment in your configuration:


After these initial setup we can now configure XFire for our use. The first step is to create the web.xml in the WEB-INF directory. Here is the content of the file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

   <!-- === Servlets === -->
      <display-name>XFire Servlet</display-name>

When all this is in place we are ready to start programming our webservice (and actually we have had the hardest part). I have created a simple model class Book:

package net.pascalalma.model;

public class BookObject
    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)
    { = author;

Now lets get to the service implementation. First the interface:


import org.codehaus.xfire.MessageContext;
import net.pascalalma.model.BookObject;

public interface BookService
   public BookObject[] getBooks(MessageContext ctx);

Here is the implementation:


import javax.jws.WebMethod;
import javax.jws.WebResult;
import javax.jws.WebService;
import net.pascalalma.model.BookObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.xfire.MessageContext;

 * @author Pascal Alma
public class BookServiceImpl implements BookService
    private static final Log LOG = LogFactory.getLog(BookServiceImpl.class);

    private BookObject oneBook;

    private BookObject twoBook;

    public BookServiceImpl()
       oneBook = new BookObject();
       oneBook.setAuthor("Pascal Alma");
       oneBook.setTitle("XFire Tutorial");

       twoBook = new BookObject();
       twoBook.setAuthor("Pascal Alma");
       twoBook.setTitle("XFire Advanced");

    @WebMethod(operationName = "getBooks", action = "urn:getBooks")
    @WebResult(name = "myAnswer")
    public BookObject[] getBooks(MessageContext ctx)
    {"Context id = " + ctx.getId());
       return new BookObject[] { oneBook, twoBook };

In this class I have used several annotations to configure the webservice. See the manual to for a detailed explanation of these annotations. The final step is to configure the webservice in the ‘services.xml’ file that is placed in the ‘conf/META-INF/xfire’ directory. Here is the content:

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="">
		<!-- <implementationClass></implementationClass> -->
	<bean id="bindingProvider" class="org.codehaus.xfire.aegis.AegisBindingProvider">
	<bean id="jsr181annotations" class="org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations">
	<bean id="serviceFactory" class="org.codehaus.xfire.annotations.AnnotationServiceFactory">
		<constructor-arg index="0" ref="jsr181annotations" />
		<constructor-arg index="1" ref="xfire.transportManager" />
		<constructor-arg index="2" ref="bindingProvider" />

So this is it. Although we haven’t done anything with SOAP and XML this is all that’s necessary to create the webservice. We can now run Ant and deploy this project as web-application to our JBoss instance. AFter successful execution you should be able to obtain the WSDL created by XFire with the url ‘http://localhost:8080/XFireTest/services/BookService?wsdl&#8217;. In the next blog I will show you how to create a webservice client generated by Ant based on this WSDL file.


About Pascal Alma

Pascal is a senior IT consultant and has been working in IT since 1997. He is monitoring the latest development in new technologies (Mobile, Cloud, Big Data) closely and particularly interested in Java open source tool stacks, cloud related technologies like AWS and mobile development like building iOS apps with Swift. Specialties: Java/JEE/Spring Amazon AWS API/REST Big Data Continuous Delivery Swift/iOS
This entry was posted in Web Service and tagged . Bookmark the permalink.

2 Responses to Working with XFire

  1. Hi Pascal,

    I notice you player with Oracle BPEL on occasion :). Have you by any chance got BPEL to call Xfire or CXF? It just doesnt seem to work for me!


  2. Pascal Alma says:

    Hi Ashley,

    That’s an interesting combination but I haven’t been using Oracle BPEL for a while, so I can not help you with this, unfortunately.
    But theoretically spoken, it should not make a difference if BPEL is calling a web service implemented by XFire or something else. But I guess that’s just in theory 🙂

Comments are closed.