Simple Web Service with XFire

August 31, 2006

This post describes how to implement as simple http web service using xfire (a next-generation java SOAP framework).

WEB-INF/Web.xml

Configure the XFire servlet in the web.xml:

<servlet>

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

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

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

WEB-INF/classes/META-INF/xfire/services.xml

Configure the services.xml file for xfire with the details of the service to expose:

<service>

<name>StockQuote</name>
<namespace>http://localhost:8080/xfire-stockquote/services/stockQuote</namespace>
<serviceClass>demo.xfire.service.StockQuoteService</serviceClass>
<implementationClass>demo.xfire.service.StockQuoteService</implementationClass>

</service>

StockQuoteService.java

The service class:

package demo.xfire.service;

import java.util.Random;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class StockQuoteService {

protected final Log log = LogFactory.getLog(getClass());

public Float getStockQuote(String security)
  {
    Random rand = new Random();
    log.debug("Retrieving quote for "+ security);
    return new Float(rand.nextInt(101));
  }
}

Testing

After the demo application has been deployed the url will be similar to http://localhost:8080/xfire-stockquote/services/StockQuote?wsdl for tomcat.

To run requests against the web service you could use soapUI

The Code

You can download the war file with the code here: zip filexfire-stockquote.war.

If you are not using Tomcat you need to change the location of the log file in the log4j.properties file.


What is OpenLaszlo?

August 21, 2006

OpenLaszlo is the leading open source platform for the development and delivery of browser based Rich Internet applications”. OpenLaszlo programs are written in XML and JavaScript and transparently compiled to Flash and soon DHTML. The OpenLaszlo APIs provide animation, layout, data binding, server communication, and declarative UI. A good example of a laszlo application is LaszloMail. I have been working with laszlo on and off for about a year now, over the next while I will post about some of my experiences.


What is Mule?

August 21, 2006

Mule is an opensource Enterprise Integration Bus. An ESB can be described as “A framework that allows for interactions between services and applications using disparate transport and messaging technologies”. Mule offers many transports out of the box including:

  • HTTP
  • JMS
  • SMTP
  • TCP
  • JDBC
  • RMI
  • FTP
  • Etc…

It also has integrates with many proven open source technologies including:

  • Spring
  • Quartz
  • Apache Axis
  • XFire
  • Spring
  • Acegi
  • Etc…

Some good introductory articles for mule can be found here. I have been working with mule in an enterprise integration project for the last few months so over the next while I will post some more information on my experiences.


Welcome

August 9, 2006

I will use this blog to post on technologies I am working on – mostly J2EE but also any “bandwagon” I am on at the time.