Unity Logo

Spring Remoting

This page outlines how to set up XFire for use via Spring's Remoting framework.

Setup the DispatcherServlet in the web.xml:

You'll need to include the DispatcherServlet in your web.xml. Notice that it provides the locations of where your spring beans are.

Notice how we're including /org/codehaus/xfire/spring/xfire.xml off the classpath. This contains some standard bean definitions for the TransportManager, ServiceRegistry and some simple ServiceFactorys.

Remote Exporter

When using a RemoteExporter, you should define a service interface and (at least) one implementation of that interface.

Service Interface

Service Implementation

XFireExporter

Then, you'll need to create a exporter definition for the service you want to expose. Typically, you'll do this in the servlet context configuration file. Since the dispatcher servlet is named xfire, this file should be called xfire-servlet.xml.

Thus, the methods defined in the Echo interface are exposed at the path /EchoService, backed by the EchoImpl bean.

 The EchoImpl bean should be defined as follows, in applicationContext.xml:

If you are using JSR 181 Annotations in the service interface and implementation(s), the interface class should not be specified as the serviceClass property. In this case, either the implementation class should be specified in the serviceClass property or the serviceBean property should be specified, but both together are not necessary. This is because the implementing class already specifies the endpointInterface in the @WebService annotation.

Remoting Clients

With protocols like Hessian or RMI, you just need a service interface to configure a Spring remoting client. However, SOAP is a bit more complicated.

XFire has the concept of a service model. It uses your service class and various extra information to build this service model. Any information you use to configure your client must be used to configure your client as well. For instance, say you specify a custom a custom namespace on your service, you must also specify that on your client.

XFire comes with a helper class to facilitate creating client using Spring: org.codehaus.xfire.spring.remoting.XFireClientFactoryBean. It is modelled after the JaxRpcPortProxyFactoryBean present in Spring, and allows you to configure a client bean in a Spring applicationContext.xml. All that needs to be specified is the service interface (or class in case of JSR 181 Annotations) and a WSDL url location for the service. Additional configuration, such as username/password or namespace, can be explicitly configured using properties.

Example client bean for applicationContext.xml:

 * Note that this may cause problems if used in the same applicationContext as the service itself (which one might try to do for running unit tests): this bean would attempt to access the WSDL before it became available, preventing the application from loading. To prevent this, set the lookupServiceOnStartup property to false.

Check out the Client API page to learn more about options when creating clients using XFire.

The full example is available in the ./examples/spring/ folder (within the XFire distribution).

© 2003-2008 Codehaus