September 20, 2004

XFire: SOAP With Sizzle

After a weekend of hacking in Guelph, Ontario with fellow programmers Jason van Zyl and Bob McWhirter, I am happy to announce the first release of XFire.

XFire is a SOAP server framework based on STAX. It consists of a processing core with several modules which allow you to interface with the XML how you desire. There is now a traditional Java/XML mapper, an OGNL/XML mapper, and an XMLBeans handler (courtesy of James Strachan). Time for a couple highlights:

Easy to use API

The XFire core can be completely manipulated via the API quite easily. For example:

DefaultXFire xfire = new DefaultXFire();

SimpleService service = new SimpleService();
service.setName("Echo");
service.setSoapVersion(SOAPConstants.SOAP12_ENVELOPE_NS);
service.setWSDLURL(getClass().getResource("/org/codehaus/xfire/echo11.wsdl").toString());
        
service.setServiceHandler(new EchoHandler());
service.setFaultHandler(new SOAP12FaultHandler());
        
xfire.getServiceRegistry().register(service);

xfire.invoke( messageContext, new FileInputStream("echo.xml") );

You can also use the Plexus module to configure your services. For more information, see the User's Guide.

STAX core

If you want you can easily get access to the STAX incoming stream to quickly route or process if speed is a concern. The XMLBeans Handler does this since it can take the stream directly and build its objects.

Interesting modules

Another feature of note is the OGNL/XML mapper. With it you can use the powerful expression language of OGNL and a pseudo-xsd language to create a web service model independent of your java model. For instance:

<operation name="FindBook">
  Finds a book.
  <request>
    <string name="isbn" ognl="#this" key="isbn"/>
  </request>
  <response>
    <bean name="Book" key="book">
      <string name="author" ognl="#author"/>
      <string name="title" ognl="#title"/>
      <string name="isbn" ognl="#isbn"/>
    </bean>
  </response>
</operation>

and the corresponding java:

public Map FindBook(Map mapContext)
{
    String isbn = (String) mapContext.get("isbn");
    
    HashMap results = new HashMap();
    results.put("author", "Dan Diephouse");
    results.put("title", "Boring Biography");
    results.put("isbn", isbn);
    
    return results;
}

Looking at the above, its easy to see you get results of the OGNL expressions in the request and put the response in a response Map. These are then accessible via syntax like "#author" - or if you had a book object "#book.Author" would execute the method book.getAuthor().

Time to download!

So enjoy some SOAP with sizzle and get your downloads here

Posted by dan at September 20, 2004 05:53 PM