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

We are working on adding support for annotations in XFire via Java 5, commons-attributes, and Backport 175. The Java 5 implementation will follow the JSR 181 spec and the commons-attributes/BP175 implementations will mimic the spec in a pre-Java 5 way.

Status:

Annotation General Status Java 5 Commons-attributes BP 175
WebService Supported. wsdlLocation not supported yet. Yes Yes Yes
WebMethod Done. Yes Yes Yes
WebParam Started. No header support yet. Yes Yes BP 175 doesn't support parameter annotations.
WebResult Done. Yes Yes BP 175 doesn't support parameter annotations.
OneWay Done. Yes Yes Yes
SOAPBinding Done. Yes Yes Yes
SOAPMessageHandler Not started. No No No
SOAPMessageHandlers Not started. No No No
HandlerChain Not started. No No No
InitParam Not started. No No No

Overview

As covered before, [ServiceFactories] are used to create services from classes. The default ServiceFactory is ObjectServiceFactory. To use annotations you must use the AnnotationsServiceFactory. You must pass it an annotation reader in the constructor which will read the particular type of annotation you are using.

Using Java 5 Annotations

XFire xfire = XFireFactory.getInstance().getXFire();
TypeMappingRegistry registry = new DefaultTypeMappingRegistry();

AnnotationServiceFactory factory = 
    new AnnotationServiceFactory(new Jsr181WebAnnotations(), xfire.getTransportManager(), registry);
Service service = factory.create(YourService.class)
xfire.getServiceRegistry().register(service);

In your services.xml, it would look like this:

<service>
  
  <name>ServiceName</name>
  <namespace>urn:your:namespace</namespace>
  <serviceClass>your.service.Class</serviceClass>
  <annotations>org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations</annotations>

</service>

Using Commons-Attributes Annotations

To use the commons-attributes annotations, you will need to follow these instructions on how to install the commons-attributes ant or maven plugin.

XFire xfire = XFireFactory.getInstance().getXFire();
TypeMappingRegistry registry = new DefaultTypeMappingRegistry();

AnnotationServiceFactory factory = 
    new AnnotationServiceFactory(new CommonsWebAttributes(), xfire.getTransportManager(), registry);
Service service = factory.create(YourService.class)
xfire.getServiceRegistry().register(service);

In your services.xml, it would look like this:

<service>
  
  <name>ServiceName</name>
  <namespace>urn:your:namespace</namespace>
  <serviceClass>your.service.Class</serviceClass>
  <annotations>org.codehaus.xfire.annotations.commons.CommonsWebAttributes</annotations>

</service>

Writing Services with Annotations

Javadocs (See the javax.jws packages only).

Example:

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

@WebService(name = "EchoService", targetNamespace = "http://www.openuri.org/2004/04/HelloWorld")
        public class Jsr181EchoService
{
    @WebMethod(operationName = "echoString", action = "urn:EchoString")
    @WebResult(name = "echoResult")
    public String echo(@WebParam(name = "echoParam", header = true) String input)
    {
        return input;
    }
}

To do this with commons-attributes instead, you will need to import the attributes from a different location and use the commons-attributes syntax:

import org.codehaus.xfire.annotations.commons.WebMethod;
import org.codehaus.xfire.annotations.commons.WebParam;
import org.codehaus.xfire.annotations.commons.WebResult;
import org.codehaus.xfire.annotations.commons.WebService;

/**
 * @@WebService(name = "EchoService", targetNamespace = "http://www.openuri.org/2004/04/HelloWorld")
 * @@org.codehaus.xfire.annotations.commons.soap.SOAPBinding(style = 1)
 */
public class CommonsEchoService
{

    /**
     * Returns the input.
     *
     * @param input the input.
     * @return the input.
     * @@WebMethod(operationName = "echoString", action="urn:EchoString")
     * @@.echoParam WebParam("echoParam")
     * @@.return WebResult("echoResult")
     */
    public String echo(String inputString)
    {
        return inputString;
    }
}