At the moment, there are a lot of web service framework.
Firstly, let’s try to build XFire web service. XFire is now CXF(http://cxf.apache.org/).
Codehaus XFire is a next-generation java SOAP framework. Codehaus XFire makes service oriented development approachable through its easy to use API and support for standards. It is also highly performant since it is built on a low memory StAX based model.
1. Create a Web Service Project, which name is TestWS_XFire
Chose XFire Framework and java EE 5.0.
2. MyEclipse automatically produces J2EE directory including web.xml file, importing XFile 1.2 core libraries
3. In XFire framework, it has a XFireServlet servlet
the content of web.xml is listed below
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>XFireServlet</servlet-name>
<servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
4.Create a new web service
select web service
chose XFire Framework
chose ‘create web service from Java class ‘ and tick ‘Create new Java bean’
5. Input web service name, create a new java package,and MyEclipse will produce interface and impl class base on the service name, chose default soap style/use
6.MyEclipse will produce a interface and implements class, at the same time it will fill in service.xml
interface Iweather
public interface Iweather {
public String example(String message);
}
modify class weatherImpl
public class weatherImpl implements Iweather {
public String example(String message) {
String reStr = "Hello "+message.toUpperCase()+" ,Welcome the world of Web Service";
return reStr;
}
}
services.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
<name>weather</name>
<serviceClass>com.jack.ws.Iweather</serviceClass>
<implementationClass>
com.jack.ws.weatherImpl
</implementationClass>
<style>wrapped</style>
<use>literal</use>
<scope>application</scope>
</service></beans>
7. run tomcat 6 server
8. deploy the app into tomcat 6 server
9.The outcome of tomcat console
27/07/2010 10:58:06 PM org.apache.catalina.startup.HostConfig checkResources
INFO: Reloading context [/TestWS_XFire]
27/07/2010 10:58:06 PM org.springframework.context.support.AbstractApplicationContext close
INFO: Closing application context [org.codehaus.xfire.spring.GenericApplicationContext;hashCode=13501060]
27/07/2010 10:58:06 PM org.springframework.beans.factory.support.AbstractBeanFactory destroySingletons
INFO: Destroying singletons in factory {org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [xfire.customEditorConfigurer,xfire.serviceRegistry,xfire.transportManager,xfire,xfire.typeMappingRegistry,xfire.aegisBindingProvider,xfire.serviceFactory,xfire.servletController,xfire.messageServiceFactory,xfire.messageBindingProvider,org.codehaus.xfire.spring.ServiceBean]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans []; root of BeanFactory hierarchy}
27/07/2010 10:58:07 PM org.springframework.context.support.AbstractApplicationContext refresh
INFO: No beans defined in application context [org.codehaus.xfire.transport.http.XFireConfigurableServlet$GenericWebApplicationContextX;hashCode=5493403]
27/07/2010 10:58:07 PM org.springframework.context.support.AbstractApplicationContext initMessageSource
INFO: Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@d81c91]
27/07/2010 10:58:07 PM org.springframework.context.support.AbstractApplicationContext initApplicationEventMulticaster
INFO: Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@3b7f4e]
27/07/2010 10:58:07 PM org.springframework.ui.context.support.UiApplicationContextUtils initThemeSource
INFO: Unable to locate ThemeSource with name 'themeSource': using default [org.springframework.ui.context.support.ResourceBundleThemeSource@22fde7]
27/07/2010 10:58:07 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans []; root of BeanFactory hierarchy]
27/07/2010 10:58:07 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [org/codehaus/xfire/spring/xfire.xml]
27/07/2010 10:58:07 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [org/codehaus/xfire/spring/customEditors.xml]
27/07/2010 10:58:07 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [META-INF/xfire/services.xml]
27/07/2010 10:58:07 PM org.springframework.context.support.AbstractApplicationContext refresh
INFO: 11 beans defined in application context [org.codehaus.xfire.spring.GenericApplicationContext;hashCode=30062719]
27/07/2010 10:58:08 PM org.springframework.context.support.AbstractApplicationContext initMessageSource
INFO: Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@1abe751]
27/07/2010 10:58:08 PM org.springframework.context.support.AbstractApplicationContext initApplicationEventMulticaster
INFO: Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@df8508]
27/07/2010 10:58:08 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [xfire.customEditorConfigurer,xfire.serviceRegistry,xfire.transportManager,xfire,xfire.typeMappingRegistry,xfire.aegisBindingProvider,xfire.serviceFactory,xfire.servletController,xfire.messageServiceFactory,xfire.messageBindingProvider,org.codehaus.xfire.spring.ServiceBean]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans []; root of BeanFactory hierarchy]
27/07/2010 10:58:08 PM org.codehaus.xfire.spring.ServiceBean afterPropertiesSet
INFO: Exposing service with name {http://ws.jack.com}weather
10. Launch SOAP Web Services Explorer in MyEclipse
11.Click ‘WSDL Main’, input ‘http://localhost:8080/TestWS_XFire/services/weather’
12.click go, it will present ‘Operations’ and ‘Endpoints’
13. click example, then input ‘jack’,and then click ‘go’
14. check the exampleResponse
exampleResponse
out (string): Hello JACK ,Welcome the world of Web Service