So after an entire weekend of frustration with tutorials such as and I think I have come up with a way to test XFire services deployed through Tomcat during my Maven build.

So I created an annotated version of an Echo Service:

package com.baselogic.service;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

@WebService(name = "EchoService",
targetNamespace = "")
public interface EchoService {

@WebMethod(operationName = "echoString", action = "urn:EchoString")
@WebResult(name = "echoResult", targetNamespace = "")
public String echoString(
@WebParam(name = "echoParam", targetNamespace = "", header = true)
String echoParam);

Then created my implementation class:
package com.baselogic.service;

import javax.jws.WebService;

* Echo XFire Web Service
@WebService(serviceName = "Echo",
targetNamespace = "", endpointInterface = "com.baselogic.service.EchoService")
public class EchoImpl implements EchoService {

public String echoString(String input) {
return "Echo Response: " + input;
I then created a /WEB-INF/xfire-servlet.xml resource that only contains the following mappings:

In my web.xml, I added my xfire-servlet.xml:
contextConfigLocation      classpath:/applicationContext-resources.xml
I added my xfire spring servlet:
Now I kept seeing several JUnit examples with many convenience methods, but I wanted to use TestNG instead. So I created a testng-functional.xml file with some parameters that I needed.

Then I used those in my TestNG test like:

package com.baselogic.service;

import com.baselogic.service.impl.UserManagerImpl;
import com.baselogic.util.StringUtil;
import com.baselogic.domain.User;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
import org.codehaus.xfire.XFire;
import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.aegis.AegisBindingProvider;
import org.codehaus.xfire.annotations.AnnotationServiceFactory;
import org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.ServiceRegistry;
import org.codehaus.xfire.xmlbeans.XmlBeansTypeRegistry;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class UserServiceTest {

// configure log4j
static {
URL log4j = Thread.currentThread().getContextClassLoader().getResource(

protected Logger log = Logger.getLogger(getClass());

protected String echoUrl = "http://localhost:8080/services/Echo";
protected String serviceUrlLocal;

Service serviceModel;
AnnotationServiceFactory factory;
ServiceRegistry serviceRegistry;
XFire xfire;

@BeforeClass(groups = {"functional"})
protected void init(String serviceUrlLocal) throws Exception {"Setup XFire Registry");
this.serviceUrlLocal = serviceUrlLocal;

xfire = XFireFactory.newInstance().getXFire();

AnnotationServiceFactory factory = new AnnotationServiceFactory(new Jsr181WebAnnotations(),
new AegisBindingProvider(new XmlBeansTypeRegistry()));
serviceModel = factory.create(UserManagerImpl.class);

serviceRegistry = xfire.getServiceRegistry();

@AfterClass(groups = {"functional"})
protected void stop() throws Exception {"Stopping XFire Registry");

@Test(groups = {"functional"})
public void testGetUser() throws Exception {

XFireProxyFactory xFireProxyFactory = new XFireProxyFactory(xfire);
UserManager userManager = null;
User user = null;
try {
userManager = (UserManager) xFireProxyFactory.create(serviceModel, serviceUrlLocal);
user = userManager.getUser("mknutson");

AssertJUnit.assertEquals("mknutson", user.getUsername());
} catch (MalformedURLException e) {
log.debug("WsClient.callWebService(): EXCEPTION: " + e.toString());
catch (Exception e) {
throw e;
The difference I found out that was different in testNG from the examples I saw, was the use of a local URL verse the full service url. I could never get the full url o work, but I assume that the JUnit helper classes from xfire resolve that url to a local anyways. When I changed to the local url, my service started working fine. I later removed the serviceUrl parameter later and just used the serviceUrlLocal parameter for my tests going forward.

Mick Knutson

Java, JavaEE, J2EE, WebLogic, WebSphere, JBoss, Tomcat, Oracle, Spring, Maven, Architecture, Design, Mentoring, Instructor and Agile Consulting.

View all posts

Java / JavaEE / Spring Boot Channel

BLiNC Supporters

BLiNC Adsense