XFireHome DocumentationJavadocs QuicklinksAegis Binding DevelopersDeveloper Space |
OverviewYou've probably skipped over the rest of the user's guide and landed here because you're only interested in Spring configuration, right? If so, read the Quick Start section before you dive into how to leverage Spring container management. It outlines, from start to finish, writing, configuring and exposing a simple SOAP Web service. More importantly, although the section doesn't say it, it is actually using the Spring framework under the hood, making it a very good starting point. Using XBean and SpringXFire uses a great project called XBean under the covers for its XML Configuration. XBean allows us to create a custom syntax and be able to intermix it with the spring syntax. Before you continue you should make sure you have Spring 1.2.4+. Now lets take a look at some examples. Here is an example of how to declare a simple service: <beans xmlns="http://xfire.codehaus.org/config/1.0"> <service> <name>Echo</name> <serviceClass>org.codehaus.xfire.test.Echo</serviceClass> </service> </beans>
And you can easily load it via XBean's Classpath application context: import junit.framework.TestCase; import org.apache.xbean.spring.context.ClassPathXmlApplicationContext; import org.codehaus.xfire.service.ServiceRegistry; public class XBeanExampleTest extends TestCase { public void testLoading() throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "/org/codehaus/xfire/spring/examples/simple.xml", "/org/codehaus/xfire/spring/xfire.xml" }); ServiceRegistry reg = (ServiceRegistry) context.getBean("xfire.serviceRegistry"); assertTrue(reg.hasService("Echo")); } }
As you can see, that registered our service easily enough. From here we can also intermix the Spring and XFire syntax: <beans xmlns="http://xfire.codehaus.org/config/1.0"> <service> <name>Echo</name> <serviceBean>#echoBean</serviceBean> </service> <bean id="echoBean" class="org.codehaus.xfire.services.Echo"/> </beans>
Using XFire without XBean: The ServiceBeanThe above examples with XBean are really just using the ServiceBean class behind the scenes. If you don't want to use the XBean ApplicationContext you can easily configure your service via the ServiceBean class: <bean name="echoService" class="org.codehaus.xfire.spring.ServiceBean"> <property name="serviceBean" ref="echo"/> <property name="serviceClass" value="org.codehaus.xfire.test.Echo"/> <property name="inHandlers"> <list> <ref bean="addressingHandler"/> </list> </property> </bean> <bean id="echo" class="org.codehaus.xfire.test.EchoImpl"/> <bean id="addressingHandler" class="org.codehaus.xfire.addressing.AddressingInHandler"/>
You will need to use the servlet below to get access to these services. Configuring the XFireSpringServletThe XFireSpringServlet to expose your services over HTTP if you are not using the XFireConfigurableServlet and you are not using any of the Spring remoting features. Here is an example on how to use it: <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <servlet> <servlet-name>XFireServlet</servlet-name> <display-name>XFire Servlet</display-name> <servlet-class> org.codehaus.xfire.spring.XFireSpringServlet </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-app>
The servlet gets at the application context like so: ApplicationContext appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletConfig.getServletContext());
If you need to provide your own XFire instance another way, extend XFireServlet and override the getXFire method. |